base

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	Started bool
	// contains filtered or unexported fields
}

Base is a base abstraction for MCP clients and servers

func NewBase

func NewBase(t transport.Transport) *Base

NewBase creates a new base instance

func (*Base) Close

func (b *Base) Close() error

Close shuts down the client

func (*Base) Done

func (b *Base) Done() <-chan struct{}

Done returns a channel that is closed when the transport is closed

func (*Base) GetRouter

func (b *Base) GetRouter() *transport.MessageRouter

GetRouter returns the message router

func (*Base) Logf

func (b *Base) Logf(format string, args ...interface{})

Logf logs a formatted message

func (*Base) RegisterNotificationHandler

func (b *Base) RegisterNotificationHandler(method string, handler NotificationHandler)

RegisterNotificationHandler registers a handler for a notification method

func (*Base) RegisterRequestHandler

func (b *Base) RegisterRequestHandler(method string, handler RequestHandler)

RegisterRequestHandler registers a handler for a request method

func (*Base) SendNotification

func (b *Base) SendNotification(ctx context.Context, method string, params interface{}) error

SendNotification sends a notification (no response expected)

func (*Base) SendRequest

func (b *Base) SendRequest(ctx context.Context, method string, params interface{}) (*types.Message, error)

SendRequest sends a request and waits for the response

func (*Base) SendResponse

func (b *Base) SendResponse(ctx context.Context, reqID types.ID, result interface{}, err error) error

SendResponse sends a response to a request

func (*Base) SetLogger

func (b *Base) SetLogger(l logger.Logger)

SetLogger sets the logger for the base

func (*Base) Start

func (b *Base) Start(ctx context.Context) error

Start begins processing messages

type NotificationHandler

type NotificationHandler func(ctx context.Context, params json.RawMessage)

NotificationHandler handles MCP notifications

type RequestHandler

type RequestHandler func(ctx context.Context, params *json.RawMessage) (interface{}, error)

RequestHandler handles MCP requests and returns a response

Jump to

Keyboard shortcuts

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