server

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package server provides HTTP and stdio transports for MCP.

Package server provides stdio transport for MCP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPServer

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

HTTPServer provides HTTP transport for MCP.

func NewHTTPServer

func NewHTTPServer(registry *mcp.ToolRegistry, cache *mcp.HashCache, port int) *HTTPServer

NewHTTPServer creates a new HTTP MCP server.

func (*HTTPServer) Addr

func (s *HTTPServer) Addr() string

Addr returns the server address.

func (*HTTPServer) Port

func (s *HTTPServer) Port() int

Port returns the actual port (may differ from requested if 0).

func (*HTTPServer) Start

func (s *HTTPServer) Start() error

Start starts the HTTP server.

func (*HTTPServer) Stop

func (s *HTTPServer) Stop(ctx context.Context) error

Stop gracefully stops the server.

type JSONRPCError

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC 2.0 error.

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

JSONRPCRequest represents a JSON-RPC 2.0 request.

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id,omitempty"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

JSONRPCResponse represents a JSON-RPC 2.0 response.

type StdioServer

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

StdioServer provides stdio transport for MCP.

func NewStdioServer

func NewStdioServer(registry *mcp.ToolRegistry, cache *mcp.HashCache) *StdioServer

NewStdioServer creates a new stdio MCP server.

func NewStdioServerWithStreams

func NewStdioServerWithStreams(registry *mcp.ToolRegistry, cache *mcp.HashCache, in io.Reader, out, err io.Writer) *StdioServer

NewStdioServerWithStreams creates a server with custom I/O streams (for testing).

func (*StdioServer) IsRunning

func (s *StdioServer) IsRunning() bool

IsRunning returns true if the server is running.

func (*StdioServer) LogError

func (s *StdioServer) LogError(format string, args ...interface{})

LogError writes an error message to the error stream.

func (*StdioServer) LogInfo

func (s *StdioServer) LogInfo(format string, args ...interface{})

LogInfo writes an info message to the error stream.

func (*StdioServer) Start

func (s *StdioServer) Start() error

Start begins processing messages from stdin.

func (*StdioServer) Stop

func (s *StdioServer) Stop(ctx context.Context) error

Stop gracefully stops the server.

type ToolContent

type ToolContent struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

ToolContent represents content in a tool result.

Jump to

Keyboard shortcuts

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