Documentation
¶
Overview ¶
Package mcp defines the core types and interfaces for the Model Context Protocol (MCP). MCP is a protocol for communication between LLM-powered applications and their supporting services.
Index ¶
- Constants
- func ExtractMap(data map[string]any, key string) map[string]any
- func ExtractString(data map[string]any, key string) string
- func ParseArgument(request CallToolRequest, key string, defaultVal any) any
- func ParseBoolean(request CallToolRequest, key string, defaultValue bool) bool
- func ParseFloat32(request CallToolRequest, key string, defaultValue float32) float32
- func ParseFloat64(request CallToolRequest, key string, defaultValue float64) float64
- func ParseInt(request CallToolRequest, key string, defaultValue int) int
- func ParseInt16(request CallToolRequest, key string, defaultValue int16) int16
- func ParseInt32(request CallToolRequest, key string, defaultValue int32) int32
- func ParseInt64(request CallToolRequest, key string, defaultValue int64) int64
- func ParseInt8(request CallToolRequest, key string, defaultValue int8) int8
- func ParseString(request CallToolRequest, key string, defaultValue string) string
- func ParseStringMap(request CallToolRequest, key string, defaultValue map[string]any) map[string]any
- func ParseUInt(request CallToolRequest, key string, defaultValue uint) uint
- func ParseUInt16(request CallToolRequest, key string, defaultValue uint16) uint16
- func ParseUInt32(request CallToolRequest, key string, defaultValue uint32) uint32
- func ParseUInt64(request CallToolRequest, key string, defaultValue uint64) uint64
- func ParseUInt8(request CallToolRequest, key string, defaultValue uint8) uint8
- type Annotated
- type Annotations
- type ArgumentOption
- type BlobResourceContents
- type CallToolRequest
- type CallToolResult
- func FormatNumberResult(value float64) *CallToolResult
- func NewToolResultError(text string) *CallToolResult
- func NewToolResultErrorFromErr(text string, err error) *CallToolResult
- func NewToolResultImage(text, imageData, mimeType string) *CallToolResult
- func NewToolResultResource(text string, resource ResourceContents) *CallToolResult
- func NewToolResultText(text string) *CallToolResult
- func ParseCallToolResult(rawMessage *json.RawMessage) (*CallToolResult, error)
- type CancelledNotification
- type ClientCapabilities
- type ClientNotification
- type ClientRequest
- type ClientResult
- type CompleteRequest
- type CompleteResult
- type Content
- type CreateMessageRequest
- type CreateMessageResult
- type Cursor
- type EmbeddedResource
- type EmptyResult
- type GetPromptRequest
- type GetPromptResult
- type ImageContent
- type Implementation
- type InitializeRequest
- type InitializeResult
- type InitializedNotification
- type JSONRPCError
- type JSONRPCMessage
- type JSONRPCNotification
- type JSONRPCRequest
- type JSONRPCResponse
- type ListPromptsRequest
- type ListPromptsResult
- type ListResourceTemplatesRequest
- type ListResourceTemplatesResult
- type ListResourcesRequest
- type ListResourcesResult
- type ListRootsRequest
- type ListRootsResult
- type ListToolsRequest
- type ListToolsResult
- type LoggingLevel
- type LoggingMessageNotification
- type MCPMethod
- type ModelHint
- type ModelPreferences
- type Notification
- type NotificationParams
- type PaginatedRequest
- type PaginatedResult
- type Params
- type PingRequest
- type ProgressNotification
- type ProgressToken
- type Prompt
- type PromptArgument
- type PromptListChangedNotification
- type PromptMessage
- type PromptOption
- type PromptReference
- type PropertyOption
- func AdditionalProperties(schema interface{}) PropertyOption
- func DefaultArray[T any](value []T) PropertyOption
- func DefaultBool(value bool) PropertyOption
- func DefaultNumber(value float64) PropertyOption
- func DefaultString(value string) PropertyOption
- func Description(desc string) PropertyOption
- func Enum(values ...string) PropertyOption
- func Items(schema interface{}) PropertyOption
- func Max(max float64) PropertyOption
- func MaxItems(max int) PropertyOption
- func MaxLength(max int) PropertyOption
- func MaxProperties(max int) PropertyOption
- func Min(min float64) PropertyOption
- func MinItems(min int) PropertyOption
- func MinLength(min int) PropertyOption
- func MinProperties(min int) PropertyOption
- func MultipleOf(value float64) PropertyOption
- func Pattern(pattern string) PropertyOption
- func Properties(props map[string]interface{}) PropertyOption
- func PropertyNames(schema map[string]interface{}) PropertyOption
- func Required() PropertyOption
- func Title(title string) PropertyOption
- func UniqueItems(unique bool) PropertyOption
- type ReadResourceRequest
- type ReadResourceResult
- type Request
- type RequestId
- type Resource
- type ResourceContents
- type ResourceListChangedNotification
- type ResourceOption
- type ResourceReference
- type ResourceTemplate
- type ResourceTemplateOption
- type ResourceUpdatedNotification
- type Result
- type Role
- type Root
- type RootsListChangedNotification
- type SamplingMessage
- type ServerCapabilities
- type ServerNotification
- type ServerRequest
- type ServerResult
- type SetLevelRequest
- type SubscribeRequest
- type TextContent
- type TextResourceContents
- type Tool
- type ToolAnnotation
- type ToolInputSchema
- type ToolListChangedNotification
- type ToolOption
- func WithArray(name string, opts ...PropertyOption) ToolOption
- func WithBoolean(name string, opts ...PropertyOption) ToolOption
- func WithDescription(description string) ToolOption
- func WithNumber(name string, opts ...PropertyOption) ToolOption
- func WithObject(name string, opts ...PropertyOption) ToolOption
- func WithString(name string, opts ...PropertyOption) ToolOption
- func WithToolAnnotation(annotation ToolAnnotation) ToolOption
- type URITemplate
- type UnsubscribeRequest
Constants ¶
const ( PARSE_ERROR = -32700 INVALID_REQUEST = -32600 METHOD_NOT_FOUND = -32601 INVALID_PARAMS = -32602 INTERNAL_ERROR = -32603 )
Standard JSON-RPC error codes
const JSONRPC_VERSION = "2.0"
JSONRPC_VERSION is the version of JSON-RPC used by MCP.
const LATEST_PROTOCOL_VERSION = "2024-11-05"
LATEST_PROTOCOL_VERSION is the most recent version of the MCP protocol.
const (
RESOURCE_NOT_FOUND = -32002
)
MCP error codes
Variables ¶
This section is empty.
Functions ¶
func ParseArgument ¶ added in v0.22.0
func ParseArgument(request CallToolRequest, key string, defaultVal any) any
func ParseBoolean ¶ added in v0.22.0
func ParseBoolean(request CallToolRequest, key string, defaultValue bool) bool
ParseBoolean extracts and converts a boolean parameter from a CallToolRequest. If the key is not found in the Arguments map, the defaultValue is returned. The function uses cast.ToBool for conversion which handles various string representations such as "true", "yes", "1", etc.
func ParseFloat32 ¶ added in v0.22.0
func ParseFloat32(request CallToolRequest, key string, defaultValue float32) float32
ParseFloat32 extracts and converts a float32 parameter from a CallToolRequest.
func ParseFloat64 ¶ added in v0.22.0
func ParseFloat64(request CallToolRequest, key string, defaultValue float64) float64
ParseFloat64 extracts and converts a float64 parameter from a CallToolRequest.
func ParseInt ¶ added in v0.22.0
func ParseInt(request CallToolRequest, key string, defaultValue int) int
ParseInt extracts and converts an int parameter from a CallToolRequest.
func ParseInt16 ¶ added in v0.22.0
func ParseInt16(request CallToolRequest, key string, defaultValue int16) int16
ParseInt16 extracts and converts an int16 parameter from a CallToolRequest.
func ParseInt32 ¶ added in v0.22.0
func ParseInt32(request CallToolRequest, key string, defaultValue int32) int32
ParseInt32 extracts and converts an int32 parameter from a CallToolRequest.
func ParseInt64 ¶ added in v0.22.0
func ParseInt64(request CallToolRequest, key string, defaultValue int64) int64
ParseInt64 extracts and converts an int64 parameter from a CallToolRequest. If the key is not found in the Arguments map, the defaultValue is returned.
func ParseInt8 ¶ added in v0.22.0
func ParseInt8(request CallToolRequest, key string, defaultValue int8) int8
ParseInt8 extracts and converts an int8 parameter from a CallToolRequest.
func ParseString ¶ added in v0.22.0
func ParseString(request CallToolRequest, key string, defaultValue string) string
ParseString extracts and converts a string parameter from a CallToolRequest.
func ParseStringMap ¶ added in v0.22.0
func ParseStringMap(request CallToolRequest, key string, defaultValue map[string]any) map[string]any
ParseStringMap extracts and converts a string map parameter from a CallToolRequest.
func ParseUInt ¶ added in v0.22.0
func ParseUInt(request CallToolRequest, key string, defaultValue uint) uint
ParseUInt extracts and converts an uint parameter from a CallToolRequest.
func ParseUInt16 ¶ added in v0.22.0
func ParseUInt16(request CallToolRequest, key string, defaultValue uint16) uint16
ParseUInt16 extracts and converts an uint16 parameter from a CallToolRequest.
func ParseUInt32 ¶ added in v0.22.0
func ParseUInt32(request CallToolRequest, key string, defaultValue uint32) uint32
ParseUInt32 extracts and converts an uint32 parameter from a CallToolRequest.
func ParseUInt64 ¶ added in v0.22.0
func ParseUInt64(request CallToolRequest, key string, defaultValue uint64) uint64
ParseUInt64 extracts and converts an uint64 parameter from a CallToolRequest.
func ParseUInt8 ¶ added in v0.22.0
func ParseUInt8(request CallToolRequest, key string, defaultValue uint8) uint8
ParseUInt8 extracts and converts an uint8 parameter from a CallToolRequest.
Types ¶
type Annotated ¶ added in v0.4.0
type Annotated struct {
Annotations *Annotations `json:"annotations,omitempty"`
}
Annotated is the base for objects that include optional annotations for the client. The client can use annotations to inform how objects are used or displayed
type Annotations ¶
type Annotations struct { // Describes who the intended customer of this object or data is. // // It can include multiple entries to indicate content useful for multiple // audiences (e.g., `["user", "assistant"]`). Audience []Role `json:"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"` }
type ArgumentOption ¶ added in v0.5.10
type ArgumentOption func(*PromptArgument)
ArgumentOption is a function that configures a PromptArgument. It allows for flexible configuration of prompt arguments using the functional options pattern.
func ArgumentDescription ¶ added in v0.5.10
func ArgumentDescription(desc string) ArgumentOption
ArgumentDescription adds a description to a prompt argument. The description should explain the purpose and expected values of the argument.
func RequiredArgument ¶ added in v0.5.10
func RequiredArgument() ArgumentOption
RequiredArgument marks an argument as required in the prompt. Required arguments must be provided when getting the prompt.
type BlobResourceContents ¶
type BlobResourceContents struct { // The URI of this resource. URI string `json:"uri"` // The MIME type of this resource, if known. MIMEType string `json:"mimeType,omitempty"` // A base64-encoded string representing the binary data of the item. Blob string `json:"blob"` }
func AsBlobResourceContents ¶ added in v0.5.0
func AsBlobResourceContents(content interface{}) (*BlobResourceContents, bool)
AsBlobResourceContents attempts to cast the given interface to BlobResourceContents
type CallToolRequest ¶ added in v0.4.0
type CallToolRequest struct { Request Params struct { Name string `json:"name"` Arguments map[string]interface{} `json:"arguments,omitempty"` Meta *struct { // If specified, the caller is requesting out-of-band progress // notifications for this request (as represented by // notifications/progress). The value of this parameter is an // opaque token that will be attached to any subsequent // notifications. The receiver is not obligated to provide these // notifications. ProgressToken ProgressToken `json:"progressToken,omitempty"` } `json:"_meta,omitempty"` } `json:"params"` }
CallToolRequest is used by the client to invoke a tool provided by the server.
type CallToolResult ¶
type CallToolResult struct { Result Content []Content `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource // Whether the tool call ended in an error. // // If not set, this is assumed to be false (the call was successful). IsError bool `json:"isError,omitempty"` }
CallToolResult is the server's response to a tool call.
Any errors that originate from the tool SHOULD be reported inside the result object, with `isError` set to true, _not_ as an MCP protocol-level error response. Otherwise, the LLM would not be able to see that an error occurred and self-correct.
However, any errors in _finding_ the tool, an error indicating that the server does not support tool calls, or any other exceptional conditions, should be reported as an MCP error response.
func FormatNumberResult ¶ added in v0.5.1
func FormatNumberResult(value float64) *CallToolResult
FormatNumberResult Helper for formatting numbers in tool results
func NewToolResultError ¶ added in v0.5.1
func NewToolResultError(text string) *CallToolResult
NewToolResultError creates a new CallToolResult with an error message. Any errors that originate from the tool SHOULD be reported inside the result object.
func NewToolResultErrorFromErr ¶ added in v0.21.0
func NewToolResultErrorFromErr(text string, err error) *CallToolResult
NewToolResultErrorFromErr creates a new CallToolResult with an error message. If an error is provided, its details will be appended to the text message. Any errors that originate from the tool SHOULD be reported inside the result object.
func NewToolResultImage ¶ added in v0.5.1
func NewToolResultImage(text, imageData, mimeType string) *CallToolResult
NewToolResultImage creates a new CallToolResult with both text and image content
func NewToolResultResource ¶ added in v0.5.1
func NewToolResultResource( text string, resource ResourceContents, ) *CallToolResult
NewToolResultResource creates a new CallToolResult with an embedded resource
func NewToolResultText ¶ added in v0.5.1
func NewToolResultText(text string) *CallToolResult
NewToolResultText creates a new CallToolResult with a text content
func ParseCallToolResult ¶ added in v0.9.0
func ParseCallToolResult(rawMessage *json.RawMessage) (*CallToolResult, error)
type CancelledNotification ¶ added in v0.4.0
type CancelledNotification struct { Notification Params struct { // The ID of the request to cancel. // // This MUST correspond to the ID of a request previously issued // in the same direction. RequestId RequestId `json:"requestId"` // An optional string describing the reason for the cancellation. This MAY // be logged or presented to the user. Reason string `json:"reason,omitempty"` } `json:"params"` }
CancelledNotification can be sent by either side to indicate that it is cancelling a previously-issued request.
The request SHOULD still be in-flight, but due to communication latency, it is always possible that this notification MAY arrive after the request has already finished.
This notification indicates that the result will be unused, so any associated processing SHOULD cease.
A client MUST NOT attempt to cancel its `initialize` request.
type ClientCapabilities ¶
type ClientCapabilities struct { // Experimental, non-standard capabilities that the client supports. Experimental map[string]interface{} `json:"experimental,omitempty"` // Present if the client supports listing roots. Roots *struct { // Whether the client supports notifications for changes to the roots list. ListChanged bool `json:"listChanged,omitempty"` } `json:"roots,omitempty"` // Present if the client supports sampling from an LLM. Sampling *struct{} `json:"sampling,omitempty"` }
ClientCapabilities represents capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
type ClientNotification ¶ added in v0.4.0
type ClientNotification interface{}
ClientNotification represents any notification that can be sent from client to server.
type ClientRequest ¶ added in v0.4.0
type ClientRequest interface{}
ClientRequest represents any request that can be sent from client to server.
type ClientResult ¶ added in v0.4.0
type ClientResult interface{}
ClientResult represents any result that can be sent from client to server.
type CompleteRequest ¶ added in v0.4.0
type CompleteRequest struct { Request Params struct { Ref interface{} `json:"ref"` // Can be PromptReference or ResourceReference Argument struct { // The name of the argument Name string `json:"name"` // The value of the argument to use for completion matching. Value string `json:"value"` } `json:"argument"` } `json:"params"` }
CompleteRequest is a request from the client to the server, to ask for completion options.
type CompleteResult ¶
type CompleteResult struct { Result Completion struct { // An array of completion values. Must not exceed 100 items. Values []string `json:"values"` // The total number of completion options available. This can exceed the // number of values actually sent in the response. Total int `json:"total,omitempty"` // Indicates whether there are additional completion options beyond those // provided in the current response, even if the exact total is unknown. HasMore bool `json:"hasMore,omitempty"` } `json:"completion"` }
CompleteResult is the server's response to a completion/complete request
type CreateMessageRequest ¶ added in v0.4.0
type CreateMessageRequest struct { Request Params struct { 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"` } `json:"params"` }
CreateMessageRequest is a request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
type CreateMessageResult ¶ added in v0.4.0
type CreateMessageResult struct { Result SamplingMessage // The name of the model that generated the message. Model string `json:"model"` // The reason why sampling stopped, if known. StopReason string `json:"stopReason,omitempty"` }
CreateMessageResult is the client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
type Cursor ¶ added in v0.4.0
type Cursor string
Cursor is an opaque token used to represent a cursor for pagination.
type EmbeddedResource ¶
type EmbeddedResource struct { Annotated Type string `json:"type"` Resource ResourceContents `json:"resource"` }
EmbeddedResource represents 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 AsEmbeddedResource ¶ added in v0.5.0
func AsEmbeddedResource(content interface{}) (*EmbeddedResource, bool)
AsEmbeddedResource attempts to cast the given interface to EmbeddedResource
func NewEmbeddedResource ¶ added in v0.5.0
func NewEmbeddedResource(resource ResourceContents) EmbeddedResource
NewEmbeddedResource Helper function to create a new EmbeddedResource
type EmptyResult ¶ added in v0.5.0
type EmptyResult Result
EmptyResult represents a response that indicates success but carries no data.
type GetPromptRequest ¶ added in v0.4.0
type GetPromptRequest struct { Request Params struct { // The name of the prompt or prompt template. Name string `json:"name"` // Arguments to use for templating the prompt. Arguments map[string]string `json:"arguments,omitempty"` } `json:"params"` }
GetPromptRequest is used by the client to get a prompt provided by the server.
type GetPromptResult ¶
type GetPromptResult struct { Result // An optional description for the prompt. Description string `json:"description,omitempty"` Messages []PromptMessage `json:"messages"` }
GetPromptResult is the server's response to a prompts/get request from the client.
func NewGetPromptResult ¶ added in v0.5.1
func NewGetPromptResult( description string, messages []PromptMessage, ) *GetPromptResult
NewGetPromptResult creates a new GetPromptResult
func ParseGetPromptResult ¶ added in v0.9.0
func ParseGetPromptResult(rawMessage *json.RawMessage) (*GetPromptResult, error)
type ImageContent ¶
type ImageContent struct { Annotated Type string `json:"type"` // Must be "image" // The base64-encoded image data. Data string `json:"data"` // The MIME type of the image. Different providers may support different image types. MIMEType string `json:"mimeType"` }
ImageContent represents an image provided to or from an LLM. It must have Type set to "image".
func AsImageContent ¶ added in v0.5.0
func AsImageContent(content interface{}) (*ImageContent, bool)
AsImageContent attempts to cast the given interface to ImageContent
func NewImageContent ¶ added in v0.5.0
func NewImageContent(data, mimeType string) ImageContent
NewImageContent Helper function to create a new ImageContent
type Implementation ¶
Implementation describes the name and version of an MCP implementation.
type InitializeRequest ¶ added in v0.4.0
type InitializeRequest struct { Request Params struct { // The latest version of the Model Context Protocol that the client supports. // The client MAY decide to support older versions as well. ProtocolVersion string `json:"protocolVersion"` Capabilities ClientCapabilities `json:"capabilities"` ClientInfo Implementation `json:"clientInfo"` } `json:"params"` }
InitializeRequest is sent from the client to the server when it first connects, asking it to begin initialization.
type InitializeResult ¶
type InitializeResult struct { Result // 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"` Capabilities ServerCapabilities `json:"capabilities"` ServerInfo Implementation `json:"serverInfo"` // 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"` }
InitializeResult is sent after receiving an initialize request from the client.
func NewInitializeResult ¶ added in v0.5.1
func NewInitializeResult( protocolVersion string, capabilities ServerCapabilities, serverInfo Implementation, instructions string, ) *InitializeResult
NewInitializeResult creates a new InitializeResult
type InitializedNotification ¶ added in v0.4.0
type InitializedNotification struct {
Notification
}
InitializedNotification is sent from the client to the server after initialization has finished.
type JSONRPCError ¶ added in v0.4.0
type JSONRPCError struct { JSONRPC string `json:"jsonrpc"` ID RequestId `json:"id"` Error struct { // The error type that occurred. Code int `json:"code"` // A short description of the error. The message SHOULD be limited // to a concise single sentence. Message string `json:"message"` // Additional information about the error. The value of this member // is defined by the sender (e.g. detailed error information, nested errors etc.). Data interface{} `json:"data,omitempty"` } `json:"error"` }
JSONRPCError represents a non-successful (error) response to a request.
func NewJSONRPCError ¶ added in v0.5.0
func NewJSONRPCError( id RequestId, code int, message string, data interface{}, ) JSONRPCError
NewJSONRPCError creates a new JSONRPCResponse with the given id, code, and message
type JSONRPCMessage ¶ added in v0.4.0
type JSONRPCMessage interface{}
JSONRPCMessage represents either a JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, or JSONRPCError
type JSONRPCNotification ¶ added in v0.4.0
type JSONRPCNotification struct { JSONRPC string `json:"jsonrpc"` Notification }
JSONRPCNotification represents a notification which does not expect a response.
type JSONRPCRequest ¶ added in v0.4.0
type JSONRPCRequest struct { JSONRPC string `json:"jsonrpc"` ID RequestId `json:"id"` Params interface{} `json:"params,omitempty"` Request }
JSONRPCRequest represents a request that expects a response.
type JSONRPCResponse ¶ added in v0.4.0
type JSONRPCResponse struct { JSONRPC string `json:"jsonrpc"` ID RequestId `json:"id"` Result interface{} `json:"result"` }
JSONRPCResponse represents a successful (non-error) response to a request.
func NewJSONRPCResponse ¶ added in v0.5.0
func NewJSONRPCResponse(id RequestId, result Result) JSONRPCResponse
NewJSONRPCResponse creates a new JSONRPCResponse with the given id and result
type ListPromptsRequest ¶ added in v0.4.0
type ListPromptsRequest struct {
PaginatedRequest
}
ListPromptsRequest is sent from the client to request a list of prompts and prompt templates the server has.
type ListPromptsResult ¶
type ListPromptsResult struct { PaginatedResult Prompts []Prompt `json:"prompts"` }
ListPromptsResult is the server's response to a prompts/list request from the client.
func NewListPromptsResult ¶ added in v0.5.1
func NewListPromptsResult( prompts []Prompt, nextCursor Cursor, ) *ListPromptsResult
NewListPromptsResult creates a new ListPromptsResult
type ListResourceTemplatesRequest ¶ added in v0.4.0
type ListResourceTemplatesRequest struct {
PaginatedRequest
}
ListResourceTemplatesRequest is sent from the client to request a list of resource templates the server has.
type ListResourceTemplatesResult ¶ added in v0.4.0
type ListResourceTemplatesResult struct { PaginatedResult ResourceTemplates []ResourceTemplate `json:"resourceTemplates"` }
ListResourceTemplatesResult is the server's response to a resources/templates/list request from the client.
func NewListResourceTemplatesResult ¶ added in v0.5.1
func NewListResourceTemplatesResult( templates []ResourceTemplate, nextCursor Cursor, ) *ListResourceTemplatesResult
NewListResourceTemplatesResult creates a new ListResourceTemplatesResult
type ListResourcesRequest ¶ added in v0.4.0
type ListResourcesRequest struct {
PaginatedRequest
}
ListResourcesRequest is sent from the client to request a list of resources the server has.
type ListResourcesResult ¶
type ListResourcesResult struct { PaginatedResult Resources []Resource `json:"resources"` }
ListResourcesResult is the server's response to a resources/list request from the client.
func NewListResourcesResult ¶ added in v0.5.1
func NewListResourcesResult( resources []Resource, nextCursor Cursor, ) *ListResourcesResult
NewListResourcesResult creates a new ListResourcesResult
type ListRootsRequest ¶ added in v0.4.0
type ListRootsRequest struct {
Request
}
ListRootsRequest is sent from the server to request a list of root URIs from the client. Roots allow servers to ask for specific directories or files to operate on. A common example for roots is providing a set of repositories or directories a server should operate on.
This request is typically used when the server needs to understand the file system structure or access specific locations that the client has permission to read from.
type ListRootsResult ¶ added in v0.4.0
ListRootsResult is the client's response to a roots/list request from the server. This result contains an array of Root objects, each representing a root directory or file that the server can operate on.
type ListToolsRequest ¶ added in v0.4.0
type ListToolsRequest struct {
PaginatedRequest
}
ListToolsRequest is sent from the client to request a list of tools the server has.
type ListToolsResult ¶
type ListToolsResult struct { PaginatedResult Tools []Tool `json:"tools"` }
ListToolsResult is the server's response to a tools/list request from the client.
func NewListToolsResult ¶ added in v0.5.1
func NewListToolsResult(tools []Tool, nextCursor Cursor) *ListToolsResult
NewListToolsResult creates a new ListToolsResult
type LoggingLevel ¶
type LoggingLevel string
LoggingLevel represents the severity of a log message.
These map to syslog message severities, as specified in RFC-5424: https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
const ( LoggingLevelDebug LoggingLevel = "debug" LoggingLevelInfo LoggingLevel = "info" LoggingLevelNotice LoggingLevel = "notice" LoggingLevelWarning LoggingLevel = "warning" LoggingLevelError LoggingLevel = "error" LoggingLevelCritical LoggingLevel = "critical" LoggingLevelAlert LoggingLevel = "alert" LoggingLevelEmergency LoggingLevel = "emergency" )
type LoggingMessageNotification ¶ added in v0.4.0
type LoggingMessageNotification struct { Notification Params struct { // The severity of this log message. Level LoggingLevel `json:"level"` // An optional name of the logger issuing this message. Logger string `json:"logger,omitempty"` // The data to be logged, such as a string message or an object. Any JSON // serializable type is allowed here. Data interface{} `json:"data"` } `json:"params"` }
LoggingMessageNotification is a notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
func NewLoggingMessageNotification ¶ added in v0.5.0
func NewLoggingMessageNotification( level LoggingLevel, logger string, data interface{}, ) LoggingMessageNotification
NewLoggingMessageNotification Helper function for creating a logging message notification
type MCPMethod ¶ added in v0.16.0
type MCPMethod string
const ( // MethodInitialize initiates connection and negotiates protocol capabilities. // https://modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle/#initialization MethodInitialize MCPMethod = "initialize" // MethodPing verifies connection liveness between client and server. // https://modelcontextprotocol.io/specification/2024-11-05/basic/utilities/ping/ MethodPing MCPMethod = "ping" // MethodResourcesList lists all available server resources. // https://modelcontextprotocol.io/specification/2024-11-05/server/resources/ MethodResourcesList MCPMethod = "resources/list" // MethodResourcesTemplatesList provides URI templates for constructing resource URIs. // https://modelcontextprotocol.io/specification/2024-11-05/server/resources/ MethodResourcesTemplatesList MCPMethod = "resources/templates/list" // MethodResourcesRead retrieves content of a specific resource by URI. // https://modelcontextprotocol.io/specification/2024-11-05/server/resources/ MethodResourcesRead MCPMethod = "resources/read" // MethodPromptsList lists all available prompt templates. // https://modelcontextprotocol.io/specification/2024-11-05/server/prompts/ MethodPromptsList MCPMethod = "prompts/list" // MethodPromptsGet retrieves a specific prompt template with filled parameters. // https://modelcontextprotocol.io/specification/2024-11-05/server/prompts/ MethodPromptsGet MCPMethod = "prompts/get" // MethodToolsList lists all available executable tools. // https://modelcontextprotocol.io/specification/2024-11-05/server/tools/ MethodToolsList MCPMethod = "tools/list" // MethodToolsCall invokes a specific tool with provided parameters. // https://modelcontextprotocol.io/specification/2024-11-05/server/tools/ MethodToolsCall MCPMethod = "tools/call" // MethodNotificationResourcesListChanged notifies when the list of available resources changes. // https://modelcontextprotocol.io/specification/2025-03-26/server/resources#list-changed-notification MethodNotificationResourcesListChanged = "notifications/resources/list_changed" MethodNotificationResourceUpdated = "notifications/resources/updated" // MethodNotificationPromptsListChanged notifies when the list of available prompt templates changes. // https://modelcontextprotocol.io/specification/2025-03-26/server/prompts#list-changed-notification MethodNotificationPromptsListChanged = "notifications/prompts/list_changed" // MethodNotificationToolsListChanged notifies when the list of available tools changes. // https://spec.modelcontextprotocol.io/specification/2024-11-05/server/tools/list_changed/ MethodNotificationToolsListChanged = "notifications/tools/list_changed" )
type ModelHint ¶ added in v0.4.0
type ModelHint struct { // A hint for a model name. // // The client SHOULD treat this as a substring of a model name; for example: // - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022` // - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc. // - `claude` should match any Claude model // // The client MAY also map the string to a different provider's model name or // a different model family, as long as it fills a similar niche; for example: // - `gemini-1.5-flash` could match `claude-3-haiku-20240307` Name string `json:"name,omitempty"` }
ModelHint represents hints to use for model selection.
Keys not declared here are currently left unspecified by the spec and are up to the client to interpret.
type ModelPreferences ¶ added in v0.4.0
type ModelPreferences struct { // Optional hints to use for model selection. // // If multiple hints are specified, the client MUST evaluate them in order // (such that the first match is taken). // // The client SHOULD prioritize these hints over the numeric priorities, but // MAY still use the priorities to select from ambiguous matches. Hints []ModelHint `json:"hints,omitempty"` // How much to prioritize cost when selecting a model. A value of 0 means cost // is not important, while a value of 1 means cost is the most important // factor. CostPriority float64 `json:"costPriority,omitempty"` // How much to prioritize sampling speed (latency) when selecting a model. A // value of 0 means speed is not important, while a value of 1 means speed is // the most important factor. SpeedPriority float64 `json:"speedPriority,omitempty"` // How much to prioritize intelligence and capabilities when selecting a // model. A value of 0 means intelligence is not important, while a value of 1 // means intelligence is the most important factor. IntelligencePriority float64 `json:"intelligencePriority,omitempty"` }
ModelPreferences represents the server's preferences for model selection, requested of the client during sampling.
Because LLMs can vary along multiple dimensions, choosing the "best" modelis rarely straightforward. Different models excel in different areas—some are faster but less capable, others are more capable but more expensive, and so on. This interface allows servers to express their priorities across multiple dimensions to help clients make an appropriate selection for their use case.
These preferences are always advisory. The client MAY ignore them. It is also up to the client to decide how to interpret these preferences and how to balance them against other considerations.
type Notification ¶ added in v0.4.0
type Notification struct { Method string `json:"method"` Params NotificationParams `json:"params,omitempty"` }
type NotificationParams ¶ added in v0.4.0
type NotificationParams struct { // This parameter name is reserved by MCP to allow clients and // servers to attach additional metadata to their notifications. Meta map[string]interface{} `json:"_meta,omitempty"` // Additional fields can be added to this map AdditionalFields map[string]interface{} `json:"-"` }
func (NotificationParams) MarshalJSON ¶ added in v0.8.0
func (p NotificationParams) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling
func (*NotificationParams) UnmarshalJSON ¶ added in v0.8.0
func (p *NotificationParams) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling
type PaginatedRequest ¶ added in v0.4.0
type PaginatedResult ¶ added in v0.4.0
type PingRequest ¶ added in v0.4.0
type PingRequest struct {
Request
}
PingRequest represents a ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
type ProgressNotification ¶ added in v0.4.0
type ProgressNotification struct { Notification Params struct { // The progress token which was given in the initial request, used to // associate this notification with the request that is proceeding. ProgressToken ProgressToken `json:"progressToken"` // The progress thus far. This should increase every time progress is made, // even if the total is unknown. Progress float64 `json:"progress"` // Total number of items to process (or total progress required), if known. Total float64 `json:"total,omitempty"` // Message related to progress. This should provide relevant human-readable // progress information. Message string `json:"message,omitempty"` } `json:"params"` }
ProgressNotification is an out-of-band notification used to inform the receiver of a progress update for a long-running request.
func NewProgressNotification ¶ added in v0.5.0
func NewProgressNotification( token ProgressToken, progress float64, total *float64, message *string, ) ProgressNotification
NewProgressNotification Helper function for creating a progress notification
type ProgressToken ¶ added in v0.4.0
type ProgressToken interface{}
ProgressToken is used to associate progress notifications with the original request.
type Prompt ¶
type Prompt struct { // The name of the prompt or prompt template. Name string `json:"name"` // An optional description of what this prompt provides Description string `json:"description,omitempty"` // A list of arguments to use for templating the prompt. // The presence of arguments indicates this is a template prompt. Arguments []PromptArgument `json:"arguments,omitempty"` }
Prompt represents a prompt or prompt template that the server offers. If Arguments is non-nil and non-empty, this indicates the prompt is a template that requires argument values to be provided when calling prompts/get. If Arguments is nil or empty, this is a static prompt that takes no arguments.
func NewPrompt ¶ added in v0.5.0
func NewPrompt(name string, opts ...PromptOption) Prompt
NewPrompt creates a new Prompt with the given name and options. The prompt will be configured based on the provided options. Options are applied in order, allowing for flexible prompt configuration.
type PromptArgument ¶
type PromptArgument struct { // The name of the argument. Name string `json:"name"` // A human-readable description of the argument. Description string `json:"description,omitempty"` // Whether this argument must be provided. // If true, clients must include this argument when calling prompts/get. Required bool `json:"required,omitempty"` }
PromptArgument describes an argument that a prompt template can accept. When a prompt includes arguments, clients must provide values for all required arguments when making a prompts/get request.
type PromptListChangedNotification ¶ added in v0.4.0
type PromptListChangedNotification struct {
Notification
}
PromptListChangedNotification is an optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
type PromptMessage ¶
type PromptMessage struct { Role Role `json:"role"` Content Content `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource }
PromptMessage describes a message returned as part of a prompt.
This is similar to `SamplingMessage`, but also supports the embedding of resources from the MCP server.
func NewPromptMessage ¶ added in v0.5.0
func NewPromptMessage(role Role, content Content) PromptMessage
NewPromptMessage Helper function to create a new PromptMessage
type PromptOption ¶ added in v0.5.10
type PromptOption func(*Prompt)
PromptOption is a function that configures a Prompt. It provides a flexible way to set various properties of a Prompt using the functional options pattern.
func WithArgument ¶ added in v0.5.10
func WithArgument(name string, opts ...ArgumentOption) PromptOption
WithArgument adds an argument to the prompt's argument list. The argument will be configured based on the provided options.
func WithPromptDescription ¶ added in v0.5.10
func WithPromptDescription(description string) PromptOption
WithPromptDescription adds a description to the Prompt. The description should provide a clear, human-readable explanation of what the prompt does.
type PromptReference ¶
type PromptReference struct { Type string `json:"type"` // The name of the prompt or prompt template Name string `json:"name"` }
PromptReference identifies a prompt.
type PropertyOption ¶ added in v0.5.1
type PropertyOption func(map[string]interface{})
PropertyOption is a function that configures a property in a Tool's input schema. It allows for flexible configuration of JSON Schema properties using the functional options pattern.
func AdditionalProperties ¶ added in v0.13.0
func AdditionalProperties(schema interface{}) PropertyOption
AdditionalProperties specifies whether additional properties are allowed in the object or defines a schema for additional properties
func DefaultArray ¶ added in v0.21.0
func DefaultArray[T any](value []T) PropertyOption
DefaultArray sets the default value for an array property. This value will be used if the property is not explicitly provided.
func DefaultBool ¶ added in v0.5.1
func DefaultBool(value bool) PropertyOption
DefaultBool sets the default value for a boolean property. This value will be used if the property is not explicitly provided.
func DefaultNumber ¶ added in v0.5.1
func DefaultNumber(value float64) PropertyOption
DefaultNumber sets the default value for a number property. This value will be used if the property is not explicitly provided.
func DefaultString ¶ added in v0.5.1
func DefaultString(value string) PropertyOption
DefaultString sets the default value for a string property. This value will be used if the property is not explicitly provided.
func Description ¶ added in v0.5.1
func Description(desc string) PropertyOption
Description adds a description to a property in the JSON Schema. The description should explain the purpose and expected values of the property.
func Enum ¶ added in v0.5.1
func Enum(values ...string) PropertyOption
Enum specifies a list of allowed values for a string property. The property value must be one of the specified enum values.
func Items ¶ added in v0.13.0
func Items(schema interface{}) PropertyOption
Items defines the schema for array items
func Max ¶ added in v0.5.1
func Max(max float64) PropertyOption
Max sets the maximum value for a number property. The number value must not exceed this maximum.
func MaxItems ¶ added in v0.13.0
func MaxItems(max int) PropertyOption
MaxItems sets the maximum number of items for an array
func MaxLength ¶ added in v0.5.1
func MaxLength(max int) PropertyOption
MaxLength sets the maximum length for a string property. The string value must not exceed this length.
func MaxProperties ¶ added in v0.13.0
func MaxProperties(max int) PropertyOption
MaxProperties sets the maximum number of properties for an object
func Min ¶ added in v0.5.1
func Min(min float64) PropertyOption
Min sets the minimum value for a number property. The number value must not be less than this minimum.
func MinItems ¶ added in v0.13.0
func MinItems(min int) PropertyOption
MinItems sets the minimum number of items for an array
func MinLength ¶ added in v0.5.1
func MinLength(min int) PropertyOption
MinLength sets the minimum length for a string property. The string value must be at least this length.
func MinProperties ¶ added in v0.13.0
func MinProperties(min int) PropertyOption
MinProperties sets the minimum number of properties for an object
func MultipleOf ¶ added in v0.5.1
func MultipleOf(value float64) PropertyOption
MultipleOf specifies that a number must be a multiple of the given value. The number value must be divisible by this value.
func Pattern ¶ added in v0.5.1
func Pattern(pattern string) PropertyOption
Pattern sets a regex pattern that a string property must match. The string value must conform to the specified regular expression.
func Properties ¶ added in v0.13.0
func Properties(props map[string]interface{}) PropertyOption
Properties defines the properties for an object schema
func PropertyNames ¶ added in v0.13.0
func PropertyNames(schema map[string]interface{}) PropertyOption
PropertyNames defines a schema for property names in an object
func Required ¶ added in v0.5.1
func Required() PropertyOption
Required marks a property as required in the tool's input schema. Required properties must be provided when using the tool.
func Title ¶ added in v0.5.1
func Title(title string) PropertyOption
Title adds a display-friendly title to a property in the JSON Schema. This title can be used by UI components to show a more readable property name.
func UniqueItems ¶ added in v0.13.0
func UniqueItems(unique bool) PropertyOption
UniqueItems specifies whether array items must be unique
type ReadResourceRequest ¶ added in v0.4.0
type ReadResourceRequest struct { Request Params struct { // The URI of the resource to read. The URI can use any protocol; it is up // to the server how to interpret it. URI string `json:"uri"` // Arguments to pass to the resource handler Arguments map[string]interface{} `json:"arguments,omitempty"` } `json:"params"` }
ReadResourceRequest is sent from the client to the server, to read a specific resource URI.
type ReadResourceResult ¶
type ReadResourceResult struct { Result Contents []ResourceContents `json:"contents"` // Can be TextResourceContents or BlobResourceContents }
ReadResourceResult is the server's response to a resources/read request from the client.
func NewReadResourceResult ¶ added in v0.5.1
func NewReadResourceResult(text string) *ReadResourceResult
NewReadResourceResult creates a new ReadResourceResult with text content
func ParseReadResourceResult ¶ added in v0.10.2
func ParseReadResourceResult(rawMessage *json.RawMessage) (*ReadResourceResult, error)
type Request ¶ added in v0.4.0
type Request struct { Method string `json:"method"` Params struct { Meta *struct { // If specified, the caller is requesting out-of-band progress // notifications for this request (as represented by // notifications/progress). The value of this parameter is an // opaque token that will be attached to any subsequent // notifications. The receiver is not obligated to provide these // notifications. ProgressToken ProgressToken `json:"progressToken,omitempty"` } `json:"_meta,omitempty"` } `json:"params,omitempty"` }
type RequestId ¶ added in v0.4.0
type RequestId interface{}
RequestId is a uniquely identifying ID for a request in JSON-RPC. It can be any JSON-serializable value, typically a number or string.
type Resource ¶
type Resource struct { Annotated // The URI of this resource. URI string `json:"uri"` // A human-readable name for this resource. // // This can be used by clients to populate UI elements. Name string `json:"name"` // 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"` // The MIME type of this resource, if known. MIMEType string `json:"mimeType,omitempty"` }
Resource represents a known resource that the server is capable of reading.
func NewResource ¶ added in v0.5.0
func NewResource(uri string, name string, opts ...ResourceOption) Resource
NewResource creates a new Resource with the given URI, name and options. The resource will be configured based on the provided options. Options are applied in order, allowing for flexible resource configuration.
type ResourceContents ¶
type ResourceContents interface {
// contains filtered or unexported methods
}
ResourceContents represents the contents of a specific resource or sub- resource.
func ParseResourceContents ¶ added in v0.10.2
func ParseResourceContents(contentMap map[string]any) (ResourceContents, error)
type ResourceListChangedNotification ¶ added in v0.4.0
type ResourceListChangedNotification struct {
Notification
}
ResourceListChangedNotification is an optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.
type ResourceOption ¶ added in v0.6.0
type ResourceOption func(*Resource)
ResourceOption is a function that configures a Resource. It provides a flexible way to set various properties of a Resource using the functional options pattern.
func WithAnnotations ¶ added in v0.6.0
func WithAnnotations(audience []Role, priority float64) ResourceOption
WithAnnotations adds annotations to the Resource. Annotations can provide additional metadata about the resource's intended use.
func WithMIMEType ¶ added in v0.6.0
func WithMIMEType(mimeType string) ResourceOption
WithMIMEType sets the MIME type for the Resource. This should indicate the format of the resource's contents.
func WithResourceDescription ¶ added in v0.6.0
func WithResourceDescription(description string) ResourceOption
WithResourceDescription adds a description to the Resource. The description should provide a clear, human-readable explanation of what the resource represents.
type ResourceReference ¶
type ResourceReference struct { Type string `json:"type"` // The URI or URI template of the resource. URI string `json:"uri"` }
ResourceReference is a reference to a resource or resource template definition.
type ResourceTemplate ¶ added in v0.4.0
type ResourceTemplate struct { Annotated // A URI template (according to RFC 6570) that can be used to construct // resource URIs. URITemplate *URITemplate `json:"uriTemplate"` // A human-readable name for the type of resource this template refers to. // // This can be used by clients to populate UI elements. Name string `json:"name"` // A description of what this template is for. // // 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"` // The MIME type for all resources that match this template. This should only // be included if all resources matching this template have the same type. MIMEType string `json:"mimeType,omitempty"` }
ResourceTemplate represents a template description for resources available on the server.
func NewResourceTemplate ¶ added in v0.6.0
func NewResourceTemplate(uriTemplate string, name string, opts ...ResourceTemplateOption) ResourceTemplate
NewResourceTemplate creates a new ResourceTemplate with the given URI template, name and options. The template will be configured based on the provided options. Options are applied in order, allowing for flexible template configuration.
type ResourceTemplateOption ¶ added in v0.6.0
type ResourceTemplateOption func(*ResourceTemplate)
ResourceTemplateOption is a function that configures a ResourceTemplate. It provides a flexible way to set various properties of a ResourceTemplate using the functional options pattern.
func WithTemplateAnnotations ¶ added in v0.6.0
func WithTemplateAnnotations(audience []Role, priority float64) ResourceTemplateOption
WithTemplateAnnotations adds annotations to the ResourceTemplate. Annotations can provide additional metadata about the template's intended use.
func WithTemplateDescription ¶ added in v0.6.0
func WithTemplateDescription(description string) ResourceTemplateOption
WithTemplateDescription adds a description to the ResourceTemplate. The description should provide a clear, human-readable explanation of what resources this template represents.
func WithTemplateMIMEType ¶ added in v0.6.0
func WithTemplateMIMEType(mimeType string) ResourceTemplateOption
WithTemplateMIMEType sets the MIME type for the ResourceTemplate. This should only be set if all resources matching this template will have the same type.
type ResourceUpdatedNotification ¶ added in v0.4.0
type ResourceUpdatedNotification struct { Notification Params struct { // The URI of the resource that has been updated. This might be a sub- // resource of the one that the client actually subscribed to. URI string `json:"uri"` } `json:"params"` }
ResourceUpdatedNotification is a notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
type Result ¶ added in v0.4.0
type Result struct { // This result property is reserved by the protocol to allow clients and // servers to attach additional metadata to their responses. Meta map[string]interface{} `json:"_meta,omitempty"` }
type Role ¶
type Role string
Role represents the sender or recipient of messages and data in a conversation.
type Root ¶ added in v0.4.0
type Root struct { // The URI identifying the root. This *must* start with file:// for now. // This restriction may be relaxed in future versions of the protocol to allow // other URI schemes. URI string `json:"uri"` // An optional name for the root. This can be used to provide a human-readable // identifier for the root, which may be useful for display purposes or for // referencing the root in other parts of the application. Name string `json:"name,omitempty"` }
Root represents a root directory or file that the server can operate on.
type RootsListChangedNotification ¶ added in v0.4.0
type RootsListChangedNotification struct {
Notification
}
RootsListChangedNotification is a notification from the client to the server, informing it that the list of roots has changed. This notification should be sent whenever the client adds, removes, or modifies any root. The server should then request an updated list of roots using the ListRootsRequest.
type SamplingMessage ¶ added in v0.4.0
type SamplingMessage struct { Role Role `json:"role"` Content interface{} `json:"content"` // Can be TextContent or ImageContent }
SamplingMessage describes a message issued to or received from an LLM API.
type ServerCapabilities ¶
type ServerCapabilities struct { // Experimental, non-standard capabilities that the server supports. Experimental map[string]interface{} `json:"experimental,omitempty"` // Present if the server supports sending log messages to the client. Logging *struct{} `json:"logging,omitempty"` // Present if the server offers any prompt templates. Prompts *struct { // Whether this server supports notifications for changes to the prompt list. ListChanged bool `json:"listChanged,omitempty"` } `json:"prompts,omitempty"` // Present if the server offers any resources to read. Resources *struct { // Whether this server supports subscribing to resource updates. Subscribe bool `json:"subscribe,omitempty"` // Whether this server supports notifications for changes to the resource // list. ListChanged bool `json:"listChanged,omitempty"` } `json:"resources,omitempty"` // Present if the server offers any tools to call. Tools *struct { // Whether this server supports notifications for changes to the tool list. ListChanged bool `json:"listChanged,omitempty"` } `json:"tools,omitempty"` }
ServerCapabilities represents 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 ServerNotification ¶ added in v0.4.0
type ServerNotification interface{}
ServerNotification represents any notification that can be sent from server to client.
type ServerRequest ¶ added in v0.4.0
type ServerRequest interface{}
ServerRequest represents any request that can be sent from server to client.
type ServerResult ¶ added in v0.4.0
type ServerResult interface{}
ServerResult represents any result that can be sent from server to client.
type SetLevelRequest ¶ added in v0.4.0
type SetLevelRequest struct { Request Params struct { // The level of logging that the client wants to receive from the server. // The server should send all logs at this level and higher (i.e., more severe) to // the client as notifications/logging/message. Level LoggingLevel `json:"level"` } `json:"params"` }
SetLevelRequest is a request from the client to the server, to enable or adjust logging.
type SubscribeRequest ¶ added in v0.4.0
type SubscribeRequest struct { Request Params struct { // The URI of the resource to subscribe to. The URI can use any protocol; it // is up to the server how to interpret it. URI string `json:"uri"` } `json:"params"` }
SubscribeRequest is sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
type TextContent ¶
type TextContent struct { Annotated Type string `json:"type"` // Must be "text" // The text content of the message. Text string `json:"text"` }
TextContent represents text provided to or from an LLM. It must have Type set to "text".
func AsTextContent ¶ added in v0.5.0
func AsTextContent(content interface{}) (*TextContent, bool)
AsTextContent attempts to cast the given interface to TextContent
func NewTextContent ¶ added in v0.5.0
func NewTextContent(text string) TextContent
NewTextContent Helper function to create a new TextContent
type TextResourceContents ¶
type TextResourceContents struct { // The URI of this resource. URI string `json:"uri"` // The MIME type of this resource, if known. MIMEType string `json:"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"` }
func AsTextResourceContents ¶ added in v0.5.0
func AsTextResourceContents(content interface{}) (*TextResourceContents, bool)
AsTextResourceContents attempts to cast the given interface to TextResourceContents
type Tool ¶
type Tool struct { // The name of the tool. Name string `json:"name"` // A human-readable description of the tool. Description string `json:"description,omitempty"` // A JSON Schema object defining the expected parameters for the tool. InputSchema ToolInputSchema `json:"inputSchema"` // Alternative to InputSchema - allows arbitrary JSON Schema to be provided RawInputSchema json.RawMessage `json:"-"` // Hide this from JSON marshaling // Optional properties describing tool behavior Annotations ToolAnnotation `json:"annotations"` }
Tool represents the definition for a tool the client can call.
func NewTool ¶ added in v0.5.0
func NewTool(name string, opts ...ToolOption) Tool
NewTool creates a new Tool with the given name and options. The tool will have an object-type input schema with configurable properties. Options are applied in order, allowing for flexible tool configuration.
func NewToolWithRawSchema ¶ added in v0.10.0
func NewToolWithRawSchema(name, description string, schema json.RawMessage) Tool
NewToolWithRawSchema creates a new Tool with the given name and a raw JSON Schema. This allows for arbitrary JSON Schema to be used for the tool's input schema.
NOTE a Tool built in such a way is incompatible with the ToolOption and runtime errors will result from supplying a ToolOption to a Tool built with this function.
func (Tool) MarshalJSON ¶ added in v0.10.0
MarshalJSON implements the json.Marshaler interface for Tool. It handles marshaling either InputSchema or RawInputSchema based on which is set.
type ToolAnnotation ¶ added in v0.21.0
type ToolAnnotation struct { // Human-readable title for the tool Title string `json:"title,omitempty"` // If true, the tool does not modify its environment ReadOnlyHint bool `json:"readOnlyHint,omitempty"` // If true, the tool may perform destructive updates DestructiveHint bool `json:"destructiveHint,omitempty"` // If true, repeated calls with same args have no additional effect IdempotentHint bool `json:"idempotentHint,omitempty"` // If true, tool interacts with external entities OpenWorldHint bool `json:"openWorldHint,omitempty"` }
type ToolInputSchema ¶
type ToolInputSchema struct { Type string `json:"type"` Properties map[string]interface{} `json:"properties,omitempty"` Required []string `json:"required,omitempty"` }
func (ToolInputSchema) MarshalJSON ¶ added in v0.24.1
func (tis ToolInputSchema) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for ToolInputSchema.
type ToolListChangedNotification ¶ added in v0.4.0
type ToolListChangedNotification struct {
Notification
}
ToolListChangedNotification is an optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
type ToolOption ¶ added in v0.5.1
type ToolOption func(*Tool)
ToolOption is a function that configures a Tool. It provides a flexible way to set various properties of a Tool using the functional options pattern.
func WithArray ¶ added in v0.13.0
func WithArray(name string, opts ...PropertyOption) ToolOption
WithArray adds an array property to the tool schema. It accepts property options to configure the array property's behavior and constraints.
func WithBoolean ¶ added in v0.5.1
func WithBoolean(name string, opts ...PropertyOption) ToolOption
WithBoolean adds a boolean property to the tool schema. It accepts property options to configure the boolean property's behavior and constraints.
func WithDescription ¶ added in v0.5.1
func WithDescription(description string) ToolOption
WithDescription adds a description to the Tool. The description should provide a clear, human-readable explanation of what the tool does.
func WithNumber ¶ added in v0.5.1
func WithNumber(name string, opts ...PropertyOption) ToolOption
WithNumber adds a number property to the tool schema. It accepts property options to configure the number property's behavior and constraints.
func WithObject ¶ added in v0.13.0
func WithObject(name string, opts ...PropertyOption) ToolOption
WithObject adds an object property to the tool schema. It accepts property options to configure the object property's behavior and constraints.
func WithString ¶ added in v0.5.1
func WithString(name string, opts ...PropertyOption) ToolOption
WithString adds a string property to the tool schema. It accepts property options to configure the string property's behavior and constraints.
func WithToolAnnotation ¶ added in v0.21.0
func WithToolAnnotation(annotation ToolAnnotation) ToolOption
type URITemplate ¶ added in v0.14.1
type URITemplate struct {
*uritemplate.Template
}
func (*URITemplate) MarshalJSON ¶ added in v0.14.1
func (t *URITemplate) MarshalJSON() ([]byte, error)
func (*URITemplate) UnmarshalJSON ¶ added in v0.14.1
func (t *URITemplate) UnmarshalJSON(data []byte) error
type UnsubscribeRequest ¶ added in v0.4.0
type UnsubscribeRequest struct { Request Params struct { // The URI of the resource to unsubscribe from. URI string `json:"uri"` } `json:"params"` }
UnsubscribeRequest is sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.