mcp-server-if

mcp-server-if

Enables AI assistants to play interactive fiction games (Glulx and Z-machine) through the Model Context Protocol, with automatic save/restore and optional journaling mode.

Category
访问服务器

README

mcp-server-if

An MCP (Model Context Protocol) server for playing interactive fiction games. Enables AI assistants like Claude to play text adventure games through a standardized interface.

Features

  • Play Glulx (.ulx, .gblorb) and Z-machine (.z3-.z8, .zblorb) games
  • Automatic game state persistence (save/restore between sessions)
  • Download games directly from the IF Archive
  • Optional journaling mode for reflective playthroughs
  • Works with Claude Desktop, Claude Code, and other MCP clients
  • Bundled interpreters (glulxe for Glulx, bocfel for Z-machine)

Installation

# Using uvx (recommended)
uvx mcp-server-if

# Or install with pip
pip install mcp-server-if

The package includes pre-compiled interpreters. No additional setup required.

Configuration

Environment Variables

Variable Description Default
IF_GAMES_DIR Directory to store games ~/.mcp-server-if/games
IF_GLULXE_PATH Override path to glulxe binary Bundled binary
IF_BOCFEL_PATH Override path to bocfel binary Bundled binary
IF_REQUIRE_JOURNAL Require journal reflections false

Command Line Arguments

mcp-server-if --help

Options:
  --games-dir PATH       Directory to store games
  --glulxe-path PATH     Path to glulxe binary (overrides bundled)
  --require-journal      Require journal reflections between turns

Usage with Claude Desktop

Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):

{
  "mcpServers": {
    "interactive-fiction": {
      "command": "uvx",
      "args": ["mcp-server-if"]
    }
  }
}

Usage with Claude Code

claude mcp add interactive-fiction -- uvx mcp-server-if

Available Tools

play_if

Play a turn of interactive fiction.

play_if(game="zork", command="go north")
play_if(game="zork", command="", journal="...reflection...")  # with journaling

list_games

List available games and their save state status.

download_game

Download a game from the IF Archive or any URL.

download_game(name="advent", url="advent.ulx")
download_game(name="bronze", url="https://example.com/Bronze.gblorb")

reset_game

Reset a game to start fresh (clears save state, preserves journal).

read_journal

Read the playthrough journal for a game.

read_journal(game="zork", recent=10)  # last 10 entries

search_journal

Search journal entries by keyword.

search_journal(game="zork", query="treasure")

Supported Game Formats

Glulx (modern, uses glulxe interpreter):

  • .ulx - Raw Glulx game files
  • .gblorb - Blorb containers with Glulx games

Z-machine (classic Infocom format, uses bocfel interpreter):

  • .z3, .z4, .z5, .z7, .z8 - Z-code game files
  • .zblorb - Blorb containers with Z-machine games

Find games at the IF Archive: Glulx games, Z-code games.

Journaling Mode

Enable with --require-journal or IF_REQUIRE_JOURNAL=true. In this mode:

  1. After playing your first command, subsequent turns require a journal entry
  2. Journal entries must be at least 100 words
  3. Entries are saved to {game}/journal.jsonl
  4. Use read_journal and search_journal to review your playthrough

This encourages thoughtful, reflective gameplay rather than rushing through.

How It Works

  1. Games are stored in ~/.mcp-server-if/games/{name}/

  2. Each game directory contains:

    • The game file (.ulx, .gblorb, .z5, etc.)
    • state/ - autosave data (persists between sessions)
    • metadata.json - session metadata
    • journal.jsonl - playthrough journal (if enabled)
  3. The server selects the appropriate interpreter based on file format:

    • Glulx games → glulxe
    • Z-machine games → bocfel
  4. Both interpreters use RemGlk for JSON-based I/O

  5. Game state is automatically saved after each turn

Development

Requires uv, a C compiler (gcc or clang), a C++ compiler (g++ or clang++), make, and git.

git clone --recursive https://github.com/davidar/mcp-server-if.git
cd mcp-server-if
uv sync --group dev
uv run pytest -v

uv sync compiles the bundled interpreters (glulxe and bocfel) from source automatically. If binaries are missing after a fresh clone, run uv sync --reinstall-package mcp-server-if to force recompilation.

Troubleshooting

"glulxe binary not found"

This shouldn't happen with pip/uvx installs. If it does:

  • Try reinstalling: pip install --force-reinstall mcp-server-if or uv sync --reinstall-package mcp-server-if
  • Or set IF_GLULXE_PATH to a manually installed glulxe

"Game file not found"

Use list_games to see available games, or download_game to get new ones.

Save/restore commands don't work

In-game save/restore triggers file dialogs that aren't supported. Use the automatic autosave system instead - your game state persists between sessions automatically.

License

MIT License - see LICENSE for details.

Credits

  • glulxe - The Glulx VM interpreter by Andrew Plotkin
  • bocfel - Z-machine interpreter by Chris Spiegel
  • RemGlk - Remote Glk library for JSON I/O
  • MCP - Model Context Protocol by Anthropic

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选