FoundryVTT MCP Server

FoundryVTT MCP Server

A Model Context Protocol server that integrates with FoundryVTT, allowing AI assistants to interact with tabletop gaming sessions through natural language to query actors, roll dice, generate content, and manage game worlds.

Category
访问服务器

README

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 actors, items, scenes, and journal entries
  • 📊 Game State - Access current scene, combat status, and world information
  • 🎭 Content Generation - Generate NPCs, loot, and random encounters
  • 📝 Rule Lookup - Query game rules and mechanical information

Real-time Integration

  • 🔄 Live Updates - WebSocket connection for real-time game state
  • ⚔️ Combat Management - Track initiative and combat state
  • 👥 User Awareness - See who's online and their status

AI-Powered Features

  • 🧠 Tactical Suggestions - Get combat advice and strategy tips
  • 🎪 Story Assistance - Generate plot hooks and narrative elements
  • 🎨 World Building - Create locations, NPCs, and quests on demand

Installation

Prerequisites

  • Node.js 18+
  • FoundryVTT server running and accessible
  • MCP-compatible AI client (Claude Desktop, etc.)

Setup

  1. Clone and install:
git clone <repository-url>
cd foundry-mcp-server
npm install
  1. Configure environment:
cp .env.example .env
# Edit .env with your FoundryVTT details
  1. Required environment variables:
FOUNDRY_URL=http://localhost:30000
FOUNDRY_API_KEY=your_api_key_here
# OR use username/password:
FOUNDRY_USERNAME=your_username
FOUNDRY_PASSWORD=your_password
  1. Build and start:
npm run build
npm start

Development Mode

npm run dev

FoundryVTT Configuration

Option 1: API Key (Recommended)

  1. In FoundryVTT, go to Settings → Configure Settings
  2. Enable "Enable API Access"
  3. Generate an API key for external access
  4. Add the key to your .env file

Option 2: Username/Password

  1. Ensure your FoundryVTT user has appropriate permissions
  2. Add credentials to .env file
  3. The server will authenticate automatically

Permissions Required

Your FoundryVTT user needs these permissions:

  • View actors, items, scenes, and journals
  • Create and modify journal entries (for content generation)
  • 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"
  • "Generate a tavern with NPCs and plot hooks"

Advanced Features

Rule Lookups:

  • "Look up the grappling rules"
  • "How does the Fireball spell work?"
  • "What are the conditions for being frightened?"

Tactical Advice:

  • "Suggest tactics for fighting a dragon"
  • "What should our wizard do this turn?"
  • "Analyze this combat encounter"

World Building:

  • "Create a mysterious forest location"
  • "Generate a side quest involving missing merchants"
  • "Design a magic item appropriate for level 8 characters"

Available Tools

Data Access

  • search_actors - Find characters, NPCs, monsters
  • search_items - Find equipment, spells, consumables
  • search_journals - Search notes and handouts
  • get_scene_info - Current scene details
  • get_actor_details - Detailed character information

Game Mechanics

  • roll_dice - Roll dice with any formula
  • update_actor_hp - Modify character health
  • get_combat_status - Combat state and initiative
  • lookup_rule - Game rules and spell descriptions

Content Generation

  • generate_npc - Create random NPCs
  • generate_loot - Create treasure appropriate for level
  • roll_table - Random encounters, events, weather
  • suggest_tactics - Combat advice and strategy

Available Resources

The server exposes these FoundryVTT resources:

  • foundry://world/info - World and campaign information
  • foundry://world/actors - All actors in the world
  • foundry://scene/current - Current active scene
  • foundry://combat/current - Active combat state
  • foundry://compendium/spells - Spell database
  • foundry://compendium/monsters - Monster database

Configuration

Server Settings

Edit .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

Security

  • Use API keys instead of passwords when possible
  • Limit FoundryVTT user permissions to minimum required
  • Run server on internal network only
  • Monitor logs for suspicious activity

Troubleshooting

Connection Issues

# Test FoundryVTT connection
curl http://localhost:30000/api/status

# Check server logs
npm run dev  # Shows detailed logging

Common Problems

"Failed to connect to FoundryVTT"

  • Verify FOUNDRY_URL is correct
  • Check if FoundryVTT is running
  • Ensure API access is enabled

"Authentication failed"

  • Verify API key or username/password
  • Check user permissions in FoundryVTT
  • Ensure user is not banned/restricted

"Tool not found" errors

  • Update to latest server version
  • Check tool name spelling
  • Review available tools in logs

Development

Project Structure

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

Adding New Tools

  1. Define tool schema in src/tools/index.ts
  2. Add handler method in src/index.ts
  3. Implement FoundryVTT API calls in src/foundry/client.ts
  4. Add TypeScript types in src/foundry/types.ts
  5. Test with your AI assistant

Testing

# Run tests
npm test

# Run with coverage
npm run test:coverage

# Lint code
npm run lint

Building

# Development build
npm run build

# Clean build
npm run clean && npm run build

API Reference

Environment Variables

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

Tool Schemas

roll_dice

{
  "formula": "1d20+5",
  "reason": "Attack roll against goblin"
}

search_actors

{
  "query": "goblin",
  "type": "npc",
  "limit": 10
}

generate_npc

{
  "race": "human",
  "level": 5,
  "role": "merchant",
  "alignment": "neutral good"
}

Integration Examples

Claude Desktop Configuration

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"
      }
    }
  }
}

Custom MCP Client

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"
    }
  }
});

Roadmap

Version 0.2.0

  • [ ] Combat management tools (start/end combat, advance initiative)
  • [ ] Token manipulation (move, update status effects)
  • [ ] Scene navigation and switching
  • [ ] Playlist controls and ambient audio

Version 0.3.0

  • [ ] Character sheet editing (level up, add equipment)
  • [ ] Journal entry creation and editing
  • [ ] Macro execution and management
  • [ ] Advanced content generation (dungeons, NPCs with full stats)

Version 1.0.0

  • [ ] Multi-world support
  • [ ] User permission management
  • [ ] Webhook support for external triggers
  • [ ] Performance optimization and caching
  • [ ] Full test coverage
  • [ ] 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:

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).

📚 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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Commit: git commit -m 'Add amazing feature'
  5. Push: git push origin feature/amazing-feature
  6. Open 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.

Support

Acknowledgments

  • FoundryVTT team for the excellent VTT platform
  • Anthropic for the Model Context Protocol
  • The tabletop gaming community for inspiration and feedback

Happy Gaming! 🎲

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选