Book supports the Model Context Protocol (MCP) as an MCP client. MCP servers expose tools that Book discovers and registers alongside its built-in tools, making them available to the agent loop without any code changes.

This page covers configuring MCP servers. For the client architecture internals (McpClientFacade, namespacing, tool adaptation), see Embedding Book via MCP (Phase 4).

~/.bk/mcp.json โ€” Server Configuration

MCP servers are declared in one or both of the following files:

File Scope Priority

~/.bk/mcp.json

Global โ€” applies to all projects

Lower

<cwd>/.bk/mcp.json

Project-local โ€” overrides global for this directory

Higher

Format

{
  "mcpServers": {
    "<server-name>": {
      "command": "<executable>",
      "args": ["<arg1>", "<arg2>"],
      "env": {
        "ENV_VAR": "value"
      }
    }
  }
}
Field Type Required Description

command

String

โœ…

Executable to spawn (e.g. npx, uvx, node).

args

List<String>

No (default [])

Command-line arguments.

env

Map<String,String>

No (default {})

Extra environment variables for the subprocess.

Example

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "<your-token>" }
    }
  }
}

Merge Semantics

When both files exist, Book merges them with the following rules:

  • If the same name key appears in both files, the project-local entry wins.

  • Servers unique to either file are retained (not dropped).

  • Malformed JSON in either file is silently skipped; [] is returned for that file.

This lets you maintain a global set of always-available servers (e.g. filesystem, github) and override individual entries per-project (e.g. a project-specific postgres server).

--mode mcp โ€” Standalone Startup

Pass --mode mcp to load MCP servers at startup regardless of whether ACP mode is active.

# TUI with MCP servers loaded
bk --mode mcp

# Headless prompt with MCP servers loaded
bk --mode mcp --prompt "list files in /tmp"

# Explicitly add TUI (same as default when --mode acp is absent)
bk --mode tui --mode mcp

Behaviour

  1. Book merges ~/.bk/mcp.json and <cwd>/.bk/mcp.json.

  2. Each server subprocess is spawned, initialize + tools/list are exchanged (10 s timeout each), and discovered tools are registered alongside the built-in tools.

  3. Servers that fail to respond within the timeout are skipped โ€” Book starts normally with the remaining servers.

  4. MCP tools become immediately available to the agent loop for the lifetime of the process.

ACP + MCP interaction

When --mode acp is also present, --mode mcp is silently ignored at startup:

bk --mode acp --mode mcp   # mcp.json is NOT consulted at startup

In ACP mode, MCP server configuration is supplied per-session by the IDE client via the session/new _meta (see below). This prevents a mismatch between the IDE’s project context and a static global mcp.json read at process start time.

Per-Session MCP via ACP session/new

In ACP server mode (bk --mode acp / bk serve), MCP servers are wired per-session rather than at process startup.

The IDE client includes an mcpServers array in the session/new request _meta:

{
  "jsonrpc": "2.0",
  "method": "session/new",
  "params": {
    "cwd": "/path/to/project",
    "_meta": {
      "mcpServers": [
        {
          "name": "filesystem",
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
        }
      ]
    }
  }
}

Each session’s MCP tools are independent โ€” one session can have filesystem loaded while another has github. Tools are deregistered when the session ends.

MCP Tool Naming

All MCP-sourced tools are registered with the prefix mcp_<server-name>_<tool-name>:

MCP server name MCP tool name Registered as

filesystem

read_file

mcp_filesystem_read_file

github

search_repositories

mcp_github_search_repositories

The prefix prevents collisions between built-in tools (e.g. read_file) and MCP tools with identical names from different servers. If two MCP servers declare a tool with the same name, the prefix ensures they remain distinct โ€” no deduplication occurs, both are registered.

Disconnecting

MCP connections are process-scoped. When book exits, all active subprocess clients are closed and all MCP tools are deregistered automatically. There is no explicit disconnect flag.

Troubleshooting

MCP server not appearing as a tool

  1. Check the server name in mcp.json โ€” it must be a valid identifier (no spaces).

  2. Run with --prompt "list tools" to see the full registered tool list at startup.

  3. Check the logs under ~/.bk/agent/logs/ for Failed to parse MCP config file or connect timeout entries.

mcp.json changes not reflected

mcp.json is read once at startup (or once per session/new in ACP mode). Restart book to pick up changes.