protocol

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 11 Imported by: 27

Documentation

Index

Constants

View Source
const (
	ParseError     = -32700 // Invalid JSON
	InvalidRequest = -32600 // The JSON sent is not a valid Request object
	MethodNotFound = -32601 // The method does not exist / is not available
	InvalidParams  = -32602 // Invalid method parameter(s)
	InternalError  = -32603 // Internal JSON-RPC error

	// 可以定义自己的错误代码,范围在-32000 以上。
	ConnectionError = -32400
)

Standard JSON-RPC error codes

View Source
const ProgressTokenKey = "progressToken"
View Source
const Version = "2025-03-26"

Variables

View Source
var SupportedVersion = map[string]struct{}{
	"2024-11-05": {},
	"2025-03-26": {},
}

Functions

func IsInitializedRequest added in v0.2.9

func IsInitializedRequest(rawParams json.RawMessage) bool

func VerifyAndUnmarshal added in v0.1.4

func VerifyAndUnmarshal(content json.RawMessage, v any) error

Types

type Annotated

type Annotated struct {
	Annotations *Annotations `json:"annotations,omitempty"`
}

Annotated represents base objects that include optional annotations

type Annotations

type Annotations struct {
	Audience []Role  `json:"audience,omitempty"`
	Priority float64 `json:"priority,omitempty"`
}

Annotations represents optional annotations for objects

type AudioContent added in v0.1.15

type AudioContent struct {
	Annotated
	Type     string `json:"type"`
	Data     []byte `json:"data"`
	MimeType string `json:"mimeType"`
}

func (*AudioContent) GetType added in v0.1.15

func (i *AudioContent) GetType() string

type BlobResourceContents

type BlobResourceContents struct {
	URI      string `json:"uri"`
	Blob     []byte `json:"blob"`
	MimeType string `json:"mimeType,omitempty"`
}

func (*BlobResourceContents) GetMimeType

func (b *BlobResourceContents) GetMimeType() string

func (*BlobResourceContents) GetURI

func (b *BlobResourceContents) GetURI() string

type CallToolRequest

type CallToolRequest struct {
	Meta         map[string]interface{} `json:"_meta,omitempty"`
	Name         string                 `json:"name"`
	Arguments    map[string]interface{} `json:"arguments,omitempty"`
	RawArguments json.RawMessage        `json:"-"`
}

CallToolRequest represents a request to call a specific tool

func NewCallToolRequest

func NewCallToolRequest(name string, arguments map[string]interface{}) *CallToolRequest

NewCallToolRequest creates a new call tool request

func NewCallToolRequestWithRawArguments added in v0.1.11

func NewCallToolRequestWithRawArguments(name string, rawArguments json.RawMessage) *CallToolRequest

func (*CallToolRequest) MarshalJSON added in v0.1.11

func (r *CallToolRequest) MarshalJSON() ([]byte, error)

func (*CallToolRequest) UnmarshalJSON added in v0.1.2

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

type CallToolResult

type CallToolResult struct {
	Content []Content `json:"content"`
	IsError bool      `json:"isError,omitempty"`
}

CallToolResult represents the response to a tool call

func NewCallToolResult

func NewCallToolResult(content []Content, isError bool) *CallToolResult

NewCallToolResult creates a new call tool response

func (*CallToolResult) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface for CallToolResult

type CancelledNotification

type CancelledNotification struct {
	RequestID RequestID `json:"requestId"`
	Reason    string    `json:"reason,omitempty"`
}

CancelledNotification represents a notification that a request has been canceled

func NewCancelledNotification

func NewCancelledNotification(requestID RequestID, reason string) *CancelledNotification

NewCancelledNotification creates a new canceled notification

type ClientCapabilities

type ClientCapabilities struct {
	// Experimental map[string]interface{} `json:"experimental,omitempty"`
	// Roots        *RootsCapability       `json:"roots,omitempty"`
	Sampling interface{} `json:"sampling,omitempty"`
}

ClientCapabilities capabilities

type ClientNotify

type ClientNotify interface{}

type ClientRequest

type ClientRequest interface{}

type ClientResponse

type ClientResponse interface{}

type Complete

type Complete struct {
	Values  []string `json:"values"`
	HasMore bool     `json:"hasMore,omitempty"`
	Total   int      `json:"total,omitempty"`
}

type CompleteRequest

type CompleteRequest struct {
	Argument struct {
		Name  string `json:"name"`
		Value string `json:"value"`
	} `json:"argument"`
	Ref interface{} `json:"ref"` // Can be PromptReference or ResourceReference
}

CompleteRequest represents a request for completion options

func NewCompleteRequest

func NewCompleteRequest(argName string, argValue string, ref interface{}) *CompleteRequest

NewCompleteRequest creates a new completion request

type CompleteResult

type CompleteResult struct {
	Completion *Complete `json:"completion"`
}

CompleteResult represents the response to a completion request

func NewCompleteResult

func NewCompleteResult(values []string, hasMore bool, total int) *CompleteResult

NewCompleteResult creates a new completion response

type Content

type Content interface {
	GetType() string
}

Content interfaces and types

type CreateMessageOption

type CreateMessageOption func(*CreateMessageRequest)

CreateMessageOption represents an option for creating a message

func WithIncludeContext

func WithIncludeContext(ctx string) CreateMessageOption

WithIncludeContext sets the include context option for the request

func WithMetadata

func WithMetadata(metadata map[string]interface{}) CreateMessageOption

WithMetadata sets the metadata for the request

func WithModelPreferences

func WithModelPreferences(prefs *ModelPreferences) CreateMessageOption

WithModelPreferences sets the model preferences for the request

func WithStopSequences

func WithStopSequences(sequences []string) CreateMessageOption

WithStopSequences sets the stop sequences for the request

func WithSystemPrompt

func WithSystemPrompt(prompt string) CreateMessageOption

WithSystemPrompt sets the system prompt for the request

func WithTemperature

func WithTemperature(temp float64) CreateMessageOption

WithTemperature sets the temperature for the request

type CreateMessageRequest

type CreateMessageRequest struct {
	Messages         []*SamplingMessage     `json:"messages"`
	MaxTokens        int                    `json:"maxTokens"`
	Temperature      float64                `json:"temperature,omitempty"`
	StopSequences    []string               `json:"stopSequences,omitempty"`
	SystemPrompt     string                 `json:"systemPrompt,omitempty"`
	ModelPreferences *ModelPreferences      `json:"modelPreferences,omitempty"`
	IncludeContext   string                 `json:"includeContext,omitempty"`
	Metadata         map[string]interface{} `json:"metadata,omitempty"`
}

CreateMessageRequest represents a request to create a message through sampling

func NewCreateMessageRequest

func NewCreateMessageRequest(messages []*SamplingMessage, maxTokens int, opts ...CreateMessageOption) *CreateMessageRequest

NewCreateMessageRequest creates a new create message request

type CreateMessageResult

type CreateMessageResult struct {
	Content    Content `json:"content"`
	Role       Role    `json:"role"`
	Model      string  `json:"model"`
	StopReason string  `json:"stopReason,omitempty"`
}

CreateMessageResult represents the response to a create message request

func NewCreateMessageResult

func NewCreateMessageResult(content Content, role Role, model string, stopReason string) *CreateMessageResult

NewCreateMessageResult creates a new create message response

func (*CreateMessageResult) UnmarshalJSON added in v0.2.3

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

UnmarshalJSON implements the json.Unmarshaler interface for CreateMessageResult

type Cursor added in v0.2.6

type Cursor string

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

func PaginationLimit added in v0.2.6

func PaginationLimit[T Named](allElements []T, cursor Cursor, limit int) ([]T, Cursor, error)

type DataType added in v0.1.2

type DataType string
const (
	ObjectT DataType = "object"
	Number  DataType = "number"
	Integer DataType = "integer"
	String  DataType = "string"
	Array   DataType = "array"
	Null    DataType = "null"
	Boolean DataType = "boolean"
)

type EmbeddedResource

type EmbeddedResource struct {
	Type        string           `json:"type"` // Must be "resource"
	Resource    ResourceContents `json:"resource"`
	Annotations *Annotations     `json:"annotations,omitempty"`
}

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 NewEmbeddedResource

func NewEmbeddedResource(resource ResourceContents, annotations *Annotations) *EmbeddedResource

NewEmbeddedResource creates a new EmbeddedResource

func (*EmbeddedResource) GetType

func (i *EmbeddedResource) GetType() string

type GetPromptRequest

type GetPromptRequest struct {
	Name      string            `json:"name"`
	Arguments map[string]string `json:"arguments,omitempty"`
}

GetPromptRequest represents a request to get a specific prompt

func NewGetPromptRequest

func NewGetPromptRequest(name string, arguments map[string]string) *GetPromptRequest

NewGetPromptRequest creates a new get prompt request

type GetPromptResult

type GetPromptResult struct {
	Messages    []*PromptMessage `json:"messages"`
	Description string           `json:"description,omitempty"`
}

GetPromptResult represents the response to a get prompt request

func NewGetPromptResult

func NewGetPromptResult(messages []*PromptMessage, description string) *GetPromptResult

NewGetPromptResult creates a new get prompt response

type ImageContent

type ImageContent struct {
	Annotated
	Type     string `json:"type"`
	Data     []byte `json:"data"`
	MimeType string `json:"mimeType"`
}

func (*ImageContent) GetType

func (i *ImageContent) GetType() string

type Implementation

type Implementation struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Implementation describes the name and version of an MCP implementation

type InitializeRequest

type InitializeRequest struct {
	ClientInfo      *Implementation     `json:"clientInfo"`
	Capabilities    *ClientCapabilities `json:"capabilities"`
	ProtocolVersion string              `json:"protocolVersion"`
}

InitializeRequest represents the initialize request sent from client to server

func NewInitializeRequest

func NewInitializeRequest(clientInfo *Implementation, capabilities *ClientCapabilities) *InitializeRequest

NewInitializeRequest creates a new initialize request

type InitializeResult

type InitializeResult struct {
	ServerInfo      *Implementation     `json:"serverInfo"`
	Capabilities    *ServerCapabilities `json:"capabilities"`
	ProtocolVersion string              `json:"protocolVersion"`
	Instructions    string              `json:"instructions,omitempty"`
}

InitializeResult represents the server's response to an initialize request

func NewInitializeResult

func NewInitializeResult(serverInfo *Implementation, capabilities *ServerCapabilities, version string, instructions string) *InitializeResult

NewInitializeResult creates a new initialize response

type InitializedNotification

type InitializedNotification struct {
	Meta map[string]interface{} `json:"_meta,omitempty"`
}

InitializedNotification represents the notification sent from client to server after initialization

func NewInitializedNotification

func NewInitializedNotification() *InitializedNotification

NewInitializedNotification creates a new initialized notification

type InputSchema

type InputSchema struct {
	Type       InputSchemaType      `json:"type"`
	Properties map[string]*Property `json:"properties,omitempty"`
	Required   []string             `json:"required,omitempty"`
}

InputSchema represents a JSON Schema object defining the expected parameters for a tool

type InputSchemaType

type InputSchemaType string
const Object InputSchemaType = "object"

type JSONRPCNotification

type JSONRPCNotification struct {
	JSONRPC   string          `json:"jsonrpc"`
	Method    Method          `json:"method"`
	Params    interface{}     `json:"params,omitempty"`
	RawParams json.RawMessage `json:"-"`
}

func NewJSONRPCNotification

func NewJSONRPCNotification(method Method, params interface{}) *JSONRPCNotification

NewJSONRPCNotification creates a new JSON-RPC notification

func (*JSONRPCNotification) UnmarshalJSON

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

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC   string          `json:"jsonrpc"`
	ID        RequestID       `json:"id"`
	Method    Method          `json:"method"`
	Params    interface{}     `json:"params,omitempty"`
	RawParams json.RawMessage `json:"-"`
}

func NewJSONRPCRequest

func NewJSONRPCRequest(id RequestID, method Method, params interface{}) *JSONRPCRequest

NewJSONRPCRequest creates a new JSON-RPC request

func (*JSONRPCRequest) IsValid

func (r *JSONRPCRequest) IsValid() bool

IsValid checks if the request is valid according to JSON-RPC 2.0 spec

func (*JSONRPCRequest) UnmarshalJSON

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

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC   string          `json:"jsonrpc"`
	ID        RequestID       `json:"id"`
	Result    interface{}     `json:"result,omitempty"`
	RawResult json.RawMessage `json:"-"`
	Error     *responseErr    `json:"error,omitempty"`
}

JSONRPCResponse represents a response to a request.

func NewJSONRPCErrorResponse

func NewJSONRPCErrorResponse(id RequestID, code int, message string) *JSONRPCResponse

NewJSONRPCErrorResponse NewError creates a new JSON-RPC error response

func NewJSONRPCSuccessResponse

func NewJSONRPCSuccessResponse(id RequestID, result interface{}) *JSONRPCResponse

NewJSONRPCSuccessResponse creates a new JSON-RPC response

func (*JSONRPCResponse) UnmarshalJSON

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

type ListPromptsRequest

type ListPromptsRequest struct {
	Cursor Cursor `json:"cursor,omitempty"`
}

ListPromptsRequest represents a request to list available prompts

func NewListPromptsRequest

func NewListPromptsRequest() *ListPromptsRequest

NewListPromptsRequest creates a new list prompts request

type ListPromptsResult

type ListPromptsResult struct {
	Prompts    []*Prompt `json:"prompts"`
	NextCursor Cursor    `json:"nextCursor,omitempty"`
}

ListPromptsResult represents the response to a list prompts request

func NewListPromptsResult

func NewListPromptsResult(prompts []*Prompt, nextCursor Cursor) *ListPromptsResult

NewListPromptsResult creates a new list prompts response

type ListResourceTemplatesRequest

type ListResourceTemplatesRequest struct {
	Cursor Cursor `json:"cursor,omitempty"`
}

ListResourceTemplatesRequest represents a request to list resource templates

func NewListResourceTemplatesRequest

func NewListResourceTemplatesRequest() *ListResourceTemplatesRequest

NewListResourceTemplatesRequest creates a new list resource templates request

type ListResourceTemplatesResult

type ListResourceTemplatesResult struct {
	ResourceTemplates []*ResourceTemplate `json:"resourceTemplates"`
	NextCursor        Cursor              `json:"nextCursor,omitempty"`
}

ListResourceTemplatesResult represents the response to a list resource templates request

func NewListResourceTemplatesResult

func NewListResourceTemplatesResult(templates []*ResourceTemplate, nextCursor Cursor) *ListResourceTemplatesResult

NewListResourceTemplatesResult creates a new list resource templates response

type ListResourcesRequest

type ListResourcesRequest struct {
	Cursor Cursor `json:"cursor,omitempty"`
}

ListResourcesRequest Sent from the client to request a list of resources the server has.

func NewListResourcesRequest

func NewListResourcesRequest() *ListResourcesRequest

NewListResourcesRequest creates a new list resources request

type ListResourcesResult

type ListResourcesResult struct {
	Resources []*Resource `json:"resources"`
	/**
	 * 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"`
}

ListResourcesResult The server's response to a resources/list request from the client.

func NewListResourcesResult

func NewListResourcesResult(resources []*Resource, nextCursor Cursor) *ListResourcesResult

NewListResourcesResult creates a new list resources response

type ListRootsRequest

type ListRootsRequest struct{}

ListRootsRequest represents a request to list root directories

func NewListRootsRequest

func NewListRootsRequest() *ListRootsRequest

NewListRootsRequest creates a new list roots request

type ListRootsResult

type ListRootsResult struct {
	Roots []*Root `json:"roots"`
}

ListRootsResult represents the response to a list roots request

func NewListRootsResult

func NewListRootsResult(roots []*Root) *ListRootsResult

NewListRootsResult creates a new list roots response

type ListToolsRequest

type ListToolsRequest struct {
	Cursor Cursor `json:"cursor,omitempty"`
}

ListToolsRequest represents a request to list available tools

func NewListToolsRequest

func NewListToolsRequest() *ListToolsRequest

NewListToolsRequest creates a new list tools request

type ListToolsResult

type ListToolsResult struct {
	Tools      []*Tool `json:"tools"`
	NextCursor Cursor  `json:"nextCursor,omitempty"`
}

ListToolsResult represents the response to a list tools request

func NewListToolsResult

func NewListToolsResult(tools []*Tool, nextCursor Cursor) *ListToolsResult

NewListToolsResult creates a new list tools response

type LogMessageNotification

type LogMessageNotification struct {
	Level   LoggingLevel           `json:"level"`
	Message string                 `json:"message"`
	Meta    map[string]interface{} `json:"meta,omitempty"`
}

LogMessageNotification represents a log message notification

func NewLogMessageNotification

func NewLogMessageNotification(level LoggingLevel, message string, meta map[string]interface{}) *LogMessageNotification

NewLogMessageNotification creates a new log message notification

type LoggingLevel

type LoggingLevel string

LoggingLevel represents the severity of a log message

const (
	LogEmergency LoggingLevel = "emergency"
	LogAlert     LoggingLevel = "alert"
	LogCritical  LoggingLevel = "critical"
	LogError     LoggingLevel = "error"
	LogWarning   LoggingLevel = "warning"
	LogNotice    LoggingLevel = "notice"
	LogInfo      LoggingLevel = "info"
	LogDebug     LoggingLevel = "debug"
)

type Method

type Method string

Method represents the JSON-RPC method name

const (
	// Core methods
	Ping                    Method = "ping"
	Initialize              Method = "initialize"
	NotificationInitialized Method = "notifications/initialized"

	// Root related methods
	RootsList                    Method = "roots/list"
	NotificationRootsListChanged Method = "notifications/roots/list_changed"

	// Resource related methods
	ResourcesList                    Method = "resources/list"
	ResourceListTemplates            Method = "resources/templates/list"
	ResourcesRead                    Method = "resources/read"
	ResourcesSubscribe               Method = "resources/subscribe"
	ResourcesUnsubscribe             Method = "resources/unsubscribe"
	NotificationResourcesListChanged Method = "notifications/resources/list_changed"
	NotificationResourcesUpdated     Method = "notifications/resources/updated"

	// Tool related methods
	ToolsList                    Method = "tools/list"
	ToolsCall                    Method = "tools/call"
	NotificationToolsListChanged Method = "notifications/tools/list_changed"

	// Prompt related methods
	PromptsList                    Method = "prompts/list"
	PromptsGet                     Method = "prompts/get"
	NotificationPromptsListChanged Method = "notifications/prompts/list_changed"

	// Sampling related methods
	SamplingCreateMessage Method = "sampling/createMessage"

	// Logging related methods
	LoggingSetLevel        Method = "logging/setLevel"
	NotificationLogMessage Method = "notifications/message"

	// Completion related methods
	CompletionComplete Method = "completion/complete"

	// progress related methods
	NotificationProgress  Method = "notifications/progress"
	NotificationCancelled Method = "notifications/cancelled" // nolint:misspell
)

type ModelHint

type ModelHint struct {
	Name string `json:"name,omitempty"`
}

ModelHint represents hints to use for model selection

type ModelPreferences

type ModelPreferences struct {
	CostPriority         float64     `json:"costPriority,omitempty"`
	IntelligencePriority float64     `json:"intelligencePriority,omitempty"`
	SpeedPriority        float64     `json:"speedPriority,omitempty"`
	Hints                []ModelHint `json:"hints,omitempty"`
}

ModelPreferences represents the server's preferences for model selection

type Named added in v0.2.6

type Named interface {
	GetName() string
}

type OutputSchema added in v0.2.20

type OutputSchema InputSchema

OutputSchema represents a Optional JSON Schema object defining expected output structure for a tool

type PaginatedRequest

type PaginatedRequest struct {
	Cursor Cursor `json:"cursor,omitempty"`
}

PaginatedRequest represents a request that supports pagination

type PaginatedResult

type PaginatedResult struct {
	NextCursor Cursor `json:"nextCursor,omitempty"`
}

PaginatedResult represents a response that supports pagination

type PingRequest

type PingRequest struct{}

func NewPingRequest

func NewPingRequest() *PingRequest

NewPingRequest creates a new ping request

type PingResult

type PingResult struct{}

func NewPingResult

func NewPingResult() *PingResult

NewPingResult creates a new ping response

type ProgressNotification

type ProgressNotification struct {
	ProgressToken ProgressToken `json:"progressToken"`
	Progress      float64       `json:"progress"`
	Total         float64       `json:"total,omitempty"`
	Message       string        `json:"message,omitempty"`
}

ProgressNotification represents a progress notification for a long-running request

func NewProgressNotification

func NewProgressNotification(progress float64, total float64, message string) *ProgressNotification

NewProgressNotification creates a new progress notification

type ProgressToken

type ProgressToken interface{} // can be string or integer

ProgressToken represents a token used to associate progress notifications with the original request

type Prompt

type Prompt struct {
	Name        string            `json:"name"`
	Description string            `json:"description,omitempty"`
	Arguments   []*PromptArgument `json:"arguments,omitempty"`
}

Prompt related types

func (*Prompt) GetName added in v0.2.6

func (p *Prompt) GetName() string

type PromptArgument

type PromptArgument struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

type PromptListChangedNotification

type PromptListChangedNotification struct {
	Meta map[string]interface{} `json:"_meta,omitempty"`
}

PromptListChangedNotification represents a notification that the prompt list has changed

func NewPromptListChangedNotification

func NewPromptListChangedNotification() *PromptListChangedNotification

NewPromptListChangedNotification creates a new prompt list changed notification

type PromptMessage

type PromptMessage struct {
	Role    Role    `json:"role"`
	Content Content `json:"content"`
}

func (*PromptMessage) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface for PromptMessage

type PromptReference

type PromptReference struct {
	Type string `json:"type"`
	Name string `json:"name"`
}

Reference types

type PromptsCapability

type PromptsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type Property added in v0.1.2

type Property struct {
	Type DataType `json:"type"`
	// Description is the description of the schema.
	Description string `json:"description,omitempty"`
	// Items specifies which data type an array contains, if the schema type is Array.
	Items *Property `json:"items,omitempty"`
	// Properties describes the properties of an object, if the schema type is Object.
	Properties map[string]*Property `json:"properties,omitempty"`
	Required   []string             `json:"required,omitempty"`
	Enum       []any                `json:"enum,omitempty"`
	// Default specifies the default value for the property.
	Default any `json:"default,omitempty"`
}

type ReadResourceRequest

type ReadResourceRequest struct {
	URI       string                 `json:"uri"`
	Arguments map[string]interface{} `json:"-"`
}

ReadResourceRequest represents a request to read a specific resource

func NewReadResourceRequest

func NewReadResourceRequest(uri string) *ReadResourceRequest

NewReadResourceRequest creates a new read resource request

type ReadResourceResult

type ReadResourceResult struct {
	Contents []ResourceContents `json:"contents"`
}

ReadResourceResult The server's response to a resources/read request from the client.

func NewReadResourceResult

func NewReadResourceResult(contents []ResourceContents) *ReadResourceResult

NewReadResourceResult creates a new read resource response

func (*ReadResourceResult) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface for ReadResourceResult

type RequestID

type RequestID interface{} // 字符串/数值

type Resource

type Resource struct {
	Annotated
	// Name A human-readable name for this resource. This can be used by clients to populate UI elements.
	Name string `json:"name"`
	// URI The URI of this resource.
	URI string `json:"uri"`
	// Description 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"`
	// MimeType The MIME type of this resource, if known.
	MimeType string `json:"mimeType,omitempty"`
	Size     int64  `json:"size,omitempty"`
}

Resource A known resource that the server is capable of reading.

func (*Resource) GetName added in v0.2.6

func (r *Resource) GetName() string

type ResourceContents

type ResourceContents interface {
	GetURI() string
	GetMimeType() string
}
type ResourceLink struct {
	Annotated
	Type        string `json:"type"` // Must be "resource_link"
	URI         string `json:"uri"`
	Name        string `json:"name"`
	Description string `json:"description"`
	MIMEType    string `json:"mimeType"`
}

func (*ResourceLink) GetType added in v0.2.16

func (r *ResourceLink) GetType() string

type ResourceListChangedNotification

type ResourceListChangedNotification struct {
	Meta map[string]interface{} `json:"_meta,omitempty"`
}

ResourceListChangedNotification represents a notification that the resource list has changed

func NewResourceListChangedNotification

func NewResourceListChangedNotification() *ResourceListChangedNotification

NewResourceListChangedNotification creates a new resource list changed notification

type ResourceReference

type ResourceReference struct {
	Type string `json:"type"`
	URI  string `json:"uri"`
}

type ResourceTemplate

type ResourceTemplate struct {
	Annotated
	Name              string                `json:"name"`
	URITemplate       string                `json:"uriTemplate"`
	URITemplateParsed *uritemplate.Template `json:"-"`
	Description       string                `json:"description,omitempty"`
	MimeType          string                `json:"mimeType,omitempty"`
}

func (*ResourceTemplate) GetName added in v0.2.6

func (t *ResourceTemplate) GetName() string

func (*ResourceTemplate) GetURITemplate

func (t *ResourceTemplate) GetURITemplate() *uritemplate.Template

func (*ResourceTemplate) ParseURITemplate

func (t *ResourceTemplate) ParseURITemplate() error

func (*ResourceTemplate) UnmarshalJSON

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

type ResourceUpdatedNotification

type ResourceUpdatedNotification struct {
	URI string `json:"uri"`
}

ResourceUpdatedNotification represents a notification that a resource has been updated

func NewResourceUpdatedNotification

func NewResourceUpdatedNotification(uri string) *ResourceUpdatedNotification

NewResourceUpdatedNotification creates a new resource updated notification

type ResourcesCapability

type ResourcesCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
	Subscribe   bool `json:"subscribe,omitempty"`
}

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

type Root

type Root struct {
	Name string `json:"name,omitempty"`
	URI  string `json:"uri"`
}

Root represents a root directory or file that the server can operate on

type RootsCapability

type RootsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type RootsListChangedNotification

type RootsListChangedNotification struct {
	Meta map[string]interface{} `json:"_meta,omitempty"`
}

RootsListChangedNotification represents a notification that the roots list has changed

func NewRootsListChangedNotification

func NewRootsListChangedNotification() *RootsListChangedNotification

NewRootsListChangedNotification creates a new roots list changed notification

type SamplingMessage

type SamplingMessage struct {
	Role    Role    `json:"role"`
	Content Content `json:"content"`
}

func (*SamplingMessage) UnmarshalJSON added in v0.2.3

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

UnmarshalJSON implements the json.Unmarshaler interface for SamplingMessage

type ServerCapabilities

type ServerCapabilities struct {
	// Experimental map[string]interface{} `json:"experimental,omitempty"`
	// Logging      interface{}            `json:"logging,omitempty"`
	Prompts   *PromptsCapability   `json:"prompts,omitempty"`
	Resources *ResourcesCapability `json:"resources,omitempty"`
	Tools     *ToolsCapability     `json:"tools,omitempty"`
}

type ServerNotify

type ServerNotify interface{}

type ServerRequest

type ServerRequest interface{}

type ServerResponse

type ServerResponse interface{}

type SetLoggingLevelRequest

type SetLoggingLevelRequest struct {
	Level LoggingLevel `json:"level"`
}

SetLoggingLevelRequest represents a request to set the logging level

func NewSetLoggingLevelRequest

func NewSetLoggingLevelRequest(level LoggingLevel) *SetLoggingLevelRequest

NewSetLoggingLevelRequest creates a new set logging level request

type SetLoggingLevelResult

type SetLoggingLevelResult struct {
	Success bool `json:"success"`
}

SetLoggingLevelResult represents the response to a set logging level request

func NewSetLoggingLevelResult

func NewSetLoggingLevelResult(success bool) *SetLoggingLevelResult

NewSetLoggingLevelResult creates a new set logging level response

type SubscribeRequest

type SubscribeRequest struct {
	URI string `json:"uri"`
}

SubscribeRequest represents a request to subscribe to resource updates

func NewSubscribeRequest

func NewSubscribeRequest(uri string) *SubscribeRequest

NewSubscribeRequest creates a new subscribe request

type SubscribeResult

type SubscribeResult struct{}

func NewSubscribeResult

func NewSubscribeResult() *SubscribeResult

type TextContent

type TextContent struct {
	Annotated
	Type string `json:"type"`
	Text string `json:"text"`
}

func (*TextContent) GetType

func (t *TextContent) GetType() string

type TextResourceContents

type TextResourceContents struct {
	URI      string `json:"uri"`
	Text     string `json:"text"`
	MimeType string `json:"mimeType,omitempty"`
}

func (*TextResourceContents) GetMimeType

func (t *TextResourceContents) GetMimeType() string

func (*TextResourceContents) GetURI

func (t *TextResourceContents) GetURI() string

type Tool

type Tool struct {
	// Name is the unique identifier of the tool
	Name string `json:"name"`

	// Description is a human-readable description of the tool
	Description string `json:"description,omitempty"`

	// InputSchema defines the expected parameters for the tool using JSON Schema
	InputSchema InputSchema `json:"inputSchema"`

	// OutputSchema defines expected output structure for the tool using Optional JSON Schema
	OutputSchema OutputSchema `json:"outputSchema"`

	// Annotations provides additional hints about the tool's behavior
	Annotations *ToolAnnotations `json:"annotations,omitempty"`

	RawInputSchema json.RawMessage `json:"-"`
}

Tool represents a tool definition that the client can call

func NewTool added in v0.1.2

func NewTool(name string, description string, inputReqStruct interface{}) (*Tool, error)

NewTool create a tool

func NewToolWithRawSchema added in v0.1.2

func NewToolWithRawSchema(name, description string, schema json.RawMessage) *Tool

func (*Tool) GetName added in v0.2.6

func (t *Tool) GetName() string

func (*Tool) MarshalJSON added in v0.1.2

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

type ToolAnnotations added in v0.2.9

type ToolAnnotations struct {
	// Title is a human-readable title for the tool, useful for UI display
	Title string `json:"title,omitempty"`

	// ReadOnlyHint indicates the tool does not modify its environment
	ReadOnlyHint *bool `json:"readOnlyHint,omitempty"`

	// DestructiveHint indicates the tool may perform destructive updates
	// (only meaningful when ReadOnlyHint is false)
	DestructiveHint *bool `json:"destructiveHint,omitempty"`

	// IdempotentHint indicates calling the tool repeatedly with the same arguments
	// has no additional effect (only meaningful when ReadOnlyHint is false)
	IdempotentHint *bool `json:"idempotentHint,omitempty"`

	// OpenWorldHint indicates the tool may interact with an "open world" of external entities
	OpenWorldHint *bool `json:"openWorldHint,omitempty"`
}

ToolAnnotations contains hints about the tool's behavior

type ToolListChangedNotification

type ToolListChangedNotification struct {
	Meta map[string]interface{} `json:"_meta,omitempty"`
}

ToolListChangedNotification represents a notification that the tool list has changed

func NewToolListChangedNotification

func NewToolListChangedNotification() *ToolListChangedNotification

NewToolListChangedNotification creates a new tool list changed notification

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

type UnsubscribeRequest

type UnsubscribeRequest struct {
	URI string `json:"uri"`
}

UnsubscribeRequest represents a request to unsubscribe from resource updates

func NewUnsubscribeRequest

func NewUnsubscribeRequest(uri string) *UnsubscribeRequest

NewUnsubscribeRequest creates a new unsubscribe request

type UnsubscribeResult

type UnsubscribeResult struct{}

func NewUnsubscribeResult

func NewUnsubscribeResult() *UnsubscribeResult

Jump to

Keyboard shortcuts

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