contextpulse-mcp
Real-time context budget tracking for AI coding agents with token counting, loop detection, and alerts, backed by PostgreSQL.
README
contextpulse-mcp
Real-time context budget tracking for any AI coding agent.
Plug into Claude Code, Cursor, or any MCP-compatible tool and get:
- 📊 Live token budget bar per agent run
- 🔁 Loop detection (when an agent calls the same tool 3× in a row)
- ⚠️ Warning / critical alerts before context overflow
- 🗄️ Full run history stored in PostgreSQL
- 📈 Budget timeline for every run
No cloud. No telemetry. Runs entirely on your machine.
How it works
ContextPulse is a transparent MCP server. You call its tracking tools from
your agent's workflow. It counts tokens using tiktoken, updates a live budget
in memory, persists everything to PostgreSQL, and fires alerts when thresholds
are crossed.
Your agent → calls cp_track_tool_call → ContextPulse counts tokens
→ updates live budget
→ warns at 70% / 90%
→ detects loops
→ saves to DB
Quick start
1. Start PostgreSQL
# macOS with Homebrew
brew services start postgresql@16
# or via Docker
docker run -d --name contextpulse-db \
-e POSTGRES_DB=contextpulse \
-p 5432:5432 postgres:16
2. Add to Claude Code (~/.claude/settings.json)
{
"mcpServers": {
"contextpulse": {
"command": "npx",
"args": ["-y", "contextpulse-mcp"],
"env": {
"DATABASE_URL": "postgresql://apple@localhost:5432/contextpulse"
}
}
}
}
3. Add to Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"contextpulse": {
"command": "npx",
"args": ["-y", "contextpulse-mcp"],
"env": {
"DATABASE_URL": "postgresql://localhost:5432/contextpulse"
}
}
}
}
The DB schema is created automatically on first run.
Usage in your agent
1. cp_start_session → get sessionId
2. cp_start_run → get runId
3. cp_track_tool_call → after every tool call (pass tool name, args, output)
4. cp_get_budget → check current budget at any time
5. cp_get_run_summary → full run summary with timeline
6. cp_end_run → clean up
Example response from cp_track_tool_call
{
"toolCallId": "a1b2c3...",
"inputTokens": 142,
"outputTokens": 87,
"totalTokens": 229,
"budget": {
"used": 14820,
"limit": 200000,
"percentUsed": 7.41
},
"budgetStatus": "ok",
"alert": null
}
When budget hits 70%:
{
"budgetStatus": "warning",
"alert": "warning"
}
Environment variables
| Variable | Default | Description |
|---|---|---|
DATABASE_URL |
postgresql://apple@localhost:5432/contextpulse |
PostgreSQL connection string |
CONTEXT_LIMIT |
200000 |
Token limit per session |
WARNING_THRESHOLD_PCT |
70 |
Warning alert threshold (%) |
CRITICAL_THRESHOLD_PCT |
90 |
Critical alert threshold (%) |
LOOP_DETECTION_THRESHOLD |
3 |
Same tool calls before loop alert |
MODEL |
claude-sonnet-4-6 |
Model label for records |
What gets stored
cp_sessions -- one row per coding session
cp_runs -- one row per agent task
cp_tool_calls -- every intercepted tool call
cp_budget_snapshots -- token usage timeline per run
cp_alerts -- warnings, criticals, loop detections
Roadmap
- [ ] Phase 2: Next.js real-time dashboard with WebSocket stream
- [ ] Phase 3: Loop detection graph + BullMQ alert jobs
- [ ] Phase 4: Run diff engine — compare two agent runs side by side
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。