Documentation
¶
Index ¶
- func Logger(ctx context.Context, name string) *slog.Logger
- func NewStdioTransport(ctx context.Context, handler *Handler, opts *StdioTransportOptions) (context.Context, jsonrpc2.Listener, jsonrpc2.Binder)
- func NextCursor(ctx context.Context) (string, bool)
- func SetLogWriterToContext(ctx context.Context, w io.Writer) context.Context
- type Annotations
- type AudioContent
- type BlobResourceContent
- type CallToolContent
- type CallToolResult
- type CompleteRequestParams
- type CompleteResult
- type CompletionArgument
- type CompletionReferenceType
- type EmbeddedResource
- type GetPromptResult
- type Handler
- type ImageContent
- type ListResourcesResult
- type PromptMessage
- type PromptMessageContent
- type ReadResourceRequest
- type ReadResourceResult
- type Reference
- type Resource
- type ResourceContent
- type ResourceTemplate
- type Role
- type ServerCompletionHandler
- type ServerResourceHandler
- type StdioTransportOptions
- type TextContent
- type TextResourceContent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Logger ¶
Logger creates a new logger with the given name. Note that this logger is for communication with the client, not for internal logging. The logged messages are sent as notifications to the client.
See https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/logging#logging
func NewStdioTransport ¶
func NewStdioTransport( ctx context.Context, handler *Handler, opts *StdioTransportOptions, ) (context.Context, jsonrpc2.Listener, jsonrpc2.Binder)
NewStdioTransport creates a new stdio transport.
See https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/stdio#stdio
func NextCursor ¶
NextCursor returns the next cursor from the context. If there is no next cursor or the API doesn't support pagination, it returns false.
Types ¶
type Annotations ¶
type Annotations struct {
// Audience 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,omitzero"`
// Priority 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,omitzero"` // 0: optional, 1: required
}
Annotations represents optional annotations for the client. Annotations are used by the client to inform how objects are used or displayed.
type AudioContent ¶
type AudioContent struct {
// Data is the audio data.
Data io.Reader
// MimeType is the MIME type of the audio. Different providers may support different audio types.
MimeType string
// Annotations are optional annotations for the client.
Annotations *Annotations
}
AudioContent represents audio data.
func (AudioContent) MarshalJSON ¶
func (a AudioContent) MarshalJSON() ([]byte, error)
type BlobResourceContent ¶
type BlobResourceContent struct {
// URI is the URI of this resource.
URI string
// MimeType is the MIME type of this resource, if known.
MimeType string
// Blob is the binary data of the item.
Blob io.Reader
}
BlobResourceContent represents binary resource content.
func (BlobResourceContent) MarshalJSON ¶
func (b BlobResourceContent) MarshalJSON() ([]byte, error)
type CallToolContent ¶
type CallToolContent interface {
// contains filtered or unexported methods
}
CallToolContent is the interface for content that can be returned by a tool call. TextContent and EmbeddedResource are the only valid types.
type CallToolResult ¶
type CallToolResult struct {
// Content is the content of the tool call.
// TextContent and EmbeddedResource are the only valid types.
Content []CallToolContent `json:"content"`
// IsError indicates 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,omitzero"`
}
CallToolResult represents 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.
type CompleteRequestParams ¶
type CompleteRequestParams struct {
// Ref is a reference to a prompt or resource
Ref Reference `json:"ref"`
// Argument contains the argument's information
Argument CompletionArgument `json:"argument"`
}
CompleteRequestParams is a request from the client to the server, to ask for completion options.
type CompleteResult ¶
type CompleteResult struct {
// Values is an array of completion values. Must not exceed 100 items.
Values []string `json:"values"`
// Total is the total number of completion options available. This can exceed the number of values actually sent in the response.
Total int `json:"total,omitzero"`
// HasMore 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,omitzero"`
}
CompleteResult represents the completion options for argument autocompletion.
type CompletionArgument ¶
type CompletionArgument struct {
// Name is the name of the argument
Name string `json:"name"`
// Value is the value of the argument to use for completion matching.
Value string `json:"value"`
}
CompletionArgument represents an argument for completion.
type CompletionReferenceType ¶
type CompletionReferenceType string
CompletionReferenceType represents the type of a completion reference.
const ( // CompletionReferenceTypePrompt identifies a prompt. CompletionReferenceTypePrompt CompletionReferenceType = "ref/prompt" // CompletionReferenceTypeResource is a reference to a resource or resource template definition. CompletionReferenceTypeResource CompletionReferenceType = "ref/resource" )
type EmbeddedResource ¶
type EmbeddedResource struct {
// Resource is the resource content to embed.
Resource ResourceContent `json:"resource"`
// Annotations are optional annotations for the client.
Annotations *Annotations `json:"annotations,omitzero"`
}
EmbeddedResource represents the contents of a resource, embedded into a prompt or tool call result. EmbeddedResource is rendered by the client in a way that best serves the benefit of the LLM and/or the user.
type GetPromptResult ¶
type GetPromptResult struct {
// Description is an optional description for the prompt.
Description string `json:"description,omitzero"`
// Arguments is a list of arguments to use for templating the prompt.
Messages []PromptMessage `json:"messages"`
}
GetPromptResult represents the server's response to a prompts/get request from the client.
type Handler ¶
type Handler struct {
Capabilities protocol.ServerCapabilities
Implementation protocol.Implementation
Prompts []protocol.Prompt
PromptHandler serverHandler[protocol.GetPromptRequestParams]
Tools []protocol.Tool
ToolHandler serverHandler[protocol.CallToolRequestParams]
ResourceHandler ServerResourceHandler
ResourceTemplates []ResourceTemplate
CompletionHandler ServerCompletionHandler
// contains filtered or unexported fields
}
Handler is the main handler for MCP server implementation. Note that exported fields are exported for accessing by generated code. Do not access/modify them directly.
func (*Handler) IsSubscribed ¶
IsSubscribed checks if the given resource is subscribed.
type ImageContent ¶
type ImageContent struct {
// Data is the image data.
Data io.Reader
// MimeType is the MIME type of the image. Different providers may support different image types.
MimeType string
// Annotations are optional annotations for the client.
Annotations *Annotations
}
ImageContent represents image data.
func (ImageContent) MarshalJSON ¶
func (i ImageContent) MarshalJSON() ([]byte, error)
type ListResourcesResult ¶
type ListResourcesResult struct {
// NextCursor is an opaque token representing the current pagination position.
// If provided, the server should return results starting after this cursor.
NextCursor string `json:"nextCursor,omitzero"`
// Resources is a list of resources the server offers.
Resources []Resource `json:"resources"`
}
ListResourcesResult represents the response for resources list. ListResourcesResult is a PaginatedResult that contains a list of resources the server offers.
type PromptMessage ¶
type PromptMessage struct {
// Role represents the role of the message sender/recipient.
Role Role `json:"role"`
// Content represents the content of the message.
// TextContent, ImageContent, AudioContent, or EmbeddedResource.
Content PromptMessageContent `json:"content"`
}
PromptMessage describes a message returned as part of a prompt. PromptMessage is similar to SamplingMessage, but also supports the embedding of resources from the MCP server.
type PromptMessageContent ¶
type PromptMessageContent interface {
// contains filtered or unexported methods
}
PromptMessageContent is the interface for content that can be included in a prompt message. TextContent, ImageContent, AudioContent, or EmbeddedResource.
type ReadResourceRequest ¶
type ReadResourceRequest struct {
// URI is 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"`
}
ReadResourceRequest represents a request to read a specific resource. ReadResourceRequest is sent from the client to the server, to read a specific resource URI.
type ReadResourceResult ¶
type ReadResourceResult struct {
// Contents is a list of contents of the resource.
Contents []ResourceContent `json:"contents"`
}
ReadResourceResult represents the response for a resource read operation. ReadResourceResult is the server's response to a resources/read request from the client.
type Reference ¶
type Reference struct {
Type CompletionReferenceType `json:"type"`
// Name is the name of the prompt or URI of the resource
Name string `json:"name"`
}
Reference represents a reference to a completion item.
type Resource ¶
type Resource struct {
// URI is the URI of this resource.
URI string `json:"uri"` // URI (e.g. file://...)
// Name is a human-readable name for this resource.
// This can be used by clients to populate UI elements.
Name string `json:"name"`
// Description is 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,omitzero"`
// MimeType is the MIME type of this resource, if known.
MimeType string `json:"mimeType,omitzero"`
// Size is the size of the raw resource content, if known.
// This can be used by Hosts to display file sizes and estimate context window usage.
Size int64 `json:"size,omitzero"`
// Annotations are optional annotations for the client.
Annotations *Annotations `json:"annotations,omitzero"`
}
Resource represents a resource handled by the server. Resource is a known resource that the server is capable of reading.
type ResourceContent ¶
type ResourceContent interface {
// contains filtered or unexported methods
}
ResourceContent is the interface for contents of a specific resource or sub-resource.
type ResourceTemplate ¶
type ResourceTemplate struct {
// URITemplate is a URI template (according to RFC 6570) that can be used to construct resource URIs.
URITemplate string `json:"uriTemplate"`
// Name is 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"`
// Description is 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,omitzero"`
// MimeType is 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,omitzero"`
// Annotations are optional annotations for the client.
Annotations *Annotations `json:"annotations,omitzero"`
}
ResourceTemplate represents a resource template definition. ResourceTemplate is a template description for resources available on the server.
type Role ¶
type Role string
Role represents the sender or recipient of messages and data in a conversation.
type ServerCompletionHandler ¶
type ServerCompletionHandler interface {
// HandleComplete handles a completion (completion/complete) request.
HandleComplete(ctx context.Context, req *CompleteRequestParams) (*CompleteResult, error)
}
ServerCompletionHandler is the interface for a server that can handle completion requests.
type ServerResourceHandler ¶
type ServerResourceHandler interface {
// HandleResourcesList handles a resources/list request.
HandleResourcesList(ctx context.Context) (*ListResourcesResult, error)
// HandleResourcesRead handles a resources/read request.
HandleResourcesRead(ctx context.Context, req *ReadResourceRequest) (*ReadResourceResult, error)
}
ServerResourceHandler is the interface for a server that can handle resource-related requests.
type StdioTransportOptions ¶
type StdioTransportOptions struct {
// MaxConns is the maximum number of connections that can be handled by the transport.
// If this is not set, 5 connections are allowed.
MaxConns int
// Preempter is the preempter for the transport.
// If this is not set, no preemption is done.
Preempter jsonrpc2.Preempter
}
type TextContent ¶
type TextContent struct {
// Text is the text content of the message.
Text string `json:"text"`
// Annotations are optional annotations for the client.
Annotations *Annotations `json:"annotations,omitzero"`
}
TextContent represents text data.
func (TextContent) MarshalJSON ¶
func (t TextContent) MarshalJSON() ([]byte, error)
type TextResourceContent ¶
type TextResourceContent struct {
// URI is the URI of this resource.
URI string
// MimeType is the MIME type of this resource, if known.
MimeType string
// Text is the text of the item. This must only be set if the item can actually be represented as text (not binary data).
Text string
}
TextResourceContent represents textual resource content.
func (TextResourceContent) MarshalJSON ¶
func (t TextResourceContent) MarshalJSON() ([]byte, error)
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
weather
Code generated by mcp-codegen.
|
Code generated by mcp-codegen. |
|
weather/cmd/mcpgen
command
|
|
|
weather/cmd/weather
command
|
|