Unified AI System

セルフホスト型のMCPおよびAIゲートウェイで、粗い自然言語を構造化されたプロンプトに変換し、Codex、Cursor、Cline向けに管理されたルーティングと再現可能な検証を提供します。

ドキュメント

Unified AI System: Self-Hosted AI Gateway & MCP Server

Open-source AI gateway for deterministic prompt enhancement, governed execution, and reproducible verification.

English | zh-CN | Project Site

GitHub stars CI Release Official MCP Registry: active License

Unified AI System — self-hosted AI gateway with 12 governed MCP tools, 900+ tests, 16 blocked attack classes, zero credentials to try

Unified AI System turns a rough request into a structured, reviewable prompt before execution. It gives teams one self-hosted surface for OpenAI-compatible SDKs, MCP, A2A, CLI, and HTTP while keeping provider calls explicit — with the feature set you'd expect from a commercial LLM gateway: virtual keys with token budgets, exact + semantic response caching, reverse MCP governance with REST→MCP generation, and production observability.

Try Before Installing

Unified AI System turns a rough request into a structured coding prompt
The original request stays visible. The local enhancer adds execution requirements, output requirements, and completion criteria.

Open a ready-to-run coding example in the browser Prompt Lab

The link loads a real request and renders the enhanced prompt locally. No account, API key, or provider call is required.

Run the same proof against the published container:

docker run --rm ghcr.io/happy520ai/unified-ai-system/ai-gateway-service:0.5.0 pnpm gateway demo "Build a small API for my team" --enhance --profile coding --evidence

The evidence confirms that the original request was preserved, the result is deterministic, and providerCalled=false. Codex, VS Code, Claude Code, Gemini CLI, OpenCode, Cursor, Cline, Continue, and generic stdio clients can reach the same gateway through twelve governed MCP tools. The source build also provides a protocol-tested MCP Streamable HTTP endpoint for clients that connect by URL.

Useful in a real workflow? Star the repository or share one reproducible result.

The Gateway at a Glance

Architecture: OpenAI/Anthropic SDKs, MCP clients, A2A, CLI, and HTTP enter one gateway that adds prompt enhancement, virtual keys, exact + semantic cache, reverse MCP governance, observability, and audit — providers stay behind a three-gate whitelist with the fake provider as the credential-free default
Clients keep their native protocols; the gateway adds keys, budgets, cache, and audit. Twelve governed MCP tools are inspectable from any MCP client.

Choose Your First Path

Your goalStart hereWhat you get
Try it before installingBrowser Prompt LabA local, deterministic preview with no account or API key.
Verify the published runtime60-second Docker demoA disposable fake-provider run with visible evidence and cleanup.
Connect an agent clientCodex and MCP quickstartA pinned MCP container and twelve inspectable tools.
Choose a client pathMCP compatibility matrixInstall commands, first checks, and honest evidence boundaries.
Integrate with an applicationPrompt enhancement guideCLI, HTTP, SDK, curl, Python, and JavaScript paths.
Keep an existing OpenAI clientOpenAI-compatible APIPoint baseURL at /v1 for Chat Completions, function tools, Responses, streaming, and model discovery.
Connect another agentA2A v1.0 gatewayDiscover an Agent Card and execute tracked fake-provider tasks over JSON-RPC.
Check client runtime certificationClient runtime certificationCurrent evidence-backed catalog state: 52 verified, 2,084 pending manual evidence, and 0 failed across 2,136 unique entries.
Run mainstream certification one-by-oneClient runtime certificationRun node tools/verify-client-runtimes-serial.mjs --client tag:mainstream for sequential reports and explicit manual evidence states.
Run global protocol coverageClient runtime certificationRun node tools/run-global-client-discovery.mjs --source-manifest docs/client-runtime-catalog-sources-worldwide.json --execute --serial --max 0.
Run strict global certificationClient runtime certificationAdd --require-manual-evidence --manual-evidence docs/client-runtime-evidence.example.json to fail on missing manual proof.
Inspect the enhancement contractCredential-free evaluationEight representative cases for profiles, languages, signals, determinism, and zero provider calls.
Diagnose a first-run problemTroubleshooting matrixShell-specific checks without exposing credentials.
Verify an MCP clientMCP client reportRecord one Codex, Cursor, Cline, or generic stdio run with a small evidence set.
Contribute or report a runUsage report or good first issue #106A reproducible feedback path for users and maintainers.

Gateway Capabilities

Everything below runs from the same self-hosted process — opt-in and fake-provider-first, so you can try every feature with zero credentials:

Capability cards: OpenAI + Anthropic APIs, virtual keys and budgets, exact + semantic cache, reverse MCP governance, chat-native observability, local-first RAG, provider governance, and a 16-attack security regression

CapabilityWhat you getDocs
OpenAI + Anthropic + Gemini compatible APIs/v1/chat/completions (SSE streaming, tools), /v1/messages with native Anthropic streaming, the native Gemini generateContent adapter, the Responses API, and model discovery — keep your existing SDK, change only the base URL.OpenAI-compatible API · Gemini
Virtual keys + budgetsIssue uai- keys with periodic token budgets (daily/monthly windows), per-key request limits, soft-budget alerts, spend attribution, and instant revocation. Consumers never hold provider keys.Virtual keys · Spend reporting
Response cache — exact + semanticTenant-scoped hot-path caching with byte-identical JSON/SSE replay, an opt-in semantic layer for paraphrased requests, TTL and size caps, and a full audit trail.Response cache
Guardrails — deterministic & localInput/output scans: pasted secrets block, PII redacts, injection phrasings warn, banned terms and size limits enforce — no cloud tier, no extra credentials, <0.2 ms measured overhead, runtime-configurable per rule.Guardrails
Reverse MCP governanceAggregate upstream MCP servers (Streamable HTTP and stdio) behind one authenticated, audited, allow-listed surface — plus REST→MCP: any OpenAPI 3 spec becomes governed MCP tools.Reverse MCP governance
ObservabilityChat-specific Prometheus metrics on /metrics — tokens per model, cache hit rates, TTFT histograms, virtual-key rejections, guardrail findings — plus an opt-in Langfuse export and a per-key spend report API/CLI.Observability
Vector retrievalA credential-free deterministic embedding provider and the SQLite vector store activate mode: "vector" RAG with strict tenant isolation.Providers & knowledge
Provider governanceA three-gate whitelist matrix for real providers, a runtime credential store (locally permissioned file; virtual keys and user tokens are stored SHA-256-hashed, provider runtime credentials in cleartext for local execution — see the honest-boundaries note), request cost guards, circuit breakers, and fallback chains.Provider enablement
Enterprise governance + security drillsJWT auth, RBAC, tenant isolation with audit hash chains — verified by a repeatable 16-attack live security regression.Security drill

Published infrastructure benchmark (fake provider, single node): chat JSON p50 15.6 ms, SSE TTFT p50 2.8 ms, 402 req/s at concurrency 8, cache hits 5.6× faster than misses — see the gateway benchmark.

Why People Use It

  • Prompt enhancement for teammates who do not write perfect prompts.
  • Clean-clone verification without credentials or hidden setup.
  • Provider-free HTTP examples for curl and Python's standard library.
  • OpenAI SDK, CLI, HTTP API, shared SDK, MCP, Codex, Cursor, Cline, and Continue entry points.
  • Clear boundaries: no AGI claim, no L5 claim, no silent provider behavior.
  • Protocol-first onboarding: any OpenAI-compatible MCP, A2A, or HTTP client can be onboarded via a short setup + reproducible report path; we prioritize verification over marketing claims.

Try It in 60 Seconds

Terminal proof: one docker run command prints the enhanced prompt with providerCalled=false evidence and exits clean

Verify the project without signing in:

docker run --rm ghcr.io/happy520ai/unified-ai-system/ai-gateway-service:0.5.0 pnpm gateway demo

Expected behavior:

  • local fake-provider execution
  • visible execution: fake
  • deterministic output
  • no API key or account needed
  • container exits automatically

One-command natural-language enhancement preview:

docker run --rm ghcr.io/happy520ai/unified-ai-system/ai-gateway-service:0.5.0 \
  pnpm gateway demo "Build a small API for my team" --enhance --profile coding --evidence

This starts an isolated fake-provider gateway, enhances the request locally, prints the structured prompt, and cleans up without an API key.

You can also pipe a request directly into the published image without cloning the repository:

printf '%s' "Plan a launch for a small API" \
  | docker run --rm -i ghcr.io/happy520ai/unified-ai-system/ai-gateway-service:0.5.0 \
      pnpm --silent gateway demo --enhance --profile planning --language en --json

PowerShell equivalent for a request file:

Get-Content .\request.txt -Raw |
  docker run --rm -i ghcr.io/happy520ai/unified-ai-system/ai-gateway-service:0.5.0 `
    pnpm --silent gateway demo --enhance --profile planning --language en --json

The container still uses the disposable fake-provider path and exits after the result is printed.

Use --language zh-CN or --language en when the enhancement output should follow an explicit language instead of automatic detection.

Prompt enhancement example:

Start the gateway first (from a source checkout):

pnpm gateway serve

Then, in another terminal:

pnpm gateway enhance "Build a small API for my team" --profile coding
pnpm gateway chat "Build a small API for my team" --enhance --profile coding

The CLI also accepts a request from stdin, which is useful for shell pipelines and text files:

printf '%s' "Plan a launch for a small API" \
  | pnpm gateway enhance --profile planning --language en
cat request.txt | pnpm gateway enhance --profile auto --json

PowerShell users can pipe the same path with Get-Content .\request.txt -Raw.

Existing OpenAI SDKs

Start the source gateway with pnpm gateway serve, then keep your existing OpenAI client and change only its base URL:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "http://127.0.0.1:3100/v1",
  apiKey: process.env.PME_AUTH_TOKEN || "local-development",
});

const result = await client.chat.completions.create({
  model: "local-fake-model",
  messages: [{ role: "user", content: "Build a small API for my team" }],
});

console.log(result.choices[0].message.content);

The credential-free gate verifies this path with the official OpenAI JavaScript SDK 7.4.0. With the source gateway running, reproduce it with:

node docs/examples/openai-sdk-chat.mjs

The focused compatibility layer supports text completions, streaming, model listing, and optional local prompt enhancement. See the OpenAI-compatible API guide for Python, supported fields, auth behavior, and explicit limitations.

Prefer Node.js? The dependency-free example verifies the provider-free response before printing the enhanced JSON:

node docs/examples/prompt-enhancement.mjs "Help me plan a small API for my team" --profile planning --language en

Prefer Go? The standard-library example checks provider-free readiness and prints JSON evidence before showing the enhanced prompt:

go run docs/examples/prompt-enhancement.go "Help me plan a small API for my team" --profile planning --language en

For a no-clone prompt-enhancement walkthrough, start the published gateway image and follow the provider-free curl example:

read -rsp "Enter a random gateway token (32+ characters): " PME_AUTH_TOKEN
printf '\n'
export PME_AUTH_TOKEN
docker run --rm --publish 127.0.0.1:3100:3100 \
  --env AI_GATEWAY_SERVICE_HOST=0.0.0.0 \
  --env AI_GATEWAY_PROVIDER_MODE=fake \
  --env AI_GATEWAY_REAL_PROVIDER_ENABLED=false \
  --env PME_ENTERPRISE_AUTH_ENABLED=true \
  --env PME_AUTH_TOKEN \
  ghcr.io/happy520ai/unified-ai-system/ai-gateway-service:0.5.0

Keep that process running while you send the curl request. The response includes metadata.providerCalled=false. For a credential-free HTTP stream, use the curl SSE example to inspect start, chunk, and done events with executionMode=fake. The gateway refuses non-loopback listening when authentication is disabled; see the critical attack-chain hardening report.

Use It

Terminal Workflow

After pnpm install:

pnpm gateway serve
pnpm gateway status
pnpm gateway doctor
pnpm gateway chat "Hello from Unified AI System"

MCP / Codex / Cursor / Cline

Published MCP command:

codex mcp add unified-ai-system -- docker run --rm -i ghcr.io/happy520ai/unified-ai-system/mcp-server:0.5.0

Restart Codex, run /mcp verbose to verify the twelve tools, then follow the 60-second Codex MCP quickstart for a safe first prompt-enhancement call and removal command.

For MCP clients that connect by URL, the source build provides a loopback-only Streamable HTTP endpoint:

pnpm mcp:http
# http://127.0.0.1:3210/mcp

See the MCP server guide for remote-bind authentication and the published-release boundary.

Installable Agent Skill

codex plugin marketplace add happy520ai/unified-ai-system --ref master
npx skills add happy520ai/unified-ai-system --skill unified-ai-gateway --agent codex --copy --yes

The plugin pins the reviewed immutable v0.4.9 MCP image and starts it without container networking or Linux capabilities.

Skill hub: https://skills.sh/happy520ai/unified-ai-system/unified-ai-gateway

For local source work:

git clone https://github.com/happy520ai/unified-ai-system.git
cd unified-ai-system
corepack enable
corepack prepare pnpm@9.15.4 --activate
pnpm install --frozen-lockfile
pnpm verify:public-clone
pnpm gateway demo

For a prepared cloud workspace, use GitHub Codespaces. See the value first:

pnpm gateway demo "Build a small API for my team" --enhance --profile coding --evidence

For the complete credential-free clone check, run pnpm verify:public-clone after the demo. The repository's devcontainer keeps the default path provider-free. Codespaces availability and usage limits are controlled by GitHub.

Docker Compose

For a source checkout, start the gateway with a readiness check:

docker compose up --build -d
docker compose ps
curl http://127.0.0.1:3100/health/check

The service becomes healthy only after /health/check responds successfully. When finished, stop it with:

docker compose down

The Compose file treats .env as optional and leaves provider behavior explicit; the credential-free fake-provider path remains the default.

Share a Verified Result

If the project helps your workflow, run one reproducible path, star the repository, and share the smallest useful result through the structured Usage Report.

For a ready-to-review CLI packet, append --evidence to the enhanced demo:

pnpm gateway demo "Build a small API for my team" --enhance --profile coding --evidence

Review the original request and output before sharing the generated JSON. The packet also records detectedSignals and the item count for each compiledSections entry, so a reviewer can see which request signals were carried into the structured prompt without reading internal logs.

For the browser Prompt Lab, use its Copy evidence or Download evidence action, then paste or attach the JSON in the optional Prompt Lab evidence field of the same report. Use Copy share link when you want another browser to reproduce the same local input, profile, and language; review the prompt first because the URL fragment contains the input text.

Next Steps

Honest Boundaries

We separate what is verified from what is not claimed:

  • Clean clone + fake-provider path: Yes
  • Hosted public API: No
  • Real provider execution by default: No, must be explicitly enabled
  • Browser chat UI in this repo: No (CLI/API/MCP are first-class)
  • Production ready / AGI / L5: Not claimed

Real provider calls are disabled by default. Configure safely via .env.example and docs/providers.md.

Verify the Project

pnpm check
pnpm test
pnpm check:public
pnpm verify:public-clone
pnpm verify:mcp

CI on master runs Linux checks, container startup smoke tests, MCP discovery, and process-cleanup checks.

Project Links

Star History

If the gateway saves you a proxy migration or an afternoon of prompt cleanup, a star helps more people find it.

Star History Chart