mcp

package
v0.99.18 Latest Latest
Warning

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

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

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

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 (
	// 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"
)
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 ServerCardURL

func ServerCardURL(endpoint string) (string, error)

ServerCardURL is the discovery URL for a Streamable HTTP endpoint.

func ServerCardURLOrEmpty

func ServerCardURLOrEmpty(endpoint string) string

ServerCardURLOrEmpty returns the discovery URL, or empty when endpoint is not HTTP.

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 ValidateInputSchema

func ValidateInputSchema(schema map[string]any) error

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

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 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.

Jump to

Keyboard shortcuts

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