client

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents an MCP client that can use different transports

func NewClient

func NewClient(logger zerolog.Logger, transport Transport) *Client

NewClient creates a new client instance

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]interface{}) (*protocol.ToolResult, error)

CallTool calls a specific tool on the server

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes the client connection

func (*Client) CreateMessage

func (c *Client) CreateMessage(ctx context.Context, messages []protocol.Message, modelPreferences protocol.ModelPreferences, systemPrompt string, maxTokens int) (*protocol.Message, error)

CreateMessage sends a sampling request to create a message

func (*Client) GetPrompt

func (c *Client) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*protocol.PromptMessage, error)

GetPrompt retrieves a specific prompt from the server

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, capabilities protocol.ClientCapabilities) error

Initialize initializes the connection with the server

func (*Client) ListPrompts

func (c *Client) ListPrompts(ctx context.Context, cursor string) ([]protocol.Prompt, string, error)

ListPrompts retrieves the list of available prompts from the server

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context, cursor string) ([]protocol.Resource, string, error)

ListResources retrieves the list of available resources from the server

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context, cursor string) ([]protocol.Tool, string, error)

ListTools retrieves the list of available tools from the server

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping sends a ping request to the server

func (*Client) ReadResource

func (c *Client) ReadResource(ctx context.Context, uri string) (*protocol.ResourceContent, error)

ReadResource retrieves the content of a specific resource from the server

type SSETransport

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

SSETransport implements Transport using Server-Sent Events

func NewSSETransport

func NewSSETransport(baseURL string, logger zerolog.Logger) *SSETransport

NewSSETransport creates a new SSE transport

func (*SSETransport) Close

func (t *SSETransport) Close(ctx context.Context) error

Close closes the transport

func (*SSETransport) Send

func (t *SSETransport) Send(ctx context.Context, request *protocol.Request) (*protocol.Response, error)

Send sends a request and returns the response

func (*SSETransport) SetNotificationHandler added in v0.0.2

func (t *SSETransport) SetNotificationHandler(handler func(*protocol.Response))

SetNotificationHandler sets the handler for notifications

type StdioTransport

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

StdioTransport implements Transport using standard input/output

func NewCommandStdioTransport

func NewCommandStdioTransport(logger zerolog.Logger, command string, args ...string) (*StdioTransport, error)

NewCommandStdioTransport creates a new stdio transport that launches a command

func NewStdioTransport

func NewStdioTransport(logger zerolog.Logger) *StdioTransport

NewStdioTransport creates a new stdio transport

func (*StdioTransport) Close

func (t *StdioTransport) Close(ctx context.Context) error

Close closes the transport

func (*StdioTransport) Send

func (t *StdioTransport) Send(ctx context.Context, request *protocol.Request) (*protocol.Response, error)

Send sends a request and returns the response

func (*StdioTransport) SetNotificationHandler added in v0.0.2

func (t *StdioTransport) SetNotificationHandler(handler func(*protocol.Response))

SetNotificationHandler sets the handler for notifications

type Transport

type Transport interface {
	// Send sends a request and returns the response
	Send(ctx context.Context, request *protocol.Request) (*protocol.Response, error)
	// Close closes the transport connection
	Close(ctx context.Context) error
	// SetNotificationHandler sets a handler for notifications
	SetNotificationHandler(handler func(*protocol.Response))
}

Transport represents a client transport mechanism

Jump to

Keyboard shortcuts

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