Documentation
¶
Overview ¶
Package types provides shared types and interfaces for MCP components This avoids circular dependencies between packages
Index ¶
- Constants
- Variables
- func NormalizeSchema(schema map[string]any) map[string]any
- type CallToolResult
- type Component
- type ContentBlock
- type ElicitationRecord
- type MCPError
- type Prompt
- type PromptArgument
- type PromptDefinition
- type Resource
- type ResourceDefinition
- type ResourceTemplateDefinition
- type ResourceUpdate
- type ResourceUpdateType
- type SamplingRecord
- type ServerInterface
- type StagingManager
- type StagingStore
- type StagingToggle
- type Tool
- type ToolDefinition
- type ToolHandler
- type TransformRequest
- type WatchableResource
Constants ¶
const ( InvalidParams = -32602 FileSystemError = -32001 LanguageNotFound = -32002 SyntaxError = -32003 TransformFailed = -32004 CustomErrorStart = -32999 )
Error codes for MCP
const DefaultJSONSchemaURI = "https://json-schema.org/draft/2020-12/schema"
DefaultJSONSchemaURI represents the canonical JSON Schema reference for responses.
Variables ¶
var ErrResourceWatchUnsupported = errors.New("resource does not support watch")
ErrResourceWatchUnsupported is returned when a resource does not support subscriptions.
Functions ¶
Types ¶
type CallToolResult ¶ added in v1.5.0
type CallToolResult struct {
Content []ContentBlock `json:"content"`
StructuredContent any `json:"structuredContent,omitempty"`
IsError bool `json:"isError,omitempty"`
}
CallToolResult models the standard MCP response payload for tool invocations.
type ContentBlock ¶ added in v1.5.0
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
URI string `json:"uri,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Data map[string]any `json:"data,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
}
ContentBlock represents a unit of textual content returned by prompts or tools.
type ElicitationRecord ¶ added in v1.5.0
type ElicitationRecord struct {
Timestamp time.Time `json:"timestamp"`
Params map[string]any `json:"params"`
Result map[string]any `json:"result,omitempty"`
}
ElicitationRecord captures an elicitation interaction with the client.
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
MCPError represents an MCP protocol error
func NewMCPError ¶
NewMCPError creates a new MCP error
type Prompt ¶
type Prompt interface {
Component
Content() string
Arguments() []PromptArgument
}
Prompt represents a system prompt
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
PromptArgument represents an argument for a prompt
type PromptDefinition ¶
type PromptDefinition struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Arguments []PromptArgument `json:"arguments,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
}
PromptDefinition describes a prompt for the MCP client.
type ResourceDefinition ¶
type ResourceDefinition struct {
URI string `json:"uri"`
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
Size *int64 `json:"size,omitempty"`
}
ResourceDefinition describes a resource for the MCP client.
type ResourceTemplateDefinition ¶ added in v1.5.0
type ResourceTemplateDefinition struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
URITemplate string `json:"uriTemplate"`
InputSchema map[string]any `json:"inputSchema,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
}
ResourceTemplateDefinition describes a templated resource entry point exposed by the server.
type ResourceUpdate ¶ added in v1.5.0
type ResourceUpdate struct {
URI string `json:"uri,omitempty"`
Type ResourceUpdateType `json:"type,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
ResourceUpdate describes a change emitted by a watchable resource.
type ResourceUpdateType ¶ added in v1.5.0
type ResourceUpdateType string
ResourceUpdateType identifies the kind of update emitted by a watchable resource.
const ( ResourceUpdateTypeUpdated ResourceUpdateType = "updated" ResourceUpdateTypeRemoved ResourceUpdateType = "removed" ResourceUpdateTypeListChanged ResourceUpdateType = "list_changed" )
type SamplingRecord ¶ added in v1.5.0
type SamplingRecord struct {
Timestamp time.Time `json:"timestamp"`
Params map[string]any `json:"params"`
Result map[string]any `json:"result,omitempty"`
}
SamplingRecord captures a server-initiated sampling exchange with the client.
type ServerInterface ¶
type ServerInterface interface {
GetProviders() *providers.Registry
GetFileProcessor() *core.FileProcessor
GetStaging() any
GetSafety() any
GetSessionID() string
ReportProgress(ctx context.Context, progress, total float64, message string)
ConfirmApply(ctx context.Context, summary string) error
RequestSampling(ctx context.Context, params map[string]any) (map[string]any, error)
RequestElicitation(ctx context.Context, params map[string]any) (map[string]any, error)
FinalizeTransform(ctx context.Context, req TransformRequest) (map[string]any, error)
}
ServerInterface defines what tools need from the server
type StagingManager ¶ added in v1.5.0
type StagingManager interface {
StagingStore
StagingToggle
}
StagingManager combines the core staging operations needed by tools
type StagingStore ¶ added in v1.5.0
type StagingStore interface {
ListPendingStages(sessionID string) ([]models.Stage, error)
GetStage(stageID string) (*models.Stage, error)
ApplyStage(ctx context.Context, stageID string, autoApplied bool) (*models.Apply, error)
}
StagingStore captures the operations ApplyTool expects from a staging manager implementation.
type StagingToggle ¶ added in v1.5.0
type StagingToggle interface {
IsEnabled() bool
}
StagingToggle allows staged operations to advertise whether they are active.
type Tool ¶
type Tool interface {
Component
Handler() ToolHandler
InputSchema() map[string]any
}
Tool represents an executable tool with handler
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
InputSchema map[string]any `json:"inputSchema,omitempty"`
OutputSchema map[string]any `json:"outputSchema,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
StructuredKey string `json:"structuredResultKey,omitempty"`
}
ToolDefinition mirrors the spec-defined Tool metadata exposed to clients.
type ToolHandler ¶
ToolHandler represents a function that handles a tool call
type TransformRequest ¶ added in v1.5.0
type TransformRequest struct {
Language string `json:"language"`
Operation string `json:"operation"`
Target core.AgentQuery `json:"target"`
TargetJSON json.RawMessage `json:"target_json"`
Path string `json:"path,omitempty"`
OriginalSource string `json:"original_source"`
Result core.TransformResult `json:"result"`
ResponseText string `json:"response_text"`
Content string `json:"content,omitempty"`
}
TransformRequest captures the information needed to finalize a transformation.
type WatchableResource ¶ added in v1.5.0
type WatchableResource interface {
Resource
Watch(ctx context.Context) (<-chan ResourceUpdate, error)
}
WatchableResource is implemented by resources that can push update notifications.