Documentation
¶
Overview ¶
Package agentsmcp bridges a whilesmartgo/agents tool set to the Model Context Protocol, using the official MCP Go SDK for the wire protocol.
The bridge is one-directional in v0: it exposes an agents.Registry as an MCP server, so an MCP client can call the same tools an assistant would. Each MCP tool call runs the corresponding agents.Tool handler. A tool that returns an error yields an error result (IsError) rather than a protocol error, so a model on the other end can see the failure and adapt.
reg := agents.NewRegistry(tool1, tool2)
server := agentsmcp.NewServer("my-app", "v1.0.0", reg)
// serve over any MCP transport, e.g. stdio:
_ = server.Run(ctx, &mcp.StdioTransport{})
To serve over HTTP without touching the underlying SDK, use StreamableHTTPHandler, which picks the registry per request so the tool set can be scoped to the authenticated caller.
The consumer supplies authorization inside each agents.Tool handler (or via the Runner in the agents package); this bridge adds no auth of its own.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRegistry ¶
AddRegistry adds every tool in reg to an existing MCP server. Use it when the server also carries tools from other sources.
func NewServer ¶
NewServer builds an MCP server that exposes every tool in reg. name and version identify the server to MCP clients.
func StreamableHTTPHandler ¶ added in v0.2.0
func StreamableHTTPHandler(name, version string, getReg func(*http.Request) *agents.Registry) http.Handler
StreamableHTTPHandler serves a tool set over MCP's streamable-HTTP transport. name and version identify the server to clients.
getReg supplies the registry for each request, so a host can authenticate the request and hand back a caller-scoped tool set; returning nil serves 400. The handler is stateless: every call is served with the registry for that request, which is what request-scoped authorization needs. Wrapping the SDK here keeps the official MCP SDK out of consumer imports.
Types ¶
This section is empty.