Documentation
¶
Index ¶
- func AddTool[In, Out any](server McpServer, tool *Tool, ...)
- type AudioContent
- type CallToolParams
- type CallToolRequest
- type CallToolResult
- type Content
- type GetPromptParams
- type GetPromptResult
- type ImageContent
- type Implementation
- type McpConf
- type McpServer
- type Prompt
- type PromptHandler
- type PromptMessage
- type ReadResourceParams
- type ReadResourceResult
- type Resource
- type ResourceContents
- type ResourceHandler
- type SSEHandler
- type Server
- type ServerOptions
- type ServerSession
- type StreamableHTTPHandler
- type TextContent
- type Tool
- type ToolHandlerdeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTool ¶ added in v1.10.0
func AddTool[In, Out any](server McpServer, tool *Tool, handler func(context.Context, *CallToolRequest, In) (*CallToolResult, Out, error))
AddTool registers a tool with the MCP server using type-safe generics. The SDK automatically generates JSON schema from the Args struct tags.
Example:
type GreetArgs struct {
Name string `json:"name" jsonschema:"description=Name to greet"`
}
tool := &mcp.Tool{
Name: "greet",
Description: "Greet someone",
}
handler := func(ctx context.Context, req *mcp.CallToolRequest, args GreetArgs) (*mcp.CallToolResult, any, error) {
return &mcp.CallToolResult{
Content: []mcp.Content{&mcp.TextContent{Text: "Hello " + args.Name}},
}, nil, nil
}
mcp.AddTool(server, tool, handler)
Types ¶
type AudioContent ¶
type AudioContent = sdkmcp.AudioContent
Re-export commonly used SDK types for convenience
type CallToolParams ¶ added in v1.10.0
type CallToolParams = sdkmcp.CallToolParams
Re-export commonly used SDK types for convenience
type CallToolRequest ¶ added in v1.10.0
type CallToolRequest = sdkmcp.CallToolRequest
Re-export commonly used SDK types for convenience
type CallToolResult ¶
type CallToolResult = sdkmcp.CallToolResult
Re-export commonly used SDK types for convenience
type GetPromptParams ¶ added in v1.10.0
type GetPromptParams = sdkmcp.GetPromptParams
Re-export commonly used SDK types for convenience
type GetPromptResult ¶ added in v1.10.0
type GetPromptResult = sdkmcp.GetPromptResult
Re-export commonly used SDK types for convenience
type ImageContent ¶
type ImageContent = sdkmcp.ImageContent
Re-export commonly used SDK types for convenience
type Implementation ¶ added in v1.10.0
type Implementation = sdkmcp.Implementation
Re-export commonly used SDK types for convenience
type McpConf ¶
type McpConf struct {
rest.RestConf
Mcp struct {
// Name is the server name reported in initialize responses
Name string `json:",optional"`
// Version is the server version reported in initialize responses
Version string `json:",default=1.0.0"`
// UseStreamable when true uses Streamable HTTP transport (2025-03-26 spec),
// otherwise uses SSE transport (2024-11-05 spec)
UseStreamable bool `json:",default=false"`
// SseEndpoint is the path for Server-Sent Events connections
// Used for SSE transport mode
SseEndpoint string `json:",default=/sse"`
// MessageEndpoint is the path for JSON-RPC requests
// Used for Streamable HTTP transport mode
MessageEndpoint string `json:",default=/message"`
// Cors contains allowed CORS origins
Cors []string `json:",optional"`
// SseTimeout is the maximum time allowed for SSE connections
SseTimeout time.Duration `json:",default=24h"`
// MessageTimeout is the maximum time allowed for request execution
MessageTimeout time.Duration `json:",default=30s"`
}
}
McpConf defines the configuration for an MCP server. It embeds rest.RestConf for HTTP server settings and adds MCP-specific configuration options.
type McpServer ¶
type McpServer interface {
// Start starts the HTTP server
Start()
// Stop stops the HTTP server
Stop()
}
McpServer defines the interface for Model Context Protocol servers using the official SDK
func NewMcpServer ¶
NewMcpServer creates a new MCP server using the official SDK
type PromptHandler ¶
type PromptHandler func( ctx context.Context, req *sdkmcp.GetPromptRequest, args map[string]string, ) (*GetPromptResult, error)
PromptHandler is a function signature for prompt handlers.
type PromptMessage ¶
type PromptMessage = sdkmcp.PromptMessage
Re-export commonly used SDK types for convenience
type ReadResourceParams ¶ added in v1.10.0
type ReadResourceParams = sdkmcp.ReadResourceParams
Re-export commonly used SDK types for convenience
type ReadResourceResult ¶ added in v1.10.0
type ReadResourceResult = sdkmcp.ReadResourceResult
Re-export commonly used SDK types for convenience
type ResourceContents ¶ added in v1.10.0
type ResourceContents = sdkmcp.ResourceContents
Re-export commonly used SDK types for convenience
type ResourceHandler ¶
type ResourceHandler func( ctx context.Context, req *sdkmcp.ReadResourceRequest, uri string, ) (*ReadResourceResult, error)
ResourceHandler is a function signature for resource handlers.
type ServerOptions ¶ added in v1.10.0
type ServerOptions = sdkmcp.ServerOptions
Re-export commonly used SDK types for convenience
type ServerSession ¶ added in v1.10.0
type ServerSession = sdkmcp.ServerSession
Re-export commonly used SDK types for convenience
type StreamableHTTPHandler ¶ added in v1.10.0
type StreamableHTTPHandler = sdkmcp.StreamableHTTPHandler
Re-export commonly used SDK types for convenience
type TextContent ¶
type TextContent = sdkmcp.TextContent
Re-export commonly used SDK types for convenience
type ToolHandler
deprecated
type ToolHandler[Args any, Meta any] func( ctx context.Context, req *CallToolRequest, args Args, ) (*CallToolResult, Meta, error)
ToolHandler is a generic function signature for tool handlers. Handlers should accept context, request, and typed arguments, and return a result, metadata, and error.
Deprecated: Use ToolHandlerFor directly from the SDK types.