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
- func Forget(file string) (int, error)
- func ProjectFile(cwd string) string
- func Remember(s Server, allow bool) error
- func Result(r *mcp.CallToolResult) (string, []docsgpt.ContentPart)
- func UserFile() string
- type Decision
- type Manager
- func (m *Manager) Call(ctx context.Context, t *Tool, args map[string]any) (*mcp.CallToolResult, error)
- func (m *Manager) Close()
- func (m *Manager) Definitions() []docsgpt.Tool
- func (m *Manager) Lookup(name string) *Tool
- func (m *Manager) Starting() bool
- func (m *Manager) Status() []Status
- func (m *Manager) Wait(ctx context.Context) error
- type Server
- type Status
- type Tool
Constants ¶
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 ¶
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 ¶
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 Result ¶
func Result(r *mcp.CallToolResult) (string, []docsgpt.ContentPart)
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.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the MCP servers of a chat or an ask run.
func Start ¶
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) Definitions ¶
Definitions are the servers' tools for a chat request, once Wait has returned (none before).
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 ¶
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 ¶
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.
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.