Wrap MCP Agents
How to use thoughtgate wrap with each supported agent type.
How Auto-Detection Works
ThoughtGate detects the agent type from the command basename (the last component of the command path):
# Auto-detected as Claude Code (basename: "claude-code")
thoughtgate wrap -- claude-code
# Auto-detected as Cursor (basename: "cursor")
thoughtgate wrap -- cursor
# Auto-detected as VS Code (basename: "code")
thoughtgate wrap -- code
# Full paths work too (basename: "claude-code")
thoughtgate wrap -- /usr/local/bin/claude-code
If detection fails, ThoughtGate exits with an error. Use --agent-type to override.
Claude Code
thoughtgate wrap -- claude-code
# or
thoughtgate wrap -- claude
Config file: ~/.claude.json (per-project servers under projects.<cwd>.mcpServers)
What happens:
- ThoughtGate reads
~/.claude.jsonand finds servers for the current working directory - Merges any
.mcp.jsonservers from the project directory - Filters to stdio-only servers (HTTP/SSE servers are skipped)
- Expands
${VAR}and${VAR:-default}environment variable references - Rewrites each server's
commandto route through the ThoughtGate shim - Launches Claude Code with the rewritten config
Notes:
- Non-stdio servers (
"type": "http","type": "sse") are left unchanged — ThoughtGate only governs stdio servers .mcp.jsonentries override~/.claude.jsonentries when they share the same server ID- The
enabledMcpjsonServersanddisabledMcpjsonServersarrays in~/.claude.jsonare respected
Claude Desktop
thoughtgate wrap -- claude-desktop
# or for macOS app bundle:
thoughtgate wrap -- /Applications/Claude.app/Contents/MacOS/Claude
Config file: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or ~/.config/Claude/claude_desktop_config.json (Linux)
What happens:
- ThoughtGate reads the Claude Desktop config
- Rewrites all servers under
mcpServers - Launches Claude Desktop
Cursor
thoughtgate wrap -- cursor
Config files:
- Global:
~/.cursor/mcp.json - Project:
.cursor/mcp.json(in working directory)
What happens:
- ThoughtGate reads the global config
- Merges project-level overrides (project entries override global by server ID)
- Rewrites all servers under
mcpServers - Launches Cursor
VS Code
thoughtgate wrap -- code
# or for Insiders:
thoughtgate wrap -- code-insiders
Config file: .vscode/mcp.json (workspace-level only)
What happens:
- ThoughtGate reads the workspace MCP config
- Filters to
"type": "stdio"entries only (SSE and other types are skipped) - Rewrites under the
serverskey (note: VS Code usesservers, notmcpServers) - Launches VS Code
Note: VS Code's MCP config uses "servers" as the top-level key, not "mcpServers".
Windsurf
thoughtgate wrap -- windsurf
Config file: ~/.codeium/windsurf/mcp_config.json
What happens:
- ThoughtGate reads the Windsurf config
- Expands
${env:VAR}environment variable references (Windsurf's syntax) - Rewrites all servers under
mcpServers - Launches Windsurf
Note: Windsurf uses ${env:VAR} syntax (with env: prefix), unlike Claude Code's ${VAR} syntax. Plain ${VAR} without the prefix is left unchanged.
Zed
thoughtgate wrap -- zed
Config file: ~/.config/zed/settings.json
What happens:
- ThoughtGate reads the Zed settings
- Parses servers under
context_servers(Zed's unique key name) - Handles Zed's nested command format:
{ "command": { "path": "...", "args": [...] } } - Launches Zed
Custom Agents
For agents not in the supported list, use --agent-type custom with --config-path:
thoughtgate wrap \
--agent-type custom \
--config-path ./my-agent-config.json \
-- ./my-agent
The custom agent's config must use the mcpServers key format (same as Claude Desktop / Cursor).
Overriding Detection
Override Agent Type
# Force Cursor adapter for a forked build
thoughtgate wrap --agent-type cursor -- /opt/cursor-fork/cursor
Override Config Path
# Use a specific config file instead of auto-discovered path
thoughtgate wrap --config-path ~/testing/mcp.json -- claude-code
Linux Paths
On Linux, ThoughtGate follows XDG conventions where applicable:
| Agent | macOS Path | Linux Path |
|---|---|---|
| Claude Desktop | ~/Library/Application Support/Claude/ | ~/.config/Claude/ |
| Zed | ~/Library/Application Support/zed/ | ~/.config/zed/ |
| Others | Home directory | Same as macOS |
Double-Wrap Prevention
If you accidentally try to wrap an already-wrapped agent, ThoughtGate detects it and exits:
Error: Config already managed by ThoughtGate — run the agent directly or restore with `thoughtgate unwrap`
Detection works two ways:
- Config-level: Checks if any server's
commandalready points to thethoughtgatebinary - Process-level: Checks for the
THOUGHTGATE_ACTIVE=1environment variable
Config Backup and Restore
When wrapping, ThoughtGate creates a backup of the original config:
| File | Purpose |
|---|---|
<config>.thoughtgate-backup | Byte-for-byte copy of the original config |
<config>.thoughtgate-lock | Advisory lock preventing concurrent modifications |
On exit (normal, SIGTERM, SIGINT, or panic), the original config is automatically restored from the backup.
To skip automatic restoration:
thoughtgate wrap --no-restore -- claude-code
See Also
- CLI Reference — Complete flag documentation
- Supported Agents — Config format details
- Use Profiles — Development vs production modes