Documentation
¶
Overview ¶
Package mcp serves ai.Tools to MCP clients over streamable HTTP and consumes remote MCP servers as ai.Tools, on the official Go MCP SDK.
Index ¶
Constants ¶
const ( // ClientName is the implementation name Connect reports to servers. ClientName = "bboxsys-ai" // DefaultHTTPTimeout bounds each HTTP exchange with a remote server // when ClientOptions.HTTPTimeout is zero. DefaultHTTPTimeout = 30 * time.Second )
const ( // DefaultServerName is the implementation name Handler advertises. DefaultServerName = "bboxsys" // DefaultServerVersion is the implementation version Handler advertises. DefaultServerVersion = "1.0.0" )
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler serves MCP over streamable HTTP with DefaultServerName and DefaultServerVersion. See HandlerWithInfo.
func HandlerWithInfo ¶
func HandlerWithInfo(name, version string, get func(r *http.Request) ([]ai.Tool, error)) http.Handler
HandlerWithInfo serves MCP over streamable HTTP. get builds the tool set for each request from whatever the route put in the request (the caller identity, for example); an error answers 400 and serves nothing.
The handler is stateless (StreamableHTTPOptions.Stateless): every POST creates a short-lived session over its own request, no Mcp-Session-Id is issued, and GET and DELETE answer 405, so instances behind a load balancer need no session affinity. The SDK connects that session with the request's context, and jsonrpc2 derives every tool handler's context from it with values preserved, so ai.CallerFromContext works inside Execute; the tools are also wrapped with the caller from the request so this does not depend on the SDK's internals. Localhost DNS rebinding protection is off because the endpoint sits behind bearer authentication and is normally reached through a reverse proxy whose Host header is not localhost.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a session with one remote MCP server.
func Connect ¶
Connect opens a streamable HTTP session with the server at endpoint, sending bearer on every request, with the default options: readOnlyHint is not trusted, so every remote tool is a write. See ConnectWithOptions.
func ConnectWithOptions ¶
func ConnectWithOptions(ctx context.Context, name, endpoint, bearer string, opts ClientOptions) (*Client, error)
ConnectWithOptions opens a streamable HTTP session with the server at endpoint, sending bearer on every request. name prefixes the wrapped tool names ("{name}_") so several servers can be offered together; it is sanitized to the tool name alphabet. Only request and response traffic is used: no standalone SSE stream is opened, so servers that answer GET with 405 work. ctx bounds the handshake; each HTTP exchange is also bounded by opts.HTTPTimeout.
type ClientOptions ¶
type ClientOptions struct {
// TrustReadOnly takes the server's readOnlyHint annotations at their
// word. Off by default: a remote server decides its own annotations,
// so a write tool could claim to be read-only and be auto-approved.
// Untrusted, every remote tool is a write and needs approval. Turn it
// on only for a server the operator controls.
TrustReadOnly bool
// HTTPTimeout bounds each HTTP exchange. Default DefaultHTTPTimeout.
HTTPTimeout time.Duration
}
ClientOptions configures ConnectWithOptions.