server

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionHandler added in v1.1.2

type Elicitor added in v1.1.1

type Elicitor interface {
	// Elicit sends an elicitation request and waits for response
	Elicit(ctx context.Context, method string, params interface{}) (*protocol.JSONRPCMessage, error)
	// CreateMessage sends a sampling request and waits for response
	CreateMessage(ctx context.Context, request *protocol.CreateMessageRequest) (*protocol.CreateMessageResult, error)
}

Elicitor interface for handling elicitation and sampling requests

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) Completion added in v1.1.2

func (f *FastMCP) Completion(handler CompletionHandler)

Completion registers a completion handler (MCP 2025-06-18)

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 prompt template fluent API

func (*FastMCP) RequestRootsList added in v1.1.2

func (f *FastMCP) RequestRootsList(ctx context.Context) (*protocol.ListRootsResult, error)

func (*FastMCP) Resource

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

Resource resource fluent API

func (*FastMCP) ResourceTemplate added in v1.1.2

func (f *FastMCP) ResourceTemplate(uriTemplate, name, description string) *ResourceTemplateBuilder

func (*FastMCP) SendNotification

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

func (*FastMCP) Server

func (f *FastMCP) Server() *MCPServer

func (*FastMCP) SetElicitor added in v1.1.1

func (f *FastMCP) SetElicitor(elicitor Elicitor)

func (*FastMCP) SetNotificationHandler

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

func (*FastMCP) SetRequestSender added in v1.1.2

func (f *FastMCP) SetRequestSender(sender func(ctx context.Context, method string, params interface{}) (*protocol.JSONRPCMessage, error))

func (*FastMCP) SimpleElicitationTool added in v1.1.1

func (f *FastMCP) SimpleElicitationTool(name, description string, handler func(ctx *MCPContext, args map[string]interface{}) (string, error)) error

SimpleElicitationTool creates a simple tool with elicitation support

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 creates a simple tool that returns structured data (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 creates a tool that returns both text and structured data

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 MCPContext added in v1.1.1

type MCPContext struct {
	context.Context
	// contains filtered or unexported fields
}

MCPContext provides MCP-specific context functionality, including elicitation support

func NewMCPContext added in v1.1.1

func NewMCPContext(ctx context.Context, server *MCPServer, elicitor Elicitor) *MCPContext

NewMCPContext creates a new MCP context

func (*MCPContext) CreateConversationMessage added in v1.1.1

func (c *MCPContext) CreateConversationMessage(messages []protocol.SamplingMessage, maxTokens int) (*protocol.CreateMessageResult, error)

CreateConversationMessage creates a sampling request with conversation history

func (*MCPContext) CreateMessage added in v1.1.1

CreateMessage sends a sampling request to the client

func (*MCPContext) CreateTextMessage added in v1.1.1

func (c *MCPContext) CreateTextMessage(userMessage string, maxTokens int) (*protocol.CreateMessageResult, error)

CreateTextMessage creates a simple text-based sampling request

func (*MCPContext) CreateTextMessageWithSystem added in v1.1.1

func (c *MCPContext) CreateTextMessageWithSystem(systemPrompt, userMessage string, maxTokens int) (*protocol.CreateMessageResult, error)

CreateTextMessageWithSystem creates a text-based sampling request with system prompt

func (*MCPContext) Elicit added in v1.1.1

func (c *MCPContext) Elicit(message string, schema protocol.JSONSchema) (*protocol.ElicitationResult, error)

Elicit sends an elicitation request

func (*MCPContext) ElicitBoolean added in v1.1.1

func (c *MCPContext) ElicitBoolean(message, name, description string, defaultValue *bool, required bool) (bool, error)

ElicitBoolean requests user to input a boolean value

func (*MCPContext) ElicitChoice added in v1.1.1

func (c *MCPContext) ElicitChoice(message, name, description string, options, optionNames []string, required bool) (string, error)

ElicitChoice requests user to choose from options

func (*MCPContext) ElicitMultiple added in v1.1.1

func (c *MCPContext) ElicitMultiple(message string, schema protocol.JSONSchema) (map[string]interface{}, error)

ElicitMultiple requests user to input multiple fields

func (*MCPContext) ElicitNumber added in v1.1.1

func (c *MCPContext) ElicitNumber(message, name, description string, min, max *float64, required bool) (float64, error)

ElicitNumber requests user to input a number

func (*MCPContext) ElicitString added in v1.1.1

func (c *MCPContext) ElicitString(message, name, description string, required bool) (string, error)

ElicitString requests user to input a string

func (*MCPContext) Server added in v1.1.1

func (c *MCPContext) Server() *MCPServer

Server gets the associated MCP server

type MCPServer

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

func NewServer

func NewServer(name, version string) *MCPServer

NewServer creates MCP server

func (*MCPServer) CreateMCPContext added in v1.1.1

func (s *MCPServer) CreateMCPContext(ctx context.Context) *MCPContext

CreateMCPContext creates MCP context with elicitation support

func (*MCPServer) GetCapabilities

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

GetCapabilities gets server capabilities

func (*MCPServer) GetServerInfo

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

GetServerInfo gets server information

func (*MCPServer) HandleMessage

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

HandleMessage handles JSON-RPC messages

func (*MCPServer) RegisterCompletionHandler added in v1.1.2

func (s *MCPServer) RegisterCompletionHandler(handler CompletionHandler)

RegisterCompletionHandler registers completion handler (MCP 2025-06-18)

func (*MCPServer) RegisterPrompt

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

RegisterPrompt registers prompt template

func (*MCPServer) RegisterResource

func (s *MCPServer) RegisterResource(uri, name, description, mimeType string, handler ResourceHandler, meta ...map[string]any) error

RegisterResource registers resource

func (*MCPServer) RegisterResourceTemplate added in v1.1.2

func (s *MCPServer) RegisterResourceTemplate(uriTemplate, name, description, mimeType string, meta ...map[string]any) error

RegisterResourceTemplate registers a resource template

func (*MCPServer) RegisterTool

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

RegisterTool registers tool with optional output schema support

func (*MCPServer) RequestRootsList added in v1.1.2

func (s *MCPServer) RequestRootsList(ctx context.Context) (*protocol.ListRootsResult, error)

RequestRootsList root list

func (*MCPServer) SendNotification

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

SendNotification sends notification

func (*MCPServer) SetElicitor added in v1.1.1

func (s *MCPServer) SetElicitor(elicitor Elicitor)

SetElicitor sets elicitation handler

func (*MCPServer) SetNotificationHandler

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

SetNotificationHandler sets notification handler

func (*MCPServer) SetRequestSender added in v1.1.2

func (s *MCPServer) SetRequestSender(sender func(ctx context.Context, method string, params interface{}) (*protocol.JSONRPCMessage, error))

SetRequestSender sets request sender for server-initiated requests

func (*MCPServer) UnregisterCompletionHandler added in v1.1.2

func (s *MCPServer) UnregisterCompletionHandler()

UnregisterCompletionHandler unregisters completion handler

func (*MCPServer) UnregisterPrompt

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

UnregisterPrompt unregisters prompt template

func (*MCPServer) UnregisterResource

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

UnregisterResource unregisters resource

func (*MCPServer) UnregisterResourceTemplate added in v1.1.2

func (s *MCPServer) UnregisterResourceTemplate(uriTemplate string) error

UnregisterResourceTemplate unregisters a resource template

func (*MCPServer) UnregisterTool

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

UnregisterTool unregisters tool

type MockElicitor added in v1.1.1

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

MockElicitor mock implementation of elicitation and sampling

func NewMockElicitor added in v1.1.1

func NewMockElicitor(handler func(ctx context.Context, method string, params interface{}) (*protocol.ElicitationResult, error)) *MockElicitor

NewMockElicitor creates a mock elicitation handler

func NewMockElicitorWithSampling added in v1.1.1

func NewMockElicitorWithSampling(
	elicitationHandler func(ctx context.Context, method string, params interface{}) (*protocol.ElicitationResult, error),
	samplingHandler func(ctx context.Context, request *protocol.CreateMessageRequest) (*protocol.CreateMessageResult, error),
) *MockElicitor

NewMockElicitorWithSampling creates a mock elicitation and sampling handler

func (*MockElicitor) CreateMessage added in v1.1.1

CreateMessage handles sampling requests (returns mock response)

func (*MockElicitor) Elicit added in v1.1.1

func (m *MockElicitor) Elicit(ctx context.Context, method string, params interface{}) (*protocol.JSONRPCMessage, error)

Elicit handles elicitation requests (returns mock response)

type PromptBuilder

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

func (*PromptBuilder) Handle

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

Handle registers prompt template handler

func (*PromptBuilder) WithArgument

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

WithArgument adds argument

func (*PromptBuilder) WithMeta added in v1.1.2

func (pb *PromptBuilder) WithMeta(key string, value any) *PromptBuilder

WithMeta sets metadata (MCP 2025-06-18)

func (*PromptBuilder) WithTitle added in v1.1.2

func (pb *PromptBuilder) WithTitle(title string) *PromptBuilder

WithTitle sets human-friendly title (MCP 2025-06-18)

type PromptHandler

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

type PromptHandlerWithElicitation added in v1.1.1

type PromptHandlerWithElicitation func(ctx *MCPContext, arguments map[string]string) (*protocol.GetPromptResult, error)

type PromptOptions added in v1.1.2

type PromptOptions struct {
	Title string         // optional human-friendly title (MCP 2025-06-18)
	Meta  map[string]any // optional metadata (MCP 2025-06-18)
}

PromptOptions prompt registration options

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 registers resource handler

func (*ResourceBuilder) WithMeta added in v1.1.2

func (rb *ResourceBuilder) WithMeta(key string, value any) *ResourceBuilder

WithMeta sets metadata (MCP 2025-06-18)

func (*ResourceBuilder) WithMimeType

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

WithMimeType sets MIME type

type ResourceHandler

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

type ResourceHandlerWithElicitation added in v1.1.1

type ResourceHandlerWithElicitation func(ctx *MCPContext) (*protocol.ReadResourceResult, error)

type ResourceRegistration

type ResourceRegistration struct {
	Resource protocol.Resource
	Handler  ResourceHandler
}

type ResourceTemplateBuilder added in v1.1.2

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

func (*ResourceTemplateBuilder) Register added in v1.1.2

func (rtb *ResourceTemplateBuilder) Register() error

Register registers resource template metadata

func (*ResourceTemplateBuilder) WithMeta added in v1.1.2

func (rtb *ResourceTemplateBuilder) WithMeta(key string, value any) *ResourceTemplateBuilder

WithMeta sets metadata (MCP 2025-06-18)

func (*ResourceTemplateBuilder) WithMimeType added in v1.1.2

func (rtb *ResourceTemplateBuilder) WithMimeType(mimeType string) *ResourceTemplateBuilder

WithMimeType sets MIME type for resource template

type ResourceTemplateRegistration added in v1.1.2

type ResourceTemplateRegistration struct {
	Template protocol.ResourceTemplate
}

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

	RequestRootsList(ctx context.Context) (*protocol.ListRootsResult, error)
}

type ToolBuilder

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

func (*ToolBuilder) Handle

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

Handle registers tool handler

func (*ToolBuilder) HandleWithElicitation added in v1.1.1

func (tb *ToolBuilder) HandleWithElicitation(handler ToolHandlerWithElicitation) error

HandleWithElicitation registers tool handler with elicitation support

func (*ToolBuilder) HandleWithValidation

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

HandleWithValidation tool handler with validation

func (*ToolBuilder) WithBoolParam

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

WithBoolParam adds boolean parameter

func (*ToolBuilder) WithInputSchema

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

WithInputSchema sets custom input schema

func (*ToolBuilder) WithIntParam

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

WithIntParam adds integer parameter

func (*ToolBuilder) WithMeta added in v1.1.2

func (tb *ToolBuilder) WithMeta(key string, value interface{}) *ToolBuilder

WithMeta sets metadata (MCP 2025-06-18)

func (*ToolBuilder) WithNumberParam

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

WithNumberParam adds number parameter (supports integers and floats)

func (*ToolBuilder) WithOutputSchema added in v1.1.0

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

WithOutputSchema sets output schema (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 automatically generates output schema using struct

func (*ToolBuilder) WithStructSchema

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

WithStructSchema automatically generates schema using struct

func (*ToolBuilder) WithTitle added in v1.1.2

func (tb *ToolBuilder) WithTitle(title string) *ToolBuilder

WithTitle sets human-friendly title (MCP 2025-06-18)

type ToolHandler

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

type ToolHandlerWithElicitation added in v1.1.1

type ToolHandlerWithElicitation func(ctx *MCPContext, arguments map[string]interface{}) (*protocol.CallToolResult, error)

type ToolOptions added in v1.1.0

type ToolOptions struct {
	Title        string              // optional human-friendly title (MCP 2025-06-18)
	OutputSchema protocol.JSONSchema // optional output schema (MCP 2025-06-18)
	Meta         map[string]any      // optional metadata (MCP 2025-06-18)
}

ToolOptions tool registration options

type ToolRegistration

type ToolRegistration struct {
	Tool    protocol.Tool
	Handler ToolHandler
}

type TransportElicitor added in v1.1.1

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

TransportElicitor implementation that sends requests through transport layer

func NewTransportElicitor added in v1.1.1

func NewTransportElicitor(sendMessage func(ctx context.Context, message *protocol.JSONRPCMessage) (*protocol.JSONRPCMessage, error)) *TransportElicitor

NewTransportElicitor creates a transport layer elicitation handler

func (*TransportElicitor) CreateMessage added in v1.1.1

CreateMessage sends sampling requests through transport layer

func (*TransportElicitor) Elicit added in v1.1.1

func (t *TransportElicitor) Elicit(ctx context.Context, method string, params interface{}) (*protocol.JSONRPCMessage, error)

Elicit sends elicitation requests through transport layer

Jump to

Keyboard shortcuts

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