server

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 16 Imported by: 622

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeStdio

func ServeStdio(server MCPServer) error

ServeStdio creates a stdio server wrapper around an existing MCPServer

Types

type CallToolFunc

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

type CompleteFunc

type CompleteFunc func(ctx context.Context, ref interface{}, argument mcp.CompleteRequestParamsArgument) (*mcp.CompleteResult, error)

type DefaultServer

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

func (*DefaultServer) HandleCallTool

func (s *DefaultServer) HandleCallTool(
	f CallToolFunc,
)

func (*DefaultServer) HandleComplete

func (s *DefaultServer) HandleComplete(
	f CompleteFunc,
)

func (*DefaultServer) HandleGetPrompt

func (s *DefaultServer) HandleGetPrompt(
	f GetPromptFunc,
)

func (*DefaultServer) HandleInitialize

func (s *DefaultServer) HandleInitialize(
	f InitializeFunc,
)

Handler registration methods

func (*DefaultServer) HandleListPrompts

func (s *DefaultServer) HandleListPrompts(
	f ListPromptsFunc,
)

func (*DefaultServer) HandleListResourceTemplates added in v0.4.1

func (s *DefaultServer) HandleListResourceTemplates(
	f ListResourceTemplatesFunc,
)

func (*DefaultServer) HandleListResources

func (s *DefaultServer) HandleListResources(
	f ListResourcesFunc,
)

func (*DefaultServer) HandleListTools

func (s *DefaultServer) HandleListTools(
	f ListToolsFunc,
)

func (*DefaultServer) HandleNotification added in v0.1.5

func (s *DefaultServer) HandleNotification(name string, f NotificationFunc)

func (*DefaultServer) HandlePing

func (s *DefaultServer) HandlePing(
	f PingFunc,
)

func (*DefaultServer) HandleReadResource

func (s *DefaultServer) HandleReadResource(
	f ReadResourceFunc,
)

func (*DefaultServer) HandleSetLevel

func (s *DefaultServer) HandleSetLevel(
	f SetLevelFunc,
)

func (*DefaultServer) HandleSubscribe

func (s *DefaultServer) HandleSubscribe(
	f SubscribeFunc,
)

func (*DefaultServer) HandleUnsubscribe

func (s *DefaultServer) HandleUnsubscribe(
	f UnsubscribeFunc,
)

func (*DefaultServer) Request

func (s *DefaultServer) Request(
	ctx context.Context,
	request JSONRPCRequest,
) JSONRPCResponse

type GetPromptFunc

type GetPromptFunc func(ctx context.Context, name string, arguments map[string]string) (*mcp.GetPromptResult, error)

type InitializeFunc

type InitializeFunc func(ctx context.Context, capabilities mcp.ClientCapabilities, clientInfo mcp.Implementation, protocolVersion string) (*mcp.InitializeResult, error)

type JSONRPCRequest

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

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   *struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error,omitempty"`
}

JSONRPCResponse represents a JSON-RPC 2.0 response

type ListPromptsFunc

type ListPromptsFunc func(ctx context.Context, cursor *string) (*mcp.ListPromptsResult, error)

type ListResourceTemplatesFunc added in v0.4.1

type ListResourceTemplatesFunc func(ctx context.Context, cursor *string) (*mcp.ListResourceTemplatesResult, error)

type ListResourcesFunc

type ListResourcesFunc func(ctx context.Context, cursor *string) (*mcp.ListResourcesResult, error)

type ListToolsFunc

type ListToolsFunc func(ctx context.Context, cursor *string) (*mcp.ListToolsResult, error)

type MCPServer

type MCPServer interface {
	Request(ctx context.Context, request JSONRPCRequest) JSONRPCResponse
	HandleInitialize(InitializeFunc)
	HandlePing(PingFunc)
	HandleListResources(ListResourcesFunc)
	HandleListResourceTemplates(ListResourceTemplatesFunc)
	HandleReadResource(ReadResourceFunc)
	HandleSubscribe(SubscribeFunc)
	HandleUnsubscribe(UnsubscribeFunc)
	HandleListPrompts(ListPromptsFunc)
	HandleGetPrompt(GetPromptFunc)
	HandleListTools(ListToolsFunc)
	HandleCallTool(CallToolFunc)
	HandleSetLevel(SetLevelFunc)
	HandleComplete(CompleteFunc)
	HandleNotification(string, NotificationFunc)
}

func NewDefaultServer

func NewDefaultServer(name, version string) MCPServer

NewDefaultServer creates a new server with default handlers

type NotificationFunc added in v0.1.2

type NotificationFunc func(ctx context.Context, args any) (any, error)

type PingFunc

type PingFunc func(ctx context.Context) error

type ReadResourceFunc

type ReadResourceFunc func(ctx context.Context, uri string) (*mcp.ReadResourceResult, error)

type SSEServer added in v0.2.0

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

func NewSSEServer added in v0.2.0

func NewSSEServer(mcpServer MCPServer, baseURL string) *SSEServer

func NewTestServer added in v0.2.0

func NewTestServer(mcpServer MCPServer) (*SSEServer, *httptest.Server)

NewTestServer creates a test server for testing purposes It returns the SSEServer and a test server that can be closed when done

func (*SSEServer) SendEventToSession added in v0.2.0

func (s *SSEServer) SendEventToSession(
	sessionID string,
	event interface{},
) error

SendEventToSession sends an event to a specific session

func (*SSEServer) Shutdown added in v0.2.0

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

func (*SSEServer) Start added in v0.2.0

func (s *SSEServer) Start(addr string) error

type SetLevelFunc

type SetLevelFunc func(ctx context.Context, level mcp.LoggingLevel) error

type StdioServer

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

StdioServer wraps a MCPServer and handles stdio communication

type SubscribeFunc

type SubscribeFunc func(ctx context.Context, uri string) error

type UnsubscribeFunc

type UnsubscribeFunc func(ctx context.Context, uri string) error

Jump to

Keyboard shortcuts

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