types

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package types defines core interfaces and common types used across the GoMCP library.

Package types defines core interfaces and common types used across the GoMCP library.

Package types defines core interfaces and common types used across the GoMCP library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientSession added in v0.1.11

type ClientSession interface {
	// SessionID returns a unique identifier for this session.
	SessionID() string

	// SendNotification sends a JSON-RPC notification to the client session.
	SendNotification(notification protocol.JSONRPCNotification) error

	// SendResponse sends a JSON-RPC response to the client session.
	SendResponse(response protocol.JSONRPCResponse) error

	// SendRequest sends a JSON-RPC request to the client session.
	SendRequest(request protocol.JSONRPCRequest) error

	// Close terminates the client session and cleans up resources.
	Close() error

	// Initialize marks the session as having completed the MCP handshake.
	Initialize()

	// Initialized returns true if the session has completed the MCP handshake.
	Initialized() bool

	// SetNegotiatedVersion stores the protocol version agreed upon during initialization.
	SetNegotiatedVersion(version string)

	// GetNegotiatedVersion returns the protocol version agreed upon during initialization.
	GetNegotiatedVersion() string

	// StoreClientCapabilities stores the capabilities received from the client during initialization.
	StoreClientCapabilities(caps protocol.ClientCapabilities)

	// GetClientCapabilities returns the stored client capabilities.
	GetClientCapabilities() protocol.ClientCapabilities
	// GetWriter returns the underlying io.Writer for the session.
	GetWriter() io.Writer
}

ClientSession represents an active connection from a single client. The core MCPServer uses this interface to interact with connected clients, primarily for sending asynchronous messages like notifications or responses that aren't part of a direct request-response flow handled by HandleMessage.

type Logger

type Logger interface {
	// Debug logs a debug message.
	Debug(msg string, args ...interface{})

	// Info logs an informational message.
	Info(msg string, args ...interface{})

	// Warn logs a warning message.
	Warn(msg string, args ...interface{})

	// Error logs an error message.
	Error(msg string, args ...interface{})
}

Logger defines the interface for logging within the GoMCP library. It allows for different logging implementations to be used.

type MessageHandler

type MessageHandler func(data []byte) error

MessageHandler is a function that processes received messages. It is used by higher-level components to handle incoming messages.

type Transport

type Transport interface {
	// Send transmits a message over the transport, respecting the provided context.
	// It returns an error if the message could not be sent or if the context is cancelled.
	Send(ctx context.Context, data []byte) error

	// Receive blocks until a message is received, respecting the provided context, or an error occurs.
	// It returns the received message as a byte slice and any error that occurred (including context errors).
	Receive(ctx context.Context) ([]byte, error)

	// EstablishReceiver sets up the channel for receiving messages from the server.
	// For transports like SSE, this might involve making a GET request.
	// This should be called before sending the 'initialize' request in some protocols.
	EstablishReceiver(ctx context.Context) error // ADDED

	// Close terminates the transport connection.
	// After Close is called, the transport should not be used.
	Close() error

	// IsClosed returns true if the transport connection is closed.
	IsClosed() bool
}

Transport defines the interface for communication between MCP clients and servers. It abstracts the underlying transport mechanism (stdio, websocket, etc.) and provides a consistent API for sending and receiving messages.

type TransportFactory

type TransportFactory interface {
	// NewTransport creates a new Transport instance.
	NewTransport() (Transport, error)

	// NewTransportWithOptions creates a new Transport instance with the specified options.
	NewTransportWithOptions(opts TransportOptions) (Transport, error)
}

TransportFactory creates new Transport instances. Different implementations can create different types of transports.

type TransportOptions

type TransportOptions struct {
	// BufferSize specifies the size of the read/write buffers.
	BufferSize int

	// Logger is used for logging transport-related events.
	Logger Logger

	// Custom options can be provided as key-value pairs.
	Custom map[string]interface{}
}

TransportOptions contains configuration options for creating a Transport. Different transport implementations may use different fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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