Chapter 10

MCP Server & Tools

19 MCP tools, REST API, WebSocket hub, telemetry, and cost tracking — the integration layer.

Architecture

A single Node.js process runs three subsystems — the nervous system that lets all your tools talk to each other:

MCP (stdio)

19 tools exposed via Model Context Protocol. Copilot, Claude, Cursor call these as function calls.

Express (HTTP :3100)

Dashboard UI, REST API, static files. 12+ endpoints for programmatic access.

WebSocket (:3101)

Real-time events. Dashboard subscribes for live slice progress.

Starting the Server

Terminal
# Install dependencies (first time only)
cd pforge-mcp && npm install && cd ..

# Full server: MCP + HTTP + WebSocket
node pforge-mcp/server.mjs

# Dashboard only (no MCP stdio)
node pforge-mcp/server.mjs --dashboard-only

# Custom project path
node pforge-mcp/server.mjs --project /path/to/project

With .vscode/mcp.json configured (created by setup), the server auto-starts when Copilot calls any forge tool.

MCP Tools (19)

Every tool is callable from Copilot Chat, Claude Code, Cursor, or any MCP-compatible client:

ToolDescription
forge_smithDiagnose environment, VS Code config, setup health, version currency
forge_validateValidate setup files — check counts match preset, no placeholders
forge_sweepScan for TODO/FIXME/HACK/stub/placeholder markers
forge_statusShow phases from DEPLOYMENT-ROADMAP.md with status
forge_diffCompare changes against plan's Scope Contract — detect drift
forge_analyzeCross-artifact consistency scoring (0–100, 4 dimensions)
forge_diagnoseMulti-model bug investigation — root cause + fix recommendations
forge_run_planExecute hardened plan: spawn workers, validate gates, track tokens. Supports --quorum=power (flagship) and --quorum=speed (fast) presets
forge_abortAbort currently running plan execution
forge_plan_statusGet latest execution status — per-slice results, tokens, duration
forge_cost_reportCost tracking: total spend, per-model breakdown, monthly trend
forge_new_phaseCreate new phase plan file + roadmap entry
forge_ext_searchSearch community extension catalog
forge_ext_infoDetailed info about a specific extension
forge_capabilitiesMachine-readable API surface — tools, intents, config, extensions
forge_run_skillExecute a skill programmatically with step-level tracking
forge_skill_statusGet recent skill execution events from hub
forge_generate_imageGenerate images via Grok Aurora or DALL-E, save with format conversion
forge_org_rulesExport org custom instructions — consolidate instruction files for GitHub org-level Copilot config
Discovery: Call forge_capabilities first — it returns the full API surface including tool schemas, config options, and available extensions.

REST API

All endpoints available at http://localhost:3100:

MethodEndpointDescription
GET/api/statusCurrent run status
GET/api/runsRun history (last 50)
GET/api/configRead .forge.json
POST/api/configWrite .forge.json
GET/api/costCost report (same as forge_cost_report)
POST/api/tool/:nameInvoke any CLI tool via HTTP
GET/api/hubWebSocket hub status + connected clients
GET/api/replay/:run/:sliceSession replay log for a specific slice
GET/api/tracesAll runs from trace index
GET/api/traces/:runIdSingle run trace detail
GET/api/capabilitiesFull capability surface (JSON)
GET/.well-known/plan-forge.jsonDiscovery endpoint

WebSocket Hub

Connect to ws://localhost:3101 for real-time events. The dashboard uses this for live progress updates.

EventWhen
connectedClient connects — includes event history replay
run-startedPlan execution begins
slice-startedSlice begins execution
slice-completedSlice passes all validation gates
slice-failedSlice or gate fails
slice-escalatedSlice escalated to quorum for multi-model consensus
run-completedAll slices finish
run-abortedExecution aborted via forge_abort
skill-startedSkill execution begins
skill-completedSkill finishes all steps
approval-requestedBridge pauses for external approval
bridge-notification-sentWebhook dispatched (Telegram, Slack, Discord)

Telemetry

Every plan execution emits OpenTelemetry (OTLP) traces stored in .forge/runs/<timestamp>/traces.json:

  • Resource context — project name, version, preset, model
  • Span hierarchy — run → slice → gate → escalation
  • Severity levels — INFO for passes, WARN for retries, ERROR for failures
  • Export — traces are OTLP-compatible — send to Jaeger, Grafana Tempo, or any collector

Cost Tracking

The orchestrator tracks tokens and computes cost per slice using a 23-model pricing table:

  • Per-slice — tokens in/out, model, duration, USD cost
  • Per-run — total cost, model breakdown
  • Monthly — aggregated in .forge/cost-history.json
  • Model performance.forge/model-performance.json tracks success rate, avg cost, avg duration per model

The orchestrator auto-selects the cheapest model with >80% historical pass rate. Use --estimate to preview costs before executing.

SDK for Integrators

The pforge-sdk/ package provides a JavaScript/TypeScript API for building integrations:

JavaScript
import { createForgeClient } from 'pforge-sdk';

const forge = createForgeClient({ baseUrl: 'http://localhost:3100' });

// Run smith diagnostics
const health = await forge.smith();

// Get cost report
const cost = await forge.costReport();

// Execute a plan
const run = await forge.runPlan('docs/plans/Phase-1.md', {
  mode: 'estimate'
});

The SDK is currently in scaffold stage (v0.1.0) — API surface defined, implementation in progress.

API Key Configuration

API keys for external providers (xAI Grok, OpenAI) are resolved in order: environment variable → .forge/secrets.json → null.

.forge/secrets.json
{
  "XAI_API_KEY": "xai-...",
  "OPENAI_API_KEY": "sk-..."
}

The .forge/ directory is gitignored by default — secrets never enter version control.

📄 Full reference: capabilities.md, EVENTS.md, tools.json