server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FastMCP

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

func New

func New(name, version string) *FastMCP

func NewFastMCP

func NewFastMCP(name, version string) *FastMCP

func (*FastMCP) GetCapabilities

func (f *FastMCP) GetCapabilities() protocol.ServerCapabilities

func (*FastMCP) GetServerInfo

func (f *FastMCP) GetServerInfo() protocol.ServerInfo

func (*FastMCP) HandleMessage

func (f *FastMCP) HandleMessage(ctx context.Context, data []byte) ([]byte, error)

func (*FastMCP) Prompt

func (f *FastMCP) Prompt(name, description string) *PromptBuilder

Prompt 提示模板链式API

func (*FastMCP) Resource

func (f *FastMCP) Resource(uri, name, description string) *ResourceBuilder

Resource 资源链式API

func (*FastMCP) SendNotification

func (f *FastMCP) SendNotification(method string, params interface{}) error

func (*FastMCP) Server

func (f *FastMCP) Server() *MCPServer

func (*FastMCP) SetNotificationHandler

func (f *FastMCP) SetNotificationHandler(handler func(method string, params interface{}) error)

func (*FastMCP) SimpleStructuredTool added in v1.1.0

func (f *FastMCP) SimpleStructuredTool(name, description string, outputSchema protocol.JSONSchema, handler func(ctx context.Context, args map[string]interface{}) (interface{}, error)) error

SimpleStructuredTool 创建返回结构化数据的简单工具 (MCP 2025-06-18)

func (*FastMCP) SimpleStructuredToolWithText added in v1.1.0

func (f *FastMCP) SimpleStructuredToolWithText(name, description string, outputSchema protocol.JSONSchema, handler func(ctx context.Context, args map[string]interface{}) (string, interface{}, error)) error

SimpleStructuredToolWithText 创建返回文本和结构化数据的工具

func (*FastMCP) SimpleTextPrompt

func (f *FastMCP) SimpleTextPrompt(name, description string, handler func(ctx context.Context, args map[string]string) (string, error)) error

func (*FastMCP) SimpleTextResource

func (f *FastMCP) SimpleTextResource(uri, name, description string, handler func(ctx context.Context) (string, error)) error

func (*FastMCP) SimpleTextTool

func (f *FastMCP) SimpleTextTool(name, description string, handler func(ctx context.Context, args map[string]interface{}) (string, error)) error

func (*FastMCP) Tool

func (f *FastMCP) Tool(name, description string) *ToolBuilder

type MCPServer

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

func NewServer

func NewServer(name, version string) *MCPServer

NewServer 创建MCP服务端

func (*MCPServer) GetCapabilities

func (s *MCPServer) GetCapabilities() protocol.ServerCapabilities

GetCapabilities 获取服务器能力

func (*MCPServer) GetServerInfo

func (s *MCPServer) GetServerInfo() protocol.ServerInfo

GetServerInfo 获取服务器信息

func (*MCPServer) HandleMessage

func (s *MCPServer) HandleMessage(ctx context.Context, message *protocol.JSONRPCMessage) (*protocol.JSONRPCMessage, error)

HandleMessage 处理JSON-RPC消息

func (*MCPServer) RegisterPrompt

func (s *MCPServer) RegisterPrompt(name, description string, arguments []protocol.PromptArgument, handler PromptHandler) error

RegisterPrompt 注册提示模板

func (*MCPServer) RegisterResource

func (s *MCPServer) RegisterResource(uri, name, description, mimeType string, handler ResourceHandler) error

RegisterResource 注册资源

func (*MCPServer) RegisterTool

func (s *MCPServer) RegisterTool(name, description string, inputSchema protocol.JSONSchema, handler ToolHandler, opts ...ToolOptions) error

RegisterTool 注册工具,支持可选的输出模式

func (*MCPServer) SendNotification

func (s *MCPServer) SendNotification(method string, params interface{}) error

SendNotification 发送通知

func (*MCPServer) SetNotificationHandler

func (s *MCPServer) SetNotificationHandler(handler func(method string, params interface{}) error)

SetNotificationHandler 设置通知处理器

func (*MCPServer) UnregisterPrompt

func (s *MCPServer) UnregisterPrompt(name string) error

UnregisterPrompt 注销提示模板

func (*MCPServer) UnregisterResource

func (s *MCPServer) UnregisterResource(uri string) error

UnregisterResource 注销资源

func (*MCPServer) UnregisterTool

func (s *MCPServer) UnregisterTool(name string) error

UnregisterTool 注销工具

type PromptBuilder

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

func (*PromptBuilder) Handle

func (pb *PromptBuilder) Handle(handler PromptHandler) error

Handle 注册提示模板处理器

func (*PromptBuilder) WithArgument

func (pb *PromptBuilder) WithArgument(name, description string, required bool) *PromptBuilder

WithArgument 添加参数

type PromptHandler

type PromptHandler func(ctx context.Context, arguments map[string]string) (*protocol.GetPromptResult, error)

type PromptRegistration

type PromptRegistration struct {
	Prompt  protocol.Prompt
	Handler PromptHandler
}

type ResourceBuilder

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

func (*ResourceBuilder) Handle

func (rb *ResourceBuilder) Handle(handler ResourceHandler) error

Handle 注册资源处理器

func (*ResourceBuilder) WithMimeType

func (rb *ResourceBuilder) WithMimeType(mimeType string) *ResourceBuilder

WithMimeType 设置MIME类型

type ResourceHandler

type ResourceHandler func(ctx context.Context) (*protocol.ReadResourceResult, error)

type ResourceRegistration

type ResourceRegistration struct {
	Resource protocol.Resource
	Handler  ResourceHandler
}

type Server

type Server interface {
	RegisterTool(name, description string, inputSchema protocol.JSONSchema, handler ToolHandler) error
	UnregisterTool(name string) error

	RegisterResource(uri, name, description, mimeType string, handler ResourceHandler) error
	UnregisterResource(uri string) error

	RegisterPrompt(name, description string, arguments []protocol.PromptArgument, handler PromptHandler) error
	UnregisterPrompt(name string) error

	GetServerInfo() protocol.ServerInfo
	GetCapabilities() protocol.ServerCapabilities

	HandleMessage(ctx context.Context, message *protocol.JSONRPCMessage) (*protocol.JSONRPCMessage, error)
	SendNotification(method string, params interface{}) error
}

type ToolBuilder

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

func (*ToolBuilder) Handle

func (tb *ToolBuilder) Handle(handler ToolHandler) error

Handle 注册工具处理器

func (*ToolBuilder) HandleWithValidation

func (tb *ToolBuilder) HandleWithValidation(handler ToolHandler) error

HandleWithValidation 带验证的工具处理器

func (*ToolBuilder) WithBoolParam

func (tb *ToolBuilder) WithBoolParam(name, description string, required bool) *ToolBuilder

WithBoolParam 添加布尔参数

func (*ToolBuilder) WithInputSchema

func (tb *ToolBuilder) WithInputSchema(schema protocol.JSONSchema) *ToolBuilder

WithInputSchema 设置自定义输入schema

func (*ToolBuilder) WithIntParam

func (tb *ToolBuilder) WithIntParam(name, description string, required bool) *ToolBuilder

WithIntParam 添加整数参数

func (*ToolBuilder) WithNumberParam

func (tb *ToolBuilder) WithNumberParam(name, description string, required bool) *ToolBuilder

WithNumberParam 添加数字参数(支持整数和浮点数)

func (*ToolBuilder) WithOutputSchema added in v1.1.0

func (tb *ToolBuilder) WithOutputSchema(schema protocol.JSONSchema) *ToolBuilder

WithOutputSchema 设置输出模式 (MCP 2025-06-18)

func (*ToolBuilder) WithStringParam

func (tb *ToolBuilder) WithStringParam(name, description string, required bool) *ToolBuilder

func (*ToolBuilder) WithStructOutputSchema added in v1.1.0

func (tb *ToolBuilder) WithStructOutputSchema(v interface{}) *ToolBuilder

WithStructOutputSchema 使用结构体自动生成输出模式

func (*ToolBuilder) WithStructSchema

func (tb *ToolBuilder) WithStructSchema(v interface{}) *ToolBuilder

WithStructSchema 使用结构体自动生成schema

type ToolHandler

type ToolHandler func(ctx context.Context, arguments map[string]interface{}) (*protocol.CallToolResult, error)

type ToolOptions added in v1.1.0

type ToolOptions struct {
	OutputSchema protocol.JSONSchema // 可选的输出模式 (MCP 2025-06-18)
}

ToolOptions 工具注册选项

type ToolRegistration

type ToolRegistration struct {
	Tool    protocol.Tool
	Handler ToolHandler
}

Jump to

Keyboard shortcuts

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