mcp

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcp connects an agent to MCP servers. It starts a local server over stdio, or talks to one over HTTP ("streamable HTTP"), lists its tools and turns each into an ordinary tool that calls the server. The same adapter lives in the TS package (agentenkit/adapters/mcp).

Index

Constants

View Source
const ProtocolVersion = "2025-06-18"

ProtocolVersion is the MCP version we ask for. A server may answer with an older one; we only use initialize, tools/list and tools/call, which every version has.

Variables

This section is empty.

Functions

func ContentText

func ContentText(res CallResult) string

ContentText is what the model reads back: the text parts joined, and a short note for anything that is not text. With no content, the structured result.

func ToolName

func ToolName(prefix, name string) string

ToolName is a name providers accept: letters, digits, _ and -, at most 64.

Types

type CallResult

type CallResult struct {
	Content           []Content       `json:"content"`
	StructuredContent json.RawMessage `json:"structuredContent,omitempty"`
	IsError           bool            `json:"isError,omitempty"`
}

CallResult is what tools/call answers.

type Connection

type Connection struct {
	Name string
	// Tools are ready to put in an agent's Tools.
	Tools []ports.Tool
	// contains filtered or unexported fields
}

Connection is a live server and its tools.

func Connect

func Connect(ctx context.Context, s Server) (*Connection, error)

Connect connects to one server, lists its tools and wraps each one. Keep the connection for as long as the workers run, and Close it on shutdown.

func ConnectAll

func ConnectAll(ctx context.Context, servers ...Server) (*Connection, error)

ConnectAll connects to several servers and merges their tools. Two tools with the same final name fail, so one never hides the other.

func (*Connection) Close

func (c *Connection) Close() error

Close stops the server process, or ends the HTTP session.

type Content

type Content struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
	Resource *struct {
		URI  string  `json:"uri,omitempty"`
		Text *string `json:"text,omitempty"`
	} `json:"resource,omitempty"`
}

Content is one part of a tool's answer.

type HTTP

type HTTP struct {
	URL     string
	Headers map[string]string
	Client  *http.Client
}

HTTP is a URL that speaks MCP over HTTP.

type Server

type Server struct {
	// Name is short, like "github". It is the default prefix of the tool
	// names, so two servers can both have a "search" tool.
	Name string
	// Set exactly one of Stdio and HTTP.
	Stdio *Stdio
	HTTP  *HTTP
	// Prefix goes before each tool's name. nil means Name + "_"; point it
	// at "" for none.
	Prefix *string
	// Tools keeps only these tools (by the server's own names). Empty: all.
	Tools []string
	// RequiresConfirmation parks these tools behind an approval (§2.5), by
	// the server's own names. ConfirmAll parks every one.
	RequiresConfirmation []string
	ConfirmAll           bool
	// Timeout is how long one request may take. Zero means 60s.
	Timeout time.Duration
}

Server says how to reach one MCP server and which of its tools to use.

type Stdio

type Stdio struct {
	Command string
	Args    []string
	// Env is added to this process's environment.
	Env map[string]string
	Dir string
}

Stdio is a local command we start and talk to over stdin/stdout.

Jump to

Keyboard shortcuts

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