server

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 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 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) 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) Resource

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

Resource resource fluent API

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

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

RegisterPrompt registers prompt template

func (*MCPServer) RegisterResource

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

RegisterResource registers resource

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

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

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 {
	OutputSchema protocol.JSONSchema // optional output schema (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