mcp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package mcp is a small Model Context Protocol client. It attaches to an MCP server, lists the tools that server offers, and calls them, so tomo can pick up typed tools from the wider ecosystem without wiring each one by hand. The protocol is JSON-RPC 2.0. The client speaks over a transport: stdio.go frames each message as one line of JSON over a subprocess pipe, and http.go POSTs each message to a URL. The Client itself is transport-agnostic.

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 is one live connection to an MCP server.

func StartHTTP

func StartHTTP(name, url string, headers map[string]string) *Client

StartHTTP attaches to an MCP server reachable over HTTP. name prefixes its tools; an empty name falls back to the URL host. headers are sent on every request, so an auth token can travel with them. No connection is opened until the first call; run Initialize before listing tools.

func StartStdio

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

StartStdio launches an MCP server as a subprocess and returns a client that speaks over its stdin and stdout. The server's stderr is forwarded to tomo's, so its own logging stays visible.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args json.RawMessage) (string, error)

CallTool invokes a tool by its server-side name and returns the text of its result. A tool that reports an error returns that text as the error.

func (*Client) Close

func (c *Client) Close() error

Close shuts the transport. Pending calls fail.

func (*Client) Initialize

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

Initialize performs the MCP handshake: an initialize request followed by the initialized notification. It must run before any tool call.

func (*Client) ListTools

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

ListTools returns every tool the server offers, following pagination.

func (*Client) Tools

func (c *Client) Tools(ctx context.Context, class tool.Class) ([]tool.Tool, error)

Tools lists the server's tools and adapts each into a tomo tool, qualified with the server name and gated at the given class. A tool with no schema is given an empty object schema so the provider still accepts it.

type Server

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

Server is the other side of the wire: it exposes a set of tomo tools over MCP so any client, Claude Code among them, can call them. It speaks JSON-RPC 2.0 over one stream, framing each message as a line of JSON, and handles one request at a time.

func NewServer

func NewServer(name string, tools []tool.Tool) *Server

NewServer builds a server that offers the given tools under a name that clients see in the handshake.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, r io.Reader, w io.Writer) error

Serve reads requests until the stream ends or ctx is cancelled. A read error other than a clean EOF is returned; EOF means the client hung up.

type ToolInfo

type ToolInfo struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	InputSchema json.RawMessage `json:"inputSchema"`
}

ToolInfo is one tool as the server describes it.

Jump to

Keyboard shortcuts

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