Context-saving MCP switchboard for AI agents - lazy-load tools, resources, and prompts only when needed
Project description
→ For agents: read llms.txt
→ For humans: send your agent this prompt:
Install mcp-switch (
pip install mcp-switch) and use it as an MCP switchboard so only the needed namespaces are loaded at a time. Read https://raw.githubusercontent.com/Zer0Wav3s/mcp-switch/main/llms.txt for setup and usage.
What It Does
When you connect a pile of MCP servers to an agent, every tool usually gets dumped into context up front. That is dumb. More tools means more noise, slower tool selection, and worse calls.
mcp-switch fixes that by exposing 5 meta-tools first:
list_namespacesload_namespaceunload_namespaceload_groupunload_group
The agent starts focused, loads what it needs, then unloads it when done.
flowchart LR
subgraph before["Without mcp-switch"]
A1["🤖 Agent"] --> T1["46 tools loaded\n(database, GitHub, Slack,\nDocker, K8s...)"]
T1 --> R1["❌ Slower, noisier,\nworse tool picks"]
end
subgraph after["With mcp-switch"]
A2["🤖 Agent"] --> T2["5 meta-tools\n(list, load, unload,\nload_group, unload_group)"]
T2 -->|"load_namespace('postgres')"| T3["+ only the database tools"]
T3 --> R2["✅ Focused, fast,\nright tool at the right time"]
T3 -->|"unload_namespace('postgres')"| T2
end
style before fill:#1a1a2e,stroke:#e74c3c,color:#fff
style after fill:#1a1a2e,stroke:#2ecc71,color:#fff
How It Works
- Define namespaces for MCP servers, hosted HTTP MCP endpoints, or CLI tools
- Start mcp-switch as one MCP server in your client
- Let the agent discover namespaces with
list_namespaces - Load only what is needed with
load_namespaceorload_group - Unload when done to keep context clean
It supports:
mcpbackends - local stdio MCP servershttpbackends - remote MCP servers over StreamableHTTP with SSE fallbackclibackends - shell commands wrapped as MCP tools- groups
idle_ttl,pinned, andmax_loaded_namespaces- tools, resources, resource templates, and prompts
Install
pip install mcp-switch
Or use uvx without installing globally:
uvx mcp-switch --help
Quick Start
1. Create a config
Fastest path:
uvx mcp-switch setup
Or import an existing MCP config:
uvx mcp-switch init
uvx mcp-switch init --from ~/.config/claude/claude_desktop_config.json
Or write one manually at ~/.config/mcp-switch/config.yaml:
max_loaded_namespaces: 3
namespaces:
postgres:
type: mcp
command: "uvx mcp-server-postgres"
args: ["--connection-string", "postgresql://localhost/mydb"]
description: "Query and manage PostgreSQL databases"
idle_ttl: 300
supabase:
type: http
url: "https://mcp.supabase.com/mcp"
headers:
Authorization: "Bearer ${SUPABASE_TOKEN}"
description: "Supabase database tools"
git:
type: cli
description: "Git version control"
tools:
git_status:
command: "git status --porcelain"
description: "Show working tree status"
git_log:
command: "git log --oneline -20"
description: "Show recent commits"
groups:
dev:
- git
- postgres
2. Verify it works
uvx mcp-switch validate
uvx mcp-switch doctor
uvx mcp-switch test --json-output
3. Add it to your MCP client
General pattern:
{
"mcpServers": {
"mcp-switch": {
"command": "uvx",
"args": ["mcp-switch", "serve", "--config", "~/.config/mcp-switch/config.yaml"]
}
}
}
Examples:
Claude Code
claude mcp add mcp-switch -- uvx mcp-switch serve --config ~/.config/mcp-switch/config.yaml
Cursor
Add to .cursor/mcp.json:
{
"mcpServers": {
"mcp-switch": {
"command": "uvx",
"args": ["mcp-switch", "serve", "--config", "~/.config/mcp-switch/config.yaml"]
}
}
}
VS Code
Add to .vscode/mcp.json:
{
"servers": {
"mcp-switch": {
"command": "uvx",
"args": ["mcp-switch", "serve", "--config", "~/.config/mcp-switch/config.yaml"]
}
}
}
Hermes
mcp_servers:
mcp-switch:
command: uvx
args: ["mcp-switch", "serve", "--config", "~/.config/mcp-switch/config.yaml"]
Or generate it:
uvx mcp-switch export hermes
Features
Namespace groups
Load related namespaces together:
groups:
dev:
- git
- postgres
- docker
Auto-unload with idle_ttl
Unload inactive namespaces automatically to keep context lean.
Pinned namespaces
Mark important namespaces as pinned: true so LRU eviction never removes them.
Max loaded namespace cap
Set max_loaded_namespaces to enforce a ceiling. If the cap is reached, mcp-switch evicts the least recently used unpinned namespace.
Full MCP surface
Tools are the main event, but resources, resource templates, and prompts are also proxied.
CLI
mcp-switch setup # interactive config wizard
mcp-switch init # import existing MCP configs
mcp-switch serve # start the MCP server
mcp-switch validate # validate config
mcp-switch doctor # check env, commands, config health
mcp-switch test # connect to backends and list tools
mcp-switch status # config and policy summary
mcp-switch list # list configured namespaces
mcp-switch export hermes # generate client-specific config
Troubleshooting
${VAR} values are not resolving
Use standard shell-style placeholders like ${SUPABASE_TOKEN}. mcp-switch expands them in both env and HTTP headers values.
doctor says an env var is missing
That means the placeholder resolved to an empty string in your current environment. Set it first, then rerun mcp-switch doctor.
Agent is not seeing new tools after loading
Some clients cache tool lists aggressively. mcp-switch sends tools/list_changed, but if your client ignores it, reconnect the MCP server.
Why does status not show what is live right now?
Because status is a config and policy summary, not a runtime inspector.
Links
- Repository: https://github.com/Zer0Wav3s/mcp-switch
- PyPI: https://pypi.org/project/mcp-switch/
- License: MIT © 2026 ZeroWaves
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_switch-0.4.1.tar.gz.
File metadata
- Download URL: mcp_switch-0.4.1.tar.gz
- Upload date:
- Size: 35.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd2b5c9cdbd6128921e2308b9a219d0c47c24379081a0201cb410eb7626a847e
|
|
| MD5 |
40e5842ce96ad88027a074b894bcf54a
|
|
| BLAKE2b-256 |
2d0c21f761e58bbe9f585e270d0f10193f1106414a63d3c2de389c664b72e8a8
|
Provenance
The following attestation bundles were made for mcp_switch-0.4.1.tar.gz:
Publisher:
publish.yml on Zer0Wav3s/mcp-switch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_switch-0.4.1.tar.gz -
Subject digest:
fd2b5c9cdbd6128921e2308b9a219d0c47c24379081a0201cb410eb7626a847e - Sigstore transparency entry: 1319419486
- Sigstore integration time:
-
Permalink:
Zer0Wav3s/mcp-switch@bab90fbaecb9c7b48e5c352e86e8aa193ef1867b -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/Zer0Wav3s
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bab90fbaecb9c7b48e5c352e86e8aa193ef1867b -
Trigger Event:
release
-
Statement type:
File details
Details for the file mcp_switch-0.4.1-py3-none-any.whl.
File metadata
- Download URL: mcp_switch-0.4.1-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0caf1764406423f283bec7395b988c8b6fce7e14c3a13d1babf3066043dc3b12
|
|
| MD5 |
1360d7db106e805292ee08fae6974de2
|
|
| BLAKE2b-256 |
b440a86b7d44d3a828bdb9616e40cbd8712fedd8d692956d5ac61781175d44c6
|
Provenance
The following attestation bundles were made for mcp_switch-0.4.1-py3-none-any.whl:
Publisher:
publish.yml on Zer0Wav3s/mcp-switch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_switch-0.4.1-py3-none-any.whl -
Subject digest:
0caf1764406423f283bec7395b988c8b6fce7e14c3a13d1babf3066043dc3b12 - Sigstore transparency entry: 1319419583
- Sigstore integration time:
-
Permalink:
Zer0Wav3s/mcp-switch@bab90fbaecb9c7b48e5c352e86e8aa193ef1867b -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/Zer0Wav3s
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bab90fbaecb9c7b48e5c352e86e8aa193ef1867b -
Trigger Event:
release
-
Statement type: