Documentation
¶
Overview ¶
Package mcp provides the Go SDK for building MCP (Model Context Protocol) handlers in WebAssembly components using pure wasip2.
Index ¶
- func AddPrompt[In any](server *Server, prompt *Prompt, ...)
- func AddTool[In any](server *Server, tool *Tool, ...)
- func ObjectSchema(properties map[string]any) json.RawMessage
- func RequiredObjectSchema(properties map[string]any, required []string) json.RawMessage
- func Schema(s string) json.RawMessage
- type CallToolResult
- type Content
- type Implementation
- type Prompt
- type PromptArgument
- type PromptMessage
- type Resource
- type Server
- type TextContent
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPrompt ¶ added in v0.2.4
func AddPrompt[In any](server *Server, prompt *Prompt, handler func(context.Context, In) ([]PromptMessage, error))
AddPrompt adds a prompt to the server with a generic typed handler. The handler is automatically wrapped to unmarshal JSON arguments into the In type.
func AddTool ¶ added in v0.2.4
func AddTool[In any](server *Server, tool *Tool, handler func(context.Context, In) (*CallToolResult, error))
AddTool adds a tool to the server with a generic typed handler. The handler is automatically wrapped to unmarshal JSON arguments into the In type.
The handler should have the signature:
func(ctx context.Context, args In) (*CallToolResult, error)
For tools that return simple text, you can return a CallToolResult with TextContent. The In type should match your tool's input schema.
Since TinyGo has limited reflection, you must manually provide the input schema. Use the Schema() helper to create schemas from JSON strings.
func ObjectSchema ¶ added in v0.2.4
func ObjectSchema(properties map[string]any) json.RawMessage
ObjectSchema creates a JSON schema for an object with properties.
func RequiredObjectSchema ¶ added in v0.2.4
func RequiredObjectSchema(properties map[string]any, required []string) json.RawMessage
RequiredObjectSchema creates a JSON schema for an object with required properties.
func Schema ¶
func Schema(s string) json.RawMessage
Schema creates a json.RawMessage from a JSON string.
Types ¶
type CallToolResult ¶ added in v0.2.4
type CallToolResult struct { Content []Content `json:"content"` IsError bool `json:"isError,omitempty"` }
CallToolResult represents the result of calling a tool.
type Content ¶ added in v0.2.4
type Content interface {
// contains filtered or unexported methods
}
Content represents content in a tool result.
type Implementation ¶ added in v0.2.4
Implementation defines the server implementation details.
type Prompt ¶ added in v0.2.4
type Prompt struct { Name string `json:"name"` Description string `json:"description,omitempty"` Arguments []PromptArgument `json:"arguments,omitempty"` }
Prompt represents an MCP prompt definition.
type PromptArgument ¶
type PromptArgument struct { Name string `json:"name"` Description string `json:"description,omitempty"` Required bool `json:"required"` }
PromptArgument defines an argument for a prompt.
type PromptMessage ¶
type PromptMessage struct { Role string `json:"role"` // "user" or "assistant" Content string `json:"content"` }
PromptMessage represents a message in a prompt conversation.
type Resource ¶ added in v0.2.4
type Resource struct { URI string `json:"uri"` Name string `json:"name"` Description string `json:"description,omitempty"` MimeType string `json:"mimeType,omitempty"` }
Resource represents an MCP resource definition.
type Server ¶ added in v0.2.4
type Server struct {
// contains filtered or unexported fields
}
Server represents an MCP server instance. In WASM components, there's only one global server.
func NewServer ¶ added in v0.2.4
func NewServer(impl *Implementation, options any) *Server
NewServer creates a new MCP server. In WASM components, this returns the global server instance.
func (*Server) AddResource ¶ added in v0.2.4
AddResource adds a resource to the server. Resources are read-only and return text or binary content.
type TextContent ¶ added in v0.2.4
type TextContent struct {
Text string `json:"text"`
}
TextContent represents text content.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
extract-wit
command
Command extract-wit extracts embedded WIT files to a specified directory.
|
Command extract-wit extracts embedded WIT files to a specified directory. |
internal
|
|
assets
Package assets contains embedded WIT files for the wasmcp-go SDK.
|
Package assets contains embedded WIT files for the wasmcp-go SDK. |
wasmcp
|
|
mcp/handler
Package handler represents the exported interface "wasmcp:mcp/handler@0.1.0".
|
Package handler represents the exported interface "wasmcp:mcp/handler@0.1.0". |
mcp/mcp-handler
Package mcphandler represents the world "wasmcp:mcp/mcp-handler@0.1.0".
|
Package mcphandler represents the world "wasmcp:mcp/mcp-handler@0.1.0". |