zmachine-mcp
Enables AI agents to play Z-Machine text adventure games (e.g., Zork) via MCP, REST, or WebSocket interfaces, with session management and optional Redis persistence.
README
zmachine-mcp
An MCP server for playing Z-Machine text adventure games (Zork, Hitchhiker's Guide, etc.) with AI agents.
Three interfaces expose the same game engine:
- MCP — stdio or HTTP transport, so AI assistants like Claude can play text adventures
- REST API — programmatic session management and input/output
- WebSocket — real-time output streaming
A built-in status page at / shows server health, active sessions, and MCP setup instructions.
Quick Start
npm install
Place your Z-Machine story files (.z3, .z4, .z5, .z7, .z8, .zblorb) in a folder and point to it:
export STORIES=../stories
Then start the server:
# Development (auto-reload, server on :3000, Vite on :5173)
npm run dev
# Production
npm run build && npm start
Open http://localhost:3000 to see the server status page.
MCP Integration
Claude Desktop (stdio)
npm run start:stdio
Add to your Claude Desktop config (claude_desktop_config.json):
{
"mcpServers": {
"zmachine": {
"command": "npx",
"args": ["tsx", "src/server/main.ts", "--stdio"],
"env": {
"STORIES": "/path/to/your/stories"
}
}
}
}
HTTP Transport
When running in HTTP mode, the MCP endpoint is available at POST /mcp.
MCP Tools
| Tool | Description |
|---|---|
list_games |
List available story files |
start_game |
Start a new session; returns session ID and opening text |
send_input |
Send a command; returns the game's response |
get_session_info |
Get session state and status line |
quit_game |
End a session |
REST API
Interactive documentation is available at /api/docs when the server is running. The raw OpenAPI spec is at /api/openapi.yml.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/status |
Server status, uptime, active sessions |
GET |
/api/games |
List available games |
GET |
/api/sessions |
List all active sessions with their IDs, game, state, and status line |
POST |
/api/sessions |
Create a new game session |
POST |
/api/sessions/:id/input |
Send input to a session |
DELETE |
/api/sessions/:id |
End a session |
WebSocket
Connect to ws://localhost:3000/ws?session=<id> for real-time output streaming.
Configuration
| Environment Variable | Default | Description |
|---|---|---|
STORIES |
../stories |
Path to folder containing Z-Machine story files |
PORT |
3000 |
HTTP server port |
REDIS_URL |
— | Redis connection URL for session persistence |
DEBUG |
— | Set to zmachine:* to enable debug logging |
Redis Persistence (optional)
Set REDIS_URL (e.g. redis://localhost:6379) to persist sessions and save data to Redis. Without it, sessions are in-memory only and lost on restart.
Development
npm run dev # Dev server with auto-reload
npm test # Run tests
npm run test:coverage # Tests with coverage report
npm run typecheck # TypeScript type checking
Project Structure
src/
server/
main.ts — Entry point (HTTP or stdio mode)
mcp-server.ts — MCP tool definitions
rest-server.ts — Express REST API
ws-server.ts — WebSocket server
session-manager.ts — Loads stories, manages sessions
game-session.ts — Single game session (wraps Z-Machine VM)
glkote-async.ts — Custom GlkOte for synchronous I/O capture
redis-store.ts — Optional Redis persistence
client/
main.ts — Status page (polls /api/status)
index.css — Status page styles
__tests__/ — Jest test suites
Tech Stack
- Runtime: Node.js + TypeScript (ESM)
- Z-Machine: ifvms + glkote-term
- Server: Express 5, WebSocket (ws)
- MCP: @modelcontextprotocol/sdk
- Client: Vanilla TypeScript, Vite
- Testing: Jest + ts-jest
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。