mcpclient

package
v0.0.0-...-f4afc28 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mcpclient provides a Go client that speaks Model Context Protocol (MCP) over stdio to downstream MCP servers running as subprocesses.

Communication uses newline-delimited JSON-RPC 2.0 over the subprocess's stdin (requests) and stdout (responses).

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 manages a connection to a single downstream MCP server subprocess.

func NewClient

func NewClient(ctx context.Context, name string, command []string, env []string) (*Client, error)

NewClient spawns a downstream MCP server as a subprocess and performs the MCP initialize handshake. The command slice must contain at least the program name; additional elements are passed as arguments. The env slice is merged with os.Environ() so the subprocess inherits the current environment plus any overrides.

func (*Client) CallTool

func (c *Client) CallTool(_ context.Context, name string, arguments map[string]any) (*mcp.ToolResult, error)

CallTool invokes a tool on the downstream MCP server by name.

func (*Client) Close

func (c *Client) Close() error

Close terminates the subprocess. It sends SIGTERM first, then SIGKILL after a 5-second timeout if the process hasn't exited.

func (*Client) DiscoverTools

func (c *Client) DiscoverTools(_ context.Context) ([]mcp.ToolDef, error)

DiscoverTools sends a tools/list request and caches the result.

func (*Client) Name

func (c *Client) Name() string

Name returns the human-readable name of this client connection.

func (*Client) Tools

func (c *Client) Tools() []mcp.ToolDef

Tools returns the cached list of tools discovered from the server.

Jump to

Keyboard shortcuts

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