Documentation
¶
Index ¶
- type Annotations
- type BlobResourceContents
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, arguments any) (*ToolResponse, error)
- func (c *Client) GetCapabilities() *ServerCapabilities
- func (c *Client) GetPrompt(ctx context.Context, name string, arguments any) (*PromptResponse, error)
- func (c *Client) Initialize(ctx context.Context) (*InitializeResponse, error)
- func (c *Client) ListPrompts(ctx context.Context, cursor *string) (*ListPromptsResponse, error)
- func (c *Client) ListResources(ctx context.Context, cursor *string) (*ListResourcesResponse, error)
- func (c *Client) ListTools(ctx context.Context, cursor *string) (*ToolsResponse, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) ReadResource(ctx context.Context, uri string) (*ResourceResponse, error)
- type ClientInfo
- type Content
- type ContentType
- type EmbeddedResource
- type ImageContent
- type InitializeResponse
- type ListPromptsResponse
- type ListResourceTemplatesResponse
- type ListResourcesResponse
- type PromptMessage
- type PromptResponse
- type PromptSchema
- type PromptSchemaArgument
- type ResourceResponse
- type ResourceSchema
- type ResourceTemplateSchema
- type Role
- type Server
- func (s *Server) CheckPromptRegistered(name string) bool
- func (s *Server) CheckResourceRegistered(uri string) bool
- func (s *Server) CheckResourceTemplateRegistered(uriTemplate string) bool
- func (s *Server) CheckToolRegistered(name string) bool
- func (s *Server) DeregisterPrompt(name string) error
- func (s *Server) DeregisterResource(uri string) error
- func (s *Server) DeregisterResourceTemplate(uriTemplate string) error
- func (s *Server) DeregisterTool(name string) error
- func (s *Server) RegisterPrompt(name string, description string, handler any) error
- func (s *Server) RegisterResource(uri string, name string, description string, mimeType string, handler any) error
- func (s *Server) RegisterResourceTemplate(uriTemplate string, name string, description string, mimeType string) error
- func (s *Server) RegisterTool(name string, description string, handler any) error
- func (s *Server) Serve() error
- type ServerCapabilities
- type ServerCapabilitiesExperimental
- type ServerCapabilitiesLogging
- type ServerCapabilitiesPrompts
- type ServerCapabilitiesResources
- type ServerCapabilitiesTools
- type ServerOptions
- type TextContent
- type TextResourceContents
- type ToolResponse
- type ToolRetType
- type ToolsResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotations ¶
type Annotations struct { // Describes who the intended customer of this object or data is. // // It can include multiple entries to indicate ToolResponse useful for multiple // audiences (e.g., `["user", "assistant"]`). Audience []Role `json:"audience,omitempty" yaml:"audience,omitempty" mapstructure:"audience,omitempty"` // Describes how important this data is for operating the server. // // A value of 1 means "most important," and indicates that the data is // effectively required, while 0 means "least important," and indicates that // the data is entirely optional. Priority *float64 `json:"priority,omitempty" yaml:"priority,omitempty" mapstructure:"priority,omitempty"` }
type BlobResourceContents ¶
type BlobResourceContents struct { // A base64-encoded string representing the binary data of the item. Blob string `json:"blob" yaml:"blob" mapstructure:"blob"` // The MIME type of this resource, if known. MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"` // The URI of this resource. Uri string `json:"uri" yaml:"uri" mapstructure:"uri"` }
type Client ¶ added in v0.5.0
type Client struct {
// contains filtered or unexported fields
}
Client represents an MCP client that can connect to and interact with MCP servers
func NewClientWithInfo ¶ added in v0.9.0
func NewClientWithInfo(transport transport.Transport, info ClientInfo) *Client
NewClientWithInfo create a new client with info. This is required by anthorpic mcp tools
func (*Client) CallTool ¶ added in v0.5.0
CallTool calls a specific tool on the server with the provided arguments
func (*Client) GetCapabilities ¶ added in v0.5.0
func (c *Client) GetCapabilities() *ServerCapabilities
GetCapabilities returns the server capabilities obtained during initialization
func (*Client) GetPrompt ¶ added in v0.5.0
func (c *Client) GetPrompt(ctx context.Context, name string, arguments any) (*PromptResponse, error)
GetPrompt retrieves a specific prompt from the server
func (*Client) Initialize ¶ added in v0.5.0
func (c *Client) Initialize(ctx context.Context) (*InitializeResponse, error)
Initialize connects to the server and retrieves its capabilities
func (*Client) ListPrompts ¶ added in v0.5.0
ListPrompts retrieves the list of available prompts from the server
func (*Client) ListResources ¶ added in v0.5.0
ListResources retrieves the list of available resources from the server
func (*Client) ListTools ¶ added in v0.5.0
ListTools retrieves the list of available tools from the server
func (*Client) ReadResource ¶ added in v0.5.0
ReadResource reads a specific resource from the server
type ClientInfo ¶ added in v0.9.0
type Content ¶
type Content struct { Type ContentType TextContent *TextContent ImageContent *ImageContent EmbeddedResource *EmbeddedResource Annotations *Annotations }
func NewBlobResourceContent ¶
NewBlobResourceContent creates a new ToolResponse that is a blob of binary data. The given data is base64-encoded; the client will decode it. The client will render this as a blob; it will not be human-readable.
func NewImageContent ¶
NewImageContent creates a new ToolResponse that is an image. The given data is base64-encoded
func NewTextContent ¶
NewTextContent creates a new ToolResponse that is a simple text string. The client will render this as a single string.
func NewTextResourceContent ¶
NewTextResourceContent creates a new ToolResponse that is an embedded resource of type "text". The given text is embedded in the response as a TextResourceContents, which contains the given MIME type and URI. The text is not base64-encoded.
func (Content) MarshalJSON ¶
Custom JSON marshaling for ToolResponse Content
func (*Content) UnmarshalJSON ¶ added in v0.5.0
func (*Content) WithAnnotations ¶
func (c *Content) WithAnnotations(annotations Annotations) *Content
type ContentType ¶
type ContentType string
const ( // The value is the value of the "type" field in the Content so do not change ContentTypeText ContentType = "text" ContentTypeImage ContentType = "image" ContentTypeEmbeddedResource ContentType = "resource" )
type EmbeddedResource ¶
type EmbeddedResource struct { EmbeddedResourceType embeddedResourceType TextResourceContents *TextResourceContents BlobResourceContents *BlobResourceContents }
The contents of a resource, embedded into a prompt or tool call result.
It is up to the client how best to render embedded resources for the benefit of the LLM and/or the user.
func NewBlobEmbeddedResource ¶
func NewBlobEmbeddedResource(uri string, base64EncodedData string, mimeType string) *EmbeddedResource
func NewTextEmbeddedResource ¶
func NewTextEmbeddedResource(uri string, text string, mimeType string) *EmbeddedResource
func (EmbeddedResource) MarshalJSON ¶
func (c EmbeddedResource) MarshalJSON() ([]byte, error)
Custom JSON marshaling for EmbeddedResource
func (*EmbeddedResource) UnmarshalJSON ¶ added in v0.13.0
func (c *EmbeddedResource) UnmarshalJSON(data []byte) error
Custom JSON unmarshaling for EmbeddedResource
type ImageContent ¶
type ImageContent struct { // The base64-encoded image data. Data string `json:"data" yaml:"data" mapstructure:"data"` // The MIME type of the image. Different providers may support different image // types. MimeType string `json:"mimeType" yaml:"mimeType" mapstructure:"mimeType"` }
An image provided to or from an LLM.
type InitializeResponse ¶ added in v0.5.0
type InitializeResponse struct { // This result property is reserved by the protocol to allow clients and servers // to attach additional metadata to their responses. Meta initializeResultMeta `json:"_meta,omitempty" yaml:"_meta,omitempty" mapstructure:"_meta,omitempty"` // Capabilities corresponds to the JSON schema field "capabilities". Capabilities ServerCapabilities `json:"capabilities" yaml:"capabilities" mapstructure:"capabilities"` // Instructions describing how to use the server and its features. // // This can be used by clients to improve the LLM's understanding of available // tools, resources, etc. It can be thought of like a "hint" to the model. For // example, this information MAY be added to the system prompt. Instructions *string `json:"instructions,omitempty" yaml:"instructions,omitempty" mapstructure:"instructions,omitempty"` // The version of the Model Context Protocol that the server wants to use. This // may not match the version that the client requested. If the client cannot // support this version, it MUST disconnect. ProtocolVersion string `json:"protocolVersion" yaml:"protocolVersion" mapstructure:"protocolVersion"` // ServerInfo corresponds to the JSON schema field "serverInfo". ServerInfo implementation `json:"serverInfo" yaml:"serverInfo" mapstructure:"serverInfo"` }
After receiving an initialize request from the client, the server sends this response.
func (*InitializeResponse) UnmarshalJSON ¶ added in v0.5.0
func (j *InitializeResponse) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type ListPromptsResponse ¶ added in v0.5.0
type ListPromptsResponse struct { // Prompts corresponds to the JSON schema field "prompts". Prompts []*PromptSchema `json:"prompts" yaml:"prompts" mapstructure:"prompts"` // NextCursor is a cursor for pagination. If not nil, there are more prompts available. NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"` }
The server's response to a prompts/list request from the client.
type ListResourceTemplatesResponse ¶ added in v0.10.0
type ListResourceTemplatesResponse struct { // Templates corresponds to the JSON schema field "templates". Templates []*ResourceTemplateSchema `json:"resourceTemplates" yaml:"resourceTemplates" mapstructure:"resourceTemplates"` // NextCursor is a cursor for pagination. If not nil, there are more templates available. NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"` }
The server's response to a resources/templates/list request from the client.
type ListResourcesResponse ¶ added in v0.5.0
type ListResourcesResponse struct { // Resources corresponds to the JSON schema field "resources". Resources []*ResourceSchema `json:"resources" yaml:"resources" mapstructure:"resources"` // NextCursor is a cursor for pagination. If not nil, there are more resources available. NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"` }
The server's response to a resources/list request from the client.
type PromptMessage ¶
type PromptMessage struct { Content *Content `json:"content" yaml:"content" mapstructure:"content"` Role Role `json:"role" yaml:"role" mapstructure:"role"` }
func NewPromptMessage ¶
func NewPromptMessage(content *Content, role Role) *PromptMessage
type PromptResponse ¶
type PromptResponse struct { // An optional description for the prompt. Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` // Messages corresponds to the JSON schema field "messages". Messages []*PromptMessage `json:"messages" yaml:"messages" mapstructure:"messages"` }
The server's response to a prompts/get request from the client.
func NewPromptResponse ¶
func NewPromptResponse(description string, messages ...*PromptMessage) *PromptResponse
type PromptSchema ¶ added in v0.5.0
type PromptSchema struct { // A list of arguments to use for templating the prompt. Arguments []PromptSchemaArgument `json:"arguments,omitempty" yaml:"arguments,omitempty" mapstructure:"arguments,omitempty"` // An optional description of what this prompt provides Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` // The name of the prompt or prompt template. Name string `json:"name" yaml:"name" mapstructure:"name"` }
A PromptSchema or prompt template that the server offers.
type PromptSchemaArgument ¶ added in v0.5.0
type PromptSchemaArgument struct { // A human-readable description of the argument. Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` // The name of the argument. Name string `json:"name" yaml:"name" mapstructure:"name"` // Whether this argument must be provided. Required *bool `json:"required,omitempty" yaml:"required,omitempty" mapstructure:"required,omitempty"` }
type ResourceResponse ¶
type ResourceResponse struct {
Contents []*EmbeddedResource `json:"contents"`
}
func NewResourceResponse ¶
func NewResourceResponse(contents ...*EmbeddedResource) *ResourceResponse
type ResourceSchema ¶ added in v0.5.0
type ResourceSchema struct { // Annotations corresponds to the JSON schema field "annotations". Annotations *Annotations `json:"annotations,omitempty" yaml:"annotations,omitempty" mapstructure:"annotations,omitempty"` // A description of what this resource represents. // // This can be used by clients to improve the LLM's understanding of available // resources. It can be thought of like a "hint" to the model. Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` // The MIME type of this resource, if known. MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"` // A human-readable name for this resource. // // This can be used by clients to populate UI elements. Name string `json:"name" yaml:"name" mapstructure:"name"` // The URI of this resource. Uri string `json:"uri" yaml:"uri" mapstructure:"uri"` }
A known resource that the server is capable of reading.
type ResourceTemplateSchema ¶ added in v0.10.0
type ResourceTemplateSchema struct { // Annotations corresponds to the JSON schema field "annotations". Annotations *Annotations `json:"annotations,omitempty" yaml:"annotations,omitempty" mapstructure:"annotations,omitempty"` // A description of what resources matching this template represent. Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` // The MIME type of resources matching this template, if known. MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"` // A human-readable name for this template. Name string `json:"name" yaml:"name" mapstructure:"name"` // The URI template following RFC 6570. UriTemplate string `json:"uriTemplate" yaml:"uriTemplate" mapstructure:"uriTemplate"` }
A resource template that defines a pattern for dynamic resources.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) CheckPromptRegistered ¶ added in v0.2.0
func (*Server) CheckResourceRegistered ¶ added in v0.2.0
func (*Server) CheckResourceTemplateRegistered ¶ added in v0.10.0
func (*Server) CheckToolRegistered ¶ added in v0.2.0
func (*Server) DeregisterPrompt ¶ added in v0.2.0
func (*Server) DeregisterResource ¶ added in v0.2.0
func (*Server) DeregisterResourceTemplate ¶ added in v0.10.0
func (*Server) DeregisterTool ¶ added in v0.2.0
func (*Server) RegisterPrompt ¶
func (*Server) RegisterResource ¶
func (*Server) RegisterResourceTemplate ¶ added in v0.10.0
func (*Server) RegisterTool ¶
RegisterTool registers a new tool with the server
type ServerCapabilities ¶ added in v0.5.0
type ServerCapabilities struct { // Experimental, non-standard capabilities that the server supports. Experimental ServerCapabilitiesExperimental `json:"experimental,omitempty" yaml:"experimental,omitempty" mapstructure:"experimental,omitempty"` // Present if the server supports sending log messages to the client. Logging ServerCapabilitiesLogging `json:"logging,omitempty" yaml:"logging,omitempty" mapstructure:"logging,omitempty"` // Present if the server offers any prompt templates. Prompts *ServerCapabilitiesPrompts `json:"prompts,omitempty" yaml:"prompts,omitempty" mapstructure:"prompts,omitempty"` // Present if the server offers any resources to read. Resources *ServerCapabilitiesResources `json:"resources,omitempty" yaml:"resources,omitempty" mapstructure:"resources,omitempty"` // Present if the server offers any tools to call. Tools *ServerCapabilitiesTools `json:"tools,omitempty" yaml:"tools,omitempty" mapstructure:"tools,omitempty"` }
Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
type ServerCapabilitiesExperimental ¶ added in v0.5.0
Experimental, non-standard capabilities that the server supports.
type ServerCapabilitiesLogging ¶ added in v0.5.0
type ServerCapabilitiesLogging map[string]interface{}
Present if the server supports sending log messages to the client.
type ServerCapabilitiesPrompts ¶ added in v0.5.0
type ServerCapabilitiesPrompts struct { // Whether this server supports notifications for changes to the prompt list. ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"` }
Present if the server offers any prompt templates.
type ServerCapabilitiesResources ¶ added in v0.5.0
type ServerCapabilitiesResources struct { // Whether this server supports notifications for changes to the resource list. ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"` // Whether this server supports subscribing to resource updates. Subscribe *bool `json:"subscribe,omitempty" yaml:"subscribe,omitempty" mapstructure:"subscribe,omitempty"` }
Present if the server offers any resources to read.
type ServerCapabilitiesTools ¶ added in v0.5.0
type ServerCapabilitiesTools struct { // Whether this server supports notifications for changes to the tool list. ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"` }
Present if the server offers any tools to call.
type ServerOptions ¶ added in v0.3.0
type ServerOptions func(*Server)
func WithInstructions ¶ added in v0.12.0
func WithInstructions(instructions string) ServerOptions
func WithName ¶ added in v0.6.0
func WithName(name string) ServerOptions
func WithPaginationLimit ¶ added in v0.3.0
func WithPaginationLimit(limit int) ServerOptions
Beware: As of 2024-12-13, it looks like Claude does not support pagination yet
func WithProtocol ¶ added in v0.3.0
func WithProtocol(protocol *protocol.Protocol) ServerOptions
func WithVersion ¶ added in v0.6.0
func WithVersion(version string) ServerOptions
type TextContent ¶
type TextContent struct { // The text ToolResponse of the message. Text string `json:"text" yaml:"text" mapstructure:"text"` }
Text provided to or from an LLM.
type TextResourceContents ¶
type TextResourceContents struct { // The MIME type of this resource, if known. MimeType *string `json:"mimeType,omitempty" yaml:"mimeType,omitempty" mapstructure:"mimeType,omitempty"` // The text of the item. This must only be set if the item can actually be // represented as text (not binary data). Text string `json:"text" yaml:"text" mapstructure:"text"` // The URI of this resource. Uri string `json:"uri" yaml:"uri" mapstructure:"uri"` }
type ToolResponse ¶
type ToolResponse struct {
Content []*Content `json:"content" yaml:"content" mapstructure:"content"`
}
This is a union type of all the different ToolResponse that can be sent back to the client. We allow creation through constructors only to make sure that the ToolResponse is valid.
func NewToolResponse ¶ added in v0.2.0
func NewToolResponse(content ...*Content) *ToolResponse
type ToolRetType ¶ added in v0.8.0
type ToolRetType struct { // A human-readable description of the tool. Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"` // A JSON Schema object defining the expected parameters for the tool. InputSchema interface{} `json:"inputSchema" yaml:"inputSchema" mapstructure:"inputSchema"` // The name of the tool. Name string `json:"name" yaml:"name" mapstructure:"name"` }
Definition for a tool the client can call.
type ToolsResponse ¶ added in v0.8.0
type ToolsResponse struct { Tools []ToolRetType `json:"tools" yaml:"tools" mapstructure:"tools"` NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"` }
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
internal
|
|
protocol
This file implements the core protocol layer for JSON-RPC communication in the MCP SDK.
|
This file implements the core protocol layer for JSON-RPC communication in the MCP SDK. |
sse/internal/sse
/* Package mcp implements Server-Sent Events (SSE) transport for JSON-RPC communication.
|
/* Package mcp implements Server-Sent Events (SSE) transport for JSON-RPC communication. |
stdio/internal/stdio
This file implements the stdio transport layer for JSON-RPC communication.
|
This file implements the stdio transport layer for JSON-RPC communication. |