goal-engine

goal-engine

Provides persistent goal-tracking with external evaluation for agentic CLIs, enabling run-until-done loops where an agent works across turns until a condition is met.

Category
访问服务器

README

goal-engine

Run-until-done /goal loops for every major agentic CLI — Claude Code, Codex CLI, OpenCode, Cursor, and any MCP-compatible agent.

You state a completion condition ("all tests pass", "the PR is ready"); the agent keeps working across turns until an external evaluator confirms the condition is verifiably met — or until a loop guard or turn budget stops a runaway session.

Architecture: three composable layers

┌─────────────────────────────────────────────────────────┐
│  Layer 3 — npm package + installer CLI                  │
│  npx -y goal-engine · goal-engine install --all         │
├─────────────────────────────────────────────────────────┤
│  Layer 2 — MCP server (goal-engine)                     │
│  set_goal / check_goal / get_status / clear_goal        │
│  Evaluator via MCP sampling (no external API key)       │
│  SQLite state · loop guard · turn budget                │
├─────────────────────────────────────────────────────────┤
│  Layer 1 — portable SKILL.md                            │
│  Works standalone on any Agent Skills runtime           │
└─────────────────────────────────────────────────────────┘

Each layer works on its own. The skill alone gives you self-checked goal loops anywhere; adding the MCP server upgrades the self-check to an independent evaluator with persistent state.

Why an external evaluator?

A skill-only goal loop asks the model to grade its own work inside the same context window — a confused agent can convince itself the goal is met. The MCP spec's sampling primitive lets this server request a completion from the connected client's own model in a fresh context, with a strict evaluation prompt. No API key, no extra provider, CLI-agnostic.

Evaluator fallback chain (strongest available wins):

  1. MCP sampling — the client's model judges the transcript (zero config)
  2. Anthropic API — set ANTHROPIC_API_KEY (model: claude-opus-4-8, override with GOAL_ENGINE_EVAL_MODEL)
  3. OpenAI API — set OPENAI_API_KEY (model: gpt-4o, override with GOAL_ENGINE_OPENAI_MODEL)
  4. Self-check — the tool returns strict self-verification instructions and never auto-completes

A flaky evaluator can never end a goal early: every evaluator failure resolves to done: false.

Install

# Install the /goal skill into every detected agent CLI
npx -y goal-engine install --all

# Or a specific one
npx -y goal-engine install --to claude-code   # also: codex, opencode, cursor

Then connect the MCP server:

Claude Code

claude mcp add goal-engine -- npx -y goal-engine

Codex CLI (~/.codex/config.toml)

[mcp_servers.goal-engine]
command = "npx"
args = ["-y", "goal-engine"]

OpenCode (~/.config/opencode/config.json)

{ "mcp": { "goal-engine": { "type": "local", "command": ["npx", "-y", "goal-engine"] } } }

Bun users can substitute bunx goal-engine everywhere — the server auto-selects bun:sqlite, node:sqlite, or a JSON file for state.

Usage

/goal all unit tests pass and lint is clean

The agent then:

  1. calls set_goal with the condition verbatim,
  2. works toward it with all available tools,
  3. calls check_goal at the end of every turn with a concrete work summary,
  4. treats each done: false reason as its next instruction,
  5. stops only on done: true (or escalates on loop_detected / budget_exhausted).

MCP tools

Tool Input Output
set_goal goal, session_id?, max_turns? (default 40) session_id, goal, max_turns, created_at
check_goal session_id, summary done, reason?, evaluator, turns_used, max_turns
get_status session_id? (defaults to latest active) goal, status, turns_used, elapsed_ms, last_check
clear_goal session_id, completed? cleared, final_status

Safety rails built into check_goal:

  • Loop guard — 3 identical consecutive summaries return loop_detected and tell the agent to change approach or ask the user.
  • Turn budgetmax_turns (default 40, max 500) returns budget_exhausted with a partial-progress instruction.
  • Strict parsing — unparseable evaluator verdicts resolve to done: false.

Optional: Claude Code Stop hook

The MCP-tool flow relies on the agent calling check_goal. The Stop hook closes the gap: it fires whenever Claude tries to stop, and blocks the stop while a goal is active and unmet.

mkdir -p ~/.goal-engine
cp hooks/stop-goal-evaluator.sh ~/.goal-engine/
chmod +x ~/.goal-engine/stop-goal-evaluator.sh

~/.claude/settings.json:

{
  "hooks": {
    "Stop": [{ "hooks": [{ "type": "command", "command": "~/.goal-engine/stop-goal-evaluator.sh" }] }]
  }
}

Notes:

  • The hook honors stop_hook_active (no infinite recursion) and lets the agent stop once the turn budget is exhausted.
  • Claude Code caps consecutive Stop-hook blocks at 8 by default; set CLAUDE_CODE_STOP_HOOK_BLOCK_CAP=40 to match the default turn budget.
  • With ANTHROPIC_API_KEY set, the hook evaluates the transcript's last assistant message; without it, the block reason instructs the agent to self-verify and finish via clear_goal completed=true.

Environment

Variable Default Purpose
GOAL_ENGINE_DB ~/.goal-engine/goal-engine.sqlite State file path
GOAL_ENGINE_HOME ~/.goal-engine Data directory
ANTHROPIC_API_KEY Evaluator fallback when MCP sampling is unavailable
GOAL_ENGINE_EVAL_MODEL claude-opus-4-8 Anthropic evaluator model
OPENAI_API_KEY Second evaluator fallback
GOAL_ENGINE_OPENAI_MODEL gpt-4o OpenAI evaluator model

Development

bun install
bun run typecheck   # tsc --noEmit
bun test            # unit + MCP integration tests (in-memory transport)
bun run build       # tsc → dist/
bun run smoke       # drives dist/index.js over stdio with raw JSON-RPC

Project layout:

SKILL.md                     Layer 1 — portable Agent Skill
src/index.ts                 CLI entry: serve (default) | install | check-hook
src/server.ts                MCP server: the four goal tools + sampling wiring
src/evaluator.ts             Evaluator chain: sampling → Anthropic → OpenAI → self-check
src/db.ts                    State: bun:sqlite | node:sqlite | JSON fallback
src/loop-guard.ts            Identical-turn loop detection
src/hook.ts                  Claude Code Stop hook logic
src/installer.ts             Cross-CLI skill installer
hooks/stop-goal-evaluator.sh Stop hook wrapper script
agents/openai.yaml           Codex plugin metadata

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

官方
精选