server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package server provides the MCP server implementation.

Package server provides the MCP server implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embeddable added in v1.1.0

type Embeddable interface {
	// ToHTTPHandler returns an http.Handler that can be used to integrate
	// the MCP server with any standard Go HTTP server
	ToHTTPHandler() http.Handler

	// AddTool adds a tool to the MCP server
	AddTool(ctx context.Context, tool *types.Tool, handler ToolHandler) error

	// GetServerInfo returns basic information about the server
	GetServerInfo() ServerInfo

	// RegisterSession registers a new client session with the server
	// This allows sending messages to specific clients
	RegisterSession(sessionID string, userAgent string, callback func([]byte) error) error

	// UnregisterSession removes a client session from the server
	UnregisterSession(sessionID string) error

	// ExecuteTool executes a tool with the given request
	ExecuteTool(ctx context.Context, request ToolCallRequest) (interface{}, error)

	// SendToSession sends a message to a specific session
	SendToSession(sessionID string, message []byte) error

	// GetTools returns all registered tools
	GetTools() map[string]*types.Tool
}

Embeddable defines an interface for MCP servers that can be embedded in other applications like PocketBase, standard HTTP servers, etc.

type HTTPAdapter added in v1.1.0

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

HTTPAdapter adapts an Embeddable to be used in an HTTP server.

func NewHTTPAdapter added in v1.1.0

func NewHTTPAdapter(embeddable Embeddable, opts ...HTTPAdapterOption) *HTTPAdapter

NewHTTPAdapter creates a new HTTPAdapter.

func (*HTTPAdapter) Handler added in v1.1.0

func (a *HTTPAdapter) Handler() http.Handler

Handler returns an http.Handler that can be registered with an HTTP server.

type HTTPAdapterOption added in v1.1.0

type HTTPAdapterOption func(*HTTPAdapter)

HTTPAdapterOption is a function that configures an HTTP adapter.

func WithPath added in v1.1.0

func WithPath(basePath string) HTTPAdapterOption

WithPath sets the base path for the HTTP adapter.

type MCPServer

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

MCPServer represents an MCP server that can be used to handle MCP protocol messages. It supports both static tool registration and dynamic provider-based tools.

func NewMCPServer

func NewMCPServer(name, version string, logger *log.Logger) *MCPServer

NewMCPServer creates a new MCP server with the specified name and version.

func (*MCPServer) AddTool

func (s *MCPServer) AddTool(ctx context.Context, tool *types.Tool, handler ToolHandler) error

AddTool adds a tool to the MCP server.

func (*MCPServer) ExecuteTool added in v1.1.0

func (s *MCPServer) ExecuteTool(ctx context.Context, request ToolCallRequest) (interface{}, error)

ExecuteTool executes a tool with the given request.

func (*MCPServer) GetAddress

func (s *MCPServer) GetAddress() string

GetAddress returns the HTTP address for the server.

func (*MCPServer) GetServerInfo added in v1.1.0

func (s *MCPServer) GetServerInfo() ServerInfo

GetServerInfo returns basic information about the server

func (*MCPServer) GetTools added in v1.1.0

func (s *MCPServer) GetTools() map[string]*types.Tool

GetTools returns all registered tools.

func (*MCPServer) RegisterProvider

func (s *MCPServer) RegisterProvider(ctx context.Context, provider plugin.Provider) error

RegisterProvider registers a tool provider with the server.

func (*MCPServer) RegisterSession added in v1.1.0

func (s *MCPServer) RegisterSession(sessionID string, userAgent string, callback func([]byte) error) error

RegisterSession registers a new client session with the server. It returns an error if the session already exists.

func (*MCPServer) SendToSession added in v1.1.0

func (s *MCPServer) SendToSession(sessionID string, message []byte) error

SendToSession sends a message to a specific session.

func (*MCPServer) ServeHTTP

func (s *MCPServer) ServeHTTP() error

ServeHTTP starts the HTTP server.

func (*MCPServer) ServeStdio

func (s *MCPServer) ServeStdio() error

ServeStdio serves the MCP server over standard I/O.

func (*MCPServer) SetAddress

func (s *MCPServer) SetAddress(addr string)

SetAddress sets the HTTP address for the server.

func (*MCPServer) SetEmbedMode added in v1.1.0

func (s *MCPServer) SetEmbedMode(embed bool)

SetEmbedMode configures the MCPServer to work in embedded mode, which prevents it from binding to a port when ToHTTPHandler is called.

func (*MCPServer) Shutdown

func (s *MCPServer) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the HTTP server.

func (*MCPServer) ToHTTPHandler added in v1.1.0

func (s *MCPServer) ToHTTPHandler() http.Handler

ToHTTPHandler returns an http.Handler for the MCP server

func (*MCPServer) UnregisterProvider

func (s *MCPServer) UnregisterProvider(ctx context.Context, providerID string) error

UnregisterProvider removes a tool provider from the server.

func (*MCPServer) UnregisterSession added in v1.1.0

func (s *MCPServer) UnregisterSession(sessionID string) error

UnregisterSession removes a client session from the server. It returns an error if the session does not exist.

type ServerInfo added in v1.1.0

type ServerInfo struct {
	// Name is the name of the server
	Name string

	// Version is the version of the server
	Version string

	// Address is the address the server is listening on
	Address string
}

ServerInfo contains basic information about the MCP server

type SessionCallback added in v1.1.0

type SessionCallback func([]byte) error

SessionCallback is a function that is called when messages need to be sent to a client.

type ToolCallRequest

type ToolCallRequest struct {
	Name       string
	Parameters map[string]interface{}
	Session    *types.ClientSession
}

ToolCallRequest represents a request to execute a tool.

type ToolHandler

type ToolHandler func(ctx context.Context, request ToolCallRequest) (interface{}, error)

ToolHandler is a function that handles tool calls.

Jump to

Keyboard shortcuts

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