smartmcp

smartmcp

Intelligent MCP proxy server that reduces context bloat by serving only the tools your AI actually needs through semantic search and a fixed two-tool surface.

Category
访问服务器

README

smartmcp

PyPI version Python 3.10+ License: MIT

<p align="center"> <img src="https://raw.githubusercontent.com/spak2005/smart-mcp/main/assets/banner.png" alt="Without smartmcp vs With smartmcp" width="700" /> </p>

PyPI package: smartmcp-router (CLI: smartmcp)

Intelligent MCP tool routing that reduces context bloat by serving only the tools your AI actually needs.

In my own setup with 8 MCP servers and 224 tools, every AI request was loading ~66,000 tokens of tool schemas before the model even started thinking. With smartmcp, that dropped to ~1,600 tokens. A 97% reduction on every request.

Without smartmcp With smartmcp
Tools in context All 224 2 (search_tools + call_discovered_tool)
Tokens per request ~66,000 ~1,600
Scales with Every tool you add (O(n)) Always 2 fixed tools (O(1))

Token counts estimated at ~4 characters per token. Actual counts vary by model tokenizer.

Most MCP setups expose every tool from every server to the AI at once. With 5+ servers, that's 50–200+ tool schemas crammed into the context window before the AI even starts thinking. smartmcp fixes this.

smartmcp is a proxy MCP server that sits between your AI client and your upstream MCP servers. It indexes all available tools using semantic embeddings and exposes a fixed two-tool surface: search_tools to discover the right upstream tool and call_discovered_tool to invoke it. The tool list never changes mid-session, so smartmcp works even with clients that ignore notifications/tools/list_changed.

How it works

AI Client (Claude Desktop / Cursor / your agent)
    ↕  stdio
smartmcp (proxy server)
    ↕  stdio (one connection per server)
[github] [filesystem] [google-workspace] [git] [memory] [puppeteer] ...

smartmcp uses a two-phase flow: discover, then call.

Phase 1: Discovery

  1. On startup, smartmcp connects to all your configured MCP servers, collects every tool schema, and builds a FAISS vector index using sentence-transformer embeddings.
  2. The AI always sees exactly two tools: search_tools and call_discovered_tool. It calls search_tools with a natural language query, for example search_tools({ "query": "create a GitHub issue" }).
  3. smartmcp runs semantic search across all indexed tools and finds the top-k matches.
  4. search_tools returns structured JSON. Each match includes the exact target identifier, the upstream server and name, the description, the relevance score, and the full upstream input_schema.

Phase 2: Calling

  1. The AI reads the matching tool's input_schema from the search response and constructs valid arguments.
  2. The AI calls call_discovered_tool({ "target": "<exact target from search>", "arguments": { ... } }). smartmcp resolves the target (for example github__create_issue), routes the call to the correct upstream server, and returns the result. Arguments are forwarded to the upstream tool unchanged.

The intelligence is in the discovery step. The AI still does its own parameter construction based on the schema returned by search_tools. smartmcp just narrows down which tools it sees, and the static two-tool surface means the flow works even with clients that snapshot tools/list once and never refresh.

Installation

pip install smartmcp-router

Requires Python 3.10+.

Recommended on macOS, especially Apple Silicon: install with pipx so SmartMCP gets an isolated environment that cannot inherit a stale torch or torchvision from other projects. This avoids the most common class of install issues (see Troubleshooting).

pipx install smartmcp-router

Quick start

1. Create a config file

Create a smartmcp.json with your upstream MCP servers (same format as Claude Desktop / Cursor config):

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/documents"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token_here"
      }
    },
    "slack": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-slack"],
      "env": {
        "SLACK_BOT_TOKEN": "xoxb-your-token-here"
      }
    }
  },
  "top_k": 5,
  "embedding_model": "all-MiniLM-L6-v2"
}

2. Add smartmcp to your AI client

Add smartmcp as your single MCP server entry. It now manages all your upstream servers defined in smartmcp.json.

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "smartmcp": {
      "command": "smartmcp",
      "args": ["--config", "/path/to/smartmcp.json"]
    }
  }
}

Cursor

Add to your .cursor/mcp.json:

{
  "mcpServers": {
    "smartmcp": {
      "command": "smartmcp",
      "args": ["--config", "/path/to/smartmcp.json"]
    }
  }
}

Custom agents

Point your MCP client at smartmcp the same way you would any stdio MCP server:

smartmcp --config /path/to/smartmcp.json

3. Use it

Your AI now sees two tools: search_tools and call_discovered_tool. When it needs to do something, it searches and then invokes:

AI calls: search_tools({ "query": "read files from disk" })

smartmcp returns: JSON with up to top-k matches. Each match includes a target (such as filesystem__read_file), the upstream tool's description, and the full input_schema.

AI sees: The complete parameter definitions inside each match. It picks the right one, builds arguments against that match's input_schema, and calls call_discovered_tool({ "target": "filesystem__read_file", "arguments": { ... } }).

smartmcp proxies the call to the filesystem server unchanged and returns the result.

Configuration reference

Field Type Default Description
mcpServers object (required) Map of server names to MCP server configs
mcpServers.<name>.command string (required) Command to spawn the server
mcpServers.<name>.args string[] [] Arguments for the command
mcpServers.<name>.env object {} Environment variables for the server
top_k integer 5 Default number of tools returned per search
embedding_model string "all-MiniLM-L6-v2" Sentence-transformers model for embeddings

Why smartmcp?

  • Less context waste: Instead of 100 tool schemas in every request, the AI sees a fixed two-tool surface and only inspects the few schemas returned by search_tools.
  • Better tool selection: Semantic search finds the right tools even when the AI doesn't know the exact name.
  • Full schema in search results: Each match returned by search_tools includes the upstream input_schema, so the AI can construct calls correctly without any further tools/list refresh.
  • Client-agnostic: The tool list never changes mid-session, so smartmcp works with clients that ignore notifications/tools/list_changed (such as Qwen Code and similar agents).
  • Works with any MCP server: If it speaks MCP over stdio, smartmcp can proxy it.
  • Drop-in replacement: Replace your list of MCP servers with one smartmcp entry. No code changes needed.
  • Graceful degradation: If some upstream servers fail to connect, smartmcp continues with whatever is available.

Troubleshooting

torchvision::nms does not exist or Could not import module 'BertModel'

If smartmcp crashes at startup with one of these errors:

RuntimeError: operator torchvision::nms does not exist
ModuleNotFoundError: Could not import module 'BertModel'. Are this object's requirements defined correctly?

This is a torch / torchvision ABI mismatch in your Python environment, not a smartmcp bug. SmartMCP itself does not depend on torchvision. The mismatch usually appears after pip install --upgrade walks transitive dependencies forward (newer sentence-transformers -> newer transformers -> newer torch) while leaving an older torchvision in place. Newer transformers eagerly imports the vision pipeline during BertModel autoload, so the mismatched torchvision extension fails to register the nms operator and the whole import chain breaks. Apple Silicon users see this more often because mixing arm64 and x86_64 wheels makes the mismatch more likely.

Try these fixes in order:

  1. Remove torchvision. SmartMCP does not need it:

    pip uninstall -y torchvision
    
  2. Reset the torch stack so torch and torchvision share an ABI:

    pip uninstall -y torch torchvision torchaudio
    pip install --upgrade torch
    
  3. Recreate a clean venv (most reliable on Apple Silicon):

    python3 -m venv ~/.venvs/smartmcp
    source ~/.venvs/smartmcp/bin/activate
    pip install --upgrade pip
    pip install smartmcp-router
    

Installing with pipx (see Installation) avoids this class of issue altogether by giving SmartMCP its own isolated environment.

Contributing

smartmcp is early-stage and actively improving. Contributions are welcome, especially around search accuracy, embedding strategies, and support for new transports.

If you have ideas, find bugs, or want to add features, open an issue or submit a PR on GitHub.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选