MCP-Lens

MCP-Lens

Acts as a proxy/router for multiple downstream MCP servers, exposing only meta-tools to the host to reduce token usage, enabling efficient search and invocation of tools from a fleet of servers.

Category
访问服务器

README

@m8t-jacob/mcp-lens

CI npm version npm downloads license: MIT

mcp-lens is an MCP (Model Context Protocol) proxy/router that sits in front of your fleet of downstream MCP servers and exposes only a handful of meta-tools to the host, instead of every downstream tool definition.

The problem

Power users of Claude Code / Claude Desktop / Cursor connect 10+ MCP servers. Each one dumps the full definition (name, description, JSON Schema) of every tool it has — often 100-200 tools total — straight into the model's context window, on every single turn. That's tokens (and money) spent before the model has even done anything.

How mcp-lens fixes it

Instead of connecting the host directly to N servers, you connect it to one mcp-lens process, and mcp-lens connects to the N servers on your behalf:

Host (Claude) ── mcp-lens ──┬── github MCP server
                             ├── slack MCP server
                             ├── filesystem MCP server
                             └── ... (N more)

The host only ever sees 4 small meta-tools:

Tool What it does
search_tools Free-text search over every downstream tool's name/description. Returns the best matches with their full schema.
describe_tool Full input schema + description for one specific server/tool pair.
call_tool Proxies an actual tools/call to the right downstream server and returns its result.
list_servers Lists connected downstream servers and their tool counts.

When the model needs a capability, it calls search_tools to find the right downstream tool, then call_tool to actually run it — the full tool list is discovered on demand, never loaded up front.

Definition-size savings

Measured by scripts/benchmark.ts (npm run benchmark), against 100 fictitious downstream tools with realistic descriptions and JSON schemas, spread across 8 servers:

Downstream tools Downstream tool definitions mcp-lens meta-tool definitions Reduction
100 79,792 bytes 1,395 bytes 98.3%

Run it yourself: npm run benchmark (accepts an optional tool-count argument, e.g. npm run benchmark -- 200).

Honest caveat: mcp-lens's own 4 meta-tool definitions have a small, fixed cost (~1.4 KB). For a single downstream server exposing only 1-2 trivial tools, that fixed cost can outweigh the savings — mcp-lens earns its keep once your fleet grows past roughly a handful of tools, and the benefit compounds from there (98%+ at 100 tools, as measured above). If you only ever connect one or two lightweight MCP servers, connecting them directly may be simpler.

Install for Claude Code / Claude Desktop

  1. Create a fleet config (see examples/mcp-lens.config.json):

    {
      "servers": {
        "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"] },
        "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"] }
      }
    }
    

    The shape matches the mcpServers object you already have in claude_desktop_config.json / .mcp.json — each entry is just { command, args?, env? }.

  2. Point your MCP client at mcp-lens instead of at each server individually:

    {
      "mcpServers": {
        "lens": {
          "command": "npx",
          "args": ["-y", "@m8t-jacob/mcp-lens", "/absolute/path/to/mcp-lens.config.json"],
          "env": { "MCP_LENS_CONFIG": "/absolute/path/to/mcp-lens.config.json" }
        }
      }
    }
    

    The config path can be passed either as the first CLI argument or via MCP_LENS_CONFIG (the argument wins if both are set).

  3. Move your existing per-server entries out of the host's own MCP config and into the mcp-lens fleet config instead — the host now only launches mcp-lens, which launches (and proxies to) the rest.

You can also run it directly to smoke-test it:

npx -y @m8t-jacob/mcp-lens ./mcp-lens.config.json

It logs a one-line summary of the definition-size savings to stderr on startup, then sits waiting for JSON-RPC requests on stdin — that's expected; it's meant to be driven by an MCP client, not used interactively.

Programmatic use

import { buildServer, ToolCatalog, ToolProxy, loadConfig } from '@m8t-jacob/mcp-lens';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const config = loadConfig('./mcp-lens.config.json');
const proxy = new ToolProxy(config.servers);
const catalog = new ToolCatalog();
await catalog.build(proxy.serverNames(), (name) => proxy.getClient(name));

const server = buildServer({ getCatalog: () => catalog.list(), proxy });
await server.connect(new StdioServerTransport());

searchTools (the ranking function behind search_tools) and ToolCatalog are also exported directly, e.g. for building your own UI over the fleet catalog. See examples/basic.ts.

Design notes

  • Built on the official @modelcontextprotocol/sdkMcpServer + StdioServerTransport on the host-facing side, Client + StdioClientTransport on the downstream-facing side (mcp-lens is both an MCP server and an MCP client).
  • Downstream connections are lazy and reused: a server is only spawned when its tools are first listed or called, and the same connection is reused afterwards. If a downstream call fails, that connection is dropped so the next call reconnects instead of repeatedly hitting a broken pipe.
  • search_tools's ranking (src/search.ts) is a small TF-like text scorer behind a Scorer interface, so it can be swapped for an embeddings-based scorer later without touching any calling code.
  • One broken downstream server doesn't take down the fleet: catalog building skips (and logs) any server that fails to connect or list its tools, the rest still work.
  • Strict TypeScript, dual ESM + CJS builds with .d.ts, zero real network calls in the test suite (an in-process InMemoryTransport end-to-end test and a real-subprocess StdioClientTransport test cover the full proxy path instead).

🇵🇱 Po polsku

@m8t-jacob/mcp-lens to proxy/router MCP, który staje przed flotą serwerów MCP i eksponuje do hosta (Claude Desktop, Claude Code, Cursor) tylko garść meta-narzędzi (search_tools, describe_tool, call_tool, list_servers) zamiast definicji wszystkich narzędzi każdego serwera. Power-userzy podłączający 10+ serwerów MCP, z których każdy wrzuca do kontekstu modelu definicje 100-200 narzędzi, zyskują dzięki temu 80-95%+ oszczędności tokenów definicji (zmierzone: 98.3% redukcji przy 100 narzędziach) — model wyszukuje potrzebne narzędzie przez search_tools, a następnie wywołuje je przez call_tool, zamiast widzieć od razu całą listę. Konfiguracja floty downstreamowych serwerów ma taki sam kształt jak mcpServers w .mcp.json/claude_desktop_config.json.

Contributing

Contributions are welcome! See CONTRIBUTING.md for the development workflow and GOOD_FIRST_ISSUES.md for ideas if you're looking for a place to start. This project follows the Contributor Covenant.

License

MIT © 2026 Jakub Jagiełło

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选