types

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LatestProtocolVersion represents the latest supported MCP version
	LatestProtocolVersion = "2024-11-05"

	// JSONRPCVersion represents the JSON-RPC version used by MCP
	JSONRPCVersion = "2.0"
)
View Source
const (
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

Standard JSON-RPC error codes

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobResourceContents

type BlobResourceContents struct {
	ResourceContents
	Blob string `json:"blob"` // base64-encoded data
}

BlobResourceContents represents binary resource contents

func NewBlobContents

func NewBlobContents(uri string, mimeType string, data []byte) BlobResourceContents

NewBlobContents creates a new BlobResourceContents from raw binary data

func (*BlobResourceContents) GetData

func (b *BlobResourceContents) GetData() ([]byte, error)

GetData decodes the blob data

type CallToolRequest

type CallToolRequest struct {
	Method    string                 `json:"method"`
	Name      string                 `json:"name"`
	Arguments map[string]interface{} `json:"arguments,omitempty"`
}

CallToolRequest represents a request to call a specific tool

type CallToolResult

type CallToolResult struct {
	Content []interface{} `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource
	IsError bool          `json:"isError,omitempty"`
}

CallToolResult represents the response from a tool call

type ClientCapabilities

type ClientCapabilities struct {
	// Experimental features support
	Experimental map[string]interface{} `json:"experimental,omitempty"`

	// Roots capability
	Roots *RootsClientCapabilities `json:"roots,omitempty"`

	// Sampling capability
	Sampling *SamplingClientCapabilities `json:"sampling,omitempty"`
}

ClientCapabilities represents the capabilities a client supports

type CreateMessageRequest

type CreateMessageRequest struct {
	Method           string            `json:"method"`
	Messages         []SamplingMessage `json:"messages"`
	ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
	SystemPrompt     string            `json:"systemPrompt,omitempty"`
	IncludeContext   string            `json:"includeContext,omitempty"`
	Temperature      float64           `json:"temperature,omitempty"`
	MaxTokens        int               `json:"maxTokens"`
	StopSequences    []string          `json:"stopSequences,omitempty"`
	Metadata         interface{}       `json:"metadata,omitempty"`
}

CreateMessageRequest represents a request to sample from an LLM

type CreateMessageResult

type CreateMessageResult struct {
	Role       Role           `json:"role"`
	Content    MessageContent `json:"content"` // Using the same MessageContent interface from prompts
	Model      string         `json:"model"`
	StopReason string         `json:"stopReason,omitempty"`
}

CreateMessageResult represents the response from a sampling request

func (CreateMessageResult) MarshalJSON

func (r CreateMessageResult) MarshalJSON() ([]byte, error)

MarshalJSON marshals a CreateMessageResult

func (*CreateMessageResult) UnmarshalJSON

func (r *CreateMessageResult) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a CreateMessageResult

type Cursor

type Cursor string

Cursor represents an opaque token for pagination

type EmbeddedResource

type EmbeddedResource struct {
	Type     string           `json:"type"`
	Resource ResourceContents `json:"resource"`
}

EmbeddedResource represents a resource embedded in a prompt

type ErrorResponse

type ErrorResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

ErrorResponse represents a JSON-RPC 2.0 error response

func NewError

func NewError(code int, message string, data ...interface{}) *ErrorResponse

NewError creates a new ErrorResponse with the given code and message

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error implements the error interface.

type GetPromptRequest

type GetPromptRequest struct {
	Method    string            `json:"method"`
	Name      string            `json:"name"`
	Arguments map[string]string `json:"arguments,omitempty"`
}

GetPromptRequest represents a request to get a specific prompt

type GetPromptResult

type GetPromptResult struct {
	Description string          `json:"description,omitempty"`
	Messages    []PromptMessage `json:"messages"`
}

GetPromptResult represents the response to a prompts/get request

type ID

type ID = jsonrpc2.ID // This is typically a string or number

ID represents a unique identifier for a request in JSON-RPC

type ImageContent

type ImageContent struct {
	Type     string `json:"type"`
	Data     string `json:"data"` // base64-encoded
	MimeType string `json:"mimeType"`
}

ImageContent represents an image provided to/from an LLM

type Implementation

type Implementation struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Implementation describes the name and version of an MCP implementation

type InitializeRequest

type InitializeRequest struct {
	// The latest version of MCP that the client supports
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ClientCapabilities `json:"capabilities"`
	ClientInfo      Implementation     `json:"clientInfo"`
}

InitializeRequest represents the initial request sent from client to server

type InitializeResult

type InitializeResult struct {
	// The version of MCP that the server will use
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ServerCapabilities `json:"capabilities"`
	ServerInfo      Implementation     `json:"serverInfo"`
	// Optional instructions for using the server
	Instructions string `json:"instructions,omitempty"`
}

InitializeResult represents the server's response to initialization

type InitializedNotification

type InitializedNotification struct {
	Method string `json:"method"`
}

InitializedNotification represents the notification sent after successful initialization

type ListPromptsRequest

type ListPromptsRequest struct {
	Method string  `json:"method"`
	Cursor *Cursor `json:"cursor,omitempty"`
}

ListPromptsRequest represents a request to list available prompts

type ListPromptsResult

type ListPromptsResult struct {
	Prompts    []Prompt `json:"prompts"`
	NextCursor *Cursor  `json:"nextCursor,omitempty"`
}

ListPromptsResult represents the response to a prompts/list request

type ListResourceTemplatesRequest

type ListResourceTemplatesRequest struct {
	Method string  `json:"method"`
	Cursor *Cursor `json:"cursor,omitempty"`
}

ListResourceTemplatesRequest represents a request to list resource templates

type ListResourceTemplatesResult

type ListResourceTemplatesResult struct {
	ResourceTemplates []ResourceTemplate `json:"resourceTemplates"`
	NextCursor        *Cursor            `json:"nextCursor,omitempty"`
}

ListResourceTemplatesResult represents the response to a resources/templates/list request

type ListResourcesRequest

type ListResourcesRequest struct {
	Method string  `json:"method"`
	Cursor *Cursor `json:"cursor,omitempty"`
}

ListResourcesRequest represents a request to list available resources

type ListResourcesResult

type ListResourcesResult struct {
	Resources  []Resource `json:"resources"`
	NextCursor *Cursor    `json:"nextCursor,omitempty"`
}

ListResourcesResult represents the response to a resources/list request

type ListRootsRequest

type ListRootsRequest struct {
	Method string `json:"method"`
}

ListRootsRequest represents a request to list available roots

type ListRootsResult

type ListRootsResult struct {
	Roots []Root `json:"roots"`
}

ListRootsResult represents the response to a roots/list request

type ListToolsRequest

type ListToolsRequest struct {
	Method string  `json:"method"`
	Cursor *Cursor `json:"cursor,omitempty"`
}

ListToolsRequest represents a request to list available tools

type ListToolsResult

type ListToolsResult struct {
	Tools      []Tool  `json:"tools"`
	NextCursor *Cursor `json:"nextCursor,omitempty"`
}

ListToolsResult represents the response to a tools/list request

type LoggingServerCapabilities

type LoggingServerCapabilities struct {
}

LoggingServerCapabilities represents logging-specific server capabilities

type McpTool

type McpTool interface {
	GetName() string
	GetDescription() string
	GetDefinition() Tool
	GetHandler() ToolHandler
}

McpTool defines the interface for a typed MCP tool

type Message

type Message struct {
	JSONRPC string           `json:"jsonrpc"`
	ID      *ID              `json:"id,omitempty"`
	Method  string           `json:"method,omitempty"`
	Params  *json.RawMessage `json:"params,omitempty"`
	Result  *json.RawMessage `json:"result,omitempty"`
	Error   *ErrorResponse   `json:"error,omitempty"`
}

Message represents either a Request, Notification, or Response

func (*Message) UnmarshalResult

func (m *Message) UnmarshalResult(v interface{}) error

UnmarshalResult unmarshals the result into the provided interface

func (*Message) Validate

func (m *Message) Validate() error

Validate validates a Message according to the JSON-RPC 2.0 spec

type MessageContent

type MessageContent interface {
	// contains filtered or unexported methods
}

MessageContent is an interface that all content types must implement

type ModelHint

type ModelHint struct {
	Name string `json:"name,omitempty"`
}

ModelHint provides hints for model selection

type ModelPreferences

type ModelPreferences struct {
	// Optional hints for model selection
	Hints []ModelHint `json:"hints,omitempty"`

	// Priority values between 0 and 1
	CostPriority         float64 `json:"costPriority,omitempty"`
	SpeedPriority        float64 `json:"speedPriority,omitempty"`
	IntelligencePriority float64 `json:"intelligencePriority,omitempty"`
}

ModelPreferences represents server preferences for model selection

type Notification

type Notification struct {
	Method string            `json:"method"`
	Params *json.RawMessage  `json:"params,omitempty"`
	Meta   *NotificationMeta `json:"_meta,omitempty"`
}

Notification represents a base MCP notification

type NotificationMeta

type NotificationMeta map[string]interface{}

NotificationMeta contains metadata for notifications

type PaginatedRequest

type PaginatedRequest struct {
	Cursor *Cursor `json:"cursor,omitempty"`
}

PaginatedRequest represents a request that supports pagination

type PaginatedResult

type PaginatedResult struct {
	NextCursor *Cursor `json:"nextCursor,omitempty"`
}

PaginatedResult represents a paginated response

type ProgressToken

type ProgressToken interface{} // string or number

ProgressToken represents a token for tracking progress of long-running operations

type Prompt

type Prompt struct {
	// Name uniquely identifies the prompt
	Name string `json:"name"`

	// Optional description
	Description string `json:"description,omitempty"`

	// Optional arguments for templating
	Arguments []PromptArgument `json:"arguments,omitempty"`
}

Prompt represents a prompt or prompt template

type PromptArgument

type PromptArgument struct {
	// Name of the argument
	Name string `json:"name"`

	// Optional description
	Description string `json:"description,omitempty"`

	// Whether this argument is required
	Required bool `json:"required,omitempty"`
}

PromptArgument describes an argument a prompt can accept

type PromptListChangedNotification

type PromptListChangedNotification struct {
	Method string `json:"method"`
}

PromptListChangedNotification represents a notification that the prompt list has changed

type PromptMessage

type PromptMessage struct {
	Role    Role           `json:"role"`
	Content MessageContent `json:"content"`
}

PromptMessage represents a message in a prompt

func (PromptMessage) MarshalJSON

func (m PromptMessage) MarshalJSON() ([]byte, error)

MarshalJSON marshals a PromptMessage

func (*PromptMessage) UnmarshalJSON

func (m *PromptMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a PromptMessage

type PromptsServerCapabilities

type PromptsServerCapabilities struct {
	// Whether the server supports notifications for changes to the prompt list
	ListChanged bool `json:"listChanged,omitempty"`
}

PromptsServerCapabilities represents prompts-specific server capabilities

type ReadResourceRequest

type ReadResourceRequest struct {
	Method string `json:"method"`
	URI    string `json:"uri"`
}

ReadResourceRequest represents a request to read a specific resource

type ReadResourceResult

type ReadResourceResult struct {
	Contents []ResourceContent `json:"contents"` // Can be TextResourceContents or BlobResourceContents
}

ReadResourceResult represents the response to a resources/read request

func (*ReadResourceResult) UnmarshalJSON

func (r *ReadResourceResult) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for ReadResourceResult

type Request

type Request struct {
	Method string           `json:"method"`
	Params *json.RawMessage `json:"params,omitempty"`
	Meta   *RequestMeta     `json:"_meta,omitempty"`
}

Request represents a base MCP request

type RequestMeta

type RequestMeta struct {
	ProgressToken ProgressToken `json:"progressToken,omitempty"`
}

RequestMeta contains metadata for requests

type Resource

type Resource struct {
	// URI identifying this resource
	URI string `json:"uri"`

	// Human-readable name
	Name string `json:"name"`

	// Optional description
	Description string `json:"description,omitempty"`

	// Optional MIME type
	MimeType string `json:"mimeType,omitempty"`
}

Resource represents a known resource that the server can read

type ResourceContent

type ResourceContent interface {
	// contains filtered or unexported methods
}

ResourceContent is an interface each content struct implements.

type ResourceContents

type ResourceContents struct {
	// URI identifying this resource
	URI string `json:"uri"`

	// Optional MIME type
	MimeType string `json:"mimeType,omitempty"`
}

ResourceContents represents the contents of a specific resource

type ResourceListChangedNotification

type ResourceListChangedNotification struct {
	Method string `json:"method"`
}

ResourceListChangedNotification represents a notification that the resource list has changed

type ResourceTemplate

type ResourceTemplate struct {
	// URI template for constructing resource URIs
	URITemplate string `json:"uriTemplate"`

	// Human-readable name
	Name string `json:"name"`

	// Optional description
	Description string `json:"description,omitempty"`

	// Optional MIME type
	MimeType string `json:"mimeType,omitempty"`
}

ResourceTemplate represents a template for available resources

type ResourceUpdatedNotification

type ResourceUpdatedNotification struct {
	Method string `json:"method"`
	URI    string `json:"uri"`
}

ResourceUpdatedNotification represents a notification that a resource has been updated

type ResourcesServerCapabilities

type ResourcesServerCapabilities struct {
	// Whether the server supports subscribing to resource updates
	Subscribe bool `json:"subscribe,omitempty"`

	// Whether the server supports notifications for changes to the resource list
	ListChanged bool `json:"listChanged,omitempty"`
}

ResourcesServerCapabilities represents resources-specific server capabilities

type Result

type Result struct {
	Meta *ResultMeta `json:"_meta,omitempty"`
}

Result represents a base MCP result

type ResultMeta

type ResultMeta map[string]interface{}

ResultMeta contains metadata for results

type Role

type Role string

Role represents the sender or recipient in a conversation

const (
	// RoleUser represents a user in an LLM conversation
	RoleUser Role = "user"

	// RoleAssistant represents an LLM assistant in an LLM conversation
	RoleAssistant Role = "assistant"
)

type Root

type Root struct {
	// URI identifying the root. Must start with file:// for now
	URI string `json:"uri"`

	// Optional name for the root
	Name string `json:"name,omitempty"`
}

Root represents a root directory or file that the server can operate on

func (*Root) Validate

func (r *Root) Validate() error

Validate checks if the root follows spec requirements

type RootsClientCapabilities

type RootsClientCapabilities struct {
	// Whether the client supports notifications for changes to the roots list
	ListChanged bool `json:"listChanged,omitempty"`
}

RootsClientCapabilities represents roots-specific client capabilities

type RootsListChangedNotification

type RootsListChangedNotification struct {
	Method string `json:"method"`
}

RootsListChangedNotification represents a notification that the roots list has changed

type SamplingClientCapabilities

type SamplingClientCapabilities struct {
}

SamplingClientCapabilities represents sampling-specific client capabilities

type SamplingHandler

type SamplingHandler func(ctx context.Context, req *CreateMessageRequest) (*CreateMessageResult, error)

SamplingHandler is a function that handles a sampling request

type SamplingMessage

type SamplingMessage struct {
	Role    Role           `json:"role"`
	Content MessageContent `json:"content"` // Using the same MessageContent interface
}

SamplingMessage represents a message in a sampling request

func (SamplingMessage) MarshalJSON

func (m SamplingMessage) MarshalJSON() ([]byte, error)

MarshalJSON marshals a SamplingMessage

func (*SamplingMessage) UnmarshalJSON

func (m *SamplingMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a SamplingMessage

type ServerCapabilities

type ServerCapabilities struct {
	// Experimental features support
	Experimental map[string]interface{} `json:"experimental,omitempty"`

	// Logging capability
	Logging *LoggingServerCapabilities `json:"logging,omitempty"`

	// Prompts capability
	Prompts *PromptsServerCapabilities `json:"prompts,omitempty"`

	// Resources capability
	Resources *ResourcesServerCapabilities `json:"resources,omitempty"`

	// Tools capability
	Tools *ToolsServerCapabilities `json:"tools,omitempty"`
}

ServerCapabilities represents the capabilities a server supports

type SubscribeRequest

type SubscribeRequest struct {
	Method string `json:"method"`
	URI    string `json:"uri"`
}

SubscribeRequest represents a request to subscribe to resource changes

type TextContent

type TextContent struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

TextContent represents text provided to/from an LLM

type TextResourceContents

type TextResourceContents struct {
	ResourceContents
	Text string `json:"text"`
}

TextResourceContents represents text-based resource contents

type Tool

type Tool struct {
	// Name of the tool
	Name string `json:"name"`

	// Optional description
	Description string `json:"description,omitempty"`

	// JSON Schema defining expected parameters
	InputSchema ToolInputSchema `json:"inputSchema"`
}

Tool represents a tool that can be called by the client

type ToolHandler

type ToolHandler func(ctx context.Context, arguments map[string]interface{}) (*CallToolResult, error)

ToolHandler is a function that handles tool invocations

type ToolInputSchema

type ToolInputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	Required   []string               `json:"required,omitempty"`
}

ToolInputSchema represents the input schema for a tool

type ToolListChangedNotification

type ToolListChangedNotification struct {
	Method string `json:"method"`
}

ToolListChangedNotification represents a notification that the tool list has changed

type ToolsServerCapabilities

type ToolsServerCapabilities struct {
	// Whether the server supports notifications for changes to the tool list
	ListChanged bool `json:"listChanged,omitempty"`
}

ToolsServerCapabilities represents tools-specific server capabilities

type TypedTool

type TypedTool[T any] struct {
	// contains filtered or unexported fields
}

TypedTool is a generic implementation of McpTool

func NewTool

func NewTool[T any](name, description string, handler TypedToolHandler[T]) *TypedTool[T]

NewTool creates a new typed MCP tool

func (*TypedTool[T]) GetDefinition

func (t *TypedTool[T]) GetDefinition() Tool

func (*TypedTool[T]) GetDescription

func (t *TypedTool[T]) GetDescription() string

func (*TypedTool[T]) GetHandler

func (t *TypedTool[T]) GetHandler() ToolHandler

func (*TypedTool[T]) GetName

func (t *TypedTool[T]) GetName() string

type TypedToolHandler

type TypedToolHandler[T any] func(ctx context.Context, input T) (*CallToolResult, error)

TypedToolHandler is a function that processes a tool's input and returns a result

type UnsubscribeRequest

type UnsubscribeRequest struct {
	Method string `json:"method"`
	URI    string `json:"uri"`
}

UnsubscribeRequest represents a request to unsubscribe from resource changes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL