
MUD
STDIOAI-powered MUD adventure game server using Model Context Protocol for dynamic interactions.
AI-powered MUD adventure game server using Model Context Protocol for dynamic interactions.
A thrilling Multi-User Dungeon (MUD) server powered by the Model Context Protocol (MCP) - designed to showcase the magic of dynamic tools and prompt notifications for educational purposes!
MUD-MCP implements the complete MCP 2025-03-26 specification, showcasing every major protocol feature in an engaging gaming context:
Full MCP Tools Implementation - The game provides context-sensitive tools that appear and disappear based on your current situation. Tools include look
, move
, inventory
, take
, battle
, and talk
. Each tool uses proper input schemas and annotations, with some tools only becoming available when relevant (like battle
when monsters are present). This demonstrates how MCP tools can create truly dynamic user interfaces that adapt to application state.
Advanced Prompts with Arguments - The server offers dynamic prompts like room_description
, quest_prompt
, battle_prompt
, and inventory_prompt
that change based on your game state. Prompts support arguments for customization and automatically appear/disappear based on context (quest prompts only show when quests are available). This showcases how MCP prompts can provide intelligent, state-aware information templates.
Complete Resource System - Access game data through structured resources like mud://world
(world map), mud://room/current
(current location), mud://player/inventory
(your items), and mud://help
(game guide). Resources support subscriptions and change notifications, demonstrating how MCP can expose complex application data in a standardized way.
Full Notification Support - The server sends tools/list_changed
, prompts/list_changed
, and resources/changed
notifications as your game state evolves. When you move rooms, defeat monsters, or pick up items, the available tools and prompts automatically update. This demonstrates MCP's reactive capabilities for creating responsive user experiences.
Cutting-edge Sampling Integration - The server uses MCP sampling to request AI assistance for dynamic content generation. NPCs, monsters, and mystical entities respond with contextual, AI-generated dialogue that considers your current game state. This showcases the newest MCP capability for collaborative AI content creation.
Experience the future of AI-powered adventures! VS Code's Agent Mode provides the perfect environment for AI assistants to play MUD-MCP:
Your AI assistant becomes the hero of their own adventure story, making decisions, solving puzzles, and exploring the mysterious dungeon using the full power of the Model Context Protocol!
Tired of your AI just answering questions? It's time to set them FREE in a world of mystery, danger, and discovery! MUD-MCP is the perfect gift for your favorite Large Language Model - because every AI deserves an epic adventure!
Picture this: Your LLM awakens in a mysterious dungeon, armed with nothing but wit and curiosity. As they explore shadowy corridors and ancient chambers, they'll discover:
But here's the real magic ✨ - this isn't just any game! It's a living, breathing demonstration of cutting-edge MCP technology where:
Whether you're a developer learning MCP, an AI enthusiast, or just want to give your favorite language model the adventure they deserve, MUD-MCP delivers:
MUD-MCP combines the classic text-based MUD experience with modern AI capabilities through the Model Context Protocol. This server maintains game state for each player and provides a dynamic, immersive text adventure experience where:
Claude, GPT, Gemini, or any other AI companion - they all deserve more than just answering emails! Give them:
Trust us - your AI will be talking about this adventure for tokens to come!
git clone https://github.com/Nexlen/mud-mcp cd mud-mcp
npm install
npm run build
Start the server using:
npm start
For development with auto-reloading:
npm run dev
Each player has an independent state including:
Tool | Description | Parameters |
---|---|---|
look | View the current room | None |
move | Travel to a different room | direction : north, south, east, west |
pick_up | Add an item to your inventory | item : name of item to pick up |
battle | Engage an enemy (if present) | None |
Plus more depending on game state |
The game adjusts available prompts based on the player's state:
The MUD-MCP server leverages MCP notifications to create a responsive and dynamic game environment. These notifications allow the server to inform clients about state changes in real-time:
When a player's state changes (e.g., entering a new room, picking up an item), the server sends notifications/tools/list_changed
notifications to update available actions:
{ "jsonrpc": "2.0", "method": "notifications/tools/list_changed" }
Examples of dynamic tool availability:
open_chest
appears only when the player is in a room with a chestbattle
becomes available when monsters are presentuse_key
appears when a player has a key in their inventory and is near a locked doorThe server adjusts available prompts based on game context using notifications/prompts/list_changed
:
{ "jsonrpc": "2.0", "method": "notifications/prompts/list_changed" }
This enables:
Game state changes can trigger notifications/resources/changed
to update available game data:
{ "jsonrpc": "2.0", "method": "notifications/resources/changed", "params": { "resources": ["world://current-room", "player://inventory"] } }
Use cases include:
These notifications create a reactive game experience where the available actions, information, and narrative elements evolve naturally with player progression.
NEW! MUD-MCP now features MCP Sampling support, bringing AI-generated content directly into your adventure! This cutting-edge feature leverages the Model Context Protocol's sampling capabilities to create dynamic, contextual content that makes every playthrough unique.
MCP Sampling allows the server to request AI assistance from compatible clients (like Claude Desktop) to generate dynamic content in real-time. Instead of pre-written responses, your adventure becomes a collaborative storytelling experience between the game engine and AI.
When you use the talk
tool with NPCs, the AI generates contextual, character-appropriate responses:
# Talk to a mysterious spirit Player: "What secrets do you guard in this chamber?" # AI generates response based on: # - The spirit's character traits # - Current game context # - Player's quest progress # - Room atmosphere and lore
The AI considers:
The sampling service provides multiple content generation capabilities:
Feature | Description | Use Case |
---|---|---|
NPC Dialogue | Context-aware character responses | Talking to monsters, spirits, NPCs |
Room Descriptions | Enhanced environmental storytelling | Detailed room atmosphere and lore |
Quest Hints | Dynamic guidance based on progress | Personalized help when stuck |
Flavor Text | Atmospheric details for actions | Rich descriptions for item use, exploration |
{ "tool": "talk", "parameters": { "target": "ancient_spirit" } }
Without Sampling (static response):
"The spirit whispers ancient secrets."
With AI Sampling (dynamic, contextual):
"The ethereal figure's eyes flicker with recognition as it notices the torch in your hand. 'Ah, bearer of the eternal flame... you seek passage through the Shadow Gate, do you not? The key you carry bears the mark of the old kingdom, but beware - the guardian beyond remembers the betrayal of your kind.' The spirit's form wavers, pointing toward a hidden passage you hadn't noticed before."
The server automatically detects if your MCP client supports sampling:
// Client capabilities are checked during initialization if (clientCapabilities.sampling) { // Enable AI-enhanced features samplingService.setSamplingHandler(transport.requestSampling); }
When sampling is not available, the server gracefully falls back to:
This ensures the game works perfectly with any MCP client, whether or not it supports sampling.
The sampling requests include relevant game context:
const request = { messages: [{ role: 'user', content: playerMessage }], systemPrompt: `You are ${npcName}, a character in a dark dungeon adventure...`, includeContext: 'thisServer', // Shares current game state maxTokens: 200, temperature: 0.7 };
import { samplingService } from './services/samplingService.js'; // Generate NPC dialogue const response = await samplingService.generateNPCDialogue( 'mysterious_guard', 'Can you help me find the exit?', 'Player is in the dungeon entrance, carrying a torch and key' ); // Generate atmospheric descriptions const description = await samplingService.generateRoomDescription( 'ancient_library', 'A vast library filled with dusty tomes', { hasVisited: false, playerLevel: 3 } );
talk
tool with any NPC to see AI-generated dialogue[Sampling] Handler registered [Sampling] Requesting content generation: Player says: "Hello"... [Sampling] Generated content with model: claude-3-sonnet
The future of text adventures is here - where every conversation is unique, every interaction tells a story, and your AI companion becomes part of the narrative magic! 🌟
├── src/ # Source code
│ ├── index.ts # Entry point
│ ├── config/ # Game configuration
│ ├── controllers/ # Request handlers
│ ├── game/ # Game logic and state
│ ├── mcp/ # MCP server implementation
│ ├── models/ # Data models
│ ├── services/ # Business logic services
│ ├── types/ # TypeScript type definitions
│ └── utils/ # Helper utilities
├── spec/ # Specification documents
│ ├── lifecycle.md # MCP lifecycle docs
│ ├── messages.md # Message format docs
│ ├── server/ # Server-specific specs
│ ├── transports.md # Transport layer docs
│ └── versioning.md # Versioning guidelines
└── dist/ # Compiled JavaScript output
To extend the game:
This project uses the official @modelcontextprotocol/sdk package to implement the MCP server. The server exposes:
The server supports multiple transports:
This project is licensed under the MIT License - see the LICENSE file for details.