mcp

package
v0.99.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mcp holds shared MCP catalog rules: deny-list, include/exclude matching, tool naming, JSON Schema mapping, result envelopes, and self-connect detection.

Index

Constants

View Source
const (
	// AgentToolPrefix is the chat-agent tool name prefix for external MCP tools.
	AgentToolPrefix = "mcp_"
	// PermissionKeyPrefix is the permission key prefix for one MCP server.
	PermissionKeyPrefix = "mcp."
)
View Source
const ServerInstructions = "" /* 427-byte string literal not displayed */

ServerInstructions is the MCP initialize instructions string.

Variables

This section is empty.

Functions

func AgentToolName

func AgentToolName(server, remote string) string

AgentToolName builds mcp_<server>_<remote> for the chat agent registry.

func AttachTrace

func AttachTrace(result any, trace map[string]any, wrapItems bool) (any, error)

AttachTrace adds trace beside a successful tool result. wrapItems is true only for pipeline.list, workflow.list, function.list, and hub.apps. Those slices become {"items", "trace"}. Objects gain a trace field. A nil result becomes {"trace": trace}.

func Denied

func Denied(capability, operation string) bool

Denied reports whether capability.operation is never exposed on /mcp.

func ErrorEnvelope

func ErrorEnvelope(errObj, trace map[string]any) map[string]any

ErrorEnvelope builds the failed structuredContent object.

func IsAgentTool

func IsAgentTool(name string) bool

IsAgentTool reports whether name is an outbound MCP agent tool (mcp_<server>_*).

func IsListTool

func IsListTool(group, op string) bool

IsListTool reports whether group.op is a paged list on /mcp.

func IsSelfMCP

func IsSelfMCP(rawURL, listen, apiPath string) bool

IsSelfMCP reports whether rawURL would reach this process's /mcp endpoint.

func Match

func Match(include, exclude []string, group, toolName string) bool

Match reports whether toolName survives include/exclude. An empty include list means all tools. Exclude always wins. A filter item matching the group (capability or MCP server name) or the full tool name is a hit. Callers that expose /mcp must also apply Denied; outbound MCP clients must not.

func OpenWorld

func OpenWorld(group string) bool

OpenWorld reports whether tools in group may affect systems outside this process. hub, pipeline, workflow, and example stay closed.

func OutputSchema

func OutputSchema(group, op string) map[string]any

OutputSchema returns the MCP outputSchema for a tool, or nil when v1.0 does not publish one. Listed tools are pipeline, workflow, and function list/get/run/get_run, hub apps and health, and capability operations whose name contains "list".

func PermissionKey

func PermissionKey(server string) string

PermissionKey returns mcp.<server> for permission evaluation.

func SchemaFromFields

func SchemaFromFields(fields []Field) map[string]any

SchemaFromFields builds a JSON Schema object for MCP / agent tool parameters.

func ServerFromAgentTool

func ServerFromAgentTool(tool string) (string, bool)

ServerFromAgentTool extracts the server id from an mcp_<server>_<remote> name.

func Title

func Title(group, description string) string

Title is the human-readable tool title: "{group}: {description}".

func ValidServerName

func ValidServerName(name string) bool

ValidServerName reports whether name is a safe MCP server id (no underscores).

func ValidateOutput

func ValidateOutput(schema, instance any) error

ValidateOutput checks instance against a tool outputSchema.

func ValidateServerName

func ValidateServerName(name string) error

ValidateServerName returns an error when name is empty or illegal.

Types

type Client

type Client string

Client is a supported MCP client snippet target.

const (
	// ClientCodex renders a Codex config.toml table.
	ClientCodex Client = "codex"
	// ClientClaude renders a claude mcp add command.
	ClientClaude Client = "claude"
	// ClientCursor renders a Cursor mcp.json fragment.
	ClientCursor Client = "cursor"
	// ClientGeneric renders a transport-neutral JSON fragment.
	ClientGeneric Client = "generic"
)

type Field

type Field struct {
	Name        string
	Type        string
	Description string
	Required    bool
	Enum        []string
}

Field is one JSON-object property used to build an MCP input schema.

type Snippet

type Snippet struct {
	Client  string `json:"client"`
	Target  string `json:"target"`
	Snippet string `json:"snippet"`
}

Snippet is one printable client configuration.

func RenderSnippet

func RenderSnippet(client Client, opt SnippetOptions) (Snippet, error)

RenderSnippet builds a paste-ready client snippet. The token value is never included.

type SnippetOptions

type SnippetOptions struct {
	// Name is the MCP server id. Empty uses flowbot.
	Name string
	// URL is the Streamable HTTP endpoint.
	URL string
	// TokenEnv is the environment variable that holds the bearer token. Empty uses FLOWBOT_MCP_TOKEN.
	TokenEnv string
	// Scope is project or user. Empty uses user for Claude and project for Cursor.
	Scope string
	// Approval is the Codex default_tools_approval_mode. Empty uses writes. Only Codex accepts it.
	Approval string
}

SnippetOptions are the inputs for a client config snippet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL