pi-auto

pi-auto

Provides usage data from @ccusage/pi and tools to switch between AI providers (e.g., Claude Code, OpenAI Codex, CursorAI) using load-balancing or high-availability strategies.

Category
访问服务器

README

pi-auto

<div align="center"> <img src="logo.png" alt="Pi Cursor Provider" width="400" /> </div>

Node TypeScript MCP License

pi-auto is a Pi package that provides the pi-auto MCP server and a Skill for pi-coding-agent: usage data from @ccusage/pi and tools to switch the active provider by strategy — load-balancing (equalize usage across backends) or high-availability (fixed priority order).


Prerequisites

Install the following (globally) before using pi-auto:

Dependency Description
Pi Coding Agent Pi CLI and coding agent (required for pi and extensions).
@ccusage/pi Pi-agent usage tracking; used by the MCP server for usage data.
Alias ccusage Shortcut to run @ccusage/pi (see bash below).
pi-mcp-adapter MCP adapter for Pi (required to run MCP servers).
@netandreus/pi-cursor-provider Cursor provider for Pi (optional; for CursorAI backend in usage/strategy).

Example: install all globally and set the ccusage alias

# 1. Pi Coding Agent
npm install -g @mariozechner/pi-coding-agent

# 2. Usage tracking (for pi-auto)
npm install -g @ccusage/pi

# 3. Alias for ccusage (pick one: bash or zsh)
echo "alias ccusage='npx @ccusage/pi@latest'" >> ~/.bashrc
# echo "alias ccusage='npx @ccusage/pi@latest'" >> ~/.zshrc

# 4. Pi MCP adapter (run after Pi is installed)
pi install npm:pi-mcp-adapter

# 5. Cursor provider for Pi (optional)
pi install npm:@netandreus/pi-cursor-provider

Then reload your shell (e.g. source ~/.bashrc or source ~/.zshrc) so ccusage is available.


Install (Pi)

Prerequisite: Install the MCP adapter in Pi so it can run MCP servers:

pi install npm:pi-mcp-adapter

Install the pi-auto package (Skill is loaded automatically):

pi install npm:@netandreus/pi-auto

Or from git:

pi install git:github.com/netandreus/pi-auto

MCP config: Add the MCP server to pi’s config so the agent can call the tools.

~/.pi/agent/mcp.json (or your pi MCP config path):

If you installed via pi install npm:@netandreus/pi-auto, pi uses global npm; point to the installed package. Using the binary name (after a global npm install of the package):

{
  "mcpServers": {
      "pi-auto": {
        "command": "pi-auto-mcp",
        "lifecycle": "keep-alive",
        "directTools": true
      }
  }
}

Or with explicit path (replace GLOBAL_NPM_ROOT with the output of npm root -g):

{
  "mcpServers": {
      "pi-auto": {
        "command": "node",
        "args": ["GLOBAL_NPM_ROOT/@netandreus/pi-auto/dist/index.js"],
        "lifecycle": "keep-alive",
        "directTools": true
      }
  }
}

Exposed tools: mcp_pi-auto_pi_get_usage, mcp_pi-auto_pi_suggest_provider, mcp_pi-auto_pi_set_provider, mcp_pi-auto_pi_get_provider, mcp_pi-auto_pi_get_strategy, mcp_pi-auto_pi_set_strategy, mcp_pi-auto_pi_get_priority, mcp_pi-auto_pi_set_priority.

Skill: The Skill is loaded automatically when the package is installed. Invoke with /skill:pi-auto or ask about usage, balancing cost, or switching provider.


MCP in Cursor Agent

To use the pi-auto MCP server from Cursor Agent (not only from Pi), connect the server, enable it, and allow its tools.

1. Connect MCP server to agent

Add the pi-auto MCP server to Cursor’s MCP config (e.g. ~/.cursor/mcp.json):

{
  "mcpServers": {
    "pi-auto": {
      "command": "pi-auto-mcp",
      "lifecycle": "keep-alive",
      "directTools": true
    }
  }
}

2. Enable the MCP server

The server may appear as “not loaded (needs approval)”. Enable and approve it:

agent mcp list
# pi-auto: not loaded (needs approval)

agent mcp enable pi-auto
# ✓ Enabled and approved MCP server: pi-auto

Check that tools are available:

agent mcp list-tools pi-auto
# Tools for pi-auto (8):
# - pi_get_priority ()
# - pi_get_provider (scope, projectPath)
# - pi_get_strategy ()
# - pi_get_usage (period)
# - pi_set_priority (priority)
# - pi_set_provider (provider, model, scope, projectPath)
# - pi_set_strategy (strategy)
# - pi_suggest_provider (period)

3. Allow tools from this MCP

Ensure Cursor Agent is allowed to call pi-auto MCP tools. In ~/.cursor/cli-config.json, under permissions.allow, include:

"permissions": {
  "allow": [
    "Shell(ls)",
    "Mcp(pi-auto:*)"
  ],
  "deny": []
}

Features

Tool Description
pi_get_usage Current usage (tokens/cost) per backend (Claude Code, OpenAI Codex, CursorAI) for a given period (e.g. daily).
pi_suggest_provider Recommends provider and model based on current strategy and priority.
pi_set_provider Writes pi’s defaultProvider and defaultModel (global or project scope).
pi_get_provider Reads current pi default provider and model.
pi_get_strategy / pi_set_strategy Get or set strategy: load-balancing or high-availability.
pi_get_priority / pi_set_priority Get or set the HA priority order (e.g. ["codex", "claude-code", "cursorai"]).

Configuration

Requirements: Node 18+, and (for usage data) @ccusage/pi available via npx.

Environment

Variable Description
PI_AGENT_DIR Override pi-agent sessions directory (used when calling @ccusage/pi; default: ~/.pi/agent/sessions).
CCUSAGE_MCP_SETTINGS_PATH Override path to pi’s global settings file (default: ~/.pi/agent/settings.json).

Server config

Strategy and priority are stored in ~/.pi/agent/pi-auto.json.

Example:

{
  "strategy": "load-balancing",
  "priority": ["codex", "claude-code", "cursorai"],
  "defaultModels": {
    "claude-code": { "provider": "anthropic", "model": "claude-sonnet-4-20250514" },
    "codex": { "provider": "openai", "model": "gpt-4o" },
    "cursorai": { "provider": "cursor", "model": "auto" }
  }
}
Field Description
strategy "load-balancing" (default) or "high-availability".
priority Ordered list of backend ids for HA; first is preferred. Valid ids: claude-code, codex, cursorai.
defaultModels Optional overrides for provider/model per backend (must match your installed pi providers).

Usage strategies

  • Load-balancingpi_suggest_provider picks the backend with the lowest current usage (total tokens). Use pi_get_usage to see per-backend totals; then call pi_suggest_provider and optionally pi_set_provider to switch.
  • High-availabilitypi_suggest_provider returns the first backend in priority (and its default model). Use pi_set_priority to change the order (e.g. prefer Codex, then Claude, then CursorAI).

When you need to balance cost or ensure a preferred provider, use the pi-auto tools: get/set strategy and priority, get current provider, get usage, suggest a provider, and set it with pi_set_provider.


Backend mapping

Usage from @ccusage/pi (with --json --breakdown) is mapped to three backends:

Backend Source
Claude Code anthropic / claude-* models
OpenAI Codex openai / gpt-* models
CursorAI cursor (e.g. @netandreus/pi-cursor-provider)

You can override mapping and default models in ~/.pi/agent/pi-auto.json if your setup differs.


Publishing (npm)

To publish to npmjs.com:

  1. Log in: npm login (use an account with access to the @netandreus scope).
  2. Bump version in package.json (e.g. 0.1.00.1.1).
  3. Build and publish:
    npm publish
    (runs prepublishOnlyyarn build, then publishes; scoped package is published as public via publishConfig.access.)

To see what will be included: npm pack --dry-run.


License

MIT

推荐服务器

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

官方
精选