This guide walks you through setting up the FoundryVTT MCP Server.
-
Install dependencies:
npm install
-
Copy environment file:
cp .env.example .env
-
Configure your connection (see below)
-
Start the server:
npm run dev
The MCP server connects to FoundryVTT via Socket.IO using a standard user account. No custom modules are required for full game data access.
- FoundryVTT server running with an active world (not on the setup screen)
- A FoundryVTT user account with appropriate permissions
Before configuring, determine your FoundryVTT deployment:
- FoundryVTT running on your local machine
- Typically uses
http://localhost:30000or similar - No reverse proxy or SSL/TLS
- FoundryVTT behind a reverse proxy (nginx, Apache, Caddy, etc.)
- Custom domains with SSL/TLS (e.g.,
https://foundry.example.com) - Cloud hosting or remote server deployments
- May use custom ports or paths
- FoundryVTT accessible via local network IP
- Different port configurations
- Direct IP access without domain names
Update your .env file based on your setup type:
Local Development:
FOUNDRY_URL=http://localhost:30000
FOUNDRY_USERNAME=your_username
FOUNDRY_PASSWORD=your_passwordReverse Proxy / Remote:
FOUNDRY_URL=https://foundry.example.com
FOUNDRY_USERNAME=your_username
FOUNDRY_PASSWORD=your_passwordNetwork/IP:
FOUNDRY_URL=http://192.168.1.100:30000
FOUNDRY_USERNAME=your_username
FOUNDRY_PASSWORD=your_passwordAll features work out of the box with username/password authentication:
- Search actors, items, scenes, and journals
- Get detailed actor/item information
- Dice rolling (evaluated locally in this mode; FoundryVTT's own
Rollengine — and with it parenthesised formulas — is used only whenFOUNDRY_API_KEYis set) - Combat state and initiative tracking
- Chat message history
- User list and online status
- Full-text world search
- World summary and scene information
- NPC and loot generation
- Rule lookups
| Variable | Required | Description | Default |
|---|---|---|---|
FOUNDRY_URL |
Yes | FoundryVTT server URL | - |
FOUNDRY_USERNAME |
Yes | FoundryVTT username | - |
FOUNDRY_PASSWORD |
Yes | FoundryVTT password | - |
FOUNDRY_USER_ID |
No | 16-char document _id (bypasses username resolution) |
- |
FOUNDRY_API_KEY |
No | REST API module key (enables diagnostics) | - |
LOG_LEVEL |
No | Logging level | info |
Installing the Foundry Local REST API module and setting FOUNDRY_API_KEY enables 5 server monitoring tools:
get_recent_logs- Retrieve filtered FoundryVTT logssearch_logs- Search logs by pattern, listing the matching entriesget_system_health- Server health status with versions, user/module counts, memory and log error counts (no CPU or disk metrics)diagnose_errors- stub: returns a fixed "no errors detected" summaryget_health_status- Comprehensive health diagnostics; note that in this mode the connection line reports the last REST request's outcome, not a live probe
To enable:
- Install the REST API module in FoundryVTT
- Enable it in your world and copy the generated API key
- Add
FOUNDRY_API_KEY=your_keyto your.envfile
npm run devLook for these success messages:
Connected to FoundryVTT successfully
FoundryVTT MCP Server running
Once the server is running, test these commands with your AI assistant:
Dice Rolling:
- "Roll 1d20+5 for an attack roll"
- "Roll 4d6 drop lowest for ability scores"
Data Queries:
- "Search for goblin actors"
- "Find all magic weapons"
- "What's the current scene information?"
- "Who's online?"
Content Generation:
- "Generate a random NPC"
- "Create some loot for a level 5 party"
- Check: FoundryVTT is running at the configured URL with an active world
- Check: No firewall blocking the connection
- Try: Test URL in browser (local:
http://localhost:30000, remote:https://foundry.example.com) - For reverse proxy: Ensure WebSocket upgrades are properly configured
- Check: Username matches a FoundryVTT user exactly (case-sensitive)
- Check: Password is correct
- Check: User has necessary permissions in FoundryVTT
- Try: Set
FOUNDRY_USER_IDto the 16-character document_idto bypass username resolution
- Check: A world is active in FoundryVTT (not on the setup screen)
- Check: Socket.IO authentication completed (check server logs)
- Try: Restart both FoundryVTT and the MCP server
- Check: Data exists in your FoundryVTT world
- Check: User has permission to view the data
- Check: World data loaded on connect (look for worldData log on startup)
- Check: FoundryVTT allows WebSocket connections
- Check: No proxy server blocking WebSocket upgrades
- Try: Different port or direct connection
SSL Certificate Problems:
- Check: SSL certificate is valid and not expired
- Check: Certificate includes your domain name
- Try: Test with curl:
curl -I https://foundry.example.com
Proxy Configuration:
- Nginx: Ensure
proxy_set_header Upgrade $http_upgrade;andproxy_set_header Connection "upgrade"; - Apache: Enable
mod_proxy_wstunnelfor WebSocket support - Caddy: WebSocket support is automatic with
reverse_proxy
Port and Path Issues:
- Check: Reverse proxy forwards to correct FoundryVTT port (usually 30000)
- Check: No path conflicts (e.g.,
/socket.io/path is preserved) - Try: Direct connection to bypass proxy temporarily
- Check logs: Run with
LOG_LEVEL=debugfor detailed information - Test manually: Try accessing FoundryVTT directly in your browser
- Network issues: Verify firewall and network configuration
If username resolution fails, set the user ID directly. Find the 16-character document _id for your user in FoundryVTT's data:
FOUNDRY_USER_ID=abc123def456ghijIf FoundryVTT uses a custom socket path:
FOUNDRY_SOCKET_PATH=/custom/socket/path/For slow connections, increase timeouts:
FOUNDRY_TIMEOUT=30000
FOUNDRY_RETRY_ATTEMPTS=5
FOUNDRY_RETRY_DELAY=2000For production use:
NODE_ENV=production
LOG_LEVEL=warnOnce you have a working connection:
- Explore all available tools: Check the README for a complete list
- Customize for your game: Many tools can be configured for specific game systems
- Add more features: The server is extensible - add your own tools and resources
- Contribute: Found bugs or want new features? Contributions welcome!
- FoundryVTT v11+: Fully supported
- FoundryVTT v10: Basic support
- Earlier versions: Not tested, may work with limitations
Need more help? Check the main README or open an issue on GitHub.