Y1

yi-111-a/mcpweigh

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

0 stars 0 forks 质量 79 趋势 14MIT

你的MCP服务器占用了多少上下文窗口?权衡Claude、Cursor、VS Code、Windsurf、Gemini、Codex、Zed和OpenCode配置中的所有工具定义。

概览

你启用的每个MCP服务器都会在每次请求中向模型发送其工具名称、描述和JSON模式。加上浏览器服务器、GitHub服务器和其他几个,你在输入单词前可以烧掉2万到4万个令牌,这需要花钱,会拖慢响应速度,并且会推送你真正关心的代码。 mcpweigh 会读取你已有的 MCP 配置(Claude Desktop、Claude Code、Cursor、VS Code、Windsurf、Gemini CLI、Codex CLI、Zed、OpenCode),启动每个服务器,询问其工具,并准确告诉你令牌的具体位置,每个服务器和每个工具,预算检查可以在 CI 里输入。 - :纯 Python 3.9+ 标准库。安装后自动使用 tiktoken(o200k_base),否则内置估计器校准(通常在 ~10% 以内)。- :stdio、可流式 HTTP(带 Mcp-Session-Id)和传统 HTTP+SSE。

概述(AI 翻译)

你的MCP服务器占用了多少上下文窗口?

你启用的每台MCP服务器都会在每一次请求中向模型发送其工具名称、描述和JSON模式。增加一个浏览器服务器、一个GitHub服务器和其他几个,你在输入单词前可以烧掉2万到4万个令牌,这需要花钱,会拖慢响应速度,并且会推送你真正关心的代码。

mcpweigh 读取你已有的MCP配置(Claude Desktop、Claude Code、Cursor、VS Code、Windsurf、Gemini CLI、Codex CLI、Zed、OpenCode),启动每个服务器,询问其工具,并准确告诉你代币的具体位置,每个服务器和每个工具,并附带预算检查,你可以在CI中查看。

  • 零依赖:纯Python 3.9+标准库。安装后自动使用tiktoken(o200k_base),否则内置估计器校准(通常在~10%范围内)。
  • 所有传输方式:stdio、可流式HTTP(带Mcp-Session-Id)和遗留HTTP+SSE。
  • 每个客户端配置:自动发现用户和项目配置文件,理解 JSONC、${env:VAR}、${workspaceFolder},禁用服务器,以及每个项目的 Claude Code 权限。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

mcpweigh

How much of your context window are your MCP servers eating?

Every MCP server you enable ships its tool names, descriptions and JSON schemas to the model on every request. Add a browser server, a GitHub server and a couple of others and you can burn 20–40k tokens before you type a word, which costs money, slows responses and pushes out the code you actually care about.

mcpweigh reads the MCP config you already have (Claude Desktop, Claude Code, Cursor, VS Code, Windsurf, Gemini CLI, Codex CLI, Zed, OpenCode), starts each server, asks it for its tools, and tells you exactly where the tokens go, per server and per tool, with a budget check you can put in CI.

  • Zero dependencies: pure Python 3.9+ standard library. Uses tiktoken (o200k_base) automatically if it is installed, otherwise a built-in estimator calibrated against it (typically within ~10%).
  • Every transport: stdio, Streamable HTTP (with Mcp-Session-Id), and legacy HTTP+SSE.
  • Every client config: auto-discovers user and project config files, understands JSONC, ${env:VAR}, ${workspaceFolder}, disabled servers, and Claude Code per-project scopes. The same server configured in several clients is weighed once.
  • Actionable output: heaviest tools, description vs schema split, server instructions, bloated or undocumented tools, and tool names shared by several servers.
  • CI friendly: --budget 8k exits 1 when you go over; --format json|markdown for bots and PR comments; --tools-json works fully offline.

Install

pipx install git+https://github.com/Yi-111-a/mcpweigh
# exact OpenAI-style token counts (optional):
pipx inject mcpweigh tiktoken

Or run it straight from a clone: python -m mcpweigh.

Usage

mcpweigh                          # weigh every server in every client config it can find
mcpweigh --list                   # just show what was discovered (never prints env values)
mcpweigh -c .cursor/mcp.json      # one config file, any supported format
mcpweigh -s github -s playwright  # only these servers
mcpweigh --context 200k           # show the share of a 200k-token window
mcpweigh --budget 8k              # exit 1 if the total is over 8,000 tokens

# one server, no config needed
mcpweigh -- npx -y @modelcontextprotocol/server-filesystem /tmp
mcpweigh --url https://example.com/mcp -H "Authorization: Bearer $TOKEN"
mcpweigh --url http://localhost:3001/sse --sse      # legacy SSE servers

# offline / CI: weigh a saved tools/list result
mcpweigh -- uvx my-server --dump snapshots/       # save raw tools/list JSON
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →