@g33ks/foundryvtt-mcp 0.0.0-stage → 2.0.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 (96) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +468 -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 +410 -0
  7. package/dist/cli/prompt.js +117 -0
  8. package/dist/cli/snippets.js +49 -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 +415 -0
  14. package/dist/diagnostics/client.js +353 -0
  15. package/dist/diagnostics/types.js +94 -0
  16. package/dist/foundry/auth.js +220 -0
  17. package/dist/foundry/browser-detect.js +170 -0
  18. package/dist/foundry/client.js +5555 -0
  19. package/dist/foundry/dice-formula.js +154 -0
  20. package/dist/foundry/event-log.js +299 -0
  21. package/dist/foundry/headless-gm-session.js +740 -0
  22. package/dist/foundry/journal-history.js +90 -0
  23. package/dist/foundry/journal-integrity.js +306 -0
  24. package/dist/foundry/module-bridge.js +413 -0
  25. package/dist/foundry/types.js +52 -0
  26. package/dist/foundry/world-cache.js +386 -0
  27. package/dist/index.js +107 -0
  28. package/dist/mcp-server.js +63 -0
  29. package/dist/server.js +159 -0
  30. package/dist/shared/build-order.js +134 -0
  31. package/dist/shared/config-hash.js +62 -0
  32. package/dist/shared/config-notice.js +55 -0
  33. package/dist/shared/control.js +255 -0
  34. package/dist/shared/daemon-link.js +135 -0
  35. package/dist/shared/daemon.js +313 -0
  36. package/dist/shared/ipc-client.js +200 -0
  37. package/dist/shared/ipc-server.js +316 -0
  38. package/dist/shared/paths.js +79 -0
  39. package/dist/shared/protocol.js +230 -0
  40. package/dist/shared/relay-config.js +65 -0
  41. package/dist/shared/relay.js +120 -0
  42. package/dist/shared/rotating-log.js +57 -0
  43. package/dist/shared/spawn.js +39 -0
  44. package/dist/shared/state-file.js +33 -0
  45. package/dist/shared/token.js +62 -0
  46. package/dist/shared/version.js +57 -0
  47. package/dist/tools/base.js +74 -0
  48. package/dist/tools/definitions.js +3109 -0
  49. package/dist/tools/handlers/actor-mutations.js +128 -0
  50. package/dist/tools/handlers/actors.js +114 -0
  51. package/dist/tools/handlers/chat-mutations.js +49 -0
  52. package/dist/tools/handlers/chat.js +36 -0
  53. package/dist/tools/handlers/combat-mutations.js +215 -0
  54. package/dist/tools/handlers/combat-order.js +94 -0
  55. package/dist/tools/handlers/combat.js +51 -0
  56. package/dist/tools/handlers/compendium.js +83 -0
  57. package/dist/tools/handlers/diagnostics.js +438 -0
  58. package/dist/tools/handlers/dice.js +54 -0
  59. package/dist/tools/handlers/effects.js +103 -0
  60. package/dist/tools/handlers/events.js +50 -0
  61. package/dist/tools/handlers/generation.js +258 -0
  62. package/dist/tools/handlers/item-mutations.js +132 -0
  63. package/dist/tools/handlers/items.js +53 -0
  64. package/dist/tools/handlers/journal-mutations.js +230 -0
  65. package/dist/tools/handlers/journals.js +80 -0
  66. package/dist/tools/handlers/module-bridge.js +421 -0
  67. package/dist/tools/handlers/placeable-mutations.js +272 -0
  68. package/dist/tools/handlers/resources.js +203 -0
  69. package/dist/tools/handlers/roll-tables.js +97 -0
  70. package/dist/tools/handlers/scene-mutations.js +159 -0
  71. package/dist/tools/handlers/scenes.js +355 -0
  72. package/dist/tools/handlers/settings.js +53 -0
  73. package/dist/tools/handlers/tile-mutations.js +56 -0
  74. package/dist/tools/handlers/token-mutations.js +356 -0
  75. package/dist/tools/handlers/users.js +59 -0
  76. package/dist/tools/handlers/utils.js +47 -0
  77. package/dist/tools/handlers/wall-mutations.js +98 -0
  78. package/dist/tools/handlers/world-documents.js +222 -0
  79. package/dist/tools/handlers/world.js +92 -0
  80. package/dist/tools/index.js +25 -0
  81. package/dist/tools/new-router.js +97 -0
  82. package/dist/tools/registry.js +79 -0
  83. package/dist/tools/resources.js +63 -0
  84. package/dist/tools/router.js +688 -0
  85. package/dist/tools/write-tools.js +97 -0
  86. package/dist/utils/cache-instance.js +30 -0
  87. package/dist/utils/cache.js +205 -0
  88. package/dist/utils/diagnostics.js +332 -0
  89. package/dist/utils/guards.js +17 -0
  90. package/dist/utils/image-size.js +160 -0
  91. package/dist/utils/log-args.js +47 -0
  92. package/dist/utils/logger.js +203 -0
  93. package/dist/utils/refusal.js +30 -0
  94. package/dist/utils/sanitize.js +22 -0
  95. package/dist/utils/serial-queue.js +22 -0
  96. package/package.json +124 -4
@@ -0,0 +1,222 @@
1
+ /**
2
+ * @fileoverview World document tool handlers (folders, macros, playlists).
3
+ */
4
+ import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
5
+ import { withToolError } from './utils.js';
6
+ // ============================================================================
7
+ // Folder handlers
8
+ // ============================================================================
9
+ export async function handleListFolders(args, foundryClient) {
10
+ return withToolError('list folders', async () => {
11
+ const folders = foundryClient.listFolders(args);
12
+ if (folders.length === 0) {
13
+ return {
14
+ content: [{ type: 'text', text: '📁 **No folders found.**' }],
15
+ };
16
+ }
17
+ const lines = folders.map((f) => `- **${f.name}** (${f.id}) — type: ${f.type}${f.parent ? `, parent: ${f.parent}` : ''}${f.color ? `, color: ${f.color}` : ''}`);
18
+ return {
19
+ content: [
20
+ {
21
+ type: 'text',
22
+ text: `📁 **Folders** (${folders.length})\n${lines.join('\n')}`,
23
+ },
24
+ ],
25
+ };
26
+ });
27
+ }
28
+ export async function handleCreateFolder(args, foundryClient) {
29
+ const { name, type } = args;
30
+ if (!name || typeof name !== 'string') {
31
+ throw new McpError(ErrorCode.InvalidParams, 'name is required and must be a string');
32
+ }
33
+ if (!type || typeof type !== 'string') {
34
+ throw new McpError(ErrorCode.InvalidParams, 'type is required and must be a string');
35
+ }
36
+ return withToolError('create folder', async () => {
37
+ const created = (await foundryClient.createFolder(name, type, args));
38
+ const folderId = created?._id ?? 'unknown';
39
+ return {
40
+ content: [
41
+ {
42
+ type: 'text',
43
+ text: `📁 **Folder Created**\n**ID:** ${folderId}\n**Name:** ${name}\n**Type:** ${type}`,
44
+ },
45
+ ],
46
+ };
47
+ });
48
+ }
49
+ // ============================================================================
50
+ // Macro handlers
51
+ // ============================================================================
52
+ export async function handleListMacros(_args, foundryClient) {
53
+ return withToolError('list macros', async () => {
54
+ const macros = foundryClient.listMacros();
55
+ if (macros.length === 0) {
56
+ return {
57
+ content: [{ type: 'text', text: '📜 **No macros found.**' }],
58
+ };
59
+ }
60
+ const lines = macros.map((m) => `- **${m.name}** (${m.id}) — type: ${m.type}, scope: ${m.scope}${m.folder ? `, folder: ${m.folder}` : ''}\n Preview: \`${m.commandPreview}\``);
61
+ return {
62
+ content: [
63
+ {
64
+ type: 'text',
65
+ text: `📜 **Macros** (${macros.length})\n${lines.join('\n')}`,
66
+ },
67
+ ],
68
+ };
69
+ });
70
+ }
71
+ export async function handleCreateMacro(args, foundryClient) {
72
+ const { name, type, command } = args;
73
+ if (!name || typeof name !== 'string') {
74
+ throw new McpError(ErrorCode.InvalidParams, 'name is required and must be a string');
75
+ }
76
+ if (type !== 'script' && type !== 'chat') {
77
+ throw new McpError(ErrorCode.InvalidParams, 'type must be "script" or "chat"');
78
+ }
79
+ if (typeof command !== 'string') {
80
+ throw new McpError(ErrorCode.InvalidParams, 'command is required and must be a string');
81
+ }
82
+ return withToolError('create macro', async () => {
83
+ const created = (await foundryClient.createMacro(name, type, command, args));
84
+ const macroId = created?._id ?? 'unknown';
85
+ return {
86
+ content: [
87
+ {
88
+ type: 'text',
89
+ text: `📜 **Macro Created**\n**ID:** ${macroId}\n**Name:** ${name}\n**Type:** ${type}\n_Note: Macros are authored and managed here, not executed._`,
90
+ },
91
+ ],
92
+ };
93
+ });
94
+ }
95
+ export async function handleDeleteMacro(args, foundryClient) {
96
+ const { macroId } = args;
97
+ if (!macroId || typeof macroId !== 'string') {
98
+ throw new McpError(ErrorCode.InvalidParams, 'macroId is required and must be a string');
99
+ }
100
+ return withToolError('delete macro', async () => {
101
+ await foundryClient.deleteMacro(macroId);
102
+ return {
103
+ content: [
104
+ {
105
+ type: 'text',
106
+ text: `🗑️ **Macro Deleted**\n**ID:** ${macroId}`,
107
+ },
108
+ ],
109
+ };
110
+ });
111
+ }
112
+ // ============================================================================
113
+ // Playlist handlers
114
+ // ============================================================================
115
+ export async function handleListPlaylists(_args, foundryClient) {
116
+ return withToolError('list playlists', async () => {
117
+ const playlists = foundryClient.listPlaylists();
118
+ if (playlists.length === 0) {
119
+ return {
120
+ content: [{ type: 'text', text: '🎵 **No playlists found.**' }],
121
+ };
122
+ }
123
+ const lines = playlists.map((p) => {
124
+ const modeLabel = ['', 'sequential', 'shuffle', 'simultaneous'][p.mode + 1] ?? 'unknown';
125
+ const soundLines = p.sounds
126
+ .map((s) => ` - ${s.name} (${s.id}) — \`${s.path}\`${s.playing ? ' [playing]' : ''}`)
127
+ .join('\n');
128
+ return `- **${p.name}** (${p.id}) — ${p.playing ? '▶️ playing' : '⏹️ stopped'}, mode: ${modeLabel}, channel: ${p.channel} (${p.soundCount} track${p.soundCount !== 1 ? 's' : ''})${soundLines ? `\n${soundLines}` : ''}`;
129
+ });
130
+ return {
131
+ content: [
132
+ {
133
+ type: 'text',
134
+ text: `🎵 **Playlists** (${playlists.length})\n${lines.join('\n')}`,
135
+ },
136
+ ],
137
+ };
138
+ });
139
+ }
140
+ export async function handleCreatePlaylist(args, foundryClient) {
141
+ const { name } = args;
142
+ if (!name || typeof name !== 'string') {
143
+ throw new McpError(ErrorCode.InvalidParams, 'name is required and must be a string');
144
+ }
145
+ return withToolError('create playlist', async () => {
146
+ const created = (await foundryClient.createPlaylist(name, args));
147
+ const playlistId = created?._id ?? 'unknown';
148
+ return {
149
+ content: [
150
+ {
151
+ type: 'text',
152
+ text: `🎵 **Playlist Created**\n**ID:** ${playlistId}\n**Name:** ${name}\n**Tracks Added:** ${args.sounds?.length ?? 0}`,
153
+ },
154
+ ],
155
+ };
156
+ });
157
+ }
158
+ export async function handleSetPlaylistState(args, foundryClient) {
159
+ const { playlistId, playing, soundId } = args;
160
+ if (!playlistId || typeof playlistId !== 'string') {
161
+ throw new McpError(ErrorCode.InvalidParams, 'playlistId is required and must be a string');
162
+ }
163
+ if (typeof playing !== 'boolean') {
164
+ throw new McpError(ErrorCode.InvalidParams, 'playing is required and must be a boolean');
165
+ }
166
+ return withToolError('set playlist state', async () => {
167
+ await foundryClient.setPlaylistState(playlistId, playing, soundId !== undefined ? { soundId } : {});
168
+ return {
169
+ content: [
170
+ {
171
+ type: 'text',
172
+ text: `🎵 **Playlist State Updated**\n**ID:** ${playlistId}${soundId ? ` (Track: ${soundId})` : ''}\n**Status:** ${playing ? '▶️ Playing' : '⏹️ Stopped'}`,
173
+ },
174
+ ],
175
+ };
176
+ });
177
+ }
178
+ export async function handleDeletePlaylist(args, foundryClient) {
179
+ const { playlistId } = args;
180
+ if (!playlistId || typeof playlistId !== 'string') {
181
+ throw new McpError(ErrorCode.InvalidParams, 'playlistId is required and must be a string');
182
+ }
183
+ return withToolError('delete playlist', async () => {
184
+ await foundryClient.deletePlaylist(playlistId);
185
+ return {
186
+ content: [
187
+ {
188
+ type: 'text',
189
+ text: `🗑️ **Playlist Deleted**\n**ID:** ${playlistId}`,
190
+ },
191
+ ],
192
+ };
193
+ });
194
+ }
195
+ // ============================================================================
196
+ // Document ownership handlers
197
+ // ============================================================================
198
+ export async function handleSetDocumentOwnership(args, foundryClient) {
199
+ const { documentType, documentId, entries } = args;
200
+ if (!documentType || typeof documentType !== 'string') {
201
+ throw new McpError(ErrorCode.InvalidParams, 'documentType is required and must be a string');
202
+ }
203
+ if (!documentId || typeof documentId !== 'string') {
204
+ throw new McpError(ErrorCode.InvalidParams, 'documentId is required and must be a string');
205
+ }
206
+ if (!Array.isArray(entries) || entries.length === 0) {
207
+ throw new McpError(ErrorCode.InvalidParams, 'entries is required and must contain at least one { target, level } entry');
208
+ }
209
+ return withToolError('set document ownership', async () => {
210
+ await foundryClient.setDocumentOwnership(documentType, documentId, entries);
211
+ const formatted = entries.map((e) => `- ${e.target}: ${e.level}`).join('\n');
212
+ return {
213
+ content: [
214
+ {
215
+ type: 'text',
216
+ text: `🔐 **Document Ownership Updated**\n**Type:** ${documentType}\n**ID:** ${documentId}\n**Permissions:**\n${formatted}`,
217
+ },
218
+ ],
219
+ };
220
+ });
221
+ }
222
+ //# sourceMappingURL=world-documents.js.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * World-level tool handlers: cross-collection search, summary, refresh
3
+ */
4
+ import { withToolError } from './utils.js';
5
+ export async function handleSearchWorld(args, foundryClient) {
6
+ return withToolError('search world', async () => {
7
+ const results = foundryClient.searchWorld(args.query);
8
+ const limit = args.limit || 5;
9
+ const sections = [];
10
+ if (results.actors.length > 0) {
11
+ const items = results.actors
12
+ .slice(0, limit)
13
+ .map((a) => ` - ${a.name} (${a.type})`)
14
+ .join('\n');
15
+ sections.push(`**Actors** (${results.actors.length})\n${items}`);
16
+ }
17
+ if (results.items.length > 0) {
18
+ const items = results.items
19
+ .slice(0, limit)
20
+ .map((i) => ` - ${i.name} (${i.type})`)
21
+ .join('\n');
22
+ sections.push(`**Items** (${results.items.length})\n${items}`);
23
+ }
24
+ if (results.scenes.length > 0) {
25
+ const items = results.scenes
26
+ .slice(0, limit)
27
+ .map((s) => ` - ${s.name}${s.active ? ' [ACTIVE]' : ''}`)
28
+ .join('\n');
29
+ sections.push(`**Scenes** (${results.scenes.length})\n${items}`);
30
+ }
31
+ if (results.journals.length > 0) {
32
+ const items = results.journals
33
+ .slice(0, limit)
34
+ .map((j) => ` - ${j.name}`)
35
+ .join('\n');
36
+ sections.push(`**Journals** (${results.journals.length})\n${items}`);
37
+ }
38
+ if (sections.length === 0) {
39
+ return {
40
+ content: [{ type: 'text', text: `No results found for "${args.query}".` }],
41
+ };
42
+ }
43
+ return {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: `**World Search** — "${args.query}"\n\n${sections.join('\n\n')}`,
48
+ },
49
+ ],
50
+ };
51
+ });
52
+ }
53
+ export async function handleGetWorldSummary(_args, foundryClient) {
54
+ return withToolError('get world summary', async () => {
55
+ const worldInfo = await foundryClient.getWorldInfo();
56
+ const counts = foundryClient.getWorldSummary();
57
+ const countLines = Object.entries(counts)
58
+ .map(([key, count]) => `- **${key}**: ${count}`)
59
+ .join('\n');
60
+ return {
61
+ content: [
62
+ {
63
+ type: 'text',
64
+ text: `**World: ${worldInfo.title}**
65
+ **System:** ${worldInfo.system} (${worldInfo.systemVersion})
66
+ **Core Version:** ${worldInfo.coreVersion}
67
+
68
+ **Collection Counts:**
69
+ ${countLines || 'No data available — not connected.'}`,
70
+ },
71
+ ],
72
+ };
73
+ });
74
+ }
75
+ export async function handleRefreshWorldData(_args, foundryClient) {
76
+ return withToolError('refresh world data', async () => {
77
+ await foundryClient.refreshWorldData();
78
+ const counts = foundryClient.getWorldSummary();
79
+ const countLines = Object.entries(counts)
80
+ .map(([key, count]) => `- **${key}**: ${count}`)
81
+ .join('\n');
82
+ return {
83
+ content: [
84
+ {
85
+ type: 'text',
86
+ text: `World data refreshed successfully.\n\n**Collection Counts:**\n${countLines}`,
87
+ },
88
+ ],
89
+ };
90
+ });
91
+ }
92
+ //# sourceMappingURL=world.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Tools module entry point
3
+ */
4
+ // Export tool and resource definitions
5
+ export { getAllTools } from './definitions.js';
6
+ export * from './handlers/actors.js';
7
+ export * from './handlers/chat.js';
8
+ export * from './handlers/combat.js';
9
+ export * from './handlers/diagnostics.js';
10
+ // Export individual handlers for testing
11
+ export * from './handlers/dice.js';
12
+ export * from './handlers/generation.js';
13
+ export * from './handlers/items.js';
14
+ export * from './handlers/journals.js';
15
+ export * from './handlers/resources.js';
16
+ export * from './handlers/scene-mutations.js';
17
+ export * from './handlers/scenes.js';
18
+ export * from './handlers/tile-mutations.js';
19
+ export * from './handlers/users.js';
20
+ export * from './handlers/wall-mutations.js';
21
+ export * from './handlers/world.js';
22
+ export { getAllResources } from './resources.js';
23
+ // Export routing functions
24
+ export { routeResourceRequest, routeToolRequest } from './router.js';
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @fileoverview New tool routing implementation using registry pattern
3
+ *
4
+ * This module provides a cleaner routing system that uses the tool registry
5
+ * and eliminates the need for manual switch statements and validation.
6
+ */
7
+ import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
8
+ import { logger } from '../utils/logger.js';
9
+ // Import legacy handlers for tools not yet converted
10
+ import { handleGetActorDetails, handleSearchActors } from './handlers/actors.js';
11
+ import { handleDiagnoseErrors, handleGetHealthStatus, handleGetRecentLogs, handleGetSystemHealth, handleSearchLogs, } from './handlers/diagnostics.js';
12
+ import { handleGenerateLoot, handleGenerateNPC, handleLookupRule } from './handlers/generation.js';
13
+ import { handleSearchItems } from './handlers/items.js';
14
+ import { handleReadResource } from './handlers/resources.js';
15
+ import { handleGetSceneInfo } from './handlers/scenes.js';
16
+ import { toolRegistry } from './registry.js';
17
+ /**
18
+ * Routes tool requests using the new registry system
19
+ */
20
+ export async function routeToolRequest(name, args, foundryClient, diagnosticsClient, diagnosticSystem) {
21
+ logger.debug(`Routing tool request: ${name}`, { args });
22
+ const context = {
23
+ foundryClient,
24
+ diagnosticsClient,
25
+ diagnosticSystem,
26
+ };
27
+ // Try to execute using the new registry system
28
+ if (toolRegistry.has(name)) {
29
+ try {
30
+ return await toolRegistry.execute(name, args, context);
31
+ }
32
+ catch (error) {
33
+ if (error instanceof McpError) {
34
+ throw error;
35
+ }
36
+ throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
37
+ }
38
+ }
39
+ // Fallback to legacy handlers for tools not yet converted
40
+ return await routeLegacyTool(name, args, foundryClient, diagnosticsClient, diagnosticSystem);
41
+ }
42
+ /**
43
+ * Legacy routing for tools not yet converted to the new system
44
+ * @deprecated This will be removed once all tools are converted
45
+ */
46
+ async function routeLegacyTool(name, args, foundryClient, diagnosticsClient, _diagnosticSystem) {
47
+ switch (name) {
48
+ // Actor tools
49
+ case 'search_actors':
50
+ return handleSearchActors(args, foundryClient);
51
+ case 'get_actor_details':
52
+ if (!('actorId' in args) || typeof args.actorId !== 'string') {
53
+ throw new Error('Missing required parameter: actorId');
54
+ }
55
+ return handleGetActorDetails(args, foundryClient);
56
+ // Item tools
57
+ case 'search_items':
58
+ return handleSearchItems(args, foundryClient);
59
+ // Scene tools
60
+ case 'get_scene_info':
61
+ return handleGetSceneInfo(args, foundryClient);
62
+ // Generation tools
63
+ case 'generate_npc':
64
+ return handleGenerateNPC(args, foundryClient);
65
+ case 'generate_loot':
66
+ return handleGenerateLoot(args, foundryClient);
67
+ case 'lookup_rule':
68
+ if (!('query' in args) || typeof args.query !== 'string') {
69
+ throw new Error('Missing required parameter: query');
70
+ }
71
+ return handleLookupRule(args, foundryClient);
72
+ // Diagnostics tools
73
+ case 'get_recent_logs':
74
+ return handleGetRecentLogs(args, diagnosticsClient);
75
+ case 'search_logs':
76
+ if (!('query' in args) || typeof args.query !== 'string') {
77
+ throw new Error('Missing required parameter: query');
78
+ }
79
+ return handleSearchLogs(args, diagnosticsClient);
80
+ case 'get_system_health':
81
+ return handleGetSystemHealth(args, diagnosticsClient);
82
+ case 'diagnose_errors':
83
+ return handleDiagnoseErrors(args, diagnosticsClient);
84
+ case 'get_health_status':
85
+ return handleGetHealthStatus(args, foundryClient, diagnosticsClient);
86
+ default:
87
+ throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
88
+ }
89
+ }
90
+ /**
91
+ * Routes resource requests to appropriate handlers
92
+ */
93
+ export async function routeResourceRequest(uri, foundryClient, diagnosticsClient) {
94
+ logger.debug(`Routing resource request: ${uri}`);
95
+ return handleReadResource(uri, foundryClient, diagnosticsClient);
96
+ }
97
+ //# sourceMappingURL=new-router.js.map
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview Tool registry for the new tool system
3
+ *
4
+ * This module manages tool registration and provides a clean interface
5
+ * for tool execution with automatic validation.
6
+ */
7
+ import { logger } from '../utils/logger.js';
8
+ import { RollDiceTool } from './handlers/dice.js';
9
+ /**
10
+ * Tool registry manages all available tools
11
+ */
12
+ export class ToolRegistry {
13
+ tools = new Map();
14
+ constructor() {
15
+ this.registerDefaultTools();
16
+ }
17
+ /**
18
+ * Register a tool in the registry
19
+ */
20
+ register(tool) {
21
+ if (this.tools.has(tool.name)) {
22
+ logger.warn(`Tool '${tool.name}' is already registered, replacing...`);
23
+ }
24
+ this.tools.set(tool.name, tool);
25
+ logger.debug(`Registered tool: ${tool.name}`);
26
+ }
27
+ /**
28
+ * Execute a tool by name with given arguments
29
+ */
30
+ async execute(name, args, context) {
31
+ const tool = this.tools.get(name);
32
+ if (!tool) {
33
+ throw new Error(`Unknown tool: ${name}`);
34
+ }
35
+ return await tool.execute(args, context);
36
+ }
37
+ /**
38
+ * Get all registered tool names
39
+ */
40
+ getToolNames() {
41
+ return Array.from(this.tools.keys());
42
+ }
43
+ /**
44
+ * Get tool definitions for MCP
45
+ */
46
+ getToolDefinitions() {
47
+ return Array.from(this.tools.values()).map((tool) => ({
48
+ name: tool.name,
49
+ description: tool.description,
50
+ inputSchema: tool.inputSchema,
51
+ }));
52
+ }
53
+ /**
54
+ * Check if a tool is registered
55
+ */
56
+ has(name) {
57
+ return this.tools.has(name);
58
+ }
59
+ /**
60
+ * Get a specific tool instance
61
+ */
62
+ get(name) {
63
+ return this.tools.get(name);
64
+ }
65
+ /**
66
+ * Register all default tools
67
+ */
68
+ registerDefaultTools() {
69
+ // Register the dice tool (converted to new system)
70
+ this.register(new RollDiceTool());
71
+ // TODO: Register other tools as they are converted
72
+ logger.info(`Registered ${this.tools.size} tools`);
73
+ }
74
+ }
75
+ /**
76
+ * Global tool registry instance
77
+ */
78
+ export const toolRegistry = new ToolRegistry();
79
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Resource definitions for FoundryVTT MCP Server
3
+ */
4
+ export const resourceDefinitions = [
5
+ {
6
+ uri: 'foundry://actors',
7
+ name: 'All Actors',
8
+ description: 'List of all actors in the current world',
9
+ mimeType: 'application/json',
10
+ },
11
+ {
12
+ uri: 'foundry://items',
13
+ name: 'All Items',
14
+ description: 'List of all items in the current world',
15
+ mimeType: 'application/json',
16
+ },
17
+ {
18
+ uri: 'foundry://scenes',
19
+ name: 'All Scenes',
20
+ description: 'List of all scenes in the current world',
21
+ mimeType: 'application/json',
22
+ },
23
+ {
24
+ uri: 'foundry://scenes/current',
25
+ name: 'Current Scene',
26
+ description: 'Information about the currently active scene',
27
+ mimeType: 'application/json',
28
+ },
29
+ {
30
+ uri: 'foundry://journals',
31
+ name: 'All Journals',
32
+ description: 'List of all journal entries in the current world',
33
+ mimeType: 'application/json',
34
+ },
35
+ {
36
+ uri: 'foundry://users',
37
+ name: 'Users',
38
+ description: 'List of users and their online status',
39
+ mimeType: 'application/json',
40
+ },
41
+ {
42
+ uri: 'foundry://combat',
43
+ name: 'Active Combat',
44
+ description: 'Current active combat encounter state',
45
+ mimeType: 'application/json',
46
+ },
47
+ {
48
+ uri: 'foundry://world/settings',
49
+ name: 'Game Settings',
50
+ description: 'Current world and game system settings',
51
+ mimeType: 'application/json',
52
+ },
53
+ {
54
+ uri: 'foundry://system/diagnostics',
55
+ name: 'System Diagnostics',
56
+ description: 'System health and diagnostic information (requires REST API module)',
57
+ mimeType: 'application/json',
58
+ },
59
+ ];
60
+ export function getAllResources() {
61
+ return resourceDefinitions;
62
+ }
63
+ //# sourceMappingURL=resources.js.map