Documentation
¶
Index ¶
- Constants
- type Client
- type ClientInfo
- type ClientOption
- type ContentBlock
- type Handler
- type InitializeParams
- type InitializeResult
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type ListToolsResult
- type Server
- type ServerCapabilities
- type ServerInfo
- type StdioClient
- type Tool
- type ToolCallParams
- type ToolCallResult
- type ToolCaller
- type ToolsCapability
Constants ¶
const ProtocolVersion = "2025-03-26"
ProtocolVersion is the MCP protocol version supported by this implementation.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an MCP Streamable HTTP client.
func NewClient ¶
func NewClient(upstream string, opts ...ClientOption) *Client
NewClient creates a new MCP client targeting upstream with the given options.
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) (*ToolCallResult, error)
CallTool invokes a named tool on the MCP server with the given arguments.
func (*Client) Initialize ¶
func (c *Client) Initialize(ctx context.Context) (*InitializeResult, error)
Initialize sends an initialize request to the MCP server.
type ClientInfo ¶
ClientInfo identifies an MCP client.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithBearerToken ¶
func WithBearerToken(envVar string) ClientOption
WithBearerToken returns a ClientOption that reads a bearer token from the given environment variable at call time and adds it as an Authorization header.
Note: Only the last auth option takes effect. WithBearerToken and WithHeader both set the auth function; later calls override earlier ones.
func WithHeader ¶
func WithHeader(headerName, envVar string) ClientOption
WithHeader returns a ClientOption that reads a value from the given environment variable at call time and sets it as a custom request header.
Note: Only the last auth option takes effect. WithHeader and WithBearerToken both set the auth function; later calls override earlier ones.
type ContentBlock ¶
ContentBlock is a content block in a tool call result.
type Handler ¶
type Handler interface {
HandleToolCall(ctx context.Context, name string, args map[string]any) (*ToolCallResult, error)
}
Handler processes MCP tool calls.
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]any `json:"capabilities"`
ClientInfo ClientInfo `json:"clientInfo"`
}
InitializeParams is the parameters for an MCP initialize request.
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo ServerInfo `json:"serverInfo"`
}
InitializeResult is the result of an MCP initialize request.
type JSONRPCError ¶
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
JSONRPCError is a JSON-RPC 2.0 error object.
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id"`
Method string `json:"method"`
Params any `json:"params,omitempty"`
}
JSONRPCRequest is a JSON-RPC 2.0 request message.
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id"`
Result any `json:"result,omitempty"`
Error *JSONRPCError `json:"error,omitempty"`
}
JSONRPCResponse is a JSON-RPC 2.0 response message.
type ListToolsResult ¶
type ListToolsResult struct {
Tools []Tool `json:"tools"`
}
ListToolsResult is the result of a tools/list request.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an MCP Streamable HTTP server.
type ServerCapabilities ¶
type ServerCapabilities struct {
Tools *ToolsCapability `json:"tools,omitempty"`
}
ServerCapabilities describes the capabilities of an MCP server.
type ServerInfo ¶
ServerInfo identifies an MCP server.
type StdioClient ¶
type StdioClient struct {
// contains filtered or unexported fields
}
StdioClient is an MCP client that communicates with a subprocess over stdio using newline-delimited JSON-RPC.
func NewStdioClient ¶
func NewStdioClient(name string, args ...string) (*StdioClient, error)
NewStdioClient creates a new StdioClient that spawns the given command. The command is started immediately. Call Close to shut it down.
func (*StdioClient) CallTool ¶
func (c *StdioClient) CallTool(ctx context.Context, name string, args map[string]any) (*ToolCallResult, error)
CallTool invokes a named tool on the MCP server with the given arguments.
func (*StdioClient) Close ¶
func (c *StdioClient) Close() error
Close shuts down the subprocess by closing stdin and killing the process.
func (*StdioClient) Initialize ¶
func (c *StdioClient) Initialize(ctx context.Context) (*InitializeResult, error)
Initialize sends an initialize request to the MCP server, followed by an initialized notification.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema any `json:"inputSchema,omitempty"`
}
Tool describes an MCP tool.
type ToolCallParams ¶
type ToolCallParams struct {
Name string `json:"name"`
Arguments map[string]any `json:"arguments,omitempty"`
}
ToolCallParams is the parameters for a tools/call request.
type ToolCallResult ¶
type ToolCallResult struct {
Content []ContentBlock `json:"content"`
IsError bool `json:"isError,omitempty"`
}
ToolCallResult is the result of a tools/call request.
type ToolCaller ¶
type ToolCaller interface {
Initialize(ctx context.Context) (*InitializeResult, error)
ListTools(ctx context.Context) ([]Tool, error)
CallTool(ctx context.Context, name string, args map[string]any) (*ToolCallResult, error)
}
ToolCaller is the interface for MCP clients that can initialize, discover tools, and call tools. Both HTTP and stdio clients implement this.
type ToolsCapability ¶
type ToolsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
ToolsCapability indicates the server supports tool operations.