MCP#
The Model Context Protocol (MCP) allows you to extend gptme with custom tools through external servers. See MCP for configuration and usage details.
MCP server discovery and management tool.
Allows searching for MCP servers in registries and dynamically loading/unloading them.
Available Commands:
/mcp search [query]- Search for MCP servers across all registries/mcp info <server-name>- Get detailed information about a specific server/mcp load <server-name> [config-json]- Dynamically load an MCP server into the current session/mcp unload <server-name>- Unload a previously loaded MCP server/mcp list- List all currently configured and loaded MCP servers
The search command queries the Official MCP Registry (registry.modelcontextprotocol.io).
Once loaded, server tools are available as <server-name>.<tool-name>.
Instructions
### When to use the mcp tool
Use mcp to discover, load, inspect, and manage MCP servers:
- `/mcp search <capability>` finds new servers
- `/mcp load <server-name>` loads one
- `/mcp list` shows what is already loaded, plus servers the user configured
in other MCP clients (Claude Code, Codex, ...) that can be loaded by name
Do not use mcp to call loaded tools; invoke them directly as
`<server-name>.<tool-name>`.
Search uses the Official MCP Registry (registry.modelcontextprotocol.io).
Other commands:
- `info <server>` shows server details
- `resources list/read` browses server resources
- `templates list` lists resource templates
- `prompts list/get` lists or fetches prompts
- `roots list/add/remove` manages advisory workspace roots
Examples
```mcp
search sqlite
```
```mcp
info sqlite
```
```mcp
load sqlite
```
```mcp
list
```
```mcp
unload sqlite
```
```mcp
load my-server
{"command": "uvx", "args": ["my-mcp-server", "--option"]}
```
```mcp
resources list sqlite
```
```mcp
resources read sqlite db://main/users
```
```mcp
templates list sqlite
```
```mcp
prompts list sqlite
```
```mcp
prompts get sqlite create-query {"table": "users"}
```
```mcp
roots list
```
```mcp
roots add filesystem file:///home/user/project Project
```
```mcp
roots remove filesystem file:///home/user/project
```
- gptme.tools.mcp.advertise_imported_servers(manager: Any = None, initial_msgs: list[Message] | None = None, **kwargs: Any) Generator[Message, None, None]
Tell the agent which servers from other MCP clients it can load.
Names and client only: never commands, URLs or env. Both the entry count and serialized entry length are bounded. Metadata is untrusted user-role JSON, separate from the static system instructions.
Discovery uses
get_imported_servers(get_config())— the same call/mcp listand/mcp loadmake — so every advertised name is one the agent can actually load.
- gptme.tools.mcp.execute_mcp(code: str | None, args: list[str] | None, kwargs: dict[str, str] | None) Generator[Message, None, None]
Execute MCP management commands.
- gptme.tools.mcp.prepare_pending_mcp(call: ToolUse) ToolUse
Show load provenance before the server client approves the call.
Records what the registry showed for this approval, even when that is nothing: the server does not ask again before executing, so a later lookup would load something nobody saw.