Skip to main content
Glama
Foundry REST API MCP

Foundry REST API MCP

by zagushka

Foundry REST API MCP

Node.js 20+ Model Context Protocol License: MIT

An MCP server that lets MCP clients work with a Foundry VTT world through the FoundryVTT REST API Relay. It is the client-facing component of the ThreeHats ecosystem:

Foundry VTT + REST API Module  <-- WebSocket -->  REST API Relay  <-- HTTPS -->  this MCP server

The MCP server connects to the relay's HTTP(S) API. Do not use the module's ws:// or wss:// relay URL for FOUNDRY_REST_API_BASE_URL.

Ecosystem and compatibility

Component

Role

FoundryVTT REST API Module

Connects a Foundry world to the relay over WebSocket.

FoundryVTT REST API Relay

Exposes the authenticated HTTP API used by this server.

Foundry REST API MCP

Exposes supported relay operations as typed foundry_* MCP tools.

Use the upstream relay documentation for module pairing, relay deployment, API-key management, and the complete REST API reference.

This project supports the relay's optional clientId and userId request scoping. A scoped API key can bind either value so the MCP client does not need to provide it. A key scoped to one world therefore does not require FOUNDRY_CLIENT_ID.

Related MCP server: FoundryMCP

Quick start

  1. Install and pair the Foundry module with either the public relay or your self-hosted relay.

  2. Create an API key in the relay with only the scopes needed for the tools you intend to use.

  3. Add this server to Codex in ~/.codex/config.toml:

[mcp_servers.foundry]
command = "npx"
args = [
  "--yes",
  "github:zagushka/foundry-rest-api-mcp#v0.5.0"
]

[mcp_servers.foundry.env]
# Public relay:
FOUNDRY_REST_API_BASE_URL = "https://foundryrestapi.com"
FOUNDRY_REST_API_KEY = "replace-with-a-scoped-secret"

# Optional: omit when the key is already scoped to exactly one world.
# FOUNDRY_CLIENT_ID = "fvtt_..."

Restart Codex after changing the configuration. Codex starts this stdio server automatically; it does not expose its own HTTP port.

Self-hosted relay

Use the HTTP API address of your relay instead of its WebSocket address. The standard local relay API listens on port 3011:

[mcp_servers.foundry.env]
FOUNDRY_REST_API_BASE_URL = "http://localhost:3011"
FOUNDRY_REST_API_KEY = "replace-with-a-scoped-secret"
# FOUNDRY_CLIENT_ID = "fvtt_..."

If Codex should inherit variables already available in its environment, use env_vars instead:

[mcp_servers.foundry]
command = "npx"
args = [
  "--yes",
  "github:zagushka/foundry-rest-api-mcp#v0.5.0"
]
env_vars = [
  "FOUNDRY_REST_API_BASE_URL",
  "FOUNDRY_REST_API_KEY",
  "FOUNDRY_CLIENT_ID"
]

The Git tag pins the installed release. Change it deliberately when upgrading.

Supported tools and permissions

All exposed tools begin with foundry_ and publish typed MCP parameters. Request the smallest set of relay scopes needed for the tools you enable:

Tool group

Capabilities

Relay scopes

World content and folders

Inspect connected worlds; inspect, search, create, update, and delete entities and folders

clients:read, structure:read, structure:write, entity:read, entity:write, search

Users

List users, create an isolated bot/service user

user:read, user:write (create is GM-only)

Actor inventory and effects

Add, update, and delete embedded Item and ActiveEffect documents

entity:write, effects:write

Files

Browse file sources, download files, and upload base64-encoded files

file:read, file:write

Scenes and canvas

Manage scenes, canvas documents, token movement, selection, and distance measurement

scene:read, scene:write, canvas:read, canvas:write

Encounters and effects

Read and manage combats, combatants, turns, and active effects

encounter:read, encounter:manage, effects:read, effects:write

Table play

Roll dice and read, send, or delete chat messages

roll:read, roll:execute, chat:read, chat:write

Read-only tools advertise readOnlyHint: true. Tools that change world state advertise readOnlyHint: false; deletion tools and chat clearing also advertise destructiveHint: true. Treat a key that grants write scopes as a privileged credential and keep it outside Git.

Actor embedded documents

Use foundry_create_actor_embedded_documents, foundry_update_actor_embedded_documents, and foundry_delete_actor_embedded_documents to manage one actor's embedded Item or ActiveEffect documents. Pass the actor UUID (for example, Actor.abc123) and an array of document data or IDs. Updates require each document's _id or id.

The relay exposes no dedicated Actor.createEmbeddedDocuments route. For items, the create tool uses its supported actor items upsert; for effects, it uses the relay's effect endpoint. Updating and deleting target the embedded document UUIDs directly.

External bot users and private replies

Use foundry_list_users to find the Foundry user ID for FOUNDRY_BOT_USER_ID; the relay resolves clientId automatically when the API key is locked to one world. foundry_create_user is available only to a GM key with user:write; it accepts no password and returns only a safe subset of user fields.

Use foundry_get_current_client (or foundry_list_clients for more than one connected world) to diagnose the resolved clientId, world ID/title, Foundry version, and connection status without setting FOUNDRY_CLIENT_ID manually.

For every bot reply use foundry_send_chat_as_user, not the generic chat tool. It sends the requested userId to the relay and rejects a response whose ChatMessage.author.id differs. The relay is the authorization boundary: a scoped API key forcibly replaces userId, so callers cannot impersonate another user; an unscoped GM key may choose an author.

For a private reply, pass chatType: 3 and whisper: [originatingPlayerUserId]. The optional live test verifies the complete flow, including invisibility to an unrelated player:

FOUNDRY_REST_API_BASE_URL=https://relay.example \
FOUNDRY_BOT_API_KEY=... FOUNDRY_PLAYER_API_KEY=... FOUNDRY_OTHER_PLAYER_API_KEY=... \
FOUNDRY_BOT_USER_ID=... FOUNDRY_PLAYER_USER_ID=... \
npm run test:private-bot-reply

It intentionally creates two Whisper messages and does not remove them. Use test-world scoped keys with chat:write for the bot/player and chat:read for the unrelated-player visibility check.

The server deliberately does not expose D&D5e-specific operations, sessions, macros, playlists, arbitrary JavaScript, relay authentication management, or SSE/WebSocket subscriptions. Use the upstream API directly when one of those capabilities is required.

Local development

git clone https://github.com/zagushka/foundry-rest-api-mcp.git
cd foundry-rest-api-mcp
npm ci
npm test

For a manual local run, copy .env.example to .env, fill in the relay address and API key, then run:

npm run build
npm run start:env

License

MIT © Peter Pshenichny

Available Tools

53 tools
foundry_add_effectC

Add a status or custom active effect.

Inputs: uuid (required), userId, clientId, statusId, +1 more.

foundry_add_to_encounterB

Add selected or named tokens to an encounter.

Inputs: uuids, userId, clientId, selected, +2 more.

foundry_clear_chatA
Destructive

Permanently clear all chat messages.

Inputs: userId, clientId.

foundry_create_actor_embedded_documentsA

Add Items or ActiveEffects to one actor. Item creation uses the relay's supported Actor items upsert.

Inputs: actorUuid (required), documents (required), documentType (required), userId, +1 more.

foundry_create_canvas_documentsA

Create one or more canvas embedded documents.

Inputs: data (required), documentType (required), userId, sceneId, +1 more.

foundry_create_entityC

Create a Foundry world entity.

Inputs: data (required), entityType (required), folder, keepId, +3 more.

foundry_create_folderC

Create a Foundry folder.

Inputs: name (required), folderType (required), userId, clientId, +1 more.

foundry_create_sceneC

Create a new scene.

Inputs: data (required), userId, clientId.

foundry_create_userA

Create a Foundry service or bot user. Requires relay scope user:write and GM access. The tool never accepts, returns, or logs a password.

Inputs: name (required), role (required), color, active, +2 more.

foundry_delete_actor_embedded_documentsB
Destructive

Delete Items or ActiveEffects embedded in one actor.

Inputs: actorUuid (required), documentIds (required), documentType (required), userId, +1 more.

foundry_delete_canvas_documentB
Destructive

Delete one canvas embedded document.

Inputs: documentId (required), documentType (required), userId, sceneId, +1 more.

foundry_delete_chat_messageA
Destructive

Delete one chat message.

Inputs: messageId (required), userId, clientId.

foundry_delete_entityB
Destructive

Delete a Foundry entity by UUID or the current selection.

Inputs: uuid, userId, clientId, selected.

foundry_delete_folderA
Destructive

Delete a Foundry folder; deleteAll also deletes its contents.

Inputs: folderId (required), userId, clientId, deleteAll.

foundry_delete_sceneB
Destructive

Delete a scene by ID or name.

Inputs: name, userId, sceneId, clientId.

foundry_download_fileB
Read-only

Download a file from a Foundry file source.

Inputs: path (required), format, source, userId, +1 more.

foundry_end_encounterC

End an encounter.

Inputs: userId, clientId, encounter.

foundry_get_canvas_documentsB
Read-only

Get canvas embedded documents from a scene.

Inputs: documentType (required), userId, sceneId, clientId, +1 more.

foundry_get_current_clientA
Read-only

Get the relay's currently resolved Foundry world. With a scoped key this identifies its clientId without FOUNDRY_CLIENT_ID.

Inputs: no named parameters.

foundry_get_effectsA
Read-only

Get active effects on an actor or token.

Inputs: uuid (required), userId, clientId.

foundry_get_entityB
Read-only

Get one Foundry document by UUID, such as Actor.abc123.

Inputs: uuid, actor, userId, clientId, +1 more.

foundry_get_folderA
Read-only

Get a folder and its contents by name.

Inputs: name (required), userId, clientId.

foundry_get_last_rollC
Read-only

Get the latest roll.

Inputs: userId, clientId.

foundry_get_scenesC
Read-only

Get one or more scenes.

Inputs: all, name, active, userId, +3 more.

foundry_get_selected_tokensB
Read-only

Get tokens selected in the Foundry client.

Inputs: userId, clientId.

foundry_get_structureC
Read-only

Read folders and document references from a Foundry world.

Inputs: path, types, userId, clientId, +3 more.

foundry_list_chat_messagesA
Read-only

Get chat messages with optional pagination and filters.

Inputs: limit, offset, userId, speaker, +2 more.

foundry_list_clientsA
Read-only

List Foundry VTT worlds connected to the relay, including their connection status and Foundry version.

Inputs: no named parameters.

foundry_list_encountersA
Read-only

List active encounters.

Inputs: userId, clientId.

foundry_list_filesA
Read-only

List files and directories in a Foundry file source.

Inputs: path, source, userId, clientId, +1 more.

foundry_list_rollsC
Read-only

Get recent rolls.

Inputs: limit, userId, clientId.

foundry_list_status_effectsB
Read-only

List status effects supported by the game system.

Inputs: userId, clientId.

foundry_list_usersA
Read-only

List Foundry users as id, name, role, isGM, active, and avatar. Requires relay scope user:read and GM access; clientId is auto-resolved for a scoped key.

Inputs: clientId.

foundry_measure_distanceB
Read-only

Measure distance between two points or tokens.

Inputs: userId, originX, originY, sceneId, +7 more.

foundry_move_tokenC

Move a token to canvas coordinates.

Inputs: x (required), y (required), name, uuid, +5 more.

foundry_next_roundB

Advance to the next encounter round.

Inputs: userId, clientId, encounter.

foundry_next_turnC

Advance to the next encounter turn.

Inputs: userId, clientId, encounter.

foundry_previous_roundB

Return to the previous encounter round.

Inputs: userId, clientId, encounter.

foundry_previous_turnB

Return to the previous encounter turn.

Inputs: userId, clientId, encounter.

foundry_remove_effectB
Destructive

Remove an active effect by ID or status.

Inputs: uuid (required), userId, clientId, effectId, +1 more.

foundry_remove_from_encounterC

Remove selected or named tokens from an encounter.

Inputs: uuids, userId, clientId, selected, +1 more.

foundry_rollC

Roll a dice formula.

Inputs: formula (required), flavor, userId, speaker, +3 more.

foundry_select_tokensC

Select tokens in the Foundry client.

Inputs: all, data, name, uuids, +3 more.

foundry_send_chat_as_userA

Create a chat message as a Foundry user and verify the returned ChatMessage.author.id. The relay permits this only for the API key's scoped user, or for a GM key; scoped keys cannot be overridden.

Inputs: userId (required), content (required), alias, speaker, +3 more.

foundry_send_chat_messageC

Create a chat message.

Inputs: content (required), alias, flavor, userId, +4 more.

foundry_start_encounterD

Start an encounter.

Inputs: name, tokens, userId, rollAll, +4 more.

foundry_switch_sceneB

Switch the player-facing active scene.

Inputs: name, userId, sceneId, clientId.

foundry_update_actor_embedded_documentsB

Update Items or ActiveEffects embedded in one actor.

Inputs: actorUuid (required), documents (required), documentType (required), userId, +1 more.

foundry_update_canvas_documentC

Update one canvas embedded document.

Inputs: data (required), documentId (required), documentType (required), userId, +2 more.

foundry_update_entityA

Update a Foundry entity by UUID or the current selection.

Inputs: data (required), uuid, actor, userId, +2 more.

foundry_update_sceneC

Update a scene by ID, name, or active status.

Inputs: data (required), name, active, userId, +2 more.

foundry_upload_fileB

Upload a base64-encoded file or data URL to a Foundry file source.

Inputs: fileData (required), filename (required), path, source, +4 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 53 tools

    Disambiguation5/5

    Each tool targets a distinct resource and action, following a clear verb_noun pattern. Even with 53 tools, descriptions are specific enough to avoid confusion between similar-sounding operations like get_folder vs get_structure or get_entity vs search.

    Naming Consistency4/5

    All tools share the 'foundry_' prefix and use a consistent verb_noun structure. Minor inconsistencies exist, such as create_canvas_documents (plural) versus update_canvas_document (singular) and send_chat_as_user versus send_chat_message, but these do not undermine overall predictability.

    Tool Count2/5

    With 53 tools, the server is well beyond the typical well-scoped range of 3-15. While the Foundry domain is broad, the excessive number of tools could overwhelm agents and makes navigation harder. Some tools, like the multiple encounter turn/round controls, could be consolidated.

    Completeness3/5

    The tool set covers many core Foundry operations, including entities, scenes, tokens, encounters, effects, rolls, and chat. However, there are notable gaps: users can be listed and created but not updated or deleted, encounters can be started/ended but not created or deleted, and folders have no update operation. These missing lifecycle operations limit full workflow coverage.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      A
      maintenance
      Connects Claude Desktop to Foundry VTT for AI-powered campaign management, enabling natural language interaction with game data including quest creation, character management, compendium searches, and dice rolling. Provides 20 MCP tools for seamless integration between Claude and your tabletop RPG sessions.
      85
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables direct interaction with FoundryVTT virtual tabletop servers via native WebSocket protocol. Supports retrieving, creating, modifying, and deleting game documents like actors, items, scenes, and journal entries without requiring additional modules.
      10 npm
      7
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients to interact with Foundry Virtual Tabletop worlds via a permissioned Windows host and GM-authorized browser companion, including document management, asset uploads, journal sessions, and background intelligence.
      10 npm
      MIT