mcp

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mcp is a standalone reimplementation of the data types from mark3labs/mcp-go/mcp.

It exists so that ToolHive and its sibling projects can migrate off mcp-go and onto the official Model Context Protocol Go SDK (github.com/modelcontextprotocol/go-sdk) by swapping imports rather than rewriting call sites: replace

github.com/mark3labs/mcp-go/mcp

with

github.com/stacklok/toolhive-core/mcpcompat/mcp

while keeping the existing import alias. The companion packages mcpcompat/server, mcpcompat/client and mcpcompat/client/transport reimplement mcp-go's protocol machinery on top of the official SDK; this package supplies the data types those APIs exchange.

The types and helpers below are standalone definitions that preserve the mcp-go JSON wire format (same struct tags, same custom marshaling). The mcp-go dependency has been removed from the tree entirely. The wire-format golden tests in this package pin the exact JSON shape of every type and are what make future changes safe.

Scope

Only the subset of mcp-go's mcp package that ToolHive actually uses is included. Unused surface (sampling, roots, completion, tasks, logging-level control, the fluent schema builder beyond WithDescription/WithString/Required, etc.) is intentionally omitted and can be added on demand.

Stability: Alpha.

Index

Constants

View Source
const (
	ContentTypeText       = "text"
	ContentTypeImage      = "image"
	ContentTypeAudio      = "audio"
	ContentTypeLink       = "resource_link"
	ContentTypeResource   = "resource"
	ContentTypeToolUse    = "tool_use"
	ContentTypeToolResult = "tool_result"

	ElicitationModeForm = "form"
	ElicitationModeURL  = "url"
)

Content type constants.

View Source
const (
	// PARSE_ERROR indicates invalid JSON was received by the server.
	PARSE_ERROR = -32700

	// INVALID_REQUEST indicates the JSON sent is not a valid Request object.
	INVALID_REQUEST = -32600

	// METHOD_NOT_FOUND indicates the method does not exist/is not available.
	METHOD_NOT_FOUND = -32601

	// INVALID_PARAMS indicates invalid method parameter(s).
	INVALID_PARAMS = -32602

	// INTERNAL_ERROR indicates internal JSON-RPC error.
	INTERNAL_ERROR = -32603

	// REQUEST_INTERRUPTED indicates a request was cancelled or timed out.
	REQUEST_INTERRUPTED = -32800
)

Standard JSON-RPC error codes

View Source
const (
	// RESOURCE_NOT_FOUND indicates that the requested resource was not found.
	RESOURCE_NOT_FOUND = -32002

	// URL_ELICITATION_REQUIRED is the error code for when URL elicitation is required.
	URL_ELICITATION_REQUIRED = -32042
)

MCP error codes

View Source
const JSONRPC_VERSION = "2.0"

JSONRPC_VERSION is the version of JSON-RPC used by MCP.

View Source
const LATEST_PROTOCOL_VERSION = "2025-11-25"

LATEST_PROTOCOL_VERSION is the most recent version of the MCP protocol.

Variables

View Source
var (
	// ErrParseError indicates a JSON parsing error (code: PARSE_ERROR).
	ErrParseError = errors.New("parse error")

	// ErrInvalidRequest indicates an invalid JSON-RPC request (code: INVALID_REQUEST).
	ErrInvalidRequest = errors.New("invalid request")

	// ErrMethodNotFound indicates the requested method does not exist (code: METHOD_NOT_FOUND).
	ErrMethodNotFound = errors.New("method not found")

	// ErrInvalidParams indicates invalid method parameters (code: INVALID_PARAMS).
	ErrInvalidParams = errors.New("invalid params")

	// ErrInternalError indicates an internal JSON-RPC error (code: INTERNAL_ERROR).
	ErrInternalError = errors.New("internal error")

	// ErrRequestInterrupted indicates a request was cancelled or timed out (code: REQUEST_INTERRUPTED).
	ErrRequestInterrupted = errors.New("request interrupted")

	// ErrResourceNotFound indicates a requested resource was not found (code: RESOURCE_NOT_FOUND).
	ErrResourceNotFound = errors.New("resource not found")
)

Sentinel errors for common JSON-RPC error codes.

Functions

func GetTextFromContent

func GetTextFromContent(content any) string

GetTextFromContent extracts text from a Content interface that might be a TextContent struct or a map[string]any that was unmarshaled from JSON. This is useful when dealing with content that comes from different transport layers that may handle JSON differently.

This function uses fallback behavior for non-text content - it returns a string representation via fmt.Sprintf for any content that cannot be extracted as text. This is a lossy operation intended for convenience in logging and display scenarios.

func MarshalContent added in v0.0.28

func MarshalContent(content Content) ([]byte, error)

MarshalContent marshals a Content value to JSON.

func ToBoolPtr added in v0.0.28

func ToBoolPtr(b bool) *bool

ToBoolPtr returns a pointer to the given boolean value

Types

type Annotated

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 ranges from 0.0 to 1.0 (1 = most important, 0 = least important).
	Priority *float64 `json:"priority,omitempty"`
	// ISO 8601 formatted timestamp (e.g., "2025-01-12T15:00:58Z")
	LastModified string `json:"lastModified,omitempty"`
}

Annotations describe audience/priority/lastModified for content.

type AudioContent

type AudioContent struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta  `json:"_meta,omitempty"`
	Type string `json:"type"` // Must be "audio"
	// The base64-encoded audio data.
	Data string `json:"data"`
	// The MIME type of the audio. Different providers may support different audio types.
	MIMEType string `json:"mimeType"`
}

AudioContent represents the contents of audio, embedded into a prompt or tool call result. It must have Type set to "audio".

func AsAudioContent

func AsAudioContent(content any) (*AudioContent, bool)

AsAudioContent attempts to cast the given interface to AudioContent

func NewAudioContent

func NewAudioContent(data, mimeType string) AudioContent

NewAudioContent creates a new AudioContent with the given base64-encoded data and MIME type.

type BlobResourceContents

type BlobResourceContents struct {
	// Raw per-resource metadata; pass-through as defined by MCP. Not the same as Meta.
	// Allows _meta to be used for MCP-UI features for example. Does not assume any specific format.
	Meta map[string]any `json:"_meta,omitempty"`
	// 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"`
}

BlobResourceContents is base64 blob resource contents.

func AsBlobResourceContents

func AsBlobResourceContents(content any) (*BlobResourceContents, bool)

AsBlobResourceContents attempts to cast the given interface to BlobResourceContents

type CallToolParams

type CallToolParams struct {
	Name      string      `json:"name"`
	Arguments any         `json:"arguments,omitempty"`
	Meta      *Meta       `json:"_meta,omitempty"`
	Task      *TaskParams `json:"task,omitempty"`
}

CallToolParams are the params of a tool call.

type CallToolRequest

type CallToolRequest struct {
	Request
	Header http.Header    `json:"-"` // HTTP headers from the original request
	Params CallToolParams `json:"params"`
}

CallToolRequest is used by the client to invoke a tool provided by the server.

func (CallToolRequest) BindArguments added in v0.0.28

func (r CallToolRequest) BindArguments(target any) error

BindArguments unmarshals the Arguments into the provided struct This is useful for working with strongly-typed arguments

func (CallToolRequest) GetArguments added in v0.0.28

func (r CallToolRequest) GetArguments() map[string]any

GetArguments returns the Arguments as map[string]any for backward compatibility If Arguments is not a map, it returns an empty map

func (CallToolRequest) GetBool added in v0.0.28

func (r CallToolRequest) GetBool(key string, defaultValue bool) bool

GetBool returns a bool argument by key, or the default value if not found

func (CallToolRequest) GetFloat added in v0.0.28

func (r CallToolRequest) GetFloat(key string, defaultValue float64) float64

GetFloat returns a float64 argument by key, or the default value if not found

func (CallToolRequest) GetInt added in v0.0.28

func (r CallToolRequest) GetInt(key string, defaultValue int) int

GetInt returns an int argument by key, or the default value if not found

func (CallToolRequest) GetRawArguments added in v0.0.28

func (r CallToolRequest) GetRawArguments() any

GetRawArguments returns the Arguments as-is without type conversion This allows users to access the raw arguments in any format

func (CallToolRequest) GetString added in v0.0.28

func (r CallToolRequest) GetString(key string, defaultValue string) string

GetString returns a string argument by key, or the default value if not found

func (CallToolRequest) RequireString added in v0.0.28

func (r CallToolRequest) RequireString(key string) (string, error)

RequireString returns a string argument by key, or an error if not found or not a string

type CallToolResult

type CallToolResult struct {
	Result
	Content []Content `json:"content"` // Can be TextContent, ImageContent, AudioContent, or EmbeddedResource
	// Structured content returned as a JSON object in the structuredContent field of a result.
	// For backwards compatibility, a tool that returns structured content SHOULD also return
	// functionally equivalent unstructured content.
	StructuredContent any `json:"structuredContent,omitempty"`
	// 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 NewToolResultError

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 NewToolResultStructuredOnly

func NewToolResultStructuredOnly(structured any) *CallToolResult

NewToolResultStructuredOnly creates a new CallToolResult with structured content and creates a JSON string fallback for backwards compatibility. This is useful when you want to provide structured data without any specific text fallback.

func NewToolResultText

func NewToolResultText(text string) *CallToolResult

NewToolResultText creates a new CallToolResult with a text content

func (CallToolResult) MarshalJSON added in v0.0.28

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

MarshalJSON implements custom JSON marshaling for CallToolResult

func (*CallToolResult) UnmarshalJSON added in v0.0.28

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

UnmarshalJSON implements custom JSON unmarshaling for CallToolResult

type ClientCapabilities

type ClientCapabilities struct {
	// Optional, present if the client is advertising extension support.
	Extensions map[string]any `json:"extensions,omitempty"`
	// Experimental, non-standard capabilities that the client supports.
	Experimental map[string]any `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 *SamplingCapability `json:"sampling,omitempty"`
	// Present if the client supports elicitation requests from the server.
	Elicitation *ElicitationCapability `json:"elicitation,omitempty"`
	// Present if the client supports task-based execution.
	Tasks *TasksCapability `json:"tasks,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 Content

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

Content is a polymorphic content element (text/image/audio/resource/...).

func UnmarshalContent

func UnmarshalContent(data []byte) (Content, error)

UnmarshalContent decodes a single JSON content object into the concrete Content implementation (TextContent, ImageContent, ...). It is used by the client shim to populate the Content interface fields of PromptMessage, which cannot be unmarshaled generically.

type Cursor added in v0.0.28

type Cursor string

Cursor is an opaque token used to represent a cursor for pagination.

type ElicitationCapability added in v0.0.28

type ElicitationCapability struct {
	Form *struct{} `json:"form,omitempty"` // Supports form mode
	URL  *struct{} `json:"url,omitempty"`  // Supports URL mode
}

ElicitationCapability represents the elicitation capabilities of a client or server.

type ElicitationParams

type ElicitationParams struct {
	Meta *Meta `json:"_meta,omitempty"`
	// Mode specifies the type of elicitation: "form" or "url". Defaults to "form".
	Mode string `json:"mode,omitempty"`
	// A human-readable message explaining what information is being requested and why.
	Message string `json:"message"`

	// A JSON Schema defining the expected structure of the user's response.
	RequestedSchema any `json:"requestedSchema,omitempty"`

	// ElicitationID is a unique identifier for the elicitation request.
	ElicitationID string `json:"elicitationId,omitempty"`
	// URL is the URL to be opened by the user.
	URL string `json:"url,omitempty"`
}

ElicitationParams contains the parameters for an elicitation request.

func (ElicitationParams) Validate added in v0.0.28

func (p ElicitationParams) Validate() error

Validate checks if the elicitation parameters are valid.

type ElicitationRequest

type ElicitationRequest struct {
	Request
	Params ElicitationParams `json:"params"`
}

ElicitationRequest is a request from the server to the client to request additional information from the user during an interaction.

type ElicitationResponse

type ElicitationResponse struct {
	// Action indicates whether the user accepted, declined, or cancelled.
	Action ElicitationResponseAction `json:"action"`
	// Content contains the user's response data if they accepted.
	// Should conform to the requestedSchema from the ElicitationRequest.
	Content any `json:"content,omitempty"`
}

ElicitationResponse represents the user's response to an elicitation request.

type ElicitationResponseAction

type ElicitationResponseAction string

ElicitationResponseAction indicates how the user responded to an elicitation request.

const (
	// ElicitationResponseActionAccept indicates the user provided the requested information.
	ElicitationResponseActionAccept ElicitationResponseAction = "accept"
	// ElicitationResponseActionDecline indicates the user explicitly declined to provide information.
	ElicitationResponseActionDecline ElicitationResponseAction = "decline"
	// ElicitationResponseActionCancel indicates the user cancelled without making a choice.
	ElicitationResponseActionCancel ElicitationResponseAction = "cancel"
)

Elicitation response actions.

type ElicitationResult

type ElicitationResult struct {
	Result
	ElicitationResponse
}

ElicitationResult represents the result of an elicitation request.

type EmbeddedResource

type EmbeddedResource struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta     *Meta            `json:"_meta,omitempty"`
	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

func AsEmbeddedResource(content any) (*EmbeddedResource, bool)

AsEmbeddedResource attempts to cast the given interface to EmbeddedResource

func NewEmbeddedResource

func NewEmbeddedResource(resource ResourceContents) EmbeddedResource

NewEmbeddedResource creates a new EmbeddedResource wrapping the given ResourceContents.

type EmptyResult

type EmptyResult Result

EmptyResult represents a response that indicates success but carries no data.

type GetPromptParams

type GetPromptParams 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"`
	// Meta carries protocol-level metadata (e.g. W3C traceparent, progressToken).
	Meta *Meta `json:"_meta,omitempty"`
}

GetPromptParams contains parameters for a prompts/get request.

type GetPromptRequest

type GetPromptRequest struct {
	Request
	Params GetPromptParams `json:"params"`
	Header http.Header     `json:"-"`
}

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.

type Icon added in v0.0.28

type Icon struct {
	// URI pointing to the icon resource (HTTPS URL or data URI)
	Src string `json:"src"`

	// Optional MIME type (e.g., "image/png", "image/svg+xml")
	MIMEType string `json:"mimeType,omitempty"`

	// Optional size specifications (e.g., ["48x48"], ["any"] for SVG)
	Sizes []string `json:"sizes,omitempty"`

	// Theme is an optional specifier for the background theme this icon is designed for.
	// Use IconThemeLight for light backgrounds or IconThemeDark for dark backgrounds.
	Theme IconTheme `json:"theme,omitempty"`
}

Icon represents a visual identifier for MCP entities.

type IconTheme added in v0.0.28

type IconTheme string

IconTheme is the background theme an icon is designed to be displayed on.

const (
	// IconThemeLight indicates the icon is designed for use with a light background.
	IconThemeLight IconTheme = "light"
	// IconThemeDark indicates the icon is designed for use with a dark background.
	IconThemeDark IconTheme = "dark"
)

Icon theme constants.

type ImageContent

type ImageContent struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta  `json:"_meta,omitempty"`
	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

func AsImageContent(content any) (*ImageContent, bool)

AsImageContent attempts to cast the given interface to ImageContent

func NewImageContent

func NewImageContent(data, mimeType string) ImageContent

NewImageContent creates a new ImageContent with the given base64-encoded data and MIME type.

type Implementation

type Implementation struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	WebsiteURL  string `json:"websiteUrl,omitempty"`
	// Icons provides visual identifiers for the implementation
	Icons []Icon `json:"icons,omitempty"`
}

Implementation describes the name and version of an MCP implementation.

type InitializeParams

type InitializeParams 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"`
}

InitializeParams are the params of an initialize request.

type InitializeRequest

type InitializeRequest struct {
	Request
	Params InitializeParams `json:"params"`
	Header http.Header      `json:"-"`
}

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.
	Instructions string `json:"instructions,omitempty"`
}

InitializeResult is sent after receiving an initialize request from the client.

type JSONRPCError

type JSONRPCError struct {
	JSONRPC string              `json:"jsonrpc"`
	ID      RequestId           `json:"id"`
	Error   JSONRPCErrorDetails `json:"error"`
}

JSONRPCError represents a non-successful (error) response to a request.

type JSONRPCErrorDetails

type JSONRPCErrorDetails 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 any `json:"data,omitempty"`
}

JSONRPCErrorDetails represents a JSON-RPC error for Go error handling. This is separate from the JSONRPCError type which represents the full JSON-RPC error response structure.

func NewJSONRPCErrorDetails

func NewJSONRPCErrorDetails(code int, message string, data any) JSONRPCErrorDetails

NewJSONRPCErrorDetails creates a new JSONRPCErrorDetails with the given code, message, and data.

func (*JSONRPCErrorDetails) UnmarshalJSON added in v0.0.28

func (e *JSONRPCErrorDetails) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both the standard JSON-RPC error object ({"code": -32600, "message": "..."}) and non-compliant servers that return the error as a plain string (e.g. "cursor_invalid").

type JSONRPCMessage

type JSONRPCMessage any

JSONRPCMessage represents either a JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, or JSONRPCError

type JSONRPCNotification

type JSONRPCNotification struct {
	JSONRPC string `json:"jsonrpc"`
	Notification
}

JSONRPCNotification represents a notification which does not expect a response.

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string    `json:"jsonrpc"`
	ID      RequestId `json:"id"`
	Result  any       `json:"result"`
}

JSONRPCResponse represents a successful (non-error) response to a request.

func NewJSONRPCResponse added in v0.0.28

func NewJSONRPCResponse(id RequestId, result Result) JSONRPCResponse

NewJSONRPCResponse creates a new JSONRPCResponse with the given id and result. NOTE: This function expects a Result struct, but JSONRPCResponse.Result is typed as `any`. The Result struct wraps the actual result data with optional metadata. For direct result assignment, use NewJSONRPCResultResponse instead.

func NewJSONRPCResultResponse

func NewJSONRPCResultResponse(id RequestId, result any) JSONRPCResponse

NewJSONRPCResultResponse creates a new JSONRPCResponse with the given id and result. This function accepts any type for the result, matching the JSONRPCResponse.Result field type.

type ListPromptsRequest

type ListPromptsRequest struct {
	PaginatedRequest
	Header http.Header `json:"-"`
}

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.

type ListResourceTemplatesRequest

type ListResourceTemplatesRequest struct {
	PaginatedRequest
	Header http.Header `json:"-"`
}

ListResourceTemplatesRequest is sent from the client to request a list of resource templates the server has.

type ListResourceTemplatesResult

type ListResourceTemplatesResult struct {
	PaginatedResult
	ResourceTemplates []ResourceTemplate `json:"resourceTemplates"`
}

ListResourceTemplatesResult is the server's response to a resources/templates/list request from the client.

type ListResourcesRequest

type ListResourcesRequest struct {
	PaginatedRequest
	Header http.Header `json:"-"`
}

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.

type ListToolsRequest

type ListToolsRequest struct {
	PaginatedRequest
	Header http.Header `json:"-"`
}

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.

type LoggingLevel added in v0.0.28

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"
)

MCP logging levels.

type MCPMethod

type MCPMethod string

MCPMethod is the type of MCP method-name constants. MCPMethod is the type of MCP method-name constants.

const (
	// MethodInitialize initiates connection and negotiates protocol capabilities.
	MethodInitialize MCPMethod = "initialize"

	// MethodPing verifies connection liveness between client and server.
	MethodPing MCPMethod = "ping"

	// MethodResourcesList lists all available server resources.
	MethodResourcesList MCPMethod = "resources/list"

	// MethodResourcesTemplatesList provides URI templates for constructing resource URIs.
	MethodResourcesTemplatesList MCPMethod = "resources/templates/list"

	// MethodResourcesRead retrieves content of a specific resource by URI.
	MethodResourcesRead MCPMethod = "resources/read"

	// MethodPromptsList lists all available prompt templates.
	MethodPromptsList MCPMethod = "prompts/list"

	// MethodPromptsGet retrieves a specific prompt template with filled parameters.
	MethodPromptsGet MCPMethod = "prompts/get"

	// MethodToolsList lists all available executable tools.
	MethodToolsList MCPMethod = "tools/list"

	// MethodToolsCall invokes a specific tool with provided parameters.
	MethodToolsCall MCPMethod = "tools/call"

	// MethodSetLogLevel configures the minimum log level for client.
	MethodSetLogLevel MCPMethod = "logging/setLevel"

	// MethodElicitationCreate requests additional information from the user during interactions.
	MethodElicitationCreate MCPMethod = "elicitation/create"

	// MethodListRoots requests roots list from the client during interactions.
	MethodListRoots MCPMethod = "roots/list"

	// MethodNotificationInitialized indicates that the client completed initialization.
	MethodNotificationInitialized MCPMethod = "notifications/initialized"
)

MCP method names.

type Meta

type 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

	// AdditionalFields are any fields present in the Meta that are not
	// otherwise defined in the protocol.
	AdditionalFields map[string]any
}

Meta is metadata attached to a request's parameters. This can include fields formally defined by the protocol or other arbitrary data.

func NewMetaFromMap

func NewMetaFromMap(m map[string]any) *Meta

NewMetaFromMap builds a *Meta from a raw map.

func (*Meta) MarshalJSON added in v0.0.28

func (m *Meta) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Meta.

func (*Meta) UnmarshalJSON added in v0.0.28

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

UnmarshalJSON implements json.Unmarshaler for Meta.

type Notification

type Notification struct {
	Method string             `json:"method"`
	Params NotificationParams `json:"params,omitzero"`
}

Notification is the base of a JSON-RPC notification (method + params).

type NotificationParams

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]any `json:"_meta,omitempty"`

	// Additional fields can be added to this map
	AdditionalFields map[string]any `json:"-"`
}

NotificationParams carries a notification's params.

func (NotificationParams) MarshalJSON added in v0.0.28

func (p NotificationParams) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling

func (*NotificationParams) UnmarshalJSON added in v0.0.28

func (p *NotificationParams) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling

type PaginatedParams added in v0.0.28

type PaginatedParams struct {
	// An opaque token representing the current pagination position.
	// If provided, the server should return results starting after this cursor.
	Cursor Cursor `json:"cursor,omitempty"`
	// Meta carries protocol-level metadata. PaginatedRequest embeds Request
	// and shadows its Params with this type, so Meta must be declared here
	// to be marshaled on paginated requests (tools/list, resources/list,
	// resources/templates/list, prompts/list, tasks/list).
	Meta *Meta `json:"_meta,omitempty"`
}

PaginatedParams carries the cursor and _meta for a paginated request.

type PaginatedRequest added in v0.0.28

type PaginatedRequest struct {
	Request
	Params PaginatedParams `json:"params,omitzero"`
}

PaginatedRequest is the base for paginated list requests.

type PaginatedResult added in v0.0.28

type PaginatedResult struct {
	Result
	// An opaque token representing the pagination position after the last
	// returned result.
	// If present, there may be more results available.
	NextCursor Cursor `json:"nextCursor,omitempty"`
}

PaginatedResult is the base for paginated list results.

type PingRequest

type PingRequest struct {
	Request
	Header http.Header `json:"-"`
}

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 ProgressToken added in v0.0.28

type ProgressToken any

ProgressToken is used to associate progress notifications with the original request.

type Prompt

type Prompt struct {
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta `json:"_meta,omitempty"`
	// The name of the prompt or prompt template.
	Name string `json:"name"`
	// Title is an optional human-readable, UI-friendly display name for the prompt.
	// If not provided, clients should fall back to Name.
	Title string `json:"title,omitempty"`
	// 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"`
	// Icons provides visual identifiers for the prompt
	Icons []Icon `json:"icons,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

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.

func (Prompt) GetName added in v0.0.28

func (p Prompt) GetName() string

GetName returns the name of the prompt.

type PromptArgument

type PromptArgument struct {
	// The name of the argument.
	Name string `json:"name"`
	// Title is an optional human-readable, UI-friendly display name for the argument.
	// If not provided, clients should fall back to Name.
	Title string `json:"title,omitempty"`
	// 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 PromptMessage

type PromptMessage struct {
	Role    Role    `json:"role"`
	Content Content `json:"content"` // Can be TextContent, ImageContent, AudioContent 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.0.28

func NewPromptMessage(role Role, content Content) PromptMessage

NewPromptMessage creates a new PromptMessage.

type PromptOption

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 WithPromptDescription

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 PropertyOption

type PropertyOption func(map[string]any)

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 Description

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 Required

func Required() PropertyOption

Required marks a property as required in the tool's input schema. Required properties must be provided when using the tool.

type ReadResourceParams

type ReadResourceParams 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]any `json:"arguments,omitempty"`
	// Meta carries protocol-level metadata (e.g. W3C traceparent, progressToken).
	Meta *Meta `json:"_meta,omitempty"`
}

ReadResourceParams are the params of a read.

type ReadResourceRequest

type ReadResourceRequest struct {
	Request
	Header http.Header        `json:"-"`
	Params ReadResourceParams `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.

type Request

type Request struct {
	Method string        `json:"method"`
	Params RequestParams `json:"params,omitzero"`
}

Request is the base type embedded in protocol request messages.

type RequestId

type RequestId struct {
	// contains filtered or unexported fields
}

RequestId is a uniquely identifying ID for a request in JSON-RPC. It can be any JSON-serializable value, typically a number or string.

func NewRequestId

func NewRequestId(value any) RequestId

NewRequestId creates a new RequestId with the given value

func (RequestId) IsNil added in v0.0.28

func (r RequestId) IsNil() bool

IsNil returns true if the RequestId is nil

func (RequestId) MarshalJSON added in v0.0.28

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

MarshalJSON implements json.Marshaler for RequestId.

func (RequestId) String added in v0.0.28

func (r RequestId) String() string

String returns a string representation of the RequestId

func (*RequestId) UnmarshalJSON added in v0.0.28

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

UnmarshalJSON implements json.Unmarshaler for RequestId.

func (RequestId) Value added in v0.0.28

func (r RequestId) Value() any

Value returns the underlying value of the RequestId

type RequestParams

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

RequestParams is the base params type carrying _meta.

type Resource

type Resource struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta `json:"_meta,omitempty"`
	// 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"`
	// Title is an optional human-readable, UI-friendly display name for this resource.
	// If not provided, clients should fall back to Name.
	Title string `json:"title,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"`
	// The MIME type of this resource, if known.
	MIMEType string `json:"mimeType,omitempty"`
	// Icons provides visual identifiers for the resource
	Icons []Icon `json:"icons,omitempty"`
	// Size is the size of the raw resource content, in bytes (i.e., before base64
	// encoding or any tokenization), if known. This can be used by hosts to
	// display file sizes and estimate context window usage.
	//
	// A pointer is used so that an explicit zero size remains distinguishable
	// from an unset value.
	Size *int64 `json:"size,omitempty"`
}

Resource represents a known resource that the server is capable of reading.

func (Resource) GetName added in v0.0.28

func (r Resource) GetName() string

GetName returns the name of the resource.

type ResourceContents

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

ResourceContents represents the contents of a specific resource or sub- resource.

type ResourceLink struct {
	Annotated
	Type string `json:"type"` // Must be "resource_link"
	// The URI of the resource.
	URI string `json:"uri"`
	// The name of the resource.
	Name string `json:"name"`
	// Title is an optional human-readable, UI-friendly display name for this resource.
	// If not provided, clients should fall back to Name.
	Title string `json:"title,omitempty"`
	// The description of the resource.
	Description string `json:"description"`
	// The MIME type of the resource.
	MIMEType string `json:"mimeType"`
	// Size is the size of the raw resource content, in bytes (i.e., before base64
	// encoding or any tokenization), if known. This can be used by hosts to
	// display file sizes and estimate context window usage.
	//
	// A pointer is used so that an explicit zero size remains distinguishable
	// from an unset value.
	Size *int64 `json:"size,omitempty"`
}

ResourceLink represents a link to a resource that the client can access.

func NewResourceLink(uri, name, description, mimeType string) ResourceLink

NewResourceLink creates a new ResourceLink with the given URI, name, description, and MIME type.

type ResourceTemplate

type ResourceTemplate struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta `json:"_meta,omitempty"`
	// A URI template (according to RFC 6570) that can be used to construct
	// resource URIs.
	URITemplate string `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"`
	// Title is an optional human-readable, UI-friendly display name for this resource template.
	// If not provided, clients should fall back to Name.
	Title string `json:"title,omitempty"`
	// 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"`
	// Icons provides visual identifiers for the resource template
	Icons []Icon `json:"icons,omitempty"`
}

ResourceTemplate represents a template description for resources available on the server.

func (ResourceTemplate) GetName added in v0.0.28

func (rt ResourceTemplate) GetName() string

GetName returns the name of the resourceTemplate.

type Result

type Result struct {
	// This result property is reserved by the protocol to allow clients and
	// servers to attach additional metadata to their responses.
	Meta *Meta `json:"_meta,omitempty"`
}

Result is the base type embedded in protocol result messages.

type Role

type Role string

Role represents the sender or recipient of messages and data in a conversation.

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
)

Message roles.

type SamplingCapability added in v0.0.28

type SamplingCapability struct {
	// Context, if non-nil, advertises that the client honours the
	// CreateMessageParams.IncludeContext field.
	Context *struct{} `json:"context,omitempty"`
	// Tools, if non-nil, advertises that the client honours the
	// CreateMessageParams.Tools and CreateMessageParams.ToolChoice fields
	// (sampling with tools).
	Tools *struct{} `json:"tools,omitempty"`
}

SamplingCapability represents the sampling capabilities of a client or server as defined by the 2025-11-25 protocol revision.

type ServerCapabilities

type ServerCapabilities struct {
	// Optional, present if the server is advertising extension support.
	Extensions map[string]any `json:"extensions,omitempty"`
	// Experimental, non-standard capabilities that the server supports.
	Experimental map[string]any `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 supports sending sampling requests to clients.
	Sampling *SamplingCapability `json:"sampling,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"`
	// Present if the server supports elicitation requests to the client.
	Elicitation *ElicitationCapability `json:"elicitation,omitempty"`
	// Present if the server supports roots requests to the client.
	Roots *struct{} `json:"roots,omitempty"`
	// Present if the server supports task-based execution.
	Tasks *TasksCapability `json:"tasks,omitempty"`
	// Present if the server supports completions requests to the client.
	Completions *struct{} `json:"completions,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 SetLevelParams added in v0.0.28

type SetLevelParams 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"`
}

SetLevelParams carries the level for a SetLevelRequest.

type SetLevelRequest added in v0.0.28

type SetLevelRequest struct {
	Request
	Params SetLevelParams `json:"params"`
	Header http.Header    `json:"-"`
}

SetLevelRequest is a request from the client to the server, to enable or adjust logging.

type TaskParams added in v0.0.28

type TaskParams struct {
	// Requested duration in milliseconds to retain task from creation.
	TTL *int64 `json:"ttl,omitempty"`
}

TaskParams represents the task metadata included when augmenting a request.

type TaskRequestsCapability added in v0.0.28

type TaskRequestsCapability struct {
	// Tool-related capabilities.
	Tools *struct {
		// Whether tools/call can be augmented with task metadata.
		Call *struct{} `json:"call,omitempty"`
	} `json:"tools,omitempty"`
	// Sampling-related capabilities.
	Sampling *struct {
		// Whether sampling/createMessage can be augmented with task metadata.
		CreateMessage *struct{} `json:"createMessage,omitempty"`
	} `json:"sampling,omitempty"`
	// Elicitation-related capabilities.
	Elicitation *struct {
		// Whether elicitation/create can be augmented with task metadata.
		Create *struct{} `json:"create,omitempty"`
	} `json:"elicitation,omitempty"`
}

TaskRequestsCapability indicates which request types support task augmentation.

type TaskSupport added in v0.0.28

type TaskSupport string

TaskSupport indicates how a tool supports task augmentation.

const (
	// TaskSupportForbidden means the tool cannot be invoked as a task (default).
	TaskSupportForbidden TaskSupport = "forbidden"
	// TaskSupportOptional means the tool can be invoked as a task or normally.
	TaskSupportOptional TaskSupport = "optional"
	// TaskSupportRequired means the tool must be invoked as a task.
	TaskSupportRequired TaskSupport = "required"
)

type TasksCapability added in v0.0.28

type TasksCapability struct {
	// Whether the party supports the tasks/list operation.
	List *struct{} `json:"list,omitempty"`
	// Whether the party supports the tasks/cancel operation.
	Cancel *struct{} `json:"cancel,omitempty"`
	// Requests that can be augmented with task metadata.
	Requests *TaskRequestsCapability `json:"requests,omitempty"`
}

TasksCapability represents the task capabilities that a client or server may support.

type TextContent

type TextContent struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta  `json:"_meta,omitempty"`
	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

func AsTextContent(content any) (*TextContent, bool)

AsTextContent attempts to cast the given interface to TextContent

func NewTextContent

func NewTextContent(text string) TextContent

NewTextContent creates a new TextContent with the given text.

type TextResourceContents

type TextResourceContents struct {
	// Raw per-resource metadata; pass-through as defined by MCP. Not the same as Meta.
	// Allows _meta to be used for MCP-UI features for example. Does not assume any specific format.
	Meta map[string]any `json:"_meta,omitempty"`
	// 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"`
}

TextResourceContents is text resource contents.

func AsTextResourceContents

func AsTextResourceContents(content any) (*TextResourceContents, bool)

AsTextResourceContents attempts to cast the given interface to TextResourceContents

type Tool

type Tool struct {
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta `json:"_meta,omitempty"`
	// The name of the tool.
	Name string `json:"name"`
	// Title is an optional human-readable, UI-friendly display name for the tool.
	// If not provided, clients should use Annotations.Title (if set) and fall back to Name.
	Title string `json:"title,omitempty"`
	// 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
	// A JSON Schema object defining the expected output returned by the tool .
	OutputSchema ToolOutputSchema `json:"outputSchema,omitzero"`
	// Optional JSON Schema defining expected output structure
	RawOutputSchema json.RawMessage `json:"-"` // Hide this from JSON marshaling
	// Optional properties describing tool behavior
	Annotations ToolAnnotation `json:"annotations"`
	// Support for deferred loading
	DeferLoading bool `json:"defer_loading,omitempty"`
	// Icons provides visual identifiers for the tool
	Icons []Icon `json:"icons,omitempty"`
	// Execution describes execution behavior for the tool
	Execution *ToolExecution `json:"execution,omitempty"`
}

Tool represents the definition for a tool the client can call.

func NewTool

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

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) GetName added in v0.0.28

func (t Tool) GetName() string

GetName returns the name of the tool.

func (Tool) MarshalJSON added in v0.0.28

func (t Tool) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Tool. It handles marshaling either InputSchema or RawInputSchema based on which is set.

type ToolAnnotation

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"`
}

ToolAnnotation carries tool behavior hints.

type ToolArgumentsSchema added in v0.0.28

type ToolArgumentsSchema struct {
	Defs                 map[string]any `json:"$defs,omitempty"`
	Type                 string         `json:"type"`
	Properties           map[string]any `json:"properties"`
	Required             []string       `json:"required,omitempty"`
	AdditionalProperties any            `json:"additionalProperties,omitempty"`
}

ToolArgumentsSchema represents a JSON Schema for tool arguments.

func (ToolArgumentsSchema) MarshalJSON added in v0.0.28

func (tas ToolArgumentsSchema) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ToolArgumentsSchema.

func (*ToolArgumentsSchema) UnmarshalJSON added in v0.0.28

func (tas *ToolArgumentsSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ToolArgumentsSchema.

type ToolExecution added in v0.0.28

type ToolExecution struct {
	// TaskSupport indicates whether the tool supports task augmentation.
	TaskSupport TaskSupport `json:"taskSupport,omitempty"`
}

ToolExecution describes execution behavior for a tool.

type ToolInputSchema

type ToolInputSchema ToolArgumentsSchema

ToolInputSchema remains a named type for retro-compatibility, so its JSON methods explicitly forward to ToolArgumentsSchema.

func (ToolInputSchema) MarshalJSON added in v0.0.28

func (tis ToolInputSchema) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ToolInputSchema.

func (*ToolInputSchema) UnmarshalJSON added in v0.0.28

func (tis *ToolInputSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ToolInputSchema.

type ToolOption

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 WithDescription

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 WithString

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.

type ToolOutputSchema

type ToolOutputSchema ToolArgumentsSchema

ToolOutputSchema is a tool's output JSON schema.

func (ToolOutputSchema) MarshalJSON added in v0.0.28

func (tos ToolOutputSchema) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ToolOutputSchema.

func (*ToolOutputSchema) UnmarshalJSON added in v0.0.28

func (tos *ToolOutputSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ToolOutputSchema.

type ToolResultContent added in v0.0.28

type ToolResultContent struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta  `json:"_meta,omitempty"`
	Type string `json:"type"` // Must be "tool_result"
	// ToolUseID is the ID of the tool use this result corresponds to.
	// This MUST match the ID from a previous ToolUseContent.
	ToolUseID string `json:"toolUseId"`
	// Content is the unstructured result content of the tool use.
	Content []Content `json:"content"`
	// Whether the tool use resulted in an error.
	IsError bool `json:"isError,omitempty"`
}

ToolResultContent represents the result of a tool invocation within a sampling message. It must have Type set to "tool_result".

func AsToolResultContent added in v0.0.28

func AsToolResultContent(content any) (*ToolResultContent, bool)

AsToolResultContent attempts to cast the given interface to ToolResultContent

func (*ToolResultContent) UnmarshalJSON added in v0.0.28

func (t *ToolResultContent) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for ToolResultContent to handle the nested Content interface slice.

type ToolUseContent added in v0.0.28

type ToolUseContent struct {
	Annotated
	// Meta is a metadata object that is reserved by MCP for storing additional information.
	Meta *Meta  `json:"_meta,omitempty"`
	Type string `json:"type"` // Must be "tool_use"
	// ID is a unique identifier for this tool use, used to match tool results to their corresponding tool uses.
	ID string `json:"id"`
	// Name is the name of the tool to call.
	Name string `json:"name"`
	// Input contains the arguments to pass to the tool, conforming to the tool's input schema.
	Input any `json:"input"`
}

ToolUseContent represents a request from the assistant to call a tool within a sampling message. It must have Type set to "tool_use".

func AsToolUseContent added in v0.0.28

func AsToolUseContent(content any) (*ToolUseContent, bool)

AsToolUseContent attempts to cast the given interface to ToolUseContent

Jump to

Keyboard shortcuts

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