mcp

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMCPPath = "/mcp"

DefaultMCPPath is the default HTTP path for the MCP server endpoint.

Variables

This section is empty.

Functions

func GenerateInputSchema

func GenerateInputSchema(paramPtrs []interface{}, bodyPtr interface{}) (json.RawMessage, map[string]ParamSource, error)

GenerateInputSchema builds a flat JSON Schema object and a ParamSource map from the given parameter and body struct pointers. All path/query params and body fields are merged into a single flat schema, making the tool input LLM-friendly. The returned paramSourceMap tracks the origin of each property so the executor can decompose arguments back into path vars, query vars, and body fields.

func NewMCPHandler

func NewMCPHandler(router *mux.Router, config Config) http.Handler

NewMCPHandler creates an http.Handler that serves the MCP protocol over Streamable HTTP transport. It lazily discovers tools from the router on first connection, similar to how OpenAPI spec generation works.

func PopulateMCPServer

func PopulateMCPServer(mcpServer *mcpsdk.Server, router *mux.Router, config Config) error

PopulateMCPServer walks the mux router and registers each documented handler as an MCP tool on the given MCP server.

Types

type Config

type Config struct {
	// ServerName is the name of the MCP server. Defaults to openapi.Config.DocPageTitle.
	ServerName string
	// ServerVersion is the version of the MCP server. Defaults to "1.0.0".
	ServerVersion string
	// Path is the HTTP path for the Streamable HTTP transport. Defaults to "/mcp".
	Path string
	// IgnoredPaths are the routes that shouldn't be exposed as MCP tools.
	IgnoredPaths []string
}

Config contains the configuration for the MCP server.

var MCPConfig Config

MCPConfig is the default MCP server config. You can update all fields to change:

- ServerName: the name of the MCP server. - ServerVersion: the version of the MCP server. - Path: the HTTP path for the MCP endpoint. - IgnoredPaths: the paths that shouldn't be exposed as MCP tools.

func (Config) GetPath

func (c Config) GetPath() string

GetPath returns the configured MCP path, or the default if not set.

func (Config) GetServerName

func (c Config) GetServerName(fallback string) string

GetServerName returns the configured server name, or the fallback.

func (Config) GetServerVersion

func (c Config) GetServerVersion() string

GetServerVersion returns the configured server version, or "1.0.0".

type ParamSource

type ParamSource struct {
	Source string // "path", "query", or "body"
	Field  string // original field name in the source struct
}

ParamSource tracks where an MCP tool argument should be routed when executing the handler.

Jump to

Keyboard shortcuts

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