Documentation
¶
Index ¶
- Constants
- func ParseArguments(args any, req any) error
- type Annotations
- type AudioContent
- type CallToolResult
- type Cursor
- type EmbeddedResource
- type FileContent
- type ImageContent
- type InputSchema
- type ListToolsResult
- type McpConf
- type McpServer
- type PaginatedParams
- type PaginatedResult
- type Prompt
- type PromptArgument
- type PromptHandler
- type PromptMessage
- type Request
- type Resource
- type ResourceContent
- type ResourceHandler
- type ResourceReadParams
- type ResourceReadResult
- type ResourceSubscribeParams
- type ResourceUpdateNotification
- type ResourcesListResult
- type Response
- type Result
- type RoleType
- type TextContent
- type Tool
- type ToolCallParams
- type ToolHandler
- type ToolResult
Constants ¶
const ( // ContentTypeObject is object content type ContentTypeObject = "object" // ContentTypeText is text content type ContentTypeText = "text" // ContentTypeImage is image content type ContentTypeImage = "image" // ContentTypeAudio is audio content type ContentTypeAudio = "audio" // ContentTypeResource is resource content type ContentTypeResource = "resource" )
Content type identifiers
Variables ¶
This section is empty.
Functions ¶
func ParseArguments ¶
ParseArguments parses the arguments and populates the request object
Types ¶
type Annotations ¶
type Annotations struct {
Audience []RoleType `json:"audience,omitempty"` // Who should see this content
Priority *float64 `json:"priority,omitempty"` // Optional priority (0-1)
}
Annotations provides additional metadata for content
type AudioContent ¶
type AudioContent struct {
Data string `json:"data"` // Base64-encoded audio data
MimeType string `json:"mimeType"` // MIME type (e.g., "audio/mp3")
}
AudioContent represents audio data in a message
type CallToolResult ¶
type CallToolResult struct {
Result
Content []any `json:"content"` // Content items (text, images, etc.)
IsError bool `json:"isError,omitempty"` // True if tool execution failed
}
CallToolResult represents a tool call result that conforms to the MCP schema
type EmbeddedResource ¶
type EmbeddedResource struct {
Type string `json:"type"` // Always "resource"
Resource ResourceContent `json:"resource"` // The resource data
}
EmbeddedResource represents a resource embedded in a message
type FileContent ¶
type FileContent struct {
URI string `json:"uri"` // URI identifying the file
MimeType string `json:"mimeType"` // MIME type of the file
Text string `json:"text"` // File content as text
}
FileContent represents file content
type ImageContent ¶
type ImageContent struct {
Data string `json:"data"` // Base64-encoded image data
MimeType string `json:"mimeType"` // MIME type (e.g., "image/png")
}
ImageContent represents image data in a message
type InputSchema ¶
type InputSchema struct {
Type string `json:"type"`
Properties map[string]any `json:"properties"` // Property definitions
Required []string `json:"required,omitempty"` // List of required properties
}
InputSchema represents tool's input schema in JSON Schema format
type ListToolsResult ¶
type ListToolsResult struct {
PaginatedResult
Tools []Tool `json:"tools"` // List of available tools
}
ListToolsResult represents the response to a tools/list request
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"`
// ProtocolVersion is the MCP protocol version implemented
ProtocolVersion string `json:",default=2024-11-05"`
// BaseUrl is the base URL for the server, used in SSE endpoint messages
// If not set, defaults to http://localhost:{Port}
BaseUrl string `json:",optional"`
// SseEndpoint is the path for Server-Sent Events connections
SseEndpoint string `json:",default=/sse"`
// MessageEndpoint is the path for JSON-RPC requests
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()
Stop()
RegisterTool(tool Tool) error
RegisterPrompt(prompt Prompt)
RegisterResource(resource Resource)
}
McpServer defines the interface for Model Context Protocol servers
func NewMcpServer ¶
type PaginatedParams ¶
type PaginatedResult ¶
type PaginatedResult struct {
Result
NextCursor Cursor `json:"nextCursor,omitempty"` // Opaque token for fetching next page
}
PaginatedResult is a base for results that support pagination
type Prompt ¶
type Prompt struct {
Name string `json:"name"` // Unique identifier for the prompt
Description string `json:"description,omitempty"` // Human-readable description
Arguments []PromptArgument `json:"arguments,omitempty"` // Arguments for customization
Content string `json:"-"` // Static content (internal use only)
Handler PromptHandler `json:"-"` // Handler for dynamic content generation
}
Prompt represents an MCP Prompt definition
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"` // Argument name
Description string `json:"description,omitempty"` // Human-readable description
Required bool `json:"required,omitempty"` // Whether this argument is required
}
PromptArgument defines a single argument that can be passed to a prompt
type PromptHandler ¶
PromptHandler is a function that dynamically generates prompt content
type PromptMessage ¶
type PromptMessage struct {
Role RoleType `json:"role"` // Message sender role
Content any `json:"content"` // Message content (TextContent, ImageContent, etc.)
}
PromptMessage represents a message in a conversation
type Request ¶
type Request struct {
SessionId string `form:"session_id"` // Session identifier for client tracking
JsonRpc string `json:"jsonrpc"` // Must be "2.0" per JSON-RPC spec
ID any `json:"id"` // Request identifier for matching responses
Method string `json:"method"` // Method name to invoke
Params json.RawMessage `json:"params"` // Parameters for the method
}
Request represents a generic MCP request following JSON-RPC 2.0 specification
type Resource ¶
type Resource struct {
URI string `json:"uri"` // Unique resource identifier (RFC3986)
Name string `json:"name"` // Human-readable name
Description string `json:"description,omitempty"` // Optional description
MimeType string `json:"mimeType,omitempty"` // Optional MIME type
Handler ResourceHandler `json:"-"` // Internal handler not sent to clients
}
Resource represents a Model Context Protocol Resource definition
type ResourceContent ¶
type ResourceContent struct {
URI string `json:"uri"` // Resource URI (required)
MimeType string `json:"mimeType,omitempty"` // MIME type of the resource
Text string `json:"text,omitempty"` // Text content (if available)
Blob string `json:"blob,omitempty"` // Base64 encoded blob data (if available)
}
ResourceContent represents the content of a resource
type ResourceHandler ¶
type ResourceHandler func(ctx context.Context) (ResourceContent, error)
ResourceHandler is a function that handles resource read requests
type ResourceReadParams ¶
type ResourceReadParams struct {
URI string `json:"uri"` // URI of the resource to read
}
ResourceReadParams contains parameters for a resources/read request
type ResourceReadResult ¶
type ResourceReadResult struct {
Result
Contents []ResourceContent `json:"contents"` // Array of resource content
}
ResourceReadResult contains the result of a resources/read request
type ResourceSubscribeParams ¶
type ResourceSubscribeParams struct {
URI string `json:"uri"` // URI of the resource to subscribe to
}
ResourceSubscribeParams contains parameters for a resources/subscribe request
type ResourceUpdateNotification ¶
type ResourceUpdateNotification struct {
URI string `json:"uri"` // URI of the updated resource
Content ResourceContent `json:"content"` // New resource content
}
ResourceUpdateNotification represents a notification about a resource update
type ResourcesListResult ¶
type ResourcesListResult struct {
PaginatedResult
Resources []Resource `json:"resources"` // List of available resources
}
ResourcesListResult represents the response to a resources/list request
type Response ¶
type Response struct {
JsonRpc string `json:"jsonrpc"` // Always "2.0"
ID any `json:"id"` // Same as request ID
Result any `json:"result"` // Result object (null if error)
Error *errorObj `json:"error,omitempty"` // Error object (null if success)
}
Response represents a JSON-RPC response
type RoleType ¶
type RoleType string
RoleType represents the sender or recipient of messages in a conversation
type TextContent ¶
type TextContent struct {
Text string `json:"text"` // The text content
Annotations *Annotations `json:"annotations,omitempty"` // Optional annotations
}
TextContent represents text content in a message
type Tool ¶
type Tool struct {
Name string `json:"name"` // Unique identifier for the tool
Description string `json:"description"` // Human-readable description
InputSchema InputSchema `json:"inputSchema"` // JSON Schema for parameters
Handler ToolHandler `json:"-"` // Not sent to clients
}
Tool represents a Model Context Protocol Tool definition
type ToolCallParams ¶
type ToolCallParams struct {
Name string `json:"name"` // Tool name
Parameters map[string]any `json:"parameters"` // Tool parameters
}
ToolCallParams contains the parameters for a tool call
type ToolHandler ¶
ToolHandler is a function that handles tool calls
type ToolResult ¶
type ToolResult struct {
Type string `json:"type"` // Content type (text, image, etc.)
Content any `json:"content"` // Result content
}
ToolResult contains the result of a tool execution