Provides community support through the FoundryVTT Discord server's #api-development channel
Used for configuration management of the MCP server through environment variables
Used for installation (cloning repository), issue tracking for bugs and feature requests, and contributing through pull requests
Automatically updates documentation when source code changes
Mentioned as a potential hosting option for the server's documentation
Serves as the runtime environment for the MCP server, required as a prerequisite (v18+) for running the FoundryVTT MCP server
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@FoundryVTT MCP Serverroll 1d20+5 for my fighter's attack"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
FoundryVTT MCP Server
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.
Features
Core Functionality
Dice Rolling - Roll dice with standard RPG notation
Data Querying - Search and inspect actors, items, scenes, and journal entries
Game State - Access combat status, chat messages, user list, and world information
Content Generation - Generate NPCs, loot tables, and rule lookups
World Search - Full-text search across all game entities
Real-time Integration
Live Connection - Socket.IO connection loads complete world state on connect
Combat Tracking - Access initiative order and combat state
User Awareness - See who's online and their current status
Chat Messages - Read recent chat history
Related MCP server: Godot MCP
Installation
Prerequisites
Node.js 18+
FoundryVTT server running with an active world
MCP-compatible AI client (Claude Desktop, etc.)
Quick Setup (Recommended)
Interactive Setup Wizard:
The setup wizard will:
Automatically detect your FoundryVTT server
Test connectivity and authentication
Generate your
.envconfiguration fileValidate the complete setup
Manual Setup
Clone and install:
Configure environment:
Required environment variables:
Test and start:
Development Mode
FoundryVTT Configuration
The MCP server connects to FoundryVTT via Socket.IO using a standard FoundryVTT user account. No custom modules are required for full game data access.
Setup
Ensure FoundryVTT is running with an active world (not on the setup screen)
Create or use an existing FoundryVTT user account with appropriate permissions
Add credentials to your
.envfile:
The server authenticates via a 4-step Socket.IO flow:
Fetches the
/joinpage to obtain a session cookieExtracts the session cookie from the response
Resolves the username to a user ID (or uses
FOUNDRY_USER_IDif set)Emits
joinGamewith credentials to receive the complete world state
Optional: Diagnostics Tools
Installing the Foundry Local REST API module adds 5 server monitoring tools (get_recent_logs, search_logs, get_system_health, diagnose_errors, get_health_status):
In FoundryVTT: Setup > Add-on Modules > Install Module
Paste:
https://github.com/laurigates/foundryvtt-mcp/releases/latest/download/module.jsonEnable the module in your world and copy the generated API key
Add to
.env:FOUNDRY_API_KEY=your_api_key_here
Required Permissions
Your FoundryVTT user needs these permissions:
View actors, items, scenes, and journals
Access compendium data
Use dice rolling API
Usage
Basic Queries
Ask your AI assistant things like:
Dice Rolling:
"Roll 1d20+5 for an attack roll"
"Roll 4d6 drop lowest for ability scores"
"Roll 2d10+3 for damage"
Game Data:
"Show me all the NPCs in this scene"
"Find magic weapons in the party's inventory"
"What's the current combat initiative order?"
"Search for healing potions"
Content Generation:
"Generate a random NPC merchant"
"Create loot for a CR 5 encounter"
"Look up the grappling rules"
World Search:
"Search the world for anything related to dragons"
"Give me a summary of the current world state"
"Who's online right now?"
Available Tools
Data Access
search_actors- Find characters, NPCs, monstersget_actor_details- Detailed character informationsearch_items- Find equipment, spells, consumablesget_scene_info- Current scene detailssearch_journals- Search notes and handoutsget_journal- Retrieve a specific journal entryget_users- List online users and their statusget_combat_state- Combat state and initiative orderget_chat_messages- Recent chat history
World
search_world- Full-text search across all game entitiesget_world_summary- Overview of the current world staterefresh_world_data- Reload world data from FoundryVTT
Game Mechanics
roll_dice- Roll dice with any formulalookup_rule- Game rules and spell descriptions
Content Generation
generate_npc- Create random NPCsgenerate_loot- Create treasure appropriate for level
Diagnostics (Optional — requires REST API module)
get_recent_logs- Retrieve filtered FoundryVTT logssearch_logs- Search logs with regex patternsget_system_health- Server performance and health metricsdiagnose_errors- Analyze errors with troubleshooting suggestionsget_health_status- Comprehensive health diagnostics
Available Resources
The server exposes these FoundryVTT resources:
foundry://actors- All actors in the worldfoundry://items- All items in the worldfoundry://scenes- All scenesfoundry://scenes/current- Current active scenefoundry://journals- All journal entriesfoundry://users- Online usersfoundry://combat- Active combat statefoundry://world/settings- World and campaign settingsfoundry://system/diagnostics- System diagnostics (requires REST API module)
Configuration
Server Settings
Edit .env to customize:
Security
Limit FoundryVTT user permissions to minimum required
Run server on internal network only
Monitor logs for suspicious activity
Diagnostics & Troubleshooting
Built-in Diagnostics
The server includes diagnostic tools to help troubleshoot connection and performance issues:
Connection Testing:
Diagnostic Tools (via AI assistant):
System Health: "Get the FoundryVTT system health status" (requires REST API module)
Error Analysis: "Diagnose recent errors and provide recommendations" (requires REST API module)
Log Search: "Search logs for 'connection' patterns in the last hour" (requires REST API module)
Connection Issues
Common Problems
"Failed to connect to FoundryVTT"
Verify FOUNDRY_URL is correct
Check if FoundryVTT is running with an active world
Ensure the URL is accessible from where the MCP server runs
"Authentication failed"
Verify username and password match a FoundryVTT user exactly (case-sensitive)
Check user permissions in FoundryVTT
Try setting
FOUNDRY_USER_IDto the 16-character document_id
"Tool not found" errors
Update to latest server version
Check tool name spelling
Review available tools in logs
Development
Project Structure
Adding New Tools
Define tool schema in
src/tools/definitions.tsAdd handler in
src/tools/handlers/Wire the handler in
src/tools/router.tsAdd TypeScript types in
src/foundry/types.tsif neededTest with your AI assistant
Testing
Building
API Reference
Environment Variables
Variable | Required | Description | Default |
| Yes | FoundryVTT server URL | - |
| Yes | FoundryVTT username | - |
| Yes | FoundryVTT password | - |
| No | 16-char document | - |
| No | REST API module key (enables diagnostics) | - |
| No | Logging verbosity |
|
| No | Environment mode |
|
| No | Request timeout (ms) |
|
| No | Retry failed requests |
|
| No | Delay between retries (ms) |
|
| No | Enable response caching |
|
| No | Cache duration (seconds) |
|
| No | Maximum cache entries | - |
Tool Schemas
roll_dice
search_world
get_combat_state
search_actors
Integration Examples
Claude Desktop Configuration
Add to your Claude Desktop MCP settings:
To enable optional diagnostics tools, add FOUNDRY_API_KEY to the env block:
Custom MCP Client
Roadmap
Completed
Socket.IO authentication and world data loading
Combat state tracking
User awareness (online status)
Journal access and search
World-wide search across all entities
Chat message history
NPC and loot generation
Rule lookups
Planned
Combat management (start/end combat, advance initiative)
Token manipulation (move, update status effects)
Scene navigation and switching
Character sheet editing (level up, add equipment)
Journal entry creation and editing
Macro execution and management
Multi-world support
Docker deployment
Documentation
Complete API documentation is available in the docs/ directory, auto-generated from TypeScript source code and JSDoc comments.
Viewing Documentation
Local development:
Online: Browse the docs/ folder in this repository or visit the GitHub Pages site (if enabled).
What's Documented
FoundryClient API - Complete client documentation with examples
TypeScript Interfaces - All data structures and type definitions
Configuration - Environment variables and setup options
Utilities - Helper functions and logging
Usage Examples - Code samples for common operations
The documentation is automatically updated via GitHub Actions when source code changes.
Contributing
Fork the repository
Create a feature branch:
git checkout -b feature/amazing-featureMake your changes and add tests
Commit:
git commit -m 'Add amazing feature'Push:
git push origin feature/amazing-featureOpen a Pull Request
Code Style
Use TypeScript strict mode
Follow existing naming conventions
Add JSDoc comments for public APIs
Write tests for new functionality
Use meaningful commit messages
License
MIT License - see LICENSE file for details.
Troubleshooting
Quick Diagnostics
Health Check
Use the get_health_status MCP tool for comprehensive diagnostics (requires REST API module), or check server logs during startup for detailed status information.
Common Issues
Connection refused: Ensure FoundryVTT is running with an active world on the configured port
Authentication failed: Verify username/password match a FoundryVTT user exactly
Empty search results: Ensure a world is active (not on setup screen) and the user has view permissions
World data not loading: Check that Socket.IO authentication completed successfully
Detailed troubleshooting guide: TROUBLESHOOTING.md
Support
Issues: GitHub Issues for bugs and feature requests
Discord: FoundryVTT Discord #api-development
Documentation: FoundryVTT API Docs
Troubleshooting: TROUBLESHOOTING.md
Acknowledgments
FoundryVTT team for the excellent VTT platform
Anthropic for the Model Context Protocol
The tabletop gaming community for inspiration and feedback