
FoundryVTT
STDIOFoundryVTT integration allowing AI assistants to interact with tabletop gaming sessions
FoundryVTT integration allowing AI assistants to interact with tabletop gaming sessions
A Model Context Protocol (MCP) server that integrates with FoundryVTT, allowing AI assistants to interact with your tabletop gaming sessions. Query actors, roll dice, generate content, and manage your game world through natural language.
git clone <repository-url> cd foundry-mcp-server npm install
cp .env.example .env # Edit .env with your FoundryVTT details
FOUNDRY_URL=http://localhost:30000 FOUNDRY_API_KEY=your_api_key_here # OR use username/password: FOUNDRY_USERNAME=your_username FOUNDRY_PASSWORD=your_password
npm run build npm start
npm run dev
The MCP server supports three authentication methods, listed from most secure to least secure:
Benefits:
Setup:
https://github.com/lgates/foundryvtt-mcp/releases/latest/download/module.json
.env
file:
FOUNDRY_URL=http://localhost:30000 FOUNDRY_API_KEY=your_local_api_key_here USE_REST_MODULE=false # Use local module instead
⚠️ Privacy Notice: This option sends your game data through external relay servers.
.env
file:
FOUNDRY_URL=http://localhost:30000 FOUNDRY_API_KEY=your_external_api_key_here USE_REST_MODULE=true
Limited functionality - Some features may not work properly.
.env
file:
FOUNDRY_URL=http://localhost:30000 FOUNDRY_USERNAME=your_username FOUNDRY_PASSWORD=your_password
Feature | Local Module | Third-Party Module | Username/Password |
---|---|---|---|
Privacy | ✅ 100% Local | ❌ External relay | ✅ Local |
Security | ✅ Your keys only | ❌ External keys | ⚠️ Password auth |
Reliability | ✅ No external deps | ❌ Service dependent | ✅ Direct connection |
Performance | ✅ Direct access | ❌ Network latency | ⚠️ Limited features |
Full Features | ✅ Complete API | ✅ Complete API | ❌ Basic only |
Setup Complexity | ⚠️ Module install | ⚠️ External signup | ✅ Simple |
Your FoundryVTT user needs these permissions:
Ask your AI assistant things like:
Dice Rolling:
Game Data:
Content Generation:
Rule Lookups:
Tactical Advice:
World Building:
search_actors
- Find characters, NPCs, monsterssearch_items
- Find equipment, spells, consumablessearch_journals
- Search notes and handoutsget_scene_info
- Current scene detailsget_actor_details
- Detailed character informationroll_dice
- Roll dice with any formulaupdate_actor_hp
- Modify character healthget_combat_status
- Combat state and initiativelookup_rule
- Game rules and spell descriptionsgenerate_npc
- Create random NPCsgenerate_loot
- Create treasure appropriate for levelroll_table
- Random encounters, events, weathersuggest_tactics
- Combat advice and strategyThe server exposes these FoundryVTT resources:
foundry://world/info
- World and campaign informationfoundry://world/actors
- All actors in the worldfoundry://scene/current
- Current active scenefoundry://combat/current
- Active combat statefoundry://compendium/spells
- Spell databasefoundry://compendium/monsters
- Monster databaseEdit .env
to customize:
# Logging LOG_LEVEL=info # debug, info, warn, error # Performance FOUNDRY_TIMEOUT=10000 # Request timeout (ms) FOUNDRY_RETRY_ATTEMPTS=3 # Retry failed requests CACHE_TTL_SECONDS=300 # Cache data for 5 minutes
# Test FoundryVTT connection curl http://localhost:30000/api/status # Check server logs npm run dev # Shows detailed logging
"Failed to connect to FoundryVTT"
"Authentication failed"
"Tool not found" errors
src/
├── config/ # Configuration management
├── foundry/ # FoundryVTT client and types
├── tools/ # MCP tool definitions
├── resources/ # MCP resource definitions
├── utils/ # Utilities and logging
└── index.ts # Main server entry point
src/tools/index.ts
src/index.ts
src/foundry/client.ts
src/foundry/types.ts
# Run tests npm test # Run with coverage npm run test:coverage # Lint code npm run lint
# Development build npm run build # Clean build npm run clean && npm run build
Variable | Required | Description | Default |
---|---|---|---|
FOUNDRY_URL | ✅ | FoundryVTT server URL | - |
FOUNDRY_API_KEY | ⭐ | API key for authentication | - |
FOUNDRY_USERNAME | ⭐ | Username (if no API key) | - |
FOUNDRY_PASSWORD | ⭐ | Password (if no API key) | - |
LOG_LEVEL | ❌ | Logging verbosity | info |
NODE_ENV | ❌ | Environment mode | development |
FOUNDRY_TIMEOUT | ❌ | Request timeout (ms) | 10000 |
FOUNDRY_RETRY_ATTEMPTS | ❌ | Retry failed requests | 3 |
CACHE_TTL_SECONDS | ❌ | Cache duration | 300 |
⭐ Either API key OR username/password required
{ "formula": "1d20+5", "reason": "Attack roll against goblin" }
{ "query": "goblin", "type": "npc", "limit": 10 }
{ "race": "human", "level": 5, "role": "merchant", "alignment": "neutral good" }
Add to your Claude Desktop MCP settings:
{ "mcpServers": { "foundry": { "command": "node", "args": ["/path/to/foundry-mcp-server/dist/index.js"], "env": { "FOUNDRY_URL": "http://localhost:30000", "FOUNDRY_API_KEY": "your_api_key_here" } } } }
import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; const transport = new StdioClientTransport({ command: 'node', args: ['./dist/index.js'] }); const client = new Client({ name: "foundry-client", version: "1.0.0" }, { capabilities: {} }); await client.connect(transport); // Roll dice const result = await client.request({ method: "tools/call", params: { name: "roll_dice", arguments: { formula: "1d20+5", reason: "Initiative roll" } } });
Complete API documentation is available in the docs/
directory, auto-generated from TypeScript source code and JSDoc comments.
Local development:
npm run docs # Generate documentation npm run docs:serve # Generate and serve locally
Online: Browse the docs/
folder in this repository or visit the GitHub Pages site (if enabled).
The documentation is automatically updated via GitHub Actions when source code changes.
git checkout -b feature/amazing-feature
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
MIT License - see LICENSE file for details.
Happy Gaming! 🎲