mcpclient

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mcpclient is the client half of MCP - what this proxy needs to forward a call ONWARD to an upstream MCP server, as opposed to internal/adapter/mcp which is the server half that agents connect to.

Having both is what makes "put the firewall in front of the MCP server you already run" possible at all: the agent talks MCP to us, we talk MCP to the real server, and the agent never holds that server's credential - we do, configured once, and it never enters the agent's context.

Written against the same Streamable HTTP transport spec the server side was validated against, so it handles the parts a real upstream may use even though this project's own server doesn't: an Mcp-Session-Id assigned at initialize (which the spec says clients MUST echo on every later request), the MCP-Protocol-Version header, and an SSE-framed response, since the spec lets a server answer a POST with either a single JSON object or an event stream and requires clients to handle both.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResult

type CallResult struct {
	Content []map[string]any `json:"content"`
	IsError bool             `json:"isError"`
}

CallResult mirrors MCP's tools/call result: content blocks plus an isError flag that is NOT a transport error - a tool can fail on its own terms and still return a perfectly valid JSON-RPC response.

func (CallResult) Text

func (r CallResult) Text() string

Text flattens the content blocks into a single string, which is what nearly every MCP tool actually returns.

type Client

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

func New

func New(url string, opts ...Option) *Client

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) (CallResult, error)

func (*Client) CallToolWithMeta

func (c *Client) CallToolWithMeta(ctx context.Context, name string, args, meta map[string]any) (CallResult, error)

CallToolWithMeta is CallTool plus the spec's own `params._meta` extension field - the same channel this project's MCP server side already accepts run ids and taint through. The proxy uses it to hand an upstream the capability token minted for this exact call, so an upstream that wants to verify independently can, without that being required of one that doesn't.

func (*Client) Initialize

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

Initialize performs the MCP handshake. Safe to call more than once - a second call is a no-op, so callers don't have to coordinate who initializes first.

func (*Client) ListTools

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

type Option

type Option func(*Client)

func WithAuthorization

func WithAuthorization(value string) Option

WithAuthorization sets a header sent on every request to the upstream - this is the credential the AGENT never gets to see.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

type Tool

type Tool struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"inputSchema"`
}

Jump to

Keyboard shortcuts

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