Skip to main content
Glama

Neurouter

Turn an OpenAPI or GraphQL API into a governed MCP server that AI agents can actually use:

  • Compiler: OpenAPI 3.0/3.1 and GraphQL (SDL or introspection) → a curated tool model, with overlays (rename, describe, hide, shape responses, composites) that survive spec re-imports.

  • Data plane: one stateless MCP endpoint per server and environment (/mcp/{server}/{env}, protocol 2026-07-28 plus the 2025-11-25 path), read-only by default, prod writes confirmed by the user through MCP elicitation, policies, rate limits, kill switches, hash-chained audit log.

  • Code mode: run_script runs short Python scripts (Pydantic Monty, sandboxed in a separate executor process) that call the API tools as functions, with dry runs and planned changes.

  • Ops tools: neurouter_begin_task, end_task, report_unmet_need, report_issue, explain_error, … so agents frame their work and tell you what the API is missing.

  • Evals: generated agent tasks run in tool and code mode, an agent-readiness score (0–100) and fix suggestions as overlay patches (npx neurouter eval, GitHub Action).

Apache-2.0. © Neurouter contributors.

Quickstart

npm install
npx tsx --conditions=@neurouter/source packages/cli/src/main.ts serve --config neurouter.example.yaml
# published package: npx neurouter serve --config neurouter.example.yaml

The example loads the Swagger Petstore against the in-process mock:

TOKEN=$(npx tsx --conditions=@neurouter/source packages/cli/src/main.ts keys create --server petstore --env dev --scopes tools:read,code:run)
claude mcp add --transport http petstore http://localhost:3000/mcp/petstore/dev --header "Authorization: Bearer $TOKEN"

Evals without an API key (deterministic stub provider, not a real model):

NEUROUTER_EVAL_LLM=stub npx tsx --conditions=@neurouter/source packages/cli/src/main.ts eval \
  --spec examples/petstore/openapi.yaml --generate --repeats 1 --md report.md

With OPENAI_API_KEY set, the same command uses the default model gpt-6-luna (BYOK). Evals also run on Anthropic (ANTHROPIC_API_KEY, claude-* models) and Gemini (GEMINI_API_KEY, gemini-* models): pass --models gpt-6-luna,claude-sonnet-5-5,gemini-3.5-flash-lite to compare them; each model goes to its provider (provider:model forces one). Keys can also be stored, encrypted, in the console (Settings › Models).

Token figures in eval reports are comparable across providers: tokens of an attempt = uncached input + cached input + output (reasoning included), summed over its turns; "tokens per multi-step task" is the mean of that over the multi-step attempts. Cached input (OpenAI cached_tokens, Anthropic cache_read_input_tokens, Gemini total_cached_tokens) is also reported on its own, and Anthropic cache writes are counted as input. --transcripts <file> writes every attempt untrimmed (--transcript-max-chars to cap each item).

Checks are outcome-based (0.2.2): expected values are computed at run time by running each task's reference calls on the same mock data, only the arguments the prompt asks for are checked, answers are compared by meaning (booleans, numbers, minor units, dates, ids), and call budgets are soft (over budget is reported as efficiency, not failure). A suite is accepted only when every task's reference solution passes its own checks (calibration; --calibrate-with <model> adds a model pass that flags disagreements for review). --max-run-tokens caps a run's spend (agent, judge and fix-suggestion tokens): every attempt in flight reserves its per-attempt token limit, so attempts running at once (--concurrency, default 4) cannot overshoot it. Per-attempt limits (turns, tool calls, tokens including cached input, wall time, enforced during calls) can be overridden per suite or per task (limits). Exact values (numbers, amounts, ids) are never passed by the equivalence judge. Details, score definitions and the 0.2.1 suite converter (--migrate-suite) and offline re-grade (--regrade): packages/evals/README.md.

Related MCP server: production-mcp-server

Agent contract

Tool results follow one of two contracts, chosen per session:

  • Contract 2 (default for servers created from this release on): every tools/call result is one envelope, {"ok","data","page","truncated","error","state"} (plus an optional hint), as the only text item and as structuredContent. data is the API's payload unchanged; page says count/total/has_more on list tools, with next_cursor: pass it as cursor to the same tool with the same other arguments for the next page, whatever the upstream's paging style (cursor tokens, page/per_page, offset/limit, starting_after, Link headers) and for the rest of a list Neurouter cut. Cursors are signed, bound to the tool, the query arguments (not fields) and the credential, and last 1 hour; a cursor sent with other arguments answers with the call that continues it. Every tool takes fields (dot paths, per item on lists; the overlay include is the default set) and list tools take limit (the upstream page size); names the upstream already uses get an nr_ prefix. truncated names the object fields Neurouter clipped and the fields call that returns them; error has a code, a short message, every invalid field with its allowed values, retry and next (the exact call to make next); state carries the environment, write mode, task and call counter (and identical-result streaks). Unknown tools answer with an envelope (unknown_tool + closest names), not a JSON-RPC error. In run_script, tool functions return plain data; ns.list_x.page(…) returns a Result (.data, .items, .page, .next(), .pages()) and ns.list_x.pages(…, max_items=500) the items of every page (ops.pages(fn="ns.list_x", …) is a deprecated alias). Tool errors raise typed exceptions: NotFound (a LookupError), InvalidArgs (ValueError), Forbidden, WritesDisabled and ConfirmationRequired (PermissionError), Timeout (TimeoutError), RateLimited and UpstreamError (RuntimeError); catch them by name, by base or as ToolError. str(e) is short (code, message, next call) and ops.error(e) returns the structured error (code, message, retry, next, fields, plan). print() output comes back as logs (up to 2,000 characters); a return value over 8,192 characters (limits.code.resultChars) is cut with truncated (truncated.next reads the rest) and a hint to return less; the cut data always fits. Inside a script, a call that hits the gateway rate limit waits for a token instead of failing (contracts 1 and 2). Each wait is bounded by the script's remaining wall time and by limits.code.rateLimitWaitSec (default 30 s; 0 fails at once). Only a wait that cannot fit raises RateLimited with retry_after_ms. The waits appear in the run's stats (rateLimitWaits, rateLimitWaitMs). One tool result inside a script may be up to 16 MiB (results over the executor's 2 MiB frame go in parts); over that, the call raises response_too_large. A search_tools result over 8,192 characters (limits.searchResultChars) keeps the full detail (doc, schema, example) for the top 3 hits only, then drops the last hits; truncated says what was cut and truncated.next is search_tools for one tool by name with its full detail. There is no task framing: Neurouter infers tasks per credential, client and MCP session (10-minute idle gap), counts state.call/streak in the task row (the same on every instance), and shows state.left when a rate limit is down to 20%. One ops tool is listed, neurouter_report(kind: done|blocked|unmet_need|tool_problem| decision, text); the v1 names still answer. Write tools take dry_run: true (the plan: target, effect, reversible). Outside prod a destructive call first answers confirmation_required with the plan and the same call carrying confirm: "ct_…" (5 minutes, single use, bound to the arguments and the credential); scripts with destructive calls do the same per plan. In prod your user approves through elicitation; tokens are not accepted.

  • Contract 1: the 0.2.x shapes. Servers created before contract 2 keep it until switched.

A client picks a version with the capability experimental["dev.neurouter/contract"] = {"versions":[2,1]} or the header X-Neurouter-Contract: 2; otherwise exposure.contract (server, or per environment in neurouter.yaml) decides. NEUROUTER_NEW_SERVER_CONTRACT (default 2) sets the contract of new servers. exposure.outputSchema is envelope (default: the shared envelope schema with an open data), none, or typed (the shaped upstream schema as data, validated before sending; a tool whose response does not match is re-listed without it and reported in the inbox).

Rate limits

  • Gateway limits. Neurouter limits calls per credential (limits.rateLimit) and per credential and tool (limits.toolRateLimit). When an environment sets neither, the defaults are 600/min (burst 120) per credential and 300/min (burst 60) per credential and tool. These are the shared DEFAULT_LIMITS; the limiter applies them and the console shows them (one source of truth since 0.3.5). An API key's own rate limit replaces the per-credential one.

  • Mock environment. The built-in mock (baseUrl: "mock:") has no gateway rate limit unless its limits or the API key set one (0.3.3).

  • Scripts. Inside run_script, inner calls wait for a token (see above).

  • Upstream backoff. A read that gets 429 or 503 from the upstream is retried when the response says when to come back: Retry-After, or X-RateLimit-Remaining: 0 with X-RateLimit-Reset. It is retried at most twice, each wait is at most 10 s, and inside a script no wait runs past its wall time. Writes are never retried: they return rate_limited with retry_after_ms.

  • Upstream concurrency. limits.upstreamConcurrency caps an environment's in-flight upstream calls (default: no cap).

Development

Command

What

npm run dev

server (tsx watch, embedded executor) + console dev server

npm test

Vitest (unit + in-process integration tests); NEUROUTER_TEST_PG_URL=postgres://… adds Postgres runs

npm run typecheck / npm run lint

TypeScript project build + test configs; ESLint incl. the data/control plane boundary

npm run keys -- gen

crypto values for .env

Layout: packages/shared (REST contract the console imports), packages/compiler, packages/evals, apps/executor (Monty pool behind a socket frame protocol), apps/server (kernel/, dataplane/, controlplane/), apps/web (console), packages/cli (npm neurouter).

Local dev uses SQLite (no Docker). Production uses Postgres with pgvector.

Deploy

  • Docker: docker build -t neurouter-core . then docker run -p 3000:3000 --env-file .env -e NEUROUTER_CONFIG=/app/neurouter.example.yaml neurouter-core.

  • Docker image: ghcr.io/neurouter/core:<version>.

  • Kubernetes: the neurouter-core chart, helm install neurouter oci://ghcr.io/neurouter/charts/neurouter-core --version <version> -f values.yaml (source in deploy/helm/neurouter-core; executor as a sidecar, or a separate Deployment with a deny-all egress NetworkPolicy, recommended for production). Model provider keys: openai.existingSecret, anthropic.existingSecret, gemini.existingSecret.

  • Cloud Run demo: deploy/cloudrun/setup.sh and deploy/cloudrun/deploy.sh (reviewed and run by a human).

See SECURITY.md for the code-mode threat model.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to safely call enterprise tools through a governed MCP gateway with permission enforcement, blast-radius controls, input validation, and a full audit trail for every invocation.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Turns existing REST/OpenAPI APIs into governed MCP tools for AI agents without modifying the APIs themselves, generating agent-friendly tools from specs, Postman collections, HAR files or cURL commands. Owners enable tools and set policies, while every call injects upstream credentials, redacts PII, projects responses to fit context limits, and produces a full audit trail.
      5
      Apache 2.0
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to connect to tools and data through a governed MCP endpoint with agent identity, scoped permissions, guardrails, and full audit trails. Access is user-controlled and can be revoked instantly, with every tool call logged by agent identity and timestamp.
      MIT