Heroku Code MCP

Heroku Code MCP

A token-efficient MCP server for the Heroku Platform API that uses a search-and-execute pattern to minimize context window overhead. It enables secure app management through just-in-time endpoint discovery and built-in safety guardrails for API mutations.

Category
访问服务器

README

Heroku Code MCP

A token-efficient MCP server for the Heroku Platform API using a Code Mode pattern: search + execute + auth_status.

Design references:

Context Comparison

Approach Tool surface Approx context cost at tool-list time Fits in a 200k-token context window?
official Heroku MCP 37 endpoint-oriented tools ~6,375 tokens Yes, but consumes meaningful budget up front
heroku-code-mcp (this repo) 3 control tools (search, execute, auth_status) ~368 tokens Yes, with minimal up-front overhead

The practical impact is that the agent starts with a much smaller tool schema, then asks the server for just-in-time endpoint discovery. This keeps prompt budget available for user intent, planning, and response quality instead of spending it on static endpoint metadata.

The Problem

Heroku’s API surface is broad, and an endpoint-per-tool MCP model makes the agent choose between many tools before it has enough task context. That usually increases tool-selection ambiguity, consumes tokens early, and makes multi-step tasks more brittle. The issue is not that many tools are inherently bad, but that model context is scarce and endpoint selection is an agent planning problem, not just a transport problem.

The Approach

This server applies a Code Mode-style control loop with deterministic inputs:

  1. search maps natural language intent to ranked operation_id candidates.
  2. execute validates and performs the selected Heroku API operation.
  3. auth_status provides explicit auth state so agents can branch cleanly.

The server holds schema intelligence and safety policy centrally. The agent gets a small control surface and a stable execution contract.

Tools

Tool What it does Why it exists
search Ranks Heroku operations from schema + docs context Reduces endpoint selection ambiguity
execute Validates params/body and executes by operation_id Gives one deterministic execution path
auth_status Returns {authenticated, scopes, expires_at} Supports explicit auth-aware planning
Agent                           MCP Server
  │                                  │
  ├──search({query: "list apps"})──►│ rank operations from catalog/index
  │◄──[GET /apps, ...]───────────────│
  │                                  │
  ├──execute({operation_id: ...})───►│ validate + call Heroku API
  │◄──{status, headers, body}────────│

Benchmark Highlights

Benchmarks were captured on February 22, 2026 on the same machine and account for both implementations. The numbers below compare this repo’s local HTTP MCP endpoint against the official Heroku MCP server over stdio.

Raw Comparison

Metric heroku-code-mcp official Heroku MCP Delta
Tool count 3 37 91.9% lower
Tool-list payload bytes 1,469 25,500 94.2% lower
Tool-list approx tokens 368 6,375 94.2% lower
Connect avg 14.8 ms 10,168.7 ms 687x faster
list_tools avg 4.3 ms 10.3 ms 2.4x faster
Read op avg 528.0 ms (execute GET /apps) 9,697.4 ms (list_apps) 18.4x faster

Comparison Graphs

These are static charts so labels stay readable in GitHub without giant auto-scaled Mermaid panels.

Context reduction chart

Latency comparison chart

How to Read These Results

The strongest win is context footprint. A 3-tool interface materially lowers initial prompt overhead and reduces tool-choice branching for the model. The second win is connection and read-path latency under this benchmark harness. In measured runs, the official Heroku MCP paid a much larger connect-time cost, and its measured read operation was substantially slower than execute GET /apps on this server.

This does not mean every endpoint in every environment will always have the same multiplier. It means the measured default experience in this setup favored the Code Mode control surface for both context economy and latency.

Benchmark Methodology

  • Date: February 22, 2026.
  • Environment: same local machine, same Heroku account, warm network.
  • Custom server run count: 10.
  • Official server run count: 3.
  • Context estimate: ceil(list_tools_json_bytes / 4) for rough token approximation.
  • Read comparison pairing:
    • Custom: execute GET /apps
    • Official: list_apps

Artifacts:

  • benchmarks/results/context-footprint-2026-02-22.json
  • benchmarks/results/custom-local-http-2026-02-22.json
  • benchmarks/results/official-heroku-mcp-start-2026-02-22.json
  • BENCHMARKS.md

Get Started

MCP URL: http://127.0.0.1:3000/mcp

cd heroku
npm install
npm run build
npm test

Option 1: OAuth (Recommended)

Configure OAuth env vars and use /oauth/start + /oauth/callback.

Option 2: Local token seeding from Heroku CLI

heroku auth:whoami
npm run seed:token

Start server:

TOKEN_STORE_PATH=./data/tokens.integration.json \
TOKEN_ENCRYPTION_KEY_BASE64='<seed-output-key>' \
PORT=3000 HOST=127.0.0.1 npm run dev

Smoke test:

curl -sS http://127.0.0.1:3000/healthz
MCP_URL=http://127.0.0.1:3000/mcp USER_ID=default npm run smoke:mcp

Add to an Agent

Direct streamable HTTP

{
  "mcpServers": {
    "heroku-code-mcp": {
      "transport": "streamable_http",
      "url": "http://127.0.0.1:3000/mcp",
      "headers": {
        "x-user-id": "default"
      }
    }
  }
}

Command bridge (if needed)

{
  "mcpServers": {
    "heroku-code-mcp": {
      "command": "npx",
      "args": ["mcp-remote", "http://127.0.0.1:3000/mcp"],
      "env": {
        "MCP_REMOTE_HEADERS": "{\"x-user-id\":\"default\"}"
      }
    }
  }
}

Typical Workflow

  1. Call auth_status.
  2. Call search with intent.
  3. Choose one operation_id.
  4. Call execute with path_params, query_params, and body as needed.
  5. For writes, run dry_run=true first, then replay with confirm_write_token and ALLOW_WRITES=true.

Example search:

{
  "query": "list apps",
  "limit": 5
}

Example read execute:

{
  "operation_id": "GET /apps"
}

Example write dry-run:

{
  "operation_id": "PATCH /apps/{app_identity}",
  "path_params": {
    "app_identity": "my-app"
  },
  "body": {
    "maintenance": true
  },
  "dry_run": true
}

Safety and Guardrails

  • Mutations (POST, PATCH, PUT, DELETE) are blocked by default.
  • Mutations require both ALLOW_WRITES=true and a matching confirm_write_token.
  • Sensitive headers and body fields are redacted.
  • Idempotent retries (GET / HEAD) are enabled for transient failures.

Performance Design

  • 3-tool MCP surface minimizes up-front tool context.
  • Persistent catalog cache (CATALOG_CACHE_PATH) avoids cold-start re-ingestion.
  • Background refresh decouples ingestion from request path.
  • Conditional fetches (ETag/Last-Modified) reduce refresh cost.
  • Short read cache (READ_CACHE_TTL_MS) improves repeated read latency.
  • Output bounds (EXECUTE_MAX_BODY_BYTES, EXECUTE_BODY_PREVIEW_CHARS) prevent oversized responses from dominating context.

Configuration

Key env vars:

  • ALLOW_WRITES
  • REQUEST_TIMEOUT_MS
  • MAX_RETRIES
  • CATALOG_CACHE_PATH
  • READ_CACHE_TTL_MS
  • EXECUTE_MAX_BODY_BYTES
  • EXECUTE_BODY_PREVIEW_CHARS

Full example: .env.example

Repository Layout

  • src/schema/*: ingestion + operation normalization + cache
  • src/search/*: search index + ranking
  • src/execute/*: validation + Heroku API execution
  • src/auth/*: OAuth + encrypted token storage
  • tests/*: catalog/search/execute tests
  • benchmarks/results/*: benchmark artifacts
  • BENCHMARKS.md: benchmark methodology details
  • REFERENCES.md: external references

Troubleshooting

  • MCP Inspector connection error: confirm URL is http://127.0.0.1:3000/mcp and server is running.
  • AUTH_REQUIRED: seed token or complete OAuth flow.
  • Write blocked: set ALLOW_WRITES=true and send matching confirm_write_token.
  • Large response body: narrow query scope or lower output caps for stricter truncation.

推荐服务器

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

官方
精选