Documentation
¶
Overview ¶
Package tinymcp provides a lightweight wrapper around the official Model Context Protocol Go SDK. It reduces boilerplate for building MCP servers (stdio, streamable HTTP, or legacy SSE) that AI clients can discover and call.
Index ¶
- func AssistantPromptMessage(text string) *mcp.PromptMessage
- func PromptResult(description string, messages ...*mcp.PromptMessage) *mcp.GetPromptResult
- func RegisterPrompt(s *TinyServer, name, description string, arguments []*mcp.PromptArgument, ...) error
- func RegisterResource(s *TinyServer, uri, name, description, mimeType string, ...) error
- func RegisterResourceTemplate(s *TinyServer, uriTemplate, name, description, mimeType string, ...) error
- func RegisterTextResource(s *TinyServer, uri, name, description, mimeType, text string) error
- func RegisterTool[In, Out any](s *TinyServer, name, description string, handler mcp.ToolHandlerFor[In, Out]) error
- func SSEHandler(s *TinyServer, opts *SSEOptions) (http.Handler, error)
- func StreamableHTTPHandler(s *TinyServer, opts *HTTPOptions) (http.Handler, error)
- func TextResource(uri, mimeType, text string) *mcp.ReadResourceResult
- func TextResourceContents(uri, mimeType, text string) *mcp.ResourceContents
- func TextResult(text string) *mcp.CallToolResult
- func UserPromptMessage(text string) *mcp.PromptMessage
- type HTTPOptions
- type SSEOptions
- type TinyServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssistantPromptMessage ¶ added in v1.1.0
func AssistantPromptMessage(text string) *mcp.PromptMessage
AssistantPromptMessage returns an assistant-role prompt message with text content.
func PromptResult ¶ added in v1.1.0
func PromptResult(description string, messages ...*mcp.PromptMessage) *mcp.GetPromptResult
PromptResult builds a GetPromptResult from prompt messages.
func RegisterPrompt ¶ added in v1.1.0
func RegisterPrompt(s *TinyServer, name, description string, arguments []*mcp.PromptArgument, handler mcp.PromptHandler) error
RegisterPrompt adds a prompt template. arguments may be nil for prompts with no parameters.
func RegisterResource ¶ added in v1.1.0
func RegisterResource(s *TinyServer, uri, name, description, mimeType string, handler mcp.ResourceHandler) error
RegisterResource adds a resource with a fixed URI. uri must be absolute (e.g. file:///docs/readme).
func RegisterResourceTemplate ¶ added in v1.1.0
func RegisterResourceTemplate(s *TinyServer, uriTemplate, name, description, mimeType string, handler mcp.ResourceHandler) error
RegisterResourceTemplate adds a resource matched by URI template (e.g. file:///docs/{path}).
func RegisterTextResource ¶ added in v1.1.0
func RegisterTextResource(s *TinyServer, uri, name, description, mimeType, text string) error
RegisterTextResource registers a static text resource at uri.
func RegisterTool ¶
func RegisterTool[In, Out any](s *TinyServer, name, description string, handler mcp.ToolHandlerFor[In, Out]) error
RegisterTool registers a tool on s with automatic JSON Schema inference from the handler's input struct (use json and jsonschema struct tags). The handler must match mcp.ToolHandlerFor[In, Out] — typically return TextResult for text tools.
func SSEHandler ¶ added in v1.1.0
func SSEHandler(s *TinyServer, opts *SSEOptions) (http.Handler, error)
SSEHandler returns an http.Handler for legacy SSE MCP clients (2024-11-05 transport).
func StreamableHTTPHandler ¶ added in v1.1.0
func StreamableHTTPHandler(s *TinyServer, opts *HTTPOptions) (http.Handler, error)
StreamableHTTPHandler returns an http.Handler for streamable HTTP MCP clients (POST JSON-RPC; responses as JSON or SSE). Wrap with auth/CORS middleware as needed.
func TextResource ¶ added in v1.1.0
func TextResource(uri, mimeType, text string) *mcp.ReadResourceResult
TextResource builds a ReadResourceResult with a single text body.
func TextResourceContents ¶ added in v1.1.0
func TextResourceContents(uri, mimeType, text string) *mcp.ResourceContents
TextResourceContents builds a text ResourceContents block for ReadResourceResult.
func TextResult ¶
func TextResult(text string) *mcp.CallToolResult
TextResult builds a successful CallToolResult with a single text content block. Use this in tool handlers so LLM clients receive consistent, readable output.
func UserPromptMessage ¶ added in v1.1.0
func UserPromptMessage(text string) *mcp.PromptMessage
UserPromptMessage returns a user-role prompt message with text content.
Types ¶
type HTTPOptions ¶ added in v1.1.0
type HTTPOptions struct {
// Stateless uses a fresh session per request (no Mcp-Session-Id). Simpler for
// stateless gateways; server-initiated requests are not supported.
Stateless bool
// JSONResponse returns application/json instead of text/event-stream for POST responses.
JSONResponse bool
// SessionTimeout closes idle sessions after this duration (zero = never).
SessionTimeout time.Duration
// DisableLocalhostProtection turns off DNS rebinding checks for localhost clients.
// Only set when you understand the security tradeoff.
DisableLocalhostProtection bool
}
HTTPOptions configures streamable HTTP transport (current MCP spec: POST + SSE).
type SSEOptions ¶ added in v1.1.0
type SSEOptions struct {
// DisableLocalhostProtection turns off DNS rebinding checks for localhost clients.
DisableLocalhostProtection bool
}
SSEOptions configures legacy SSE transport (MCP spec 2024-11-05).
type TinyServer ¶
type TinyServer struct {
// contains filtered or unexported fields
}
TinyServer wraps the official MCP Server with a simplified API for registering tools, resources, prompts, and starting transports.
func NewServer ¶
func NewServer(name, version string) *TinyServer
NewServer creates a TinyServer identified by name and version for connected clients.
func (*TinyServer) RawServer ¶
func (s *TinyServer) RawServer() *mcp.Server
RawServer returns the underlying *mcp.Server for advanced customization.
func (*TinyServer) Start ¶
func (s *TinyServer) Start() error
Start runs the server over stdin/stdout (stdio), the standard transport for local AI clients.
func (*TinyServer) StartHTTP ¶ added in v1.1.0
func (s *TinyServer) StartHTTP(addr string, opts *HTTPOptions) error
StartHTTP listens on addr and serves streamable HTTP MCP until the server stops or errors.
func (*TinyServer) StartSSE ¶ added in v1.1.0
func (s *TinyServer) StartSSE(addr string, opts *SSEOptions) error
StartSSE listens on addr and serves legacy SSE MCP until the server stops or errors.