Documentation
¶
Index ¶
- type Annotations
- type BlobResourceContents
- type Content
- type ContentType
- type EmbeddedResource
- type ImageContent
- type PromptMessage
- type PromptResponse
- type ResourceResponse
- type Role
- type Server
- func (s *Server) CheckPromptRegistered(name string) bool
- func (s *Server) CheckResourceRegistered(uri 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) 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) RegisterTool(name string, description string, handler any) error
- func (s *Server) Serve() error
- type ServerOptions
- type TextContent
- type TextResourceContents
- type ToolResponse
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 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) 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
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 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 ResourceResponse ¶
type ResourceResponse struct {
Contents []*EmbeddedResource `json:"contents"`
}
func NewResourceResponse ¶
func NewResourceResponse(contents ...*EmbeddedResource) *ResourceResponse
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) CheckToolRegistered ¶ added in v0.2.0
func (*Server) DeregisterPrompt ¶ added in v0.2.0
func (*Server) DeregisterResource ¶ added in v0.2.0
func (*Server) DeregisterTool ¶ added in v0.2.0
func (*Server) RegisterPrompt ¶
func (*Server) RegisterResource ¶
func (*Server) RegisterTool ¶
RegisterTool registers a new tool with the server
type ServerOptions ¶ added in v0.3.0
type ServerOptions func(*Server)
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
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
}
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
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
basic_tool_server
command
|
|
get_weather_tool_server
command
|
|
pagination_example
command
|
|
readme_server
command
|
|
simple_tool_docs
command
|
|
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. |