0013. AI integration: MCP server, model-agnostic adapter, generated AI docs
- Status: Accepted
- Date: 2026-11-26
- Phase: 2
Context
Section titled “Context”Creators choose their AI. External assistants (Claude, others) connect from their own clients; the web editor has a built-in assistant whose provider is swappable, with bring-your-own-key now and a platform-paid tier later.
Decision
Section titled “Decision”- Docs for AI:
llms.txt(index) andllms-full.txt(full text) generated from TypeDoc output, schema descriptions and arecipes/folder of short, tested examples. Recipes are compiled and run in CI so they cannot drift. - MCP server
apps/mcp, built with the official MCP TypeScript SDK. Transports: stdio for local projects (works with Claude Code/Desktop and other MCP clients) and Streamable HTTP with OAuth for the hosted platform (Phase 3). Tools (inputs typed by our Zod schemas):create_game_from_template,list_templates,get_project_tree,read_file,add_entity/update_entity,upsert_scene,upsert_level,validate(schemas +tsc),run_headless(N seconds or scripted inputs → logs, errors, assertions, perf stats),capture_screenshot(Playwright),search_docs,publish_draft(Phase 3). Resources: schemas, docs pages, templates. - Provider adapter
@ludrel/ai: our ownAiProviderinterface (chat, streaming, tool calls, structured output, token accounting). First implementation wraps the Vercel AI SDK (Anthropic, OpenAI, OpenAI-compatible and Ollama/local providers). Default model for the built-in assistant: Claude (latest Sonnet-class for speed, Opus-class selectable). BYOK keys are encrypted at rest (envelope encryption, KMS in the cloud) and never reach the game sandbox. AUsageMeterhook exists from day one so a platform-paid tier can meter and cap usage later. - Same tools everywhere: the editor’s built-in assistant uses the same tool implementations as the MCP server
(a shared
@ludrel/agent-toolspackage), so behaviour is identical whichever AI is used. - Version history: every AI or human change is a commit in a per-game content-addressed history (Phase 3), enabling undo.
Alternatives considered
Section titled “Alternatives considered”- Provider SDKs directly (Anthropic, OpenAI): maximal features per vendor, but N integrations to maintain.
- LangChain.js: large surface, abstractions we don’t need.
- A custom plugin protocol instead of MCP: MCP is the standard most AI clients already support.
Consequences
Section titled “Consequences”The AI SDK’s abstraction lags newest vendor features; our interface lets us drop to a vendor SDK for one provider
without changing callers. Phase 2’s success test is measured with a scripted evaluation (a fresh session gets a
task like “add a double-jump power-up” and must pass validate + run_headless assertions).
Amendment (2026-11-27, Phase 2)
Section titled “Amendment (2026-11-27, Phase 2)”- The Claude provider uses the official Anthropic SDK (
@anthropic-ai/sdk) rather than the Vercel AI SDK, as the “drop to a vendor SDK for one provider” escape hatch above allows: it gets adaptive thinking, effort, prompt caching and server-side refusal fallback (on by default) without waiting for the abstraction to catch up. - Providers own their agent loop (
AiProvider.runAgent) so each can pass its native message blocks back unchanged. - The Vercel AI SDK providers (OpenAI, OpenAI-compatible, Ollama/local) move to Phase 3, when the editor’s bring-your-own-key assistant needs them. Phase 2 also ships a scripted provider for tests and eval graders.