Documentation
¶
Overview ¶
Package mcpserver is the MCP server surface that tools are registered on, independent of any MCP library. Subpackage gosdk adapts the official go-sdk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallToolRequest ¶
type CallToolRequest struct {
// Arguments is the JSON of the call's arguments as the client sent it,
// undecoded, so that the handler can enforce a size limit before decoding.
// It is empty when the client sent no arguments.
Arguments json.RawMessage
// Header holds the headers of the HTTP request that carried the tool
// call, or nil when the MCP transport is not HTTP (e.g. stdio).
Header http.Header
}
CallToolRequest carries the arguments of an MCP tool call.
type CallToolResult ¶
CallToolResult is the response from a tool handler.
func NewToolResultError ¶
func NewToolResultError(text string) *CallToolResult
NewToolResultError creates an error text result.
func NewToolResultJSON ¶
func NewToolResultJSON(jsonBytes []byte) *CallToolResult
NewToolResultJSON creates a successful result that carries the same JSON payload as both unstructured text content (for backward compatibility) and structured content (matching the tool's output schema). The caller is responsible for passing JSON-encoded bytes; no validation is performed. The slice is copied into StructuredContent so callers may safely reuse the buffer afterwards.
func NewToolResultText ¶
func NewToolResultText(text string) *CallToolResult
NewToolResultText creates a successful text result.
type MCPServer ¶
type MCPServer interface {
AddTool(tool Tool, handler ToolHandler)
}
MCPServer is the minimal MCP server surface that tool registration (connectmcp.Register) programs against. The gosdk package adapts the official modelcontextprotocol/go-sdk server to it; other MCP libraries can be supported by implementing this one method.
type Tool ¶
type Tool struct {
Name string
Description string
RawInputSchema json.RawMessage
RawOutputSchema json.RawMessage
// Annotations describe the tool to clients; nil when there are none.
Annotations *ToolAnnotations
}
Tool describes an MCP tool independent of any MCP library.
type ToolAnnotations ¶
type ToolAnnotations struct {
// Title is the human-readable name that clients display instead of the
// tool name.
Title string
// ReadOnlyHint tells that the tool does not modify its environment.
ReadOnlyHint bool
// DestructiveHint tells whether the tool may destroy or overwrite data
// (true) or only adds to it (false); nil means MCP's default, true.
// Meaningful only when ReadOnlyHint is false.
DestructiveHint *bool
// IdempotentHint tells that calling the tool again with the same
// arguments has no additional effect. Meaningful only when ReadOnlyHint
// is false.
IdempotentHint bool
// OpenWorldHint tells whether the tool interacts with an open world of
// external entities (true) or a closed domain (false); nil means MCP's
// default, true.
OpenWorldHint *bool
}
ToolAnnotations are the display title and behavior hints of an MCP tool. They are hints for clients (e.g. which calls to confirm with the user), not guarantees. An unset hint takes MCP's default: not read-only, not idempotent, possibly destructive and open world.
func (*ToolAnnotations) IsZero ¶
func (a *ToolAnnotations) IsZero() bool
IsZero reports whether a carries no title and no hints.
type ToolHandler ¶
type ToolHandler func(ctx context.Context, request *CallToolRequest) (*CallToolResult, error)
ToolHandler is the callback invoked when an MCP client calls a tool.