Documentation
¶
Index ¶
- Constants
- type Annotated
- type CallToolRequest
- type CallToolResult
- type ClientCapabilities
- type Cursor
- type EmptyResult
- type Implementation
- type InitializeParams
- type InitializeRequest
- type InitializeResult
- type InitializedNotification
- type JSONRPCError
- type JSONRPCMessage
- type JSONRPCNotification
- type JSONRPCRequest
- type JSONRPCResponse
- type ListChanged
- type ListToolsRequest
- type ListToolsResult
- type McpError
- type Notification
- type PaginatedRequest
- type PaginatedResult
- type ProgressToken
- type Request
- type RequestId
- type Result
- type Role
- type ServerCapabilities
- type TextContent
Constants ¶
const ( PARSE_ERROR = -32700 INVALID_REQUEST = -32600 METHOD_NOT_FOUND = -32601 INVALID_PARAMS = -32602 INTERNAL_ERROR = -32603 )
Standard JSON-RPC error codes
const JSONRPC_VERSION = "2.0"
JSONRPC_VERSION is the version of JSON-RPC used by MCP.
const LATEST_PROTOCOL_VERSION = "2024-11-05"
LATEST_PROTOCOL_VERSION is the most recent version of the MCP protocol.
const SERVER_NAME = "Toolbox"
SERVER_NAME is the server name used in Implementation.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotated ¶
type Annotated struct {
Annotations *struct {
// Describes who the intended customer of this object or data is.
// It can include multiple entries to indicate content useful for multiple
// audiences (e.g., `["user", "assistant"]`).
Audience []Role `json:"audience,omitempty"`
// Describes how important this data is for operating the server.
//
// A value of 1 means "most important," and indicates that the data is
// effectively required, while 0 means "least important," and indicates that
// the data is entirely optional.
//
// @TJS-type number
// @minimum 0
// @maximum 1
Priority float64 `json:"priority,omitempty"`
} `json:"annotations,omitempty"`
}
Base for objects that include optional annotations for the client. The client can use annotations to inform how objects are used or displayed
type CallToolRequest ¶
type CallToolRequest struct {
Request
Params struct {
Name string `json:"name"`
Arguments map[string]any `json:"arguments,omitempty"`
} `json:"params,omitempty"`
}
Used by the client to invoke a tool provided by the server.
type CallToolResult ¶
type CallToolResult struct {
Result
// Could be either a TextContent, ImageContent, or EmbeddedResources
// For Toolbox, we will only be sending TextContent
Content []TextContent `json:"content"`
// Whether the tool call ended in an error.
// If not set, this is assumed to be false (the call was successful).
IsError bool `json:"isError,omitempty"`
}
The server's response to a tool call.
Any errors that originate from the tool SHOULD be reported inside the result object, with `isError` set to true, _not_ as an MCP protocol-level error response. Otherwise, the LLM would not be able to see that an error occurred and self-correct.
However, any errors in _finding_ the tool, an error indicating that the server does not support tool calls, or any other exceptional conditions, should be reported as an MCP error response.
func ToolCall ¶
func ToolCall(ctx context.Context, tool tools.Tool, params tools.ParamValues) CallToolResult
ToolCall runs tool invocation and return a CallToolResult
type ClientCapabilities ¶
type ClientCapabilities struct {
// Experimental, non-standard capabilities that the client supports.
Experimental map[string]interface{} `json:"experimental,omitempty"`
// Present if the client supports listing roots.
Roots *ListChanged `json:"roots,omitempty"`
// Present if the client supports sampling from an LLM.
Sampling struct{} `json:"sampling,omitempty"`
}
ClientCapabilities represents capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
type Cursor ¶
type Cursor string
Cursor is an opaque token used to represent a cursor for pagination.
type EmptyResult ¶
type EmptyResult Result
EmptyResult represents a response that indicates success but carries no data.
type Implementation ¶
Implementation describes the name and version of an MCP implementation.
type InitializeParams ¶
type InitializeParams struct {
// The latest version of the Model Context Protocol that the client supports.
// The client MAY decide to support older versions as well.
ProtocolVersion string `json:"protocolVersion"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo Implementation `json:"clientInfo"`
}
Params to define MCP Client during initialize request.
type InitializeRequest ¶
type InitializeRequest struct {
Request
Params InitializeParams `json:"params"`
}
InitializeRequest is sent from the client to the server when it first connects, asking it to begin initialization.
type InitializeResult ¶
type InitializeResult struct {
Result
// The version of the Model Context Protocol that the server wants to use.
// This may not match the version that the client requested. If the client cannot
// support this version, it MUST disconnect.
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo Implementation `json:"serverInfo"`
// Instructions describing how to use the server and its features.
//
// This can be used by clients to improve the LLM's understanding of
// available tools, resources, etc. It can be thought of like a "hint" to the model.
// For example, this information MAY be added to the system prompt.
Instructions string `json:"instructions,omitempty"`
}
InitializeResult is sent after receiving an initialize request from the client.
func Initialize ¶
func Initialize(version string) InitializeResult
type InitializedNotification ¶
type InitializedNotification struct {
Notification
}
InitializedNotification is sent from the client to the server after initialization has finished.
type JSONRPCError ¶
type JSONRPCError struct {
Jsonrpc string `json:"jsonrpc"`
Id RequestId `json:"id"`
Error McpError `json:"error"`
}
JSONRPCError represents a non-successful (error) response to a request.
type JSONRPCMessage ¶
type JSONRPCMessage interface{}
JSONRPCMessage represents either a JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, or JSONRPCError.
type JSONRPCNotification ¶
type JSONRPCNotification struct {
Jsonrpc string `json:"jsonrpc"`
Notification
}
JSONRPCNotification represents a notification which does not expect a response.
type JSONRPCRequest ¶
type JSONRPCRequest struct {
Jsonrpc string `json:"jsonrpc"`
Id RequestId `json:"id"`
Request
Params any `json:"params,omitempty"`
}
JSONRPCRequest represents a request that expects a response.
type JSONRPCResponse ¶
type JSONRPCResponse struct {
Jsonrpc string `json:"jsonrpc"`
Id RequestId `json:"id"`
Result interface{} `json:"result"`
}
JSONRPCResponse represents a successful (non-error) response to a request.
type ListChanged ¶
type ListChanged struct {
ListChanged *bool `json:"listChanged,omitempty"`
}
ListChange represents whether the server supports notification for changes to the capabilities.
type ListToolsRequest ¶
type ListToolsRequest struct {
PaginatedRequest
}
Sent from the client to request a list of tools the server has.
type ListToolsResult ¶
type ListToolsResult struct {
PaginatedResult
Tools []tools.McpManifest `json:"tools"`
}
The server's response to a tools/list request from the client.
func ToolsList ¶
func ToolsList(toolset tools.Toolset) ListToolsResult
ToolsList return a ListToolsResult
type McpError ¶
type McpError struct {
// The error type that occurred.
Code int `json:"code"`
// A short description of the error. The message SHOULD be limited
// to a concise single sentence.
Message string `json:"message"`
// Additional information about the error. The value of this member
// is defined by the sender (e.g. detailed error information, nested errors etc.).
Data interface{} `json:"data,omitempty"`
}
McpError represents the error content.
type Notification ¶
type Notification struct {
Method string `json:"method"`
Params struct {
Meta map[string]interface{} `json:"_meta,omitempty"`
} `json:"params,omitempty"`
}
Notification is a one-way message requiring no response.
type PaginatedRequest ¶
type PaginatedResult ¶
type ProgressToken ¶
type ProgressToken interface{}
ProgressToken is used to associate progress notifications with the original request.
type Request ¶
type Request struct {
Method string `json:"method"`
Params struct {
Meta struct {
// If specified, the caller is requesting out-of-band progress
// notifications for this request (as represented by
// notifications/progress). The value of this parameter is an
// opaque token that will be attached to any subsequent
// notifications. The receiver is not obligated to provide these
// notifications.
ProgressToken ProgressToken `json:"progressToken,omitempty"`
} `json:"_meta,omitempty"`
} `json:"params,omitempty"`
}
Request represents a bidirectional message with method and parameters expecting a response.
type RequestId ¶
type RequestId interface{}
RequestId is a uniquely identifying ID for a request in JSON-RPC. It can be any JSON-serializable value, typically a number or string.
type Result ¶
type Result struct {
// This result property is reserved by the protocol to allow clients and
// servers to attach additional metadata to their responses.
Meta map[string]interface{} `json:"_meta,omitempty"`
}
Result represents a response for the request query.
type ServerCapabilities ¶
type ServerCapabilities struct {
Tools *ListChanged `json:"tools,omitempty"`
}
ServerCapabilities represents capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
type TextContent ¶
type TextContent struct {
Annotated
Type string `json:"type"`
// The text content of the message.
Text string `json:"text"`
}
TextContent represents text provided to or from an LLM.