Documentation
¶
Index ¶
- Constants
- func ContentToJSON(content []Content) ([]json.RawMessage, error)
- func GetSupportedVersions() []string
- func IDToString(id json.RawMessage) string
- func IsVersionSupported(version string) bool
- func StringToID(id string) json.RawMessage
- func ValidateElicitationAction(action string) bool
- func ValidateStructuredOutput(data interface{}, schema JSONSchema) error
- type Annotation
- type AudioContent
- type CallToolParams
- type CallToolRequest
- type CallToolResult
- func NewToolResult(content []Content, isError bool) *CallToolResult
- func NewToolResultError(errorMsg string) *CallToolResult
- func NewToolResultText(text string) *CallToolResult
- func NewToolResultTextWithStructured(text string, structuredContent interface{}) *CallToolResult
- func NewToolResultWithStructured(content []Content, structuredContent interface{}) *CallToolResult
- type ClientCapabilities
- type ClientInfo
- type CompleteRequest
- type CompleteResult
- type CompletionArgument
- type CompletionCapability
- type CompletionContext
- type CompletionReference
- type CompletionResult
- type Content
- type ContentType
- type CreateMessageRequest
- func (cmr *CreateMessageRequest) Validate() error
- func (cmr *CreateMessageRequest) WithIncludeContext(context IncludeContext) *CreateMessageRequest
- func (cmr *CreateMessageRequest) WithMetadata(metadata map[string]interface{}) *CreateMessageRequest
- func (cmr *CreateMessageRequest) WithModelPreferences(prefs *ModelPreferences) *CreateMessageRequest
- func (cmr *CreateMessageRequest) WithStopSequences(sequences ...string) *CreateMessageRequest
- func (cmr *CreateMessageRequest) WithSystemPrompt(prompt string) *CreateMessageRequest
- func (cmr *CreateMessageRequest) WithTemperature(temp float64) *CreateMessageRequest
- type CreateMessageResult
- type ElicitationAction
- type ElicitationCapability
- type ElicitationCreateParams
- type ElicitationResult
- func (r *ElicitationResult) IsAccepted() bool
- func (r *ElicitationResult) IsCancelled() bool
- func (r *ElicitationResult) IsDeclined() bool
- func (r *ElicitationResult) MarshalJSON() ([]byte, error)
- func (r *ElicitationResult) UnmarshalJSON(data []byte) error
- func (r *ElicitationResult) Validate() error
- type EmbeddedResourceContent
- type GetPromptParams
- type GetPromptRequest
- type GetPromptResult
- type ImageContent
- type IncludeContext
- type InitializeRequest
- type InitializeResult
- type JSONRPCError
- type JSONRPCMessage
- type JSONSchema
- func CreateBooleanElicitationSchema(propertyName, description string, defaultValue *bool, required bool) JSONSchema
- func CreateElicitationSchema() JSONSchema
- func CreateEnumElicitationSchema(propertyName, description string, options []string, optionNames []string, ...) JSONSchema
- func CreateNumberElicitationSchema(propertyName, description string, min, max *float64, required bool) JSONSchema
- func CreateStringElicitationSchema(propertyName, description string, required bool) JSONSchema
- type ListPromptsParams
- type ListPromptsRequest
- type ListPromptsResult
- type ListResourceTemplatesRequest
- type ListResourceTemplatesResult
- type ListResourcesParams
- type ListResourcesRequest
- type ListResourcesResult
- type ListRootsParams
- type ListRootsRequest
- type ListRootsResult
- type ListToolsParams
- type ListToolsRequest
- type ListToolsResult
- type LoggingCapability
- type MCPError
- type ModelHint
- type ModelPreferences
- func (mp *ModelPreferences) Validate() error
- func (mp *ModelPreferences) WithCostPriority(priority float64) *ModelPreferences
- func (mp *ModelPreferences) WithHints(hints ...ModelHint) *ModelPreferences
- func (mp *ModelPreferences) WithIntelligencePriority(priority float64) *ModelPreferences
- func (mp *ModelPreferences) WithSpeedPriority(priority float64) *ModelPreferences
- type PaginatedResult
- type PaginationParams
- type Prompt
- type PromptArgument
- type PromptMessage
- type PromptReference
- type PromptsCapability
- type PromptsListChangedNotification
- type ReadResourceParams
- type ReadResourceRequest
- type ReadResourceResult
- type ReferenceType
- type Resource
- type ResourceContents
- type ResourceLinkContent
- type ResourceReference
- type ResourceTemplate
- type ResourceTemplatesListChangedNotification
- type ResourcesCapability
- type ResourcesListChangedNotification
- type ResourcesUpdatedNotification
- type Role
- type Root
- type RootsCapability
- type RootsListChangedNotification
- type SamplingCapability
- type SamplingMessage
- type ServerCapabilities
- type ServerInfo
- type StopReason
- type TextContent
- type Tool
- type ToolList
- type ToolParameter
- func BooleanParameter(name, description string, required bool) ToolParameter
- func NumberParameter(name, description string, required bool) ToolParameter
- func ObjectParameter(name, description string, required bool, properties JSONSchema, ...) ToolParameter
- func StringParameter(name, description string, required bool) ToolParameter
- type ToolsCapability
- type ToolsListChangedNotification
Constants ¶
const ( MCPVersion = "2025-06-18" JSONRPCVersion = "2.0" // 支持的协议版本列表(用于向后兼容性检查) MCPVersion2025_03_26 = "2025-03-26" MCPVersionLegacy = "2024-11-05" )
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
JSON-RPC 2.0 标准错误代码
const ( ToolNotFound = -32000 // 工具未找到 ResourceNotFound = -32002 // 资源未找到 PromptNotFound = -32001 // 提示模板未找到 InvalidTool = -32003 // 无效工具 InvalidResource = -32004 // 无效资源 InvalidPrompt = -32005 // 无效提示模板 ErrorCodeInvalidParams = InvalidParams )
MCP 特定错误代码
Variables ¶
This section is empty.
Functions ¶
func ContentToJSON ¶
func ContentToJSON(content []Content) ([]json.RawMessage, error)
func GetSupportedVersions ¶
func GetSupportedVersions() []string
func IDToString ¶
func IDToString(id json.RawMessage) string
func IsVersionSupported ¶
IsVersionSupported 检查协议版本是否受支持
func ValidateElicitationAction ¶ added in v1.1.1
ValidateElicitationAction validates whether the elicitation action is valid
func ValidateStructuredOutput ¶ added in v1.1.0
func ValidateStructuredOutput(data interface{}, schema JSONSchema) error
ValidateStructuredOutput 验证结构化输出是否符合模式
Types ¶
type Annotation ¶ added in v1.1.2
type Annotation struct {
Audience []Role `json:"audience,omitempty"` // 目标受众 (user, assistant)
Priority float64 `json:"priority,omitempty"` // 优先级 (0.0-1.0)
LastModified string `json:"lastModified,omitempty"` // 最后修改时间 (ISO 8601)
}
Annotation 内容注解 (MCP 2025-06-18)
func NewAnnotation ¶ added in v1.1.2
func NewAnnotation() *Annotation
NewAnnotation 创建注解 (MCP 2025-06-18)
func (*Annotation) WithAudience ¶ added in v1.1.2
func (a *Annotation) WithAudience(audience ...Role) *Annotation
func (*Annotation) WithLastModified ¶ added in v1.1.2
func (a *Annotation) WithLastModified(lastModified string) *Annotation
func (*Annotation) WithPriority ¶ added in v1.1.2
func (a *Annotation) WithPriority(priority float64) *Annotation
type AudioContent ¶ added in v1.1.2
type AudioContent struct {
Type ContentType `json:"type"`
Data string `json:"data"` // Base64 编码的音频数据
MimeType string `json:"mimeType"` // 例如: audio/wav, audio/mp3
Annotations *Annotation `json:"annotations,omitempty"`
}
AudioContent 音频内容 (MCP 2025-06-18)
func NewAudioContent ¶ added in v1.1.2
func NewAudioContent(data, mimeType string) AudioContent
NewAudioContent 创建音频内容 (MCP 2025-06-18)
func (AudioContent) GetType ¶ added in v1.1.2
func (ac AudioContent) GetType() ContentType
func (*AudioContent) WithAnnotations ¶ added in v1.1.2
func (ac *AudioContent) WithAnnotations(annotations *Annotation) *AudioContent
type CallToolParams ¶
type CallToolRequest ¶
type CallToolResult ¶
type CallToolResult struct {
Content []Content `json:"content"`
IsError bool `json:"isError,omitempty"`
StructuredContent any `json:"structuredContent,omitempty"` // MCP 2025-06-18
Meta map[string]any `json:"_meta,omitempty"` // MCP 2025-06-18: 扩展元数据
}
func NewToolResult ¶
func NewToolResult(content []Content, isError bool) *CallToolResult
func NewToolResultError ¶
func NewToolResultError(errorMsg string) *CallToolResult
func NewToolResultText ¶
func NewToolResultText(text string) *CallToolResult
func NewToolResultTextWithStructured ¶
func NewToolResultTextWithStructured(text string, structuredContent interface{}) *CallToolResult
NewToolResultTextWithStructured 创建带有文本和结构化内容的工具结果
func NewToolResultWithStructured ¶
func NewToolResultWithStructured(content []Content, structuredContent interface{}) *CallToolResult
NewToolResultWithStructured 创建带有结构化内容的工具结果 (MCP 2025-06-18)
func (*CallToolResult) UnmarshalJSON ¶
func (ctr *CallToolResult) UnmarshalJSON(data []byte) error
UnmarshalJSON 实现自定义JSON反序列化
type ClientCapabilities ¶
type ClientCapabilities struct {
Roots *RootsCapability `json:"roots,omitempty"`
Sampling *SamplingCapability `json:"sampling,omitempty"`
Elicitation *ElicitationCapability `json:"elicitation,omitempty"`
Experimental map[string]interface{} `json:"experimental,omitempty"`
}
type ClientInfo ¶
type CompleteRequest ¶ added in v1.1.2
type CompleteRequest struct {
Ref map[string]any `json:"ref"` // 引用 (PromptReference 或 ResourceReference)
Argument CompletionArgument `json:"argument"` // 要补全的参数
Context *CompletionContext `json:"context,omitempty"` // 可选的上下文
}
CompleteRequest 补全请求 (completion/complete)
type CompleteResult ¶ added in v1.1.2
type CompleteResult struct {
Completion CompletionResult `json:"completion"` // 补全结果
}
CompleteResult 补全响应
type CompletionArgument ¶ added in v1.1.2
type CompletionArgument struct {
Name string `json:"name"` // 参数名称
Value string `json:"value"` // 当前值
}
CompletionArgument 补全参数
type CompletionCapability ¶ added in v1.1.2
type CompletionCapability struct{}
CompletionCapability 补全能力声明
type CompletionContext ¶ added in v1.1.2
type CompletionContext struct {
Arguments map[string]string `json:"arguments,omitempty"` // 已解析的参数映射
}
CompletionContext 补全上下文
type CompletionReference ¶ added in v1.1.2
type CompletionReference interface {
GetType() ReferenceType
}
CompletionReference 补全引用 (PromptReference 或 ResourceReference)
func UnmarshalCompletionReference ¶ added in v1.1.2
func UnmarshalCompletionReference(data map[string]any) (CompletionReference, error)
UnmarshalCompletionReference 反序列化补全引用
type CompletionResult ¶ added in v1.1.2
type CompletionResult struct {
Values []string `json:"values"` // 补全建议列表 (最多 100 个)
Total *int `json:"total,omitempty"` // 可选: 总匹配数
HasMore bool `json:"hasMore"` // 是否有更多结果
}
CompletionResult 补全结果
func NewCompletionResult ¶ added in v1.1.2
func NewCompletionResult(values []string, hasMore bool) CompletionResult
NewCompletionResult 创建补全结果
func NewCompletionResultWithTotal ¶ added in v1.1.2
func NewCompletionResultWithTotal(values []string, total int, hasMore bool) CompletionResult
NewCompletionResultWithTotal 创建带总数的补全结果
type ContentType ¶
type ContentType string
const ( ContentTypeText ContentType = "text" ContentTypeImage ContentType = "image" ContentTypeAudio ContentType = "audio" // MCP 2025-06-18 ContentTypeResourceLink ContentType = "resource_link" // MCP 2025-06-18 ContentTypeResource ContentType = "resource" // MCP 2025-06-18: Embedded Resource )
type CreateMessageRequest ¶ added in v1.1.1
type CreateMessageRequest struct {
Messages []SamplingMessage `json:"messages"`
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
SystemPrompt string `json:"systemPrompt,omitempty"`
IncludeContext IncludeContext `json:"includeContext,omitempty"`
Temperature *float64 `json:"temperature,omitempty"` // 0.0-1.0
MaxTokens int `json:"maxTokens"` // 必需
StopSequences []string `json:"stopSequences,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
CreateMessageRequest 创建消息请求 (服务器发起的LLM采样)
func NewCreateMessageRequest ¶ added in v1.1.1
func NewCreateMessageRequest(messages []SamplingMessage, maxTokens int) *CreateMessageRequest
NewCreateMessageRequest 创建消息请求
func (*CreateMessageRequest) Validate ¶ added in v1.1.1
func (cmr *CreateMessageRequest) Validate() error
Validate 验证创建消息请求
func (*CreateMessageRequest) WithIncludeContext ¶ added in v1.1.1
func (cmr *CreateMessageRequest) WithIncludeContext(context IncludeContext) *CreateMessageRequest
WithIncludeContext 设置上下文包含选项
func (*CreateMessageRequest) WithMetadata ¶ added in v1.1.1
func (cmr *CreateMessageRequest) WithMetadata(metadata map[string]interface{}) *CreateMessageRequest
WithMetadata 设置元数据
func (*CreateMessageRequest) WithModelPreferences ¶ added in v1.1.1
func (cmr *CreateMessageRequest) WithModelPreferences(prefs *ModelPreferences) *CreateMessageRequest
WithModelPreferences 设置模型偏好
func (*CreateMessageRequest) WithStopSequences ¶ added in v1.1.1
func (cmr *CreateMessageRequest) WithStopSequences(sequences ...string) *CreateMessageRequest
WithStopSequences 设置停止序列
func (*CreateMessageRequest) WithSystemPrompt ¶ added in v1.1.1
func (cmr *CreateMessageRequest) WithSystemPrompt(prompt string) *CreateMessageRequest
WithSystemPrompt 设置系统提示
func (*CreateMessageRequest) WithTemperature ¶ added in v1.1.1
func (cmr *CreateMessageRequest) WithTemperature(temp float64) *CreateMessageRequest
WithTemperature 设置温度 (0.0-1.0)
type CreateMessageResult ¶ added in v1.1.1
type CreateMessageResult struct {
Role Role `json:"role"`
Content Content `json:"content"`
Model string `json:"model"`
StopReason StopReason `json:"stopReason"`
}
CreateMessageResult 创建消息结果
func NewCreateMessageResult ¶ added in v1.1.1
func NewCreateMessageResult(role Role, content Content, model string, stopReason StopReason) *CreateMessageResult
NewCreateMessageResult 创建消息结果
type ElicitationAction ¶ added in v1.1.1
type ElicitationAction string
const ( ElicitationActionAccept ElicitationAction = "accept" ElicitationActionDecline ElicitationAction = "decline" ElicitationActionCancel ElicitationAction = "cancel" )
type ElicitationCreateParams ¶ added in v1.1.1
type ElicitationCreateParams struct {
Message string `json:"message"`
RequestedSchema JSONSchema `json:"requestedSchema"`
}
func NewElicitationCreateParams ¶ added in v1.1.1
func NewElicitationCreateParams(message string, schema JSONSchema) *ElicitationCreateParams
type ElicitationResult ¶ added in v1.1.1
type ElicitationResult struct {
Action ElicitationAction `json:"action"`
Content interface{} `json:"content,omitempty"`
}
func NewElicitationAccept ¶ added in v1.1.1
func NewElicitationAccept(content interface{}) *ElicitationResult
func NewElicitationCancel ¶ added in v1.1.1
func NewElicitationCancel() *ElicitationResult
func NewElicitationDecline ¶ added in v1.1.1
func NewElicitationDecline() *ElicitationResult
func NewElicitationResult ¶ added in v1.1.1
func NewElicitationResult(action ElicitationAction, content interface{}) *ElicitationResult
func (*ElicitationResult) IsAccepted ¶ added in v1.1.1
func (r *ElicitationResult) IsAccepted() bool
func (*ElicitationResult) IsCancelled ¶ added in v1.1.1
func (r *ElicitationResult) IsCancelled() bool
func (*ElicitationResult) IsDeclined ¶ added in v1.1.1
func (r *ElicitationResult) IsDeclined() bool
func (*ElicitationResult) MarshalJSON ¶ added in v1.1.1
func (r *ElicitationResult) MarshalJSON() ([]byte, error)
func (*ElicitationResult) UnmarshalJSON ¶ added in v1.1.1
func (r *ElicitationResult) UnmarshalJSON(data []byte) error
func (*ElicitationResult) Validate ¶ added in v1.1.1
func (r *ElicitationResult) Validate() error
type EmbeddedResourceContent ¶ added in v1.1.2
type EmbeddedResourceContent struct {
Type ContentType `json:"type"`
Resource ResourceContents `json:"resource"`
}
EmbeddedResourceContent 嵌入式资源 (MCP 2025-06-18)
func NewEmbeddedResourceContent ¶ added in v1.1.2
func NewEmbeddedResourceContent(resource ResourceContents) EmbeddedResourceContent
NewEmbeddedResourceContent 创建嵌入式资源内容 (MCP 2025-06-18)
func (EmbeddedResourceContent) GetType ¶ added in v1.1.2
func (erc EmbeddedResourceContent) GetType() ContentType
type GetPromptParams ¶
type GetPromptParams struct {
Name string `json:"name"`
Arguments map[string]string `json:"arguments,omitempty"`
}
GetPromptParams 获取提示模板的参数类型
type GetPromptRequest ¶
type GetPromptRequest struct {
Name string `json:"name"`
Arguments map[string]string `json:"arguments,omitempty"`
}
GetPromptRequest prompts/get 请求和响应
type GetPromptResult ¶
type GetPromptResult struct {
Description string `json:"description,omitempty"`
Messages []PromptMessage `json:"messages"`
Meta map[string]any `json:"_meta,omitempty"`
}
func NewGetPromptResult ¶
func NewGetPromptResult(description string, messages ...PromptMessage) *GetPromptResult
type ImageContent ¶
type ImageContent struct {
Type ContentType `json:"type"`
Data string `json:"data"`
MimeType string `json:"mimeType"`
Annotations *Annotation `json:"annotations,omitempty"` // MCP 2025-06-18
}
func NewImageContent ¶
func NewImageContent(data, mimeType string) ImageContent
func (ImageContent) GetType ¶
func (ic ImageContent) GetType() ContentType
func (*ImageContent) WithAnnotations ¶ added in v1.1.2
func (ic *ImageContent) WithAnnotations(annotations *Annotation) *ImageContent
type IncludeContext ¶ added in v1.1.1
type IncludeContext string
IncludeContext 上下文包含选项
const ( IncludeContextNone IncludeContext = "none" IncludeContextThisServer IncludeContext = "thisServer" IncludeContextAllServers IncludeContext = "allServers" )
type InitializeRequest ¶
type InitializeRequest struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo ClientInfo `json:"clientInfo"`
}
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo ServerInfo `json:"serverInfo"`
Instructions string `json:"instructions,omitempty"`
}
type JSONRPCError ¶
type JSONRPCMessage ¶
type JSONRPCMessage struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *JSONRPCError `json:"error,omitempty"`
}
func (*JSONRPCMessage) GetIDString ¶
func (m *JSONRPCMessage) GetIDString() string
func (*JSONRPCMessage) IsNotification ¶
func (m *JSONRPCMessage) IsNotification() bool
type JSONSchema ¶
type JSONSchema map[string]interface{}
func CreateBooleanElicitationSchema ¶ added in v1.1.1
func CreateBooleanElicitationSchema(propertyName, description string, defaultValue *bool, required bool) JSONSchema
CreateBooleanElicitationSchema creates a schema for requesting boolean input
func CreateElicitationSchema ¶ added in v1.1.1
func CreateElicitationSchema() JSONSchema
CreateElicitationSchema creates a common elicitation schema
func CreateEnumElicitationSchema ¶ added in v1.1.1
func CreateEnumElicitationSchema(propertyName, description string, options []string, optionNames []string, required bool) JSONSchema
CreateEnumElicitationSchema creates a schema for requesting enum selection
func CreateNumberElicitationSchema ¶ added in v1.1.1
func CreateNumberElicitationSchema(propertyName, description string, min, max *float64, required bool) JSONSchema
CreateNumberElicitationSchema creates a schema for requesting number input
func CreateStringElicitationSchema ¶ added in v1.1.1
func CreateStringElicitationSchema(propertyName, description string, required bool) JSONSchema
CreateStringElicitationSchema creates a schema for requesting string input
type ListPromptsParams ¶
type ListPromptsParams struct {
Cursor string `json:"cursor,omitempty"`
}
ListPromptsParams 列表提示模板的参数类型
type ListPromptsRequest ¶
type ListPromptsRequest struct {
Cursor string `json:"cursor,omitempty"`
}
ListPromptsRequest prompts/list 请求和响应
type ListPromptsResult ¶
type ListPromptsResult struct {
Prompts []Prompt `json:"prompts"`
PaginatedResult
}
type ListResourceTemplatesRequest ¶
type ListResourceTemplatesRequest struct {
Cursor string `json:"cursor,omitempty"`
}
ListResourceTemplatesRequest resources/templates/list 请求和响应
type ListResourceTemplatesResult ¶
type ListResourceTemplatesResult struct {
ResourceTemplates []ResourceTemplate `json:"resourceTemplates"`
PaginatedResult
}
type ListResourcesParams ¶
type ListResourcesParams struct {
Cursor string `json:"cursor,omitempty"`
}
ListResourcesParams 列表资源的参数类型
type ListResourcesRequest ¶
type ListResourcesRequest struct {
Cursor string `json:"cursor,omitempty"`
}
ListResourcesRequest resources/list 请求和响应
type ListResourcesResult ¶
type ListResourcesResult struct {
Resources []Resource `json:"resources"`
PaginatedResult
}
type ListRootsRequest ¶ added in v1.1.2
type ListRootsRequest struct {
}
ListRootsRequest roots/list 请求
type ListRootsResult ¶ added in v1.1.2
type ListRootsResult struct {
Roots []Root `json:"roots"`
}
ListRootsResult roots/list 响应
func NewListRootsResult ¶ added in v1.1.2
func NewListRootsResult(roots ...Root) *ListRootsResult
NewListRootsResult 创建根目录列表结果
type ListToolsParams ¶
type ListToolsParams struct {
Cursor string `json:"cursor,omitempty"`
}
type ListToolsRequest ¶
type ListToolsRequest struct {
Cursor string `json:"cursor,omitempty"`
}
type ListToolsResult ¶
type ListToolsResult struct {
Tools []Tool `json:"tools"`
PaginatedResult
}
type LoggingCapability ¶
type LoggingCapability struct{}
type MCPError ¶ added in v1.1.1
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
MCPError MCP特定错误类型
func NewMCPError ¶ added in v1.1.1
NewMCPError 创建新的MCP错误
type ModelHint ¶ added in v1.1.1
type ModelHint struct {
Name string `json:"name,omitempty"`
}
ModelHint 模型提示
func NewModelHint ¶ added in v1.1.1
type ModelPreferences ¶ added in v1.1.1
type ModelPreferences struct {
Hints []ModelHint `json:"hints,omitempty"`
CostPriority *float64 `json:"costPriority,omitempty"` // 0-1, 成本优先级
SpeedPriority *float64 `json:"speedPriority,omitempty"` // 0-1, 速度优先级
IntelligencePriority *float64 `json:"intelligencePriority,omitempty"` // 0-1, 智能优先级
}
ModelPreferences 模型偏好设置
func NewModelPreferences ¶ added in v1.1.1
func NewModelPreferences() *ModelPreferences
func (*ModelPreferences) Validate ¶ added in v1.1.1
func (mp *ModelPreferences) Validate() error
Validate 验证模型偏好设置
func (*ModelPreferences) WithCostPriority ¶ added in v1.1.1
func (mp *ModelPreferences) WithCostPriority(priority float64) *ModelPreferences
WithCostPriority 设置成本优先级 (0-1)
func (*ModelPreferences) WithHints ¶ added in v1.1.1
func (mp *ModelPreferences) WithHints(hints ...ModelHint) *ModelPreferences
WithHints 设置模型提示
func (*ModelPreferences) WithIntelligencePriority ¶ added in v1.1.1
func (mp *ModelPreferences) WithIntelligencePriority(priority float64) *ModelPreferences
WithIntelligencePriority 设置智能优先级 (0-1)
func (*ModelPreferences) WithSpeedPriority ¶ added in v1.1.1
func (mp *ModelPreferences) WithSpeedPriority(priority float64) *ModelPreferences
WithSpeedPriority 设置速度优先级 (0-1)
type PaginatedResult ¶
type PaginatedResult struct {
NextCursor *string `json:"nextCursor,omitempty"`
}
type PaginationParams ¶
type PaginationParams struct {
Cursor string `json:"cursor,omitempty"`
}
type Prompt ¶
type Prompt struct {
Name string `json:"name"`
Title string `json:"title,omitempty"` // MCP 2025-06-18: 人类友好的标题
Description string `json:"description,omitempty"`
Arguments []PromptArgument `json:"arguments,omitempty"`
Meta map[string]any `json:"_meta,omitempty"` // MCP 2025-06-18: 扩展元数据
}
Prompt 提示模板定义
func NewPrompt ¶
func NewPrompt(name, description string, arguments ...PromptArgument) Prompt
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
PromptArgument 提示模板参数
func NewPromptArgument ¶
func NewPromptArgument(name, description string, required bool) PromptArgument
type PromptMessage ¶
PromptMessage 提示消息
func NewPromptMessage ¶
func NewPromptMessage(role Role, content Content) PromptMessage
func (*PromptMessage) UnmarshalJSON ¶
func (pm *PromptMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON 实现自定义JSON反序列化
type PromptReference ¶ added in v1.1.2
type PromptReference struct {
Type ReferenceType `json:"type"` // 必须是 "ref/prompt"
Name string `json:"name"` // 提示名称
}
PromptReference 提示引用
func NewPromptReference ¶ added in v1.1.2
func NewPromptReference(name string) PromptReference
NewPromptReference 创建提示引用
func (PromptReference) GetType ¶ added in v1.1.2
func (p PromptReference) GetType() ReferenceType
type PromptsCapability ¶
type PromptsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
type PromptsListChangedNotification ¶
type PromptsListChangedNotification struct{}
PromptsListChangedNotification 提示模板变更通知
type ReadResourceParams ¶
type ReadResourceParams struct {
URI string `json:"uri"`
}
ReadResourceParams 读取资源的参数类型
type ReadResourceRequest ¶
type ReadResourceRequest struct {
URI string `json:"uri"`
}
ReadResourceRequest resources/read 请求和响应
type ReadResourceResult ¶
type ReadResourceResult struct {
Contents []ResourceContents `json:"contents"`
}
func NewReadResourceResult ¶
func NewReadResourceResult(contents ...ResourceContents) *ReadResourceResult
type ReferenceType ¶ added in v1.1.2
type ReferenceType string
ReferenceType 引用类型
const ( ReferenceTypePrompt ReferenceType = "ref/prompt" // 提示引用 ReferenceTypeResource ReferenceType = "ref/resource" // 资源引用 )
type Resource ¶
type Resource struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Meta map[string]any `json:"_meta,omitempty"`
}
Resource 资源定义
func NewResource ¶
type ResourceContents ¶
type ResourceContents struct {
URI string `json:"uri"`
Title string `json:"title,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Text string `json:"text,omitempty"`
Blob string `json:"blob,omitempty"`
Annotations *Annotation `json:"annotations,omitempty"`
}
ResourceContents 资源内容
func NewBlobResourceContents ¶
func NewBlobResourceContents(uri, blob, mimeType string) ResourceContents
func NewTextResourceContents ¶
func NewTextResourceContents(uri, text string) ResourceContents
type ResourceLinkContent ¶ added in v1.1.2
type ResourceLinkContent struct {
Type ContentType `json:"type"`
URI string `json:"uri"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Annotations *Annotation `json:"annotations,omitempty"`
}
ResourceLinkContent 资源链接 (MCP 2025-06-18)
func NewResourceLinkContent ¶ added in v1.1.2
func NewResourceLinkContent(uri string) ResourceLinkContent
NewResourceLinkContent 创建资源链接内容 (MCP 2025-06-18)
func NewResourceLinkContentWithDetails ¶ added in v1.1.2
func NewResourceLinkContentWithDetails(uri, name, description, mimeType string) ResourceLinkContent
NewResourceLinkContentWithDetails 创建带详细信息的资源链接 (MCP 2025-06-18)
func (ResourceLinkContent) GetType ¶ added in v1.1.2
func (rlc ResourceLinkContent) GetType() ContentType
func (*ResourceLinkContent) WithAnnotations ¶ added in v1.1.2
func (rlc *ResourceLinkContent) WithAnnotations(annotations *Annotation) *ResourceLinkContent
type ResourceReference ¶ added in v1.1.2
type ResourceReference struct {
Type ReferenceType `json:"type"` // 必须是 "ref/resource"
URI string `json:"uri"` // 资源 URI (可能包含模板变量)
}
ResourceReference 资源引用
func NewResourceReference ¶ added in v1.1.2
func NewResourceReference(uri string) ResourceReference
NewResourceReference 创建资源引用
func (ResourceReference) GetType ¶ added in v1.1.2
func (r ResourceReference) GetType() ReferenceType
type ResourceTemplate ¶
type ResourceTemplate struct {
URITemplate string `json:"uriTemplate"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Meta map[string]any `json:"_meta,omitempty"`
}
func NewResourceTemplate ¶ added in v1.1.2
func NewResourceTemplate(uriTemplate, name, description, mimeType string) ResourceTemplate
type ResourceTemplatesListChangedNotification ¶ added in v1.1.2
type ResourceTemplatesListChangedNotification struct{}
type ResourcesCapability ¶
type ResourcesListChangedNotification ¶
type ResourcesListChangedNotification struct{}
ResourcesListChangedNotification 资源变更通知
type ResourcesUpdatedNotification ¶
type ResourcesUpdatedNotification struct {
URI string `json:"uri"`
Title string `json:"title,omitempty"`
}
func NewResourcesUpdatedNotification ¶
func NewResourcesUpdatedNotification(uri string, title ...string) ResourcesUpdatedNotification
NewResourcesUpdatedNotification 创建资源更新通知
type Root ¶ added in v1.1.2
type Root struct {
URI string `json:"uri"` // 根目录URI,必须是 file:// 协议
Name string `json:"name,omitempty"` // 可选的人类可读名称
}
Root 根目录定义
type RootsCapability ¶
type RootsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
type RootsListChangedNotification ¶ added in v1.1.2
type RootsListChangedNotification struct{}
RootsListChangedNotification 根目录列表变更通知
func NewRootsListChangedNotification ¶ added in v1.1.2
func NewRootsListChangedNotification() RootsListChangedNotification
NewRootsListChangedNotification 创建根目录列表变更通知
type SamplingCapability ¶
type SamplingCapability struct{}
type SamplingMessage ¶ added in v1.1.1
SamplingMessage 采样消息
func NewSamplingMessage ¶ added in v1.1.1
func NewSamplingMessage(role Role, content Content) SamplingMessage
type ServerCapabilities ¶
type ServerCapabilities struct {
Tools *ToolsCapability `json:"tools,omitempty"`
Resources *ResourcesCapability `json:"resources,omitempty"`
Prompts *PromptsCapability `json:"prompts,omitempty"`
Logging *LoggingCapability `json:"logging,omitempty"`
Completion *CompletionCapability `json:"completions,omitempty"` // MCP 2025-06-18: 参数自动补全
Experimental map[string]interface{} `json:"experimental,omitempty"`
}
type ServerInfo ¶
type StopReason ¶ added in v1.1.1
type StopReason string
const ( StopReasonEndTurn StopReason = "endTurn" StopReasonMaxTokens StopReason = "maxTokens" StopReasonStopSequence StopReason = "stopSequence" StopReasonToolUse StopReason = "toolUse" )
type TextContent ¶
type TextContent struct {
Type ContentType `json:"type"`
Text string `json:"text"`
Annotations *Annotation `json:"annotations,omitempty"` // MCP 2025-06-18
}
func NewTextContent ¶
func NewTextContent(text string) TextContent
func (TextContent) GetType ¶
func (tc TextContent) GetType() ContentType
func (*TextContent) WithAnnotations ¶ added in v1.1.2
func (tc *TextContent) WithAnnotations(annotations *Annotation) *TextContent
WithAnnotations 为内容添加注解 (MCP 2025-06-18)
type Tool ¶
type Tool struct {
Name string `json:"name"`
Title string `json:"title,omitempty"` // MCP 2025-06-18: 人类友好的标题
Description string `json:"description,omitempty"`
InputSchema JSONSchema `json:"inputSchema"`
OutputSchema JSONSchema `json:"outputSchema,omitempty"` // MCP 2025-06-18
Meta map[string]any `json:"_meta,omitempty"` // MCP 2025-06-18: 扩展元数据
}
func NewTool ¶
func NewTool(name, description string, inputSchema JSONSchema) Tool
func NewToolWithOutput ¶ added in v1.1.0
func NewToolWithOutput(name, description string, inputSchema, outputSchema JSONSchema) Tool
NewToolWithOutput 创建带有输出模式的工具 (MCP 2025-06-18)
type ToolParameter ¶
type ToolParameter struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema JSONSchema `json:"schema,omitempty"`
}
func BooleanParameter ¶
func BooleanParameter(name, description string, required bool) ToolParameter
func NumberParameter ¶
func NumberParameter(name, description string, required bool) ToolParameter
func ObjectParameter ¶
func ObjectParameter(name, description string, required bool, properties JSONSchema, required_props []string) ToolParameter
func StringParameter ¶
func StringParameter(name, description string, required bool) ToolParameter
type ToolsCapability ¶
type ToolsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
type ToolsListChangedNotification ¶
type ToolsListChangedNotification struct{}