mcp-context-inspector

mcp-context-inspector

An MCP server that records agent execution metrics and exposes a Context Window Explorer to visualize exactly what entered the model's context window across sessions, tokens, and tool calls.

Category
访问服务器

README

mcp-context-inspector

A drop-in MCP server + execution-metrics recorder for any tool-calling agent. Point your agent's loop at record_session(prompt, model_id, loop_result) after each run, and this gives you, for free:

  • A real MCP server (Streamable HTTP) any MCP client can connect to — Claude Desktop, Cursor, your own chat UI — exposing 7 read-only tools over session history, cost, token/tool metrics, and...

  • The Context Window Explorer — full transparency into exactly what entered the model's context window, block by block, with honest (explicitly-labeled-estimated) token counts, a proportional segmented bar, and a click-to-expand detail panel per block:

    Context Window Explorer

    (screenshot from the reference chat UI this was built alongside — sre-investigation-agent; the panel above is what any MCP client gets once it queries get_context_timeline.)

Most agent observability tools re-show you data your own UI already displayed. This one shows you something you can't normally see at all: system prompt vs. tool specs vs. reasoning vs. tool call/result vs. final answer, in the order they actually entered context, with a running token total against the model's real context window — and which of those blocks are ever visible to the end user vs. invisible overhead.

Install

uv add mcp-context-inspector   # or: pip install mcp-context-inspector
# while co-developing locally against an editable checkout:
uv add --editable ../mcp-context-inspector

Wire it into your agent

from metrics import store

session_id = store.record_session(prompt, model_id, loop_result)

loop_result is whatever your agent loop returns — this package only needs it to look like:

{
    "trace": [{"tool": "...", "args": {...}, "status": "ok"}, ...],
    "turns": [{"input_tokens": int, "output_tokens": int, "latency_ms": int}, ...],
    "input_tokens": int, "output_tokens": int, "total_tokens": int, "latency_ms": int,
    "context_blocks": [   # optional — omit and you just lose the Explorer, nothing crashes
        {"category": "system", "label": "...", "char_count": int, "token_estimate": int, "turn_n": int | None},
        ...
    ],
}

context_blocks categories: system, tools, user, reasoning, thinking, tool_call, tool_result (optionally carries a "status" key for color-coding failures), answer.

Run the server

uv run python -m mcp_server.server

No MCP_AUTH_TOKEN set → generates and prints one on startup, same trust model as a Jupyter server's printed token. Set it yourself for a stable value across restarts. Point any MCP client at http://127.0.0.1:8787/mcp with Authorization: Bearer <token>.

Auth — handing this server to other people

Two ways in, both accepted by the same Authorization: Bearer <token> header on /mcp and every /api/* route:

  1. Owner token — the MCP_AUTH_TOKEN above. Yours, printed on startup. Fine for solo local use.
  2. Google sign-in, per person — for anyone else you want to connect their own LLM/agent to your server, without handing them your one token (and without being able to revoke just their access later). Set GOOGLE_OAUTH_CLIENT_ID (see setup below) and point them at http://<your-host>:8787/auth/login — they sign in with their own Google account, get a personal token minted for them (mcp_server/auth_store.py), and use that as their bearer token. Signing in again returns the same token, so pasting it into an MCP client config once doesn't get invalidated by a second sign-in.

Why not a full OAuth 2.1 authorization server (the "real" way an MCP client is meant to discover and authenticate, per the MCP spec's OAuth Resource Server support)? That needs a genuine authorization server — PKCE, dynamic client registration, a consent screen, its own client/token tables — real infrastructure disproportionate to a personal-scale server. This gets the property that actually matters (each friend authenticates as themselves, with their own Google account, and you can revoke just one person) via Google Identity Services' one-tap credential flow instead: no redirect URIs, no client secret, just a signed ID token verified server-side (mcp_server/google_auth.py).

Google Cloud setup (one-time, ~2 minutes):

  1. console.cloud.google.com → create or pick a project → APIs & Services → Credentials.
  2. Create Credentials → OAuth client ID → Application type Web application.
  3. Under Authorized JavaScript origins, add the origin(s) you'll serve /auth/login from — e.g. http://127.0.0.1:8787 for local use, plus your real domain once deployed. No redirect URI needed for this flow.
  4. Copy the Client ID (safe to expose client-side — it's not a secret) and set it as GOOGLE_OAUTH_CLIENT_ID in your environment before starting the server.

Known limitation: every valid token — owner or per-user — currently sees all session history, not just its own; there's no per-user data ownership in metrics/store.py yet. This auth model answers "can you connect at all," not "whose data can you see." Revoke a friend's access with mcp_server.auth_store.revoke(google_sub) (find their sub via list_users()) if you need to cut someone off.

Storage backends

STORAGE_BACKEND=sqlite (default, local dev — data/metrics.db) or STORAGE_BACKEND=dynamodb (set METRICS_TABLE/AWS_REGION) — same function signatures either way, callers never know which is active.

The 7 MCP tools

get_session_metrics, get_token_breakdown, get_tool_metrics, get_agent_trace, get_cost_estimate, get_recent_sessions, get_context_timeline. Plain REST equivalents are also exposed under /api/* — a curl-friendly debugging alternative, calling the same underlying metrics/store.py functions.

Related repos

sre-investigation-agent — the reference chat UI + Bedrock agent this package was extracted from and is developed alongside.

推荐服务器

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

官方
精选