@g33ks/foundryvtt-mcp 0.0.0-stage → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +457 -2
  3. package/dist/character/manager.js +208 -0
  4. package/dist/cli/checks.js +307 -0
  5. package/dist/cli/config-file.js +120 -0
  6. package/dist/cli/init.js +414 -0
  7. package/dist/cli/prompt.js +117 -0
  8. package/dist/cli/snippets.js +64 -0
  9. package/dist/combat/manager.js +371 -0
  10. package/dist/config/env-layers.js +49 -0
  11. package/dist/config/index.js +298 -0
  12. package/dist/config/sources.js +201 -0
  13. package/dist/core.js +481 -0
  14. package/dist/diagnostics/client.js +291 -0
  15. package/dist/diagnostics/types.js +94 -0
  16. package/dist/foundry/auth.js +224 -0
  17. package/dist/foundry/browser-detect.js +170 -0
  18. package/dist/foundry/client.js +5874 -0
  19. package/dist/foundry/dice-formula.js +154 -0
  20. package/dist/foundry/event-log.js +298 -0
  21. package/dist/foundry/headless-gm-session.js +857 -0
  22. package/dist/foundry/journal-conflicts.js +141 -0
  23. package/dist/foundry/journal-history.js +90 -0
  24. package/dist/foundry/journal-integrity.js +322 -0
  25. package/dist/foundry/message-author.js +19 -0
  26. package/dist/foundry/module-bridge.js +441 -0
  27. package/dist/foundry/types.js +52 -0
  28. package/dist/foundry/world-cache.js +386 -0
  29. package/dist/index.js +107 -0
  30. package/dist/mcp-server.js +65 -0
  31. package/dist/server.js +159 -0
  32. package/dist/shared/build-order.js +134 -0
  33. package/dist/shared/config-hash.js +62 -0
  34. package/dist/shared/config-notice.js +55 -0
  35. package/dist/shared/control.js +291 -0
  36. package/dist/shared/daemon-link.js +135 -0
  37. package/dist/shared/daemon.js +311 -0
  38. package/dist/shared/ipc-client.js +200 -0
  39. package/dist/shared/ipc-server.js +316 -0
  40. package/dist/shared/paths.js +79 -0
  41. package/dist/shared/protocol.js +230 -0
  42. package/dist/shared/relay-config.js +65 -0
  43. package/dist/shared/relay.js +120 -0
  44. package/dist/shared/rotating-log.js +57 -0
  45. package/dist/shared/spawn.js +39 -0
  46. package/dist/shared/state-file.js +33 -0
  47. package/dist/shared/token.js +62 -0
  48. package/dist/shared/version.js +57 -0
  49. package/dist/tools/base.js +74 -0
  50. package/dist/tools/definitions.js +3109 -0
  51. package/dist/tools/handlers/actor-mutations.js +128 -0
  52. package/dist/tools/handlers/actors.js +114 -0
  53. package/dist/tools/handlers/chat-mutations.js +49 -0
  54. package/dist/tools/handlers/chat.js +38 -0
  55. package/dist/tools/handlers/combat-mutations.js +215 -0
  56. package/dist/tools/handlers/combat-order.js +94 -0
  57. package/dist/tools/handlers/combat.js +51 -0
  58. package/dist/tools/handlers/compendium.js +83 -0
  59. package/dist/tools/handlers/diagnostics.js +450 -0
  60. package/dist/tools/handlers/dice.js +54 -0
  61. package/dist/tools/handlers/effects.js +103 -0
  62. package/dist/tools/handlers/events.js +50 -0
  63. package/dist/tools/handlers/generation.js +258 -0
  64. package/dist/tools/handlers/item-mutations.js +132 -0
  65. package/dist/tools/handlers/items.js +53 -0
  66. package/dist/tools/handlers/journal-mutations.js +230 -0
  67. package/dist/tools/handlers/journals.js +80 -0
  68. package/dist/tools/handlers/module-bridge.js +421 -0
  69. package/dist/tools/handlers/placeable-mutations.js +272 -0
  70. package/dist/tools/handlers/resources.js +203 -0
  71. package/dist/tools/handlers/roll-tables.js +97 -0
  72. package/dist/tools/handlers/scene-mutations.js +159 -0
  73. package/dist/tools/handlers/scenes.js +355 -0
  74. package/dist/tools/handlers/settings.js +53 -0
  75. package/dist/tools/handlers/tile-mutations.js +56 -0
  76. package/dist/tools/handlers/token-mutations.js +356 -0
  77. package/dist/tools/handlers/users.js +59 -0
  78. package/dist/tools/handlers/utils.js +48 -0
  79. package/dist/tools/handlers/wall-mutations.js +98 -0
  80. package/dist/tools/handlers/world-documents.js +222 -0
  81. package/dist/tools/handlers/world.js +92 -0
  82. package/dist/tools/index.js +25 -0
  83. package/dist/tools/new-router.js +97 -0
  84. package/dist/tools/registry.js +79 -0
  85. package/dist/tools/resources.js +63 -0
  86. package/dist/tools/router.js +688 -0
  87. package/dist/tools/tool-dependencies.js +194 -0
  88. package/dist/tools/write-tools.js +97 -0
  89. package/dist/utils/cache-instance.js +30 -0
  90. package/dist/utils/cache.js +205 -0
  91. package/dist/utils/diagnostics.js +332 -0
  92. package/dist/utils/guards.js +17 -0
  93. package/dist/utils/image-size.js +160 -0
  94. package/dist/utils/log-args.js +47 -0
  95. package/dist/utils/logger.js +203 -0
  96. package/dist/utils/mcp-errors.js +47 -0
  97. package/dist/utils/refusal.js +30 -0
  98. package/dist/utils/sanitize.js +22 -0
  99. package/dist/utils/serial-queue.js +22 -0
  100. package/package.json +124 -4
@@ -0,0 +1,688 @@
1
+ /**
2
+ * Tool routing and handler coordination
3
+ */
4
+ import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
5
+ import { logger } from '../utils/logger.js';
6
+ import { handleCreateFullActor, handleCreateWorldActor, handleDeleteWorldActor, handleUpdateActorAttribute, } from './handlers/actor-mutations.js';
7
+ import { handleGetActorDetails, handleGetActorInventory, handleSearchActors, } from './handlers/actors.js';
8
+ import { handleGetChatMessages } from './handlers/chat.js';
9
+ import { handleSendChatMessage } from './handlers/chat-mutations.js';
10
+ import { handleGetCombatState } from './handlers/combat.js';
11
+ import { handleEndCombat, handleNextTurn, handleSetInitiative, handleStartCombat, } from './handlers/combat-mutations.js';
12
+ import { handleSearchCompendium } from './handlers/compendium.js';
13
+ import { handleDiagnoseErrors, handleGetHealthStatus, handleGetRecentLogs, handleGetSystemHealth, handleSearchLogs, } from './handlers/diagnostics.js';
14
+ // Import all tool handlers
15
+ import { handleRollDice } from './handlers/dice.js';
16
+ import { handleCreateActorEffect, handleDeleteActorEffect, handleListActorEffects, handleUpdateActorEffect, } from './handlers/effects.js';
17
+ import { handleWatchEvents } from './handlers/events.js';
18
+ import { handleGenerateLoot, handleGenerateNPC, handleLookupRule } from './handlers/generation.js';
19
+ import { handleCreateActorItem, handleDeleteActorItem, handleUpdateActorItem, } from './handlers/item-mutations.js';
20
+ import { handleSearchItems } from './handlers/items.js';
21
+ import { handleAddJournalPage, handleCreateJournalEntry, handleDeleteJournalEntry, handleUpdateJournalEntry, handleUpdateJournalPage, } from './handlers/journal-mutations.js';
22
+ import { handleGetJournal, handleSearchJournals } from './handlers/journals.js';
23
+ import { handleCaptureScene, handleGetDocumentSchema, handleGetTargets, handleImportCompendiumActor, handlePingCanvas, handleRollAndPost, handleSearchCompendiumContent, handleSetPause, handleSetTarget, handleUploadAsset, } from './handlers/module-bridge.js';
24
+ import { handleCreateDrawing, handleCreateLight, handleCreateNote, handleCreateRegion, handleCreateSound, handleCreateTemplate, handleDeleteDrawing, handleDeleteLight, handleDeleteNote, handleDeleteRegion, handleDeleteSound, handleDeleteTemplate, handleUpdateLight, } from './handlers/placeable-mutations.js';
25
+ import { handleReadResource } from './handlers/resources.js';
26
+ import { handleCreateRollTable, handleDeleteRollTable, handleListRollTables, handleRollTable, } from './handlers/roll-tables.js';
27
+ import { handleCreateScene, handleDeleteScene, handleResetFog, handleSetSceneLighting, handleSetSceneWeather, handleSwitchScene, } from './handlers/scene-mutations.js';
28
+ import { handleFindOpenCells, handleGetSceneInfo, handleListDrawings, handleListLights, handleListNotes, handleListRegions, handleListSceneAssets, handleListSounds, handleListTemplates, handleListTiles, handleListTokens, handleListWalls, } from './handlers/scenes.js';
29
+ import { handleGetWorldSetting, handleSetWorldSetting } from './handlers/settings.js';
30
+ import { handleCreateTile, handleDeleteTile } from './handlers/tile-mutations.js';
31
+ import { handleApplyStatusEffect, handleDeleteToken, handleMoveToken, handleMoveTokenPathfind, handleMoveTokens, handleSpawnToken, handleUpdateTokenVision, } from './handlers/token-mutations.js';
32
+ import { handleGetUsers, handleSetUserRole } from './handlers/users.js';
33
+ import { handleCreateWall, handleDeleteWall, handleSetDoorState, } from './handlers/wall-mutations.js';
34
+ import { handleGetWorldSummary, handleRefreshWorldData, handleSearchWorld, } from './handlers/world.js';
35
+ import { handleCreateFolder, handleCreateMacro, handleCreatePlaylist, handleDeleteMacro, handleDeletePlaylist, handleListFolders, handleListMacros, handleListPlaylists, handleSetDocumentOwnership, handleSetPlaylistState, } from './handlers/world-documents.js';
36
+ import { toolRegistry } from './registry.js';
37
+ /**
38
+ * Routes tool requests to appropriate handlers
39
+ */
40
+ export async function routeToolRequest(name, args, foundryClient, diagnosticsClient, diagnosticSystem, moduleBridge = null, headlessGmSession = null, healthRuntime = {}) {
41
+ logger.debug(`Routing tool request: ${name}`, { args });
42
+ // Try the new registry system first
43
+ if (toolRegistry.has(name)) {
44
+ const context = {
45
+ foundryClient,
46
+ diagnosticsClient,
47
+ diagnosticSystem,
48
+ };
49
+ try {
50
+ return await toolRegistry.execute(name, args, context);
51
+ }
52
+ catch (error) {
53
+ if (error instanceof McpError) {
54
+ throw error;
55
+ }
56
+ throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
57
+ }
58
+ }
59
+ switch (name) {
60
+ // Dice tools
61
+ case 'roll_dice':
62
+ if (!('formula' in args) || typeof args.formula !== 'string') {
63
+ throw new Error('Missing required parameter: formula');
64
+ }
65
+ return handleRollDice(args, foundryClient);
66
+ // Actor tools
67
+ case 'search_actors':
68
+ return handleSearchActors(args, foundryClient);
69
+ case 'get_actor_details':
70
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
71
+ throw new Error('Missing required parameter: actorId');
72
+ }
73
+ return handleGetActorDetails(args, foundryClient);
74
+ case 'get_actor_inventory':
75
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
76
+ throw new Error('Missing required parameter: actorId');
77
+ }
78
+ return handleGetActorInventory(args, foundryClient);
79
+ // Actor mutation tools (laurigates/foundryvtt-mcp#143) — WRITE via the Socket.IO modifyDocument
80
+ // protocol (foundryClient); require FOUNDRY_WRITE_ENABLED=true + a GM user.
81
+ case 'update_actor_attributes':
82
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
83
+ throw new Error('Missing required parameter: actorId');
84
+ }
85
+ if (!('patch' in args) || typeof args.patch !== 'object' || args.patch === null) {
86
+ throw new Error('Missing required parameter: patch');
87
+ }
88
+ return handleUpdateActorAttribute(args, foundryClient);
89
+ case 'create_world_actor':
90
+ if (!('name' in args) || typeof args.name !== 'string') {
91
+ throw new Error('Missing required parameter: name');
92
+ }
93
+ if (!('type' in args) || typeof args.type !== 'string') {
94
+ throw new Error('Missing required parameter: type');
95
+ }
96
+ return handleCreateWorldActor(args, foundryClient);
97
+ case 'create_full_actor':
98
+ if (!('name' in args) || typeof args.name !== 'string') {
99
+ throw new Error('Missing required parameter: name');
100
+ }
101
+ if (!('type' in args) || typeof args.type !== 'string') {
102
+ throw new Error('Missing required parameter: type');
103
+ }
104
+ return handleCreateFullActor(args, foundryClient);
105
+ case 'delete_world_actor':
106
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
107
+ throw new Error('Missing required parameter: actorId');
108
+ }
109
+ return handleDeleteWorldActor(args, foundryClient);
110
+ // Item tools
111
+ case 'search_items':
112
+ return handleSearchItems(args, foundryClient);
113
+ // Compendium tools (laurigates/foundryvtt-mcp#144)
114
+ case 'search_compendium':
115
+ if (!('query' in args) || typeof args.query !== 'string') {
116
+ throw new Error('Missing required parameter: query');
117
+ }
118
+ return handleSearchCompendium(args, foundryClient);
119
+ // Item mutation tools (WRITE) — Socket.IO modifyDocument protocol
120
+ // (foundryClient); require FOUNDRY_WRITE_ENABLED=true + a GM user.
121
+ case 'create_actor_item':
122
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
123
+ throw new Error('Missing required parameter: actorId');
124
+ }
125
+ if (!('source' in args) || typeof args.source !== 'object' || args.source === null) {
126
+ throw new Error('Missing required parameter: source');
127
+ }
128
+ return handleCreateActorItem(args, foundryClient, moduleBridge);
129
+ case 'update_actor_item':
130
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
131
+ throw new Error('Missing required parameter: actorId');
132
+ }
133
+ if (!('itemId' in args) || typeof args.itemId !== 'string') {
134
+ throw new Error('Missing required parameter: itemId');
135
+ }
136
+ if (!('patch' in args) || typeof args.patch !== 'object' || args.patch === null) {
137
+ throw new Error('Missing required parameter: patch');
138
+ }
139
+ return handleUpdateActorItem(args, foundryClient);
140
+ case 'delete_actor_item':
141
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
142
+ throw new Error('Missing required parameter: actorId');
143
+ }
144
+ if (!('itemId' in args) || typeof args.itemId !== 'string') {
145
+ throw new Error('Missing required parameter: itemId');
146
+ }
147
+ return handleDeleteActorItem(args, foundryClient);
148
+ // Scene tools
149
+ case 'get_scene_info':
150
+ return handleGetSceneInfo(args, foundryClient);
151
+ case 'create_scene':
152
+ if (!('name' in args) || typeof args.name !== 'string') {
153
+ throw new Error('Missing required parameter: name');
154
+ }
155
+ if (!('backgroundSrc' in args) || typeof args.backgroundSrc !== 'string') {
156
+ throw new Error('Missing required parameter: backgroundSrc');
157
+ }
158
+ return handleCreateScene(args, foundryClient);
159
+ case 'switch_scene':
160
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
161
+ throw new Error('Missing required parameter: sceneId');
162
+ }
163
+ return handleSwitchScene(args, foundryClient);
164
+ case 'delete_scene':
165
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
166
+ throw new Error('Missing required parameter: sceneId');
167
+ }
168
+ return handleDeleteScene(args, foundryClient);
169
+ case 'set_scene_lighting':
170
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
171
+ throw new Error('Missing required parameter: sceneId');
172
+ }
173
+ return handleSetSceneLighting(args, foundryClient);
174
+ case 'reset_fog':
175
+ return handleResetFog(args, foundryClient);
176
+ case 'set_scene_weather':
177
+ if (!('weather' in args) || typeof args.weather !== 'string') {
178
+ throw new Error('Missing required parameter: weather');
179
+ }
180
+ return handleSetSceneWeather(args, foundryClient);
181
+ // Tile read tools
182
+ case 'list_scene_assets':
183
+ return handleListSceneAssets(args, foundryClient);
184
+ case 'list_tiles':
185
+ return handleListTiles(args, foundryClient);
186
+ case 'find_open_cells':
187
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
188
+ throw new Error('Missing required parameter: sceneId');
189
+ }
190
+ return handleFindOpenCells(args, foundryClient);
191
+ // Tile mutation tools
192
+ case 'create_tile':
193
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
194
+ throw new Error('Missing required parameter: sceneId');
195
+ }
196
+ if (!('src' in args) || typeof args.src !== 'string') {
197
+ throw new Error('Missing required parameter: src');
198
+ }
199
+ return handleCreateTile(args, foundryClient);
200
+ case 'delete_tile':
201
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
202
+ throw new Error('Missing required parameter: sceneId');
203
+ }
204
+ if (!('tileId' in args) || typeof args.tileId !== 'string') {
205
+ throw new Error('Missing required parameter: tileId');
206
+ }
207
+ return handleDeleteTile(args, foundryClient);
208
+ // Wall (structural) tools
209
+ case 'list_walls':
210
+ return handleListWalls(args, foundryClient);
211
+ case 'create_wall':
212
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
213
+ throw new Error('Missing required parameter: sceneId');
214
+ }
215
+ return handleCreateWall(args, foundryClient);
216
+ case 'delete_wall':
217
+ if (!('sceneId' in args) || typeof args.sceneId !== 'string') {
218
+ throw new Error('Missing required parameter: sceneId');
219
+ }
220
+ if (!('wallId' in args) || typeof args.wallId !== 'string') {
221
+ throw new Error('Missing required parameter: wallId');
222
+ }
223
+ return handleDeleteWall(args, foundryClient);
224
+ case 'set_door_state':
225
+ if (!('wallId' in args) || typeof args.wallId !== 'string') {
226
+ throw new Error('Missing required parameter: wallId');
227
+ }
228
+ if (!('state' in args) || typeof args.state !== 'number') {
229
+ throw new Error('Missing required parameter: state');
230
+ }
231
+ return handleSetDoorState(args, foundryClient);
232
+ // Placeable tools (read)
233
+ case 'list_lights':
234
+ return handleListLights(args, foundryClient);
235
+ case 'list_sounds':
236
+ return handleListSounds(args, foundryClient);
237
+ case 'list_notes':
238
+ return handleListNotes(args, foundryClient);
239
+ case 'list_drawings':
240
+ return handleListDrawings(args, foundryClient);
241
+ case 'list_templates':
242
+ return handleListTemplates(args, foundryClient);
243
+ case 'list_regions':
244
+ return handleListRegions(args, foundryClient);
245
+ // Placeable mutation tools (WRITE)
246
+ case 'create_light':
247
+ return handleCreateLight(args, foundryClient);
248
+ case 'update_light':
249
+ if (!('lightId' in args) || typeof args.lightId !== 'string') {
250
+ throw new Error('Missing required parameter: lightId');
251
+ }
252
+ return handleUpdateLight(args, foundryClient);
253
+ case 'delete_light':
254
+ if (!('lightId' in args) || typeof args.lightId !== 'string') {
255
+ throw new Error('Missing required parameter: lightId');
256
+ }
257
+ return handleDeleteLight(args, foundryClient);
258
+ case 'create_sound':
259
+ if (!('path' in args) || typeof args.path !== 'string') {
260
+ throw new Error('Missing required parameter: path');
261
+ }
262
+ return handleCreateSound(args, foundryClient);
263
+ case 'delete_sound':
264
+ if (!('soundId' in args) || typeof args.soundId !== 'string') {
265
+ throw new Error('Missing required parameter: soundId');
266
+ }
267
+ return handleDeleteSound(args, foundryClient);
268
+ case 'create_note':
269
+ return handleCreateNote(args, foundryClient);
270
+ case 'delete_note':
271
+ if (!('noteId' in args) || typeof args.noteId !== 'string') {
272
+ throw new Error('Missing required parameter: noteId');
273
+ }
274
+ return handleDeleteNote(args, foundryClient);
275
+ case 'create_drawing':
276
+ if (!('x' in args) || typeof args.x !== 'number') {
277
+ throw new Error('Missing required parameter: x');
278
+ }
279
+ if (!('y' in args) || typeof args.y !== 'number') {
280
+ throw new Error('Missing required parameter: y');
281
+ }
282
+ return handleCreateDrawing(args, foundryClient);
283
+ case 'delete_drawing':
284
+ if (!('drawingId' in args) || typeof args.drawingId !== 'string') {
285
+ throw new Error('Missing required parameter: drawingId');
286
+ }
287
+ return handleDeleteDrawing(args, foundryClient);
288
+ case 'create_template':
289
+ if (!('distance' in args) || typeof args.distance !== 'number') {
290
+ throw new Error('Missing required parameter: distance');
291
+ }
292
+ return handleCreateTemplate(args, foundryClient);
293
+ case 'delete_template':
294
+ if (!('templateId' in args) || typeof args.templateId !== 'string') {
295
+ throw new Error('Missing required parameter: templateId');
296
+ }
297
+ return handleDeleteTemplate(args, foundryClient);
298
+ case 'create_region':
299
+ if (!('name' in args) || typeof args.name !== 'string') {
300
+ throw new Error('Missing required parameter: name');
301
+ }
302
+ return handleCreateRegion(args, foundryClient);
303
+ case 'delete_region':
304
+ if (!('regionId' in args) || typeof args.regionId !== 'string') {
305
+ throw new Error('Missing required parameter: regionId');
306
+ }
307
+ return handleDeleteRegion(args, foundryClient);
308
+ // Combat tools
309
+ case 'get_combat_state':
310
+ return handleGetCombatState(args, foundryClient);
311
+ // Combat mutation tools (FR-018, WRITE — require FOUNDRY_WRITE_ENABLED)
312
+ case 'next_turn':
313
+ return handleNextTurn(args, foundryClient);
314
+ case 'end_combat':
315
+ return handleEndCombat(args, foundryClient);
316
+ case 'set_initiative':
317
+ if (!('combatantId' in args) || typeof args.combatantId !== 'string') {
318
+ throw new Error('Missing required parameter: combatantId');
319
+ }
320
+ if (!('initiative' in args) || typeof args.initiative !== 'number') {
321
+ throw new Error('Missing required parameter: initiative');
322
+ }
323
+ return handleSetInitiative(args, foundryClient);
324
+ case 'start_combat':
325
+ return handleStartCombat(args, foundryClient);
326
+ // Token tools (read) — pure reads over cached worldData, no write gate.
327
+ case 'list_tokens':
328
+ return handleListTokens(args, foundryClient);
329
+ // Token mutation tools (FR-019, WRITE — require FOUNDRY_WRITE_ENABLED)
330
+ case 'move_token':
331
+ if (!('tokenId' in args) || typeof args.tokenId !== 'string') {
332
+ throw new Error('Missing required parameter: tokenId');
333
+ }
334
+ if (!('x' in args) || typeof args.x !== 'number') {
335
+ throw new Error('Missing required parameter: x');
336
+ }
337
+ if (!('y' in args) || typeof args.y !== 'number') {
338
+ throw new Error('Missing required parameter: y');
339
+ }
340
+ return handleMoveToken(args, foundryClient);
341
+ case 'apply_status_effect':
342
+ if (!('tokenId' in args) || typeof args.tokenId !== 'string') {
343
+ throw new Error('Missing required parameter: tokenId');
344
+ }
345
+ if (!('statusId' in args) || typeof args.statusId !== 'string') {
346
+ throw new Error('Missing required parameter: statusId');
347
+ }
348
+ return handleApplyStatusEffect(args, foundryClient);
349
+ case 'spawn_token':
350
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
351
+ throw new Error('Missing required parameter: actorId');
352
+ }
353
+ if (!('x' in args) || typeof args.x !== 'number') {
354
+ throw new Error('Missing required parameter: x');
355
+ }
356
+ if (!('y' in args) || typeof args.y !== 'number') {
357
+ throw new Error('Missing required parameter: y');
358
+ }
359
+ return handleSpawnToken(args, foundryClient);
360
+ case 'delete_token':
361
+ if (!('tokenId' in args) || typeof args.tokenId !== 'string') {
362
+ throw new Error('Missing required parameter: tokenId');
363
+ }
364
+ return handleDeleteToken(args, foundryClient);
365
+ case 'move_token_pathfind':
366
+ if (!('tokenId' in args) || typeof args.tokenId !== 'string') {
367
+ throw new Error('Missing required parameter: tokenId');
368
+ }
369
+ if (!('x' in args) || typeof args.x !== 'number') {
370
+ throw new Error('Missing required parameter: x');
371
+ }
372
+ if (!('y' in args) || typeof args.y !== 'number') {
373
+ throw new Error('Missing required parameter: y');
374
+ }
375
+ return handleMoveTokenPathfind(args, foundryClient);
376
+ case 'move_tokens':
377
+ if (!('moves' in args) || !Array.isArray(args.moves)) {
378
+ throw new Error('Missing required parameter: moves');
379
+ }
380
+ return handleMoveTokens(args, foundryClient);
381
+ case 'update_token_vision':
382
+ if (!('tokenId' in args) || typeof args.tokenId !== 'string') {
383
+ throw new Error('Missing required parameter: tokenId');
384
+ }
385
+ return handleUpdateTokenVision(args, foundryClient);
386
+ // Chat tools
387
+ case 'get_chat_messages':
388
+ return handleGetChatMessages(args, foundryClient);
389
+ case 'send_chat_message':
390
+ if (!('content' in args) || typeof args.content !== 'string') {
391
+ throw new Error('Missing required parameter: content');
392
+ }
393
+ return handleSendChatMessage(args, foundryClient);
394
+ // User tools
395
+ case 'get_users':
396
+ return handleGetUsers(args, foundryClient);
397
+ case 'set_user_role':
398
+ if (!('userId' in args) || typeof args.userId !== 'string') {
399
+ throw new Error('Missing required parameter: userId');
400
+ }
401
+ if (!('role' in args) || typeof args.role !== 'string') {
402
+ throw new Error('Missing required parameter: role');
403
+ }
404
+ return handleSetUserRole(args, foundryClient);
405
+ // Journal tools
406
+ case 'search_journals':
407
+ if (!('query' in args) || typeof args.query !== 'string') {
408
+ throw new Error('Missing required parameter: query');
409
+ }
410
+ return handleSearchJournals(args, foundryClient);
411
+ case 'get_journal':
412
+ if (!('journalId' in args) || typeof args.journalId !== 'string') {
413
+ throw new Error('Missing required parameter: journalId');
414
+ }
415
+ if ('raw' in args && args.raw !== undefined && typeof args.raw !== 'boolean') {
416
+ throw new Error('Invalid parameter: raw must be a boolean');
417
+ }
418
+ return handleGetJournal(args, foundryClient);
419
+ // Journal mutation tools (WRITE) — Socket.IO modifyDocument protocol
420
+ // (foundryClient); require FOUNDRY_WRITE_ENABLED=true + a GM user.
421
+ case 'create_journal_entry':
422
+ if (!('name' in args) || typeof args.name !== 'string') {
423
+ throw new Error('Missing required parameter: name');
424
+ }
425
+ if (!('pages' in args) || !Array.isArray(args.pages)) {
426
+ throw new Error('Missing required parameter: pages');
427
+ }
428
+ return handleCreateJournalEntry(args, foundryClient);
429
+ case 'update_journal_page':
430
+ if (!('journalId' in args) || typeof args.journalId !== 'string') {
431
+ throw new Error('Missing required parameter: journalId');
432
+ }
433
+ if (!('pageId' in args) || typeof args.pageId !== 'string') {
434
+ throw new Error('Missing required parameter: pageId');
435
+ }
436
+ if ('expectedVersion' in args &&
437
+ args.expectedVersion !== undefined &&
438
+ typeof args.expectedVersion !== 'string') {
439
+ throw new Error('Invalid parameter: expectedVersion must be a string');
440
+ }
441
+ return handleUpdateJournalPage(args, foundryClient);
442
+ case 'add_journal_page':
443
+ if (!('journalId' in args) || typeof args.journalId !== 'string') {
444
+ throw new Error('Missing required parameter: journalId');
445
+ }
446
+ if (!('name' in args) || typeof args.name !== 'string') {
447
+ throw new Error('Missing required parameter: name');
448
+ }
449
+ if (!('content' in args) || typeof args.content !== 'string') {
450
+ throw new Error('Missing required parameter: content');
451
+ }
452
+ return handleAddJournalPage(args, foundryClient);
453
+ case 'update_journal_entry':
454
+ if (!('journalId' in args) || typeof args.journalId !== 'string') {
455
+ throw new Error('Missing required parameter: journalId');
456
+ }
457
+ return handleUpdateJournalEntry(args, foundryClient);
458
+ case 'delete_journal_entry':
459
+ if (!('journalId' in args) || typeof args.journalId !== 'string') {
460
+ throw new Error('Missing required parameter: journalId');
461
+ }
462
+ return handleDeleteJournalEntry(args, foundryClient);
463
+ // Module-bridge tools (canvas-only; require the companion Foundry module)
464
+ case 'capture_scene':
465
+ return handleCaptureScene(args, moduleBridge);
466
+ case 'get_document_schema':
467
+ if (!('documentType' in args) || typeof args.documentType !== 'string') {
468
+ throw new Error('Missing required parameter: documentType');
469
+ }
470
+ if (!('type' in args) || typeof args.type !== 'string') {
471
+ throw new Error('Missing required parameter: type');
472
+ }
473
+ return handleGetDocumentSchema(args, moduleBridge);
474
+ case 'search_compendium_content':
475
+ return handleSearchCompendiumContent(args, moduleBridge);
476
+ case 'roll_and_post':
477
+ if (!('formula' in args) || typeof args.formula !== 'string') {
478
+ throw new Error('Missing required parameter: formula');
479
+ }
480
+ return handleRollAndPost(args, moduleBridge);
481
+ case 'import_compendium_actor':
482
+ if (!('compendiumId' in args) || typeof args.compendiumId !== 'string') {
483
+ throw new Error('Missing required parameter: compendiumId');
484
+ }
485
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
486
+ throw new Error('Missing required parameter: actorId');
487
+ }
488
+ return handleImportCompendiumActor(args, foundryClient, moduleBridge);
489
+ case 'set_target':
490
+ if (!('tokenIds' in args) || !Array.isArray(args.tokenIds)) {
491
+ throw new Error('Missing required parameter: tokenIds');
492
+ }
493
+ return handleSetTarget(args, moduleBridge);
494
+ case 'get_targets':
495
+ return handleGetTargets(args, moduleBridge);
496
+ case 'ping_canvas':
497
+ if (!('x' in args) || typeof args.x !== 'number') {
498
+ throw new Error('Missing required parameter: x');
499
+ }
500
+ if (!('y' in args) || typeof args.y !== 'number') {
501
+ throw new Error('Missing required parameter: y');
502
+ }
503
+ return handlePingCanvas(args, moduleBridge);
504
+ case 'set_pause':
505
+ return handleSetPause(args, moduleBridge);
506
+ case 'upload_asset':
507
+ if (!('targetDir' in args) || typeof args.targetDir !== 'string') {
508
+ throw new Error('Missing required parameter: targetDir');
509
+ }
510
+ if (!('filename' in args) || typeof args.filename !== 'string') {
511
+ throw new Error('Missing required parameter: filename');
512
+ }
513
+ return handleUploadAsset(args, moduleBridge);
514
+ // World-event tools (read-only)
515
+ case 'watch_events':
516
+ return handleWatchEvents(args, foundryClient);
517
+ // World tools
518
+ case 'search_world':
519
+ if (!('query' in args) || typeof args.query !== 'string') {
520
+ throw new Error('Missing required parameter: query');
521
+ }
522
+ return handleSearchWorld(args, foundryClient);
523
+ case 'get_world_summary':
524
+ return handleGetWorldSummary(args, foundryClient);
525
+ case 'refresh_world_data':
526
+ return handleRefreshWorldData(args, foundryClient);
527
+ // Roll table tools
528
+ case 'list_roll_tables':
529
+ return handleListRollTables(args, foundryClient);
530
+ case 'roll_table':
531
+ if (!('tableId' in args) || typeof args.tableId !== 'string') {
532
+ throw new Error('Missing required parameter: tableId');
533
+ }
534
+ return handleRollTable(args, foundryClient);
535
+ case 'create_roll_table':
536
+ if (!('name' in args) || typeof args.name !== 'string') {
537
+ throw new Error('Missing required parameter: name');
538
+ }
539
+ if (!('results' in args) || !Array.isArray(args.results)) {
540
+ throw new Error('Missing required parameter: results');
541
+ }
542
+ return handleCreateRollTable(args, foundryClient);
543
+ case 'delete_roll_table':
544
+ if (!('tableId' in args) || typeof args.tableId !== 'string') {
545
+ throw new Error('Missing required parameter: tableId');
546
+ }
547
+ return handleDeleteRollTable(args, foundryClient);
548
+ // World document tools (folders, macros, playlists)
549
+ case 'list_folders':
550
+ return handleListFolders(args, foundryClient);
551
+ case 'create_folder':
552
+ if (!('name' in args) || typeof args.name !== 'string') {
553
+ throw new Error('Missing required parameter: name');
554
+ }
555
+ if (!('type' in args) || typeof args.type !== 'string') {
556
+ throw new Error('Missing required parameter: type');
557
+ }
558
+ return handleCreateFolder(args, foundryClient);
559
+ case 'list_macros':
560
+ return handleListMacros(args, foundryClient);
561
+ case 'create_macro':
562
+ if (!('name' in args) || typeof args.name !== 'string') {
563
+ throw new Error('Missing required parameter: name');
564
+ }
565
+ if (!('type' in args) || typeof args.type !== 'string') {
566
+ throw new Error('Missing required parameter: type');
567
+ }
568
+ if (!('command' in args) || typeof args.command !== 'string') {
569
+ throw new Error('Missing required parameter: command');
570
+ }
571
+ return handleCreateMacro(args, foundryClient);
572
+ case 'delete_macro':
573
+ if (!('macroId' in args) || typeof args.macroId !== 'string') {
574
+ throw new Error('Missing required parameter: macroId');
575
+ }
576
+ return handleDeleteMacro(args, foundryClient);
577
+ case 'list_playlists':
578
+ return handleListPlaylists(args, foundryClient);
579
+ case 'create_playlist':
580
+ if (!('name' in args) || typeof args.name !== 'string') {
581
+ throw new Error('Missing required parameter: name');
582
+ }
583
+ return handleCreatePlaylist(args, foundryClient);
584
+ case 'set_playlist_state':
585
+ if (!('playlistId' in args) || typeof args.playlistId !== 'string') {
586
+ throw new Error('Missing required parameter: playlistId');
587
+ }
588
+ if (!('playing' in args) || typeof args.playing !== 'boolean') {
589
+ throw new Error('Missing required parameter: playing');
590
+ }
591
+ return handleSetPlaylistState(args, foundryClient);
592
+ case 'delete_playlist':
593
+ if (!('playlistId' in args) || typeof args.playlistId !== 'string') {
594
+ throw new Error('Missing required parameter: playlistId');
595
+ }
596
+ return handleDeletePlaylist(args, foundryClient);
597
+ case 'set_document_ownership':
598
+ if (!('documentType' in args) || typeof args.documentType !== 'string') {
599
+ throw new Error('Missing required parameter: documentType');
600
+ }
601
+ if (!('documentId' in args) || typeof args.documentId !== 'string') {
602
+ throw new Error('Missing required parameter: documentId');
603
+ }
604
+ if (!('entries' in args) || !Array.isArray(args.entries)) {
605
+ throw new Error('Missing required parameter: entries');
606
+ }
607
+ return handleSetDocumentOwnership(args, foundryClient);
608
+ // Settings tools
609
+ case 'get_world_setting':
610
+ if (!('key' in args) || typeof args.key !== 'string') {
611
+ throw new Error('Missing required parameter: key');
612
+ }
613
+ return handleGetWorldSetting(args, foundryClient);
614
+ case 'set_world_setting':
615
+ if (!('key' in args) || typeof args.key !== 'string') {
616
+ throw new Error('Missing required parameter: key');
617
+ }
618
+ if (!('value' in args)) {
619
+ throw new Error('Missing required parameter: value');
620
+ }
621
+ return handleSetWorldSetting(args, foundryClient);
622
+ // Generation tools
623
+ case 'generate_npc':
624
+ return handleGenerateNPC(args, foundryClient);
625
+ case 'generate_loot':
626
+ return handleGenerateLoot(args, foundryClient);
627
+ case 'lookup_rule':
628
+ if (!('query' in args) || typeof args.query !== 'string') {
629
+ throw new Error('Missing required parameter: query');
630
+ }
631
+ return handleLookupRule(args, foundryClient, moduleBridge);
632
+ // Diagnostics tools (require REST API module)
633
+ case 'get_recent_logs':
634
+ return handleGetRecentLogs(args, diagnosticsClient);
635
+ case 'search_logs':
636
+ if (!('query' in args) || typeof args.query !== 'string') {
637
+ throw new Error('Missing required parameter: query');
638
+ }
639
+ return handleSearchLogs(args, diagnosticsClient);
640
+ case 'get_system_health':
641
+ return handleGetSystemHealth(args, diagnosticsClient);
642
+ case 'diagnose_errors':
643
+ return handleDiagnoseErrors(args, diagnosticsClient);
644
+ case 'get_health_status':
645
+ return handleGetHealthStatus(args, foundryClient, diagnosticsClient, moduleBridge, headlessGmSession, healthRuntime);
646
+ // ActiveEffect tools (general-purpose; apply_status_effect above stays
647
+ // the simpler idempotent status toggle)
648
+ case 'create_actor_effect':
649
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
650
+ throw new Error('Missing required parameter: actorId');
651
+ }
652
+ if (!('name' in args) || typeof args.name !== 'string') {
653
+ throw new Error('Missing required parameter: name');
654
+ }
655
+ return handleCreateActorEffect(args, foundryClient);
656
+ case 'update_actor_effect':
657
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
658
+ throw new Error('Missing required parameter: actorId');
659
+ }
660
+ if (!('effectId' in args) || typeof args.effectId !== 'string') {
661
+ throw new Error('Missing required parameter: effectId');
662
+ }
663
+ return handleUpdateActorEffect(args, foundryClient);
664
+ case 'delete_actor_effect':
665
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
666
+ throw new Error('Missing required parameter: actorId');
667
+ }
668
+ if (!('effectId' in args) || typeof args.effectId !== 'string') {
669
+ throw new Error('Missing required parameter: effectId');
670
+ }
671
+ return handleDeleteActorEffect(args, foundryClient);
672
+ case 'list_actor_effects':
673
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
674
+ throw new Error('Missing required parameter: actorId');
675
+ }
676
+ return handleListActorEffects(args, foundryClient);
677
+ default:
678
+ throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
679
+ }
680
+ }
681
+ /**
682
+ * Routes resource requests to appropriate handlers
683
+ */
684
+ export async function routeResourceRequest(uri, foundryClient, diagnosticsClient) {
685
+ logger.debug(`Routing resource request: ${uri}`);
686
+ return handleReadResource(uri, foundryClient, diagnosticsClient);
687
+ }
688
+ //# sourceMappingURL=router.js.map