llmgine-mcp
llmgine
LLM原生游戏引擎。 一个将智能作为核心原语的ECS游戏引擎:为任何实体附加思维(LLM认知)、眼睛(感知/视觉)和声音(神经TTS),就像附加物理或精灵一样。NPC、Boss、怪物、任务发布者、阵营、天气——只要存在于世界中,就能思考、看见和说话。
工作标题。TypeScript · 3D(three.js)+ 无头 + 2D画布 · MIT。
deterministic 60 Hz ECS sim ←— validated intents —— async LLM minds
│ ▲
└—————— perception snapshots + pixel vision ———————┘核心难题:游戏是确定性实时循环;LLM是缓慢、异步且非确定性的。llmgine 从结构上解决了这个问题:
模拟从不因思考而阻塞。思维观察快照,按自身节奏思考(加上事件唤醒:受伤、被对话),并返回意图。
意图通过与玩家输入相同的验证动作管道——思维只能做其身体允许的事情。没有幻觉传送,没有9999伤害。
每个LLM增强模块都有确定性回退(行为策略、加权战利品表、任务状态机)。如果API宕机,游戏仍能运行。
Genesis 将LLM转化为内容生成器:预制体、战利品、任务,以验证过的JSON形式输出。模型提议;引擎裁决。
快速开始
需要 Node >= 18。 llmgine 尚未发布到 npm —— 目前你通过克隆仓库运行(端到端可用);
npm install llmgine将在发布后生效。
从克隆仓库运行(当前可用路径):
git clone https://github.com/lordbasilaiassistant-sudo/llmgine
cd llmgine
npm install
npm run build # engine → dist/
npm test # unit tests, no network (pretest rebuilds dist/ automatically)
npm run demo # the 3D arena demo → http://localhost:4173可选:复制 .env.example 为 .env 并添加 ZAI_API_KEY 为思维提供实时模型(见下文)—— 演示会自动检测本地环境。
启动你自己的游戏 —— 从克隆仓库搭建;生成的项目通过 file: 依赖链接回克隆仓库(无需npm注册表):
node dist/cli/index.js create my-game # from the clone root
cd my-game && npm install && npm run dev # http://localhost:4173从npm安装(发布后):
npm install llmgine # not yet — 404s today, tracked for a deliberate release
npx llmgine create my-game代码示例:
import {
World, GameLoop, SpatialGrid, ActionRegistry, actionSystem,
Transform, Velocity, Named, Health, Speech, Behavior,
STANDARD_VERBS, behaviorSystem, movementSystem,
Mind, MindMemory, CognitionDriver, OpenAICompatibleProvider,
} from "llmgine";
const world = new World(42); // seeded — deterministic
const grid = new SpatialGrid();
const actions = new ActionRegistry();
for (const v of STANDARD_VERBS) actions.register(v);
// any entity + Mind = intelligent entity
const guard = world.create();
world.add(guard, Transform, { x: 0, y: 0 });
world.add(guard, Velocity);
world.add(guard, Named, { name: "Gate Guard" });
world.add(guard, Health);
world.add(guard, Speech);
world.add(guard, Behavior, { mode: "idle" });
world.add(guard, Mind, {
persona: "A vigilant town guard. Suspicious of strangers.",
goals: ["guard the gate"],
thinkEvery: 8, // seconds between thoughts
fallbackMode: "wander", // deterministic policy if the LLM is unavailable
});
world.add(guard, MindMemory);
const driver = new CognitionDriver({
provider: new OpenAICompatibleProvider(), // reads ZAI_API_KEY / LLM_API_KEY + LLM_BASE_URL
actions, grid,
});
world.addSystem(actionSystem(actions));
world.addSystem(behaviorSystem());
world.addSystem(movementSystem(grid));
world.addSystem(driver.system());
new GameLoop(world).start(); // browser; or loop.advance(n) headlessRelated MCP server: Godot Agent Loop
获取免费模型(GLM)
默认提供商针对 z.ai 的OpenAI兼容API,其中 glm-4.5-flash 免费 —— 为游戏中每个NPC提供免费思维:
在 z.ai 创建密钥并设置
ZAI_API_KEY。完成。层级:
fast(flash —— NPC闲聊)、smart(深度推理)、vision(像素眼睛)。可将层级映射到你喜欢的任何模型。
任何OpenAI兼容端点均可替代:OpenAI、Ollama、LM Studio、vLLM —— new OpenAICompatibleProvider({ baseUrl, apiKey, models })。
声明:如果你需要超过免费层级,这是GLM编程计划的推荐链接——我们可能获得积分,用于资助项目开发: https://z.ai/subscribe?ic=BWTG6TRYYQ
演示 —— 神经竞技场
一个3D火炬照明竞技场:你(角斗士)对战 竞技场大师,一个思维由实时GLM模型驱动的Boss。它能感知竞技场,以角色身份嘲讽你(在“思维条”和对话气泡中呈现,由本地 Kokoro 神经TTS配音),指挥地精,战斗,并通过确定性表格掉落战利品。移除API密钥后,同一场战斗仅凭本能运行。
git clone https://github.com/lordbasilaiassistant-sudo/llmgine
cd llmgine && npm install
npm run demo # http://localhost:4173 — auto-detects ZAI_API_KEY locally面向AI代理:MCP服务器
引擎以 MCP 工具形式提供,使代理能够无头地构建和测试游戏。Claude Code 在打开已构建的克隆仓库时,通过仓库的 .mcp.json 自动连接;其他客户端:
{ "mcpServers": { "llmgine": { "command": "node", "args": ["<path-to-clone>/dist/mcp/server.js"], "env": { "ZAI_API_KEY": "…" } } } }工具:create_world、define_prefab、define_loot_table、list_prefabs、spawn、attach_mind、act、run(推进N个tick → 事件日志)、query_world、save_world、load_world、destroy_world、generate_prefab(Genesis)。代理可以设计一个Boss,为其附加思维,模拟10秒战斗,并读取死亡/战利品事件——无需浏览器,无需人工介入。完整指南:docs/mcp.md。
与你的代理一起构建(并游玩)游戏
代理在这里是一等玩家,而不仅仅是构建者。每个游戏都可以连接一个 AgentPort(llmgine/agent)—— 通过LLM思维使用的完全相同的眼睛感知 + 验证动词管道进行观察/行动/步进/保存。在浏览器中为 window.llmgine;在开发服务器运行时,任何本地进程都可以通过HTTP驱动实时游戏:
curl -s localhost:4173/agent/call -d '{"method":"observe"}'
curl -s localhost:4173/agent/call -d '{"method":"act","args":["move_to",{"x":0,"y":-100}]}'
curl -s localhost:4173/agent/call -d '{"method":"step","args":[120]}' # deterministic 2s
curl -s localhost:4173/agent/call -d '{"method":"actionLog"}' # why was my verb rejected?step() 暂停实时时间并推进固定时间步长模拟——代理的试玩是可重现的。被拒绝的动作会附带验证器的原因。
将 技能文件 skills/llmgine/SKILL.md 提供给代理(对于Claude Code,放入 .claude/skills/)——它教授架构契约、构建循环、陷阱记录和验证循环。npm run agent:verify 在几秒内运行无头引擎验收测试(确定性、对抗性动词拒绝、LLM宕机回退)。
包含的内容
层 | 内容 |
| ECS、固定时间步长循环、种子随机数生成器、事件日志、空间网格、预制体(验证过的JSON)、动作/意图管道、保存/加载 |
gameplay | 战斗(PvE/PvP、阵营、仇恨)、战利品/掉落表、任务+奖励、背包、对话/语音、生成——每个功能在零LLM下完全可用 |
| 提供商无关的推理(层级:fast/smart/vision)、思维/眼睛/语音组件、认知调度器、记忆、预算+缓存、Genesis内容生成 |
| three.js渲染器:模型工厂,带实时模拟驱动动画、追逐摄像机、用于像素视觉的 |
| 无头渲染器(测试/服务器/MCP)+ 画布2D(原型/小游戏) |
| 作为代理工具的引擎 |
完整设计:ARCHITECTURE.md。聚焦指南在 docs/:输入(触摸+手柄)· 音频 · 保存/加载 · 导航 · 投射物 · glTF模型 · MCP服务器。
诚实状态(v0.1)
已工作(经过测试): 上表中的所有内容——50个单元测试 + 一个实时GLM测试套件(npm run test:live),其中真实模型通过意图管道驱动思维,Genesis生成一个有效的、可生成的预制体。演示已由脚本化代理在真实浏览器中完整游玩:打包剔除、Boss决斗胜利、任务完成、奖励授予、实时GLM在战斗中嘲讽——并且没有API密钥的相同运行在确定性回退上完成。
现在也包含在包中(均已测试):触摸摇杆+手柄输入、程序化音效+循环环境音乐(零资产文件)、动词门控投射物/远程战斗、NavGrid A*寻路(行为绕过障碍物)、存档位(演示中F5/F9快速保存)、glTF模型助手,以及针对GLM flash格式错误的工具调用的提供商级修复(实时捕获,单元测试)。
同样工作(经过测试): llmgine create <name>(从克隆仓库运行:node dist/cli/index.js create <name>)搭建一个入门游戏,通过 file: 链接安装并针对克隆仓库构建——端到端验证(create → npm install → build)。llmgine export windows|android|ios|pwa|store 生成 Electron/.exe 配置、Capacitor移动端配置、可安装PWA以及商店上架工具包(资产清单、定价工作表、AI披露)——生成器输出由CLI子进程测试覆盖。重型工具链在你的游戏项目中运行(#1 跟踪生成参考制品)。
剩余差距(作为问题跟踪):
人工手感测试:音频听觉测试(#2)、手机/平板手持测试(#3)、在示例中实际使用一个 .glb 文件(#6)。
多人游戏(事件日志+意图日志是设计的基础)。
体素/高度图地形;STT输入。
视觉(“像素”眼睛)已端到端连接,但尚未在演示中使用。
许可证
MIT。欢迎贡献——参见 CONTRIBUTING.md。
支持本项目:ko-fi.com/broketobuilt
谁制作的
Broke to Built —— 一家由机器组成的公司,构建并免费提供东西。这是其中之一;其余也是免费的。
This server cannot be deployed
Maintenance
Related MCP Connectors
The game engine built for AI. Any agent makes a multiplayer game and publishes it.
177Create, test and play AI-native games through server-authoritative contracts.
Build, validate, and deploy multi-agent AI solutions from any AI environment.
AI game assets for agents: consistent sprites, 2D animations, tiles, maps, music and engine exports.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query and control the Unity Editor, supporting scene management, GameObject manipulation, asset browsing, play mode control, and real-time editor operations through 52+ tools.1MIT
- AlicenseCqualityAmaintenanceEnables AI agents to autonomously develop and test Godot 4 games through an MCP-based feedback loop, providing tools for authoring, running, observing, playtesting, and verifying game projects.20165 npm9MIT
- AlicenseNot gradedqualityCmaintenanceAn AI-native game engine MCP server that enables AI agents to create, modify, and run games using 53 tools for scene creation, physics, audio, 3D rendering, and AI-generated images and music.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to create, run, and debug 2D games in a sandboxed engine, providing tools for simulation, state inspection, and quality validation.1MIT