@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.
- package/LICENSE +22 -0
- package/README.md +457 -2
- package/dist/character/manager.js +208 -0
- package/dist/cli/checks.js +307 -0
- package/dist/cli/config-file.js +120 -0
- package/dist/cli/init.js +414 -0
- package/dist/cli/prompt.js +117 -0
- package/dist/cli/snippets.js +64 -0
- package/dist/combat/manager.js +371 -0
- package/dist/config/env-layers.js +49 -0
- package/dist/config/index.js +298 -0
- package/dist/config/sources.js +201 -0
- package/dist/core.js +481 -0
- package/dist/diagnostics/client.js +291 -0
- package/dist/diagnostics/types.js +94 -0
- package/dist/foundry/auth.js +224 -0
- package/dist/foundry/browser-detect.js +170 -0
- package/dist/foundry/client.js +5874 -0
- package/dist/foundry/dice-formula.js +154 -0
- package/dist/foundry/event-log.js +298 -0
- package/dist/foundry/headless-gm-session.js +857 -0
- package/dist/foundry/journal-conflicts.js +141 -0
- package/dist/foundry/journal-history.js +90 -0
- package/dist/foundry/journal-integrity.js +322 -0
- package/dist/foundry/message-author.js +19 -0
- package/dist/foundry/module-bridge.js +441 -0
- package/dist/foundry/types.js +52 -0
- package/dist/foundry/world-cache.js +386 -0
- package/dist/index.js +107 -0
- package/dist/mcp-server.js +65 -0
- package/dist/server.js +159 -0
- package/dist/shared/build-order.js +134 -0
- package/dist/shared/config-hash.js +62 -0
- package/dist/shared/config-notice.js +55 -0
- package/dist/shared/control.js +291 -0
- package/dist/shared/daemon-link.js +135 -0
- package/dist/shared/daemon.js +311 -0
- package/dist/shared/ipc-client.js +200 -0
- package/dist/shared/ipc-server.js +316 -0
- package/dist/shared/paths.js +79 -0
- package/dist/shared/protocol.js +230 -0
- package/dist/shared/relay-config.js +65 -0
- package/dist/shared/relay.js +120 -0
- package/dist/shared/rotating-log.js +57 -0
- package/dist/shared/spawn.js +39 -0
- package/dist/shared/state-file.js +33 -0
- package/dist/shared/token.js +62 -0
- package/dist/shared/version.js +57 -0
- package/dist/tools/base.js +74 -0
- package/dist/tools/definitions.js +3109 -0
- package/dist/tools/handlers/actor-mutations.js +128 -0
- package/dist/tools/handlers/actors.js +114 -0
- package/dist/tools/handlers/chat-mutations.js +49 -0
- package/dist/tools/handlers/chat.js +38 -0
- package/dist/tools/handlers/combat-mutations.js +215 -0
- package/dist/tools/handlers/combat-order.js +94 -0
- package/dist/tools/handlers/combat.js +51 -0
- package/dist/tools/handlers/compendium.js +83 -0
- package/dist/tools/handlers/diagnostics.js +450 -0
- package/dist/tools/handlers/dice.js +54 -0
- package/dist/tools/handlers/effects.js +103 -0
- package/dist/tools/handlers/events.js +50 -0
- package/dist/tools/handlers/generation.js +258 -0
- package/dist/tools/handlers/item-mutations.js +132 -0
- package/dist/tools/handlers/items.js +53 -0
- package/dist/tools/handlers/journal-mutations.js +230 -0
- package/dist/tools/handlers/journals.js +80 -0
- package/dist/tools/handlers/module-bridge.js +421 -0
- package/dist/tools/handlers/placeable-mutations.js +272 -0
- package/dist/tools/handlers/resources.js +203 -0
- package/dist/tools/handlers/roll-tables.js +97 -0
- package/dist/tools/handlers/scene-mutations.js +159 -0
- package/dist/tools/handlers/scenes.js +355 -0
- package/dist/tools/handlers/settings.js +53 -0
- package/dist/tools/handlers/tile-mutations.js +56 -0
- package/dist/tools/handlers/token-mutations.js +356 -0
- package/dist/tools/handlers/users.js +59 -0
- package/dist/tools/handlers/utils.js +48 -0
- package/dist/tools/handlers/wall-mutations.js +98 -0
- package/dist/tools/handlers/world-documents.js +222 -0
- package/dist/tools/handlers/world.js +92 -0
- package/dist/tools/index.js +25 -0
- package/dist/tools/new-router.js +97 -0
- package/dist/tools/registry.js +79 -0
- package/dist/tools/resources.js +63 -0
- package/dist/tools/router.js +688 -0
- package/dist/tools/tool-dependencies.js +194 -0
- package/dist/tools/write-tools.js +97 -0
- package/dist/utils/cache-instance.js +30 -0
- package/dist/utils/cache.js +205 -0
- package/dist/utils/diagnostics.js +332 -0
- package/dist/utils/guards.js +17 -0
- package/dist/utils/image-size.js +160 -0
- package/dist/utils/log-args.js +47 -0
- package/dist/utils/logger.js +203 -0
- package/dist/utils/mcp-errors.js +47 -0
- package/dist/utils/refusal.js +30 -0
- package/dist/utils/sanitize.js +22 -0
- package/dist/utils/serial-queue.js +22 -0
- package/package.json +124 -4
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Scene mutation tool handler
|
|
3
|
+
*
|
|
4
|
+
* WRITE operation — requires FOUNDRY_WRITE_ENABLED=true and an active
|
|
5
|
+
* Socket.IO connection (mutations use the core `modifyDocument` protocol).
|
|
6
|
+
*/
|
|
7
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import { resolveSceneId } from './scenes.js';
|
|
9
|
+
import { withToolError } from './utils.js';
|
|
10
|
+
/**
|
|
11
|
+
* Handles creating a new Scene document from a background image on disk.
|
|
12
|
+
*/
|
|
13
|
+
export async function handleCreateScene(args, foundryClient) {
|
|
14
|
+
const { name, backgroundSrc, ...options } = args;
|
|
15
|
+
if (!name || typeof name !== 'string') {
|
|
16
|
+
throw new McpError(ErrorCode.InvalidParams, 'name is required and must be a string');
|
|
17
|
+
}
|
|
18
|
+
if (!backgroundSrc || typeof backgroundSrc !== 'string') {
|
|
19
|
+
throw new McpError(ErrorCode.InvalidParams, 'backgroundSrc is required and must be a string');
|
|
20
|
+
}
|
|
21
|
+
return withToolError('create scene', async () => {
|
|
22
|
+
const scene = (await foundryClient.createScene(name, backgroundSrc, options));
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
text: `🗺️ **Scene Created**\n**Name:** ${name}\n**ID:** ${scene._id}\n**Dimensions:** ${scene.width} x ${scene.height} pixels\n**Grid:** ${scene.grid?.size}px${options.activate ? '\n**Activated:** Yes' : ''}`,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handles activating a scene, switching every connected client's canvas to it.
|
|
35
|
+
*/
|
|
36
|
+
export async function handleSwitchScene(args, foundryClient) {
|
|
37
|
+
const { sceneId } = args;
|
|
38
|
+
if (!sceneId || typeof sceneId !== 'string') {
|
|
39
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId is required and must be a string');
|
|
40
|
+
}
|
|
41
|
+
return withToolError('switch scene', async () => {
|
|
42
|
+
const scenes = foundryClient.getScenes();
|
|
43
|
+
const target = scenes.find((s) => s._id === sceneId);
|
|
44
|
+
const name = target?.name ?? sceneId;
|
|
45
|
+
await foundryClient.switchScene(sceneId);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: `🗺️ **Scene Activated**
|
|
51
|
+
**Scene:** ${name} (${sceneId})
|
|
52
|
+
All connected players' canvases now show this scene.`,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Handles permanently deleting a Scene document.
|
|
60
|
+
*/
|
|
61
|
+
export async function handleDeleteScene(args, foundryClient) {
|
|
62
|
+
const { sceneId } = args;
|
|
63
|
+
if (!sceneId || typeof sceneId !== 'string') {
|
|
64
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId is required and must be a string');
|
|
65
|
+
}
|
|
66
|
+
return withToolError('delete scene', async () => {
|
|
67
|
+
const target = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
68
|
+
const name = target?.name ?? sceneId;
|
|
69
|
+
await foundryClient.deleteScene(sceneId);
|
|
70
|
+
return {
|
|
71
|
+
content: [{ type: 'text', text: `🗑️ **Scene Deleted**\n**Scene:** ${name} (${sceneId})` }],
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Handles setting a scene's darkness level and/or global illumination fields.
|
|
77
|
+
*/
|
|
78
|
+
export async function handleSetSceneLighting(args, foundryClient) {
|
|
79
|
+
const { sceneId, darkness, globalLight, globalLightThreshold } = args;
|
|
80
|
+
if (!sceneId || typeof sceneId !== 'string') {
|
|
81
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId is required and must be a string');
|
|
82
|
+
}
|
|
83
|
+
if (darkness === undefined && globalLight === undefined && globalLightThreshold === undefined) {
|
|
84
|
+
throw new McpError(ErrorCode.InvalidParams, 'At least one of darkness, globalLight, globalLightThreshold is required');
|
|
85
|
+
}
|
|
86
|
+
return withToolError('set scene lighting', async () => {
|
|
87
|
+
const target = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
88
|
+
const name = target?.name ?? sceneId;
|
|
89
|
+
const options = {};
|
|
90
|
+
if (darkness !== undefined) {
|
|
91
|
+
options.darkness = darkness;
|
|
92
|
+
}
|
|
93
|
+
if (globalLight !== undefined) {
|
|
94
|
+
options.globalLight = globalLight;
|
|
95
|
+
}
|
|
96
|
+
if (globalLightThreshold !== undefined) {
|
|
97
|
+
options.globalLightThreshold = globalLightThreshold;
|
|
98
|
+
}
|
|
99
|
+
await foundryClient.setSceneLighting(sceneId, options);
|
|
100
|
+
const changes = [
|
|
101
|
+
darkness !== undefined ? `darkness → ${darkness}` : null,
|
|
102
|
+
globalLight !== undefined ? `globalLight → ${globalLight}` : null,
|
|
103
|
+
globalLightThreshold !== undefined ? `globalLightThreshold → ${globalLightThreshold}` : null,
|
|
104
|
+
]
|
|
105
|
+
.filter((line) => line !== null)
|
|
106
|
+
.join(', ');
|
|
107
|
+
return {
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
type: 'text',
|
|
111
|
+
text: `💡 **Scene Lighting Updated**\n**Scene:** ${name} (${sceneId})\n**Changed:** ${changes}`,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handles resetting fog of war exploration for a scene.
|
|
119
|
+
*/
|
|
120
|
+
export async function handleResetFog(args, foundryClient) {
|
|
121
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
122
|
+
return withToolError('reset fog', async () => {
|
|
123
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
124
|
+
await foundryClient.resetFog(sceneId);
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: `🌫️ **Fog of War Reset Requested**\n**Scene:** ${scene?.name ?? sceneId} (${sceneId})\n_Exploration progress reset sent via socket; verify canvas via capture_scene if needed._`,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Handles updating or clearing a scene's weather effect.
|
|
137
|
+
*/
|
|
138
|
+
export async function handleSetSceneWeather(args, foundryClient) {
|
|
139
|
+
const { weather } = args;
|
|
140
|
+
if (typeof weather !== 'string') {
|
|
141
|
+
throw new McpError(ErrorCode.InvalidParams, 'weather is required and must be a string (empty to clear)');
|
|
142
|
+
}
|
|
143
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
144
|
+
return withToolError('set scene weather', async () => {
|
|
145
|
+
const target = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
146
|
+
const name = target?.name ?? sceneId;
|
|
147
|
+
await foundryClient.setSceneWeather(sceneId, weather);
|
|
148
|
+
const label = weather ? `set to "${weather}"` : 'cleared';
|
|
149
|
+
return {
|
|
150
|
+
content: [
|
|
151
|
+
{
|
|
152
|
+
type: 'text',
|
|
153
|
+
text: `🌧️ **Scene Weather Updated**\n**Scene:** ${name} (${sceneId})\n**Weather:** ${label}`,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=scene-mutations.js.map
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Scene management tool handlers
|
|
3
|
+
*
|
|
4
|
+
* Handles scene information retrieval and management.
|
|
5
|
+
*/
|
|
6
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { withToolError } from './utils.js';
|
|
8
|
+
/**
|
|
9
|
+
* Handles scene information requests
|
|
10
|
+
*/
|
|
11
|
+
export async function handleGetSceneInfo(args, foundryClient) {
|
|
12
|
+
const { sceneId } = args;
|
|
13
|
+
return withToolError('get scene info', async () => {
|
|
14
|
+
const scene = await foundryClient.getCurrentScene(sceneId);
|
|
15
|
+
return {
|
|
16
|
+
content: [
|
|
17
|
+
{
|
|
18
|
+
type: 'text',
|
|
19
|
+
text: `🗺️ **Scene Information**
|
|
20
|
+
**Name:** ${scene.name}
|
|
21
|
+
**ID:** ${scene._id}
|
|
22
|
+
**Active:** ${scene.active ? 'Yes' : 'No'}
|
|
23
|
+
**Navigation:** ${scene.navigation ? 'Enabled' : 'Disabled'}
|
|
24
|
+
**Dimensions:** ${scene.width} x ${scene.height} pixels
|
|
25
|
+
**Padding:** ${scene.padding * 100}%
|
|
26
|
+
**Grid:** ${scene.grid ? `${scene.grid.size}px, distance ${scene.grid.distance}${scene.grid.units ? ` ${scene.grid.units}` : ''}` : 'Unknown'}
|
|
27
|
+
**Global Light:** ${scene.globalLight ? 'Enabled' : 'Disabled'}
|
|
28
|
+
**Darkness Level:** ${scene.darkness * 100}%
|
|
29
|
+
|
|
30
|
+
**Description:** ${scene.description || 'No description available.'}`,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves a sceneId, defaulting to the currently active scene if omitted.
|
|
38
|
+
* Throws an McpError if no scene is active and no sceneId is provided.
|
|
39
|
+
*/
|
|
40
|
+
export function resolveSceneId(sceneId, foundryClient) {
|
|
41
|
+
if (sceneId) {
|
|
42
|
+
return sceneId;
|
|
43
|
+
}
|
|
44
|
+
const active = foundryClient.getScenes().find((s) => s.active);
|
|
45
|
+
if (!active) {
|
|
46
|
+
throw new McpError(ErrorCode.InvalidRequest, 'No active scene and no sceneId given — pass sceneId explicitly.');
|
|
47
|
+
}
|
|
48
|
+
return active._id;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Handles listing the Tiles placed on a scene.
|
|
52
|
+
*/
|
|
53
|
+
export async function handleListTiles(args, foundryClient) {
|
|
54
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
55
|
+
return withToolError('list tiles', async () => {
|
|
56
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
57
|
+
const tiles = foundryClient.listTiles(sceneId);
|
|
58
|
+
if (tiles.length === 0) {
|
|
59
|
+
return {
|
|
60
|
+
content: [{ type: 'text', text: `🧱 **No tiles placed on ${scene?.name ?? sceneId}.**` }],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const lines = tiles.map((t) => `- **${t.src.split('/').pop()}** (${t.id}) — (${t.x}, ${t.y}) ${t.width}x${t.height}px${t.rotation ? `, rotated ${t.rotation}°` : ''}${t.hidden ? ' [hidden]' : ''}`);
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: 'text',
|
|
68
|
+
text: `🧱 **Tiles on ${scene?.name ?? sceneId}** (${tiles.length})\n${lines.join('\n')}`,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Handles listing the Walls on a scene.
|
|
76
|
+
*/
|
|
77
|
+
export async function handleListWalls(args, foundryClient) {
|
|
78
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
79
|
+
return withToolError('list walls', async () => {
|
|
80
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
81
|
+
const walls = foundryClient.listWalls(sceneId);
|
|
82
|
+
if (walls.length === 0) {
|
|
83
|
+
return {
|
|
84
|
+
content: [{ type: 'text', text: `🧱 **No walls on ${scene?.name ?? sceneId}.**` }],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const lines = walls.map((w) => {
|
|
88
|
+
const kind = w.door === 1 ? ' [door]' : w.door === 2 ? ' [secret door]' : '';
|
|
89
|
+
const state = w.door !== 0 ? ` (${['closed', 'open', 'locked'][w.ds]})` : '';
|
|
90
|
+
return `- **${w.id}** — (${w.x1}, ${w.y1}) → (${w.x2}, ${w.y2})${kind}${state}`;
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
content: [
|
|
94
|
+
{
|
|
95
|
+
type: 'text',
|
|
96
|
+
text: `🧱 **Walls on ${scene?.name ?? sceneId}** (${walls.length})\n${lines.join('\n')}`,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Handles listing the Tokens placed on a scene, defaulting to the active
|
|
104
|
+
* scene when sceneId is omitted (mirrors handleSpawnToken).
|
|
105
|
+
*/
|
|
106
|
+
export async function handleListTokens(args, foundryClient) {
|
|
107
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
108
|
+
return withToolError('list tokens', async () => {
|
|
109
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
110
|
+
const tokens = foundryClient.listTokens(sceneId);
|
|
111
|
+
if (tokens.length === 0) {
|
|
112
|
+
return {
|
|
113
|
+
content: [{ type: 'text', text: `🧍 **No tokens placed on ${scene?.name ?? sceneId}.**` }],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const dispositionLabels = {
|
|
117
|
+
[-2]: 'secret',
|
|
118
|
+
[-1]: 'hostile',
|
|
119
|
+
0: 'neutral',
|
|
120
|
+
1: 'friendly',
|
|
121
|
+
};
|
|
122
|
+
const lines = tokens.map((t) => {
|
|
123
|
+
const actorRef = t.actorId ? ` — actor ${t.actorId}${t.actorLink ? '' : ' (unlinked)'}` : '';
|
|
124
|
+
const disposition = dispositionLabels[t.disposition] ?? `disposition ${t.disposition}`;
|
|
125
|
+
return `- **${t.name || '(unnamed)'}** (${t.id}) — (${t.x}, ${t.y}) ${t.width}x${t.height} cells${t.elevation ? `, elevation ${t.elevation}` : ''}, ${disposition}${t.hidden ? ' [hidden]' : ''}${actorRef}`;
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
content: [
|
|
129
|
+
{
|
|
130
|
+
type: 'text',
|
|
131
|
+
text: `🧍 **Tokens on ${scene?.name ?? sceneId}** (${tokens.length})\n${lines.join('\n')}`,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Handles listing the AmbientLights placed on a scene.
|
|
139
|
+
*/
|
|
140
|
+
export async function handleListLights(args, foundryClient) {
|
|
141
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
142
|
+
return withToolError('list lights', async () => {
|
|
143
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
144
|
+
const lights = foundryClient.listLights(sceneId);
|
|
145
|
+
if (lights.length === 0) {
|
|
146
|
+
return {
|
|
147
|
+
content: [{ type: 'text', text: `💡 **No ambient lights on ${scene?.name ?? sceneId}.**` }],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const lines = lights.map((l) => `- **${l.id}** — (${l.x}, ${l.y}) dim: ${l.dim}, bright: ${l.bright}${l.color ? `, color: ${l.color}` : ''}${l.rotation ? `, rotated ${l.rotation}°` : ''}${l.animationType ? ` [animation: ${l.animationType}]` : ''}${l.hidden ? ' [hidden]' : ''}`);
|
|
151
|
+
return {
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: 'text',
|
|
155
|
+
text: `💡 **Ambient Lights on ${scene?.name ?? sceneId}** (${lights.length})\n${lines.join('\n')}`,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Handles listing the AmbientSounds placed on a scene.
|
|
163
|
+
*/
|
|
164
|
+
export async function handleListSounds(args, foundryClient) {
|
|
165
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
166
|
+
return withToolError('list sounds', async () => {
|
|
167
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
168
|
+
const sounds = foundryClient.listSounds(sceneId);
|
|
169
|
+
if (sounds.length === 0) {
|
|
170
|
+
return {
|
|
171
|
+
content: [{ type: 'text', text: `🔊 **No ambient sounds on ${scene?.name ?? sceneId}.**` }],
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const lines = sounds.map((s) => `- **${s.id}** — (${s.x}, ${s.y}) radius: ${s.radius}px, path: \`${s.path}\`, volume: ${s.volume}${s.repeat ? ' [repeat]' : ''}${s.hidden ? ' [hidden]' : ''}`);
|
|
175
|
+
return {
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
type: 'text',
|
|
179
|
+
text: `🔊 **Ambient Sounds on ${scene?.name ?? sceneId}** (${sounds.length})\n${lines.join('\n')}`,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Handles listing the Notes (map pins) placed on a scene.
|
|
187
|
+
*/
|
|
188
|
+
export async function handleListNotes(args, foundryClient) {
|
|
189
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
190
|
+
return withToolError('list notes', async () => {
|
|
191
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
192
|
+
const notes = foundryClient.listNotes(sceneId);
|
|
193
|
+
if (notes.length === 0) {
|
|
194
|
+
return {
|
|
195
|
+
content: [{ type: 'text', text: `📌 **No map notes on ${scene?.name ?? sceneId}.**` }],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const lines = notes.map((n) => `- **${n.id}** — (${n.x}, ${n.y})${n.text ? ` text: "${n.text}"` : ''}${n.entryId ? ` (linked journal ${n.entryId}${n.pageId ? ` page ${n.pageId}` : ''})` : ''}${n.global ? ' [global]' : ''}`);
|
|
199
|
+
return {
|
|
200
|
+
content: [
|
|
201
|
+
{
|
|
202
|
+
type: 'text',
|
|
203
|
+
text: `📌 **Map Notes on ${scene?.name ?? sceneId}** (${notes.length})\n${lines.join('\n')}`,
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Handles listing the Drawings placed on a scene.
|
|
211
|
+
*/
|
|
212
|
+
export async function handleListDrawings(args, foundryClient) {
|
|
213
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
214
|
+
return withToolError('list drawings', async () => {
|
|
215
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
216
|
+
const drawings = foundryClient.listDrawings(sceneId);
|
|
217
|
+
if (drawings.length === 0) {
|
|
218
|
+
return {
|
|
219
|
+
content: [{ type: 'text', text: `🎨 **No drawings on ${scene?.name ?? sceneId}.**` }],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const lines = drawings.map((d) => `- **${d.id}** — [${d.shapeType}] (${d.x}, ${d.y})${d.width !== null ? ` ${d.width}x${d.height}px` : ''}${d.radius !== null ? ` radius ${d.radius}px` : ''}${d.text ? ` text: "${d.text}"` : ''}${d.fillColor ? ` fill: ${d.fillColor}` : ''}${d.strokeColor ? ` stroke: ${d.strokeColor}` : ''}${d.hidden ? ' [hidden]' : ''}${d.locked ? ' [locked]' : ''}`);
|
|
223
|
+
return {
|
|
224
|
+
content: [
|
|
225
|
+
{
|
|
226
|
+
type: 'text',
|
|
227
|
+
text: `🎨 **Drawings on ${scene?.name ?? sceneId}** (${drawings.length})\n${lines.join('\n')}`,
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Handles listing the MeasuredTemplates placed on a scene.
|
|
235
|
+
*/
|
|
236
|
+
export async function handleListTemplates(args, foundryClient) {
|
|
237
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
238
|
+
return withToolError('list templates', async () => {
|
|
239
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
240
|
+
const templates = foundryClient.listTemplates(sceneId);
|
|
241
|
+
if (templates.length === 0) {
|
|
242
|
+
return {
|
|
243
|
+
content: [
|
|
244
|
+
{ type: 'text', text: `📐 **No measured templates on ${scene?.name ?? sceneId}.**` },
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const lines = templates.map((t) => `- **${t.id}** — [${t.t}] (${t.x}, ${t.y}) distance: ${t.distance}${t.direction ? `, dir: ${t.direction}°` : ''}${t.angle ? `, angle: ${t.angle}°` : ''}${t.width ? `, width: ${t.width}` : ''}${t.fillColor ? ` fill: ${t.fillColor}` : ''}${t.hidden ? ' [hidden]' : ''}`);
|
|
249
|
+
return {
|
|
250
|
+
content: [
|
|
251
|
+
{
|
|
252
|
+
type: 'text',
|
|
253
|
+
text: `📐 **Measured Templates on ${scene?.name ?? sceneId}** (${templates.length})\n${lines.join('\n')}`,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Handles scanning a scene's grid for open (wall-free, unoccupied) cells.
|
|
261
|
+
*/
|
|
262
|
+
export async function handleFindOpenCells(args, foundryClient) {
|
|
263
|
+
const { sceneId, limit } = args;
|
|
264
|
+
if (!sceneId || typeof sceneId !== 'string') {
|
|
265
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId is required and must be a string');
|
|
266
|
+
}
|
|
267
|
+
return withToolError('find open cells', async () => {
|
|
268
|
+
const cells = foundryClient.findOpenCells(sceneId, limit !== undefined ? { limit } : {});
|
|
269
|
+
if (cells.length === 0) {
|
|
270
|
+
return {
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
type: 'text',
|
|
274
|
+
text: '🔲 **No open cells found** (scene may be fully walled or occupied).',
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const lines = cells.map((c) => `- col ${c.col}, row ${c.row} → (${c.x}, ${c.y})`);
|
|
280
|
+
return {
|
|
281
|
+
content: [
|
|
282
|
+
{
|
|
283
|
+
type: 'text',
|
|
284
|
+
text: `🔲 **Open Cells** (${cells.length})\n${lines.join('\n')}`,
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Handles listing image assets under FoundryVTT's Data directory.
|
|
292
|
+
*/
|
|
293
|
+
export async function handleListSceneAssets(args, foundryClient) {
|
|
294
|
+
const { subdir, query, limit } = args;
|
|
295
|
+
return withToolError('list scene assets', async () => {
|
|
296
|
+
const options = {};
|
|
297
|
+
if (query !== undefined) {
|
|
298
|
+
options.query = query;
|
|
299
|
+
}
|
|
300
|
+
if (limit !== undefined) {
|
|
301
|
+
options.limit = limit;
|
|
302
|
+
}
|
|
303
|
+
const assets = foundryClient.listSceneAssets(subdir, options);
|
|
304
|
+
if (assets.length === 0) {
|
|
305
|
+
return {
|
|
306
|
+
content: [
|
|
307
|
+
{
|
|
308
|
+
type: 'text',
|
|
309
|
+
text: '🖼️ **No assets found.** Verify FOUNDRY_DATA_PATH is set and the folder exists.',
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const lines = assets.map((a) => `- **${a.name}** — \`${a.path}\` (${a.width}x${a.height})${a.tags.length ? ` [${a.tags.join(', ')}]` : ''}`);
|
|
315
|
+
return {
|
|
316
|
+
content: [
|
|
317
|
+
{
|
|
318
|
+
type: 'text',
|
|
319
|
+
text: `🖼️ **Scene Assets** (${assets.length})\n${lines.join('\n')}`,
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Handles listing the Scene Regions placed on a scene (FoundryVTT v12+).
|
|
327
|
+
*/
|
|
328
|
+
export async function handleListRegions(args, foundryClient) {
|
|
329
|
+
const sceneId = resolveSceneId(args.sceneId, foundryClient);
|
|
330
|
+
return withToolError('list regions', async () => {
|
|
331
|
+
const scene = foundryClient.getScenes().find((s) => s._id === sceneId);
|
|
332
|
+
const regions = foundryClient.listRegions(sceneId);
|
|
333
|
+
if (regions.length === 0) {
|
|
334
|
+
return {
|
|
335
|
+
content: [{ type: 'text', text: `🌐 **No regions on ${scene?.name ?? sceneId}.**` }],
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
const lines = regions.map((r) => {
|
|
339
|
+
const elev = r.elevation.bottom !== null || r.elevation.top !== null
|
|
340
|
+
? ` elevation: [${r.elevation.bottom ?? '-∞'}, ${r.elevation.top ?? '+∞'}]`
|
|
341
|
+
: '';
|
|
342
|
+
const color = r.color ? ` color: ${r.color}` : '';
|
|
343
|
+
return `- **${r.name || r.id}** (\`${r.id}\`)${color}${elev} (${r.shapesCount} shape${r.shapesCount === 1 ? '' : 's'}, ${r.behaviorsCount} behavior${r.behaviorsCount === 1 ? '' : 's'})`;
|
|
344
|
+
});
|
|
345
|
+
return {
|
|
346
|
+
content: [
|
|
347
|
+
{
|
|
348
|
+
type: 'text',
|
|
349
|
+
text: `🌐 **Scene Regions on ${scene?.name ?? sceneId}** (${regions.length})\n${lines.join('\n')}`,
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
};
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
//# sourceMappingURL=scenes.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview World settings tool handlers.
|
|
3
|
+
*/
|
|
4
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { withToolError } from './utils.js';
|
|
6
|
+
export async function handleGetWorldSetting(args, foundryClient) {
|
|
7
|
+
const { key } = args;
|
|
8
|
+
if (!key || typeof key !== 'string') {
|
|
9
|
+
throw new McpError(ErrorCode.InvalidParams, 'key is required and must be a string');
|
|
10
|
+
}
|
|
11
|
+
return withToolError('get world setting', async () => {
|
|
12
|
+
const setting = foundryClient.getWorldSetting(key);
|
|
13
|
+
if (!setting.exists) {
|
|
14
|
+
return {
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
text: `⚙️ **World Setting: \`${key}\`**\n**Status:** Not set in world database (using system/module default value).`,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
text: `⚙️ **World Setting: \`${key}\`**\n**Value:** \`\`\`json\n${JSON.stringify(setting.value, null, 2)}\n\`\`\``,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export async function handleSetWorldSetting(args, foundryClient) {
|
|
34
|
+
const { key, value } = args;
|
|
35
|
+
if (!key || typeof key !== 'string') {
|
|
36
|
+
throw new McpError(ErrorCode.InvalidParams, 'key is required and must be a string');
|
|
37
|
+
}
|
|
38
|
+
return withToolError('set world setting', async () => {
|
|
39
|
+
const result = await foundryClient.setWorldSetting(key, value);
|
|
40
|
+
const prevText = result.previous !== undefined
|
|
41
|
+
? `\n**Previous Value:** \`\`\`json\n${JSON.stringify(result.previous, null, 2)}\n\`\`\``
|
|
42
|
+
: '\n**Previous Value:** _(not previously set in world database)_';
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `⚙️ **World Setting Updated**\n**Key:** \`${result.key}\`\n**Action:** ${result.created ? 'Created' : 'Updated'}\n**New Value:** \`\`\`json\n${JSON.stringify(result.value, null, 2)}\n\`\`\`${prevText}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tile mutation tool handlers
|
|
3
|
+
*
|
|
4
|
+
* WRITE operations — require FOUNDRY_WRITE_ENABLED=true and an active
|
|
5
|
+
* Socket.IO connection (mutations use the core `modifyDocument` protocol).
|
|
6
|
+
* `Tile` is an embedded document of `Scene` (mirrors token mutation handlers).
|
|
7
|
+
*/
|
|
8
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import { withToolError } from './utils.js';
|
|
10
|
+
/**
|
|
11
|
+
* Handles placing a decorative Tile on a scene.
|
|
12
|
+
*/
|
|
13
|
+
export async function handleCreateTile(args, foundryClient) {
|
|
14
|
+
const { sceneId, src, ...options } = args;
|
|
15
|
+
if (!sceneId || typeof sceneId !== 'string') {
|
|
16
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId is required and must be a string');
|
|
17
|
+
}
|
|
18
|
+
if (!src || typeof src !== 'string') {
|
|
19
|
+
throw new McpError(ErrorCode.InvalidParams, 'src is required and must be a string');
|
|
20
|
+
}
|
|
21
|
+
return withToolError('create tile', async () => {
|
|
22
|
+
const tile = (await foundryClient.createTile(sceneId, src, options));
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
text: `🧱 **Tile Placed**\n**Image:** ${src.split('/').pop()}\n**ID:** ${tile._id}\n**Position:** (${tile.x}, ${tile.y})\n**Size:** ${tile.width}x${tile.height}px`,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handles removing a Tile from a scene.
|
|
35
|
+
*/
|
|
36
|
+
export async function handleDeleteTile(args, foundryClient) {
|
|
37
|
+
const { sceneId, tileId } = args;
|
|
38
|
+
if (!sceneId || typeof sceneId !== 'string') {
|
|
39
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId is required and must be a string');
|
|
40
|
+
}
|
|
41
|
+
if (!tileId || typeof tileId !== 'string') {
|
|
42
|
+
throw new McpError(ErrorCode.InvalidParams, 'tileId is required and must be a string');
|
|
43
|
+
}
|
|
44
|
+
return withToolError('delete tile', async () => {
|
|
45
|
+
await foundryClient.deleteTile(sceneId, tileId);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: `🗑️ **Tile Removed**\n**ID:** ${tileId}`,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=tile-mutations.js.map
|