server

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 11 Imported by: 618

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 DefaultServer

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.CompleteArgument) (*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) 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,
	method string,
	params json.RawMessage,
) (interface{}, error)

Request is the main entrypoint of the server

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 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,
		method string,
		params json.RawMessage,
	) (interface{}, error)
	HandleInitialize(InitializeFunc)
	HandlePing(PingFunc)
	HandleListResources(ListResourcesFunc)
	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 SetLevelFunc

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

type StdioServer

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

StdioServer wraps a DefaultServer 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