mcp

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 23 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 the CLI to MCP servers (Model Context Protocol) run over stdio, and offers their tools to the agent: the user's servers in ~/.docsgpt/mcp.json and the project's in .mcp.json.

Index

Constants

View Source
const (
	// StartTimeout is how long a server has to start and list its tools.
	StartTimeout = 30 * time.Second
	// CallTimeout is how long a tool call may take.
	CallTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func Forget

func Forget(file string) (int, error)

Forget drops the answers about the servers of the project file, so that they are asked about again. It returns how many there were.

func ProjectFile

func ProjectFile(cwd string) string

ProjectFile finds the project's .mcp.json, in cwd or the nearest directory above it up to the git root (cwd alone outside a repository), or returns "".

func Remember

func Remember(s Server, allow bool) error

Remember records the user's answer about the project's server s.

func Result

Result turns a tool's result into the text the model gets and the images that go with it. Other media are named, not sent.

func UserFile

func UserFile() string

UserFile is the user's own server list.

Types

type Decision

type Decision int

Decision is what the user said about a project's server.

const (
	Undecided Decision = iota // never asked, or the entry changed since
	Approved
	Refused
)

func Decided

func Decided(s Server) Decision

Decided returns what the user said about the project's server s as it is now. The user's own servers are always approved.

type Manager

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

Manager runs the MCP servers of a chat or an ask run.

func Start

func Start(servers []Server, version string) *Manager

Start starts the servers in the background; Wait waits for them. version is the CLI's, told to the servers.

func (*Manager) Call

func (m *Manager) Call(ctx context.Context, t *Tool, args map[string]any) (*mcp.CallToolResult, error)

Call runs the tool with args. A server that stopped is started again first; the call itself is never repeated, as the server may have acted.

func (*Manager) Close

func (m *Manager) Close()

Close stops every server.

func (*Manager) Definitions

func (m *Manager) Definitions() []docsgpt.Tool

Definitions are the servers' tools for a chat request, once Wait has returned (none before).

func (*Manager) Lookup

func (m *Manager) Lookup(name string) *Tool

Lookup finds the tool the model called by name.

func (*Manager) Starting

func (m *Manager) Starting() bool

Starting reports whether a server is still starting.

func (*Manager) Status

func (m *Manager) Status() []Status

Status reports on every server started, in order.

func (*Manager) Wait

func (m *Manager) Wait(ctx context.Context) error

Wait waits until every server has started or failed, or ctx ends.

type Server

type Server struct {
	Name     string
	Command  string
	Args     []string
	Env      map[string]string // added to the CLI's environment
	Dir      string            // where it runs
	File     string            // the file that defines it
	Project  bool              // the project's: started only once the user approves it
	Disabled bool
	Err      error // why it cannot start: a remote server, a variable not set
	// contains filtered or unexported fields
}

Server is an MCP server the CLI can start: an entry of "mcpServers" in the user's file or the project's.

func Load

func Load(cwd string) ([]Server, error)

Load reads the user's servers and the project's (which win over the user's of the same name), sorted by name. A file that is missing is fine; one that cannot be read or parsed is an error.

func (Server) CommandLine

func (s Server) CommandLine() string

CommandLine is the server's command as one line, for the user: as the file writes it, so that no secret a variable holds shows.

func (Server) Settings

func (s Server) Settings() []string

Settings are the environment variables and the directory the file sets for the server, as it writes them ("NAME=value", "cwd dir").

type Status

type Status struct {
	Server
	Starting     bool
	Running      bool
	Err          error
	Tools        []string // their names on the server
	Instructions string   // what the server tells the agent about itself
	Log          string   // the file its stderr goes to
	Stderr       []string // its last lines there
}

Status is how a server is doing, for the user.

type Tool

type Tool struct {
	Name   string // mcp__<server>__<tool>
	Server string
	Tool   *mcp.Tool // as the server describes it
}

Tool is a server's tool as the agent sees it.

func (*Tool) ReadOnly

func (t *Tool) ReadOnly() bool

ReadOnly reports whether the server says the tool changes nothing.

Directories

Path Synopsis
Package mcptest runs a small MCP server over stdio for tests: the test binary itself, started again.
Package mcptest runs a small MCP server over stdio for tests: the test binary itself, started again.

Jump to

Keyboard shortcuts

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