Documentation
¶
Overview ¶
Package mcp holds shared MCP catalog rules: deny-list, include/exclude matching, tool naming, JSON Schema mapping, result envelopes, self-connect detection, and the public Server Card document.
Index ¶
- Constants
- func AgentToolName(server, remote string) string
- func AttachTrace(result any, trace map[string]any, wrapItems bool) (any, error)
- func Denied(capability, operation string) bool
- func ErrorEnvelope(errObj, trace map[string]any) map[string]any
- func IsAgentTool(name string) bool
- func IsListTool(group, op string) bool
- func IsSelfMCP(rawURL, listen, apiPath string) bool
- func Match(include, exclude []string, group, toolName string) bool
- func OpenWorld(group string) bool
- func OutputSchema(group, op string) map[string]any
- func PermissionKey(server string) string
- func SchemaFromFields(fields []Field) map[string]any
- func ServerCardURL(endpoint string) (string, error)
- func ServerCardURLOrEmpty(endpoint string) string
- func ServerFromAgentTool(tool string) (string, bool)
- func Title(group, description string) string
- func ValidServerName(name string) bool
- func ValidateInputSchema(schema map[string]any) error
- func ValidateOutput(schema, instance any) error
- func ValidateServerName(name string) error
- type Client
- type Field
- type ServerCard
- type ServerCardRemote
- type Snippet
- type SnippetOptions
Constants ¶
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." )
const ( // ServerCardSchema is the v1 Server Card JSON Schema URL (SEP-2127). ServerCardSchema = "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json" // ServerCardName is the reverse-DNS identity advertised on the Server Card. ServerCardName = "flowline-io/flowbot" // ServerCardMediaType is the media type for a hosted Server Card. ServerCardMediaType = "application/mcp-server-card+json" // SupportedProtocolVersion is the MCP protocol version this server speaks. SupportedProtocolVersion = "2026-07-28" )
const ServerInstructions = "" /* 427-byte string literal not displayed */
ServerInstructions is the MCP initialize instructions string.
Variables ¶
This section is empty.
Functions ¶
func AgentToolName ¶
AgentToolName builds mcp_<server>_<remote> for the chat agent registry.
func AttachTrace ¶
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 ErrorEnvelope ¶
ErrorEnvelope builds the failed structuredContent object.
func IsAgentTool ¶
IsAgentTool reports whether name is an outbound MCP agent tool (mcp_<server>_*).
func IsListTool ¶
IsListTool reports whether group.op is a paged list on /mcp.
func Match ¶
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 ¶
OpenWorld reports whether tools in group may affect systems outside this process. hub, pipeline, workflow, and example stay closed.
func OutputSchema ¶
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 ¶
PermissionKey returns mcp.<server> for permission evaluation.
func SchemaFromFields ¶
SchemaFromFields builds a JSON Schema object for MCP / agent tool parameters.
func ServerCardURL ¶
ServerCardURL is the discovery URL for a Streamable HTTP endpoint.
func ServerCardURLOrEmpty ¶
ServerCardURLOrEmpty returns the discovery URL, or empty when endpoint is not HTTP.
func ServerFromAgentTool ¶
ServerFromAgentTool extracts the server id from an mcp_<server>_<remote> name.
func ValidServerName ¶
ValidServerName reports whether name is a safe MCP server id (no underscores).
func ValidateInputSchema ¶
ValidateInputSchema checks an advertised MCP inputSchema. The compiler is pinned to JSON Schema draft 2020-12. The schema object itself stays without a $schema keyword. Property descriptions are required at every depth. items only needs a type. Bare object and array schemas are allowed.
func ValidateOutput ¶
ValidateOutput checks instance against a tool outputSchema.
func ValidateServerName ¶
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 ServerCard ¶
type ServerCard struct {
// Schema is the Server Card JSON Schema URL.
Schema string `json:"$schema"`
// Name is the reverse-DNS server identity.
Name string `json:"name"`
// Version is the server build version.
Version string `json:"version"`
// Description is the public summary. It does not list tools.
Description string `json:"description"`
// Remotes are the HTTP endpoints a client can open.
Remotes []ServerCardRemote `json:"remotes"`
}
ServerCard is a public SEP-2127 discovery document. It identifies the server and one remote endpoint. It does not list tools.
func NewServerCard ¶
func NewServerCard(endpoint, version string) (ServerCard, error)
NewServerCard returns the public card for one Streamable HTTP endpoint. The document has no tool list. An endpoint that is not HTTP, or a blank version, returns an error.
type ServerCardRemote ¶
type ServerCardRemote struct {
// Type is the MCP transport. This server uses streamable-http.
Type string `json:"type"`
// URL is the Streamable HTTP endpoint.
URL string `json:"url"`
// SupportedProtocolVersions lists the protocol versions this endpoint speaks.
SupportedProtocolVersions []string `json:"supportedProtocolVersions"`
}
ServerCardRemote is one HTTP transport on a Server Card.
type Snippet ¶
type Snippet struct {
Client string `json:"client"`
Target string `json:"target"`
Snippet string `json:"snippet"`
// ServerCard is the public discovery URL for URL. Empty when URL is not http or https.
ServerCard string `json:"server_card,omitempty"`
}
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. ServerCard is set when URL is an HTTP endpoint. The snippet text does not include it.
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.