contextpulse-mcp

contextpulse-mcp

Real-time context budget tracking for AI coding agents with token counting, loop detection, and alerts, backed by PostgreSQL.

Category
Visit Server

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured