@g33ks/foundryvtt-mcp 2.2.0 → 3.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.
- package/README.md +68 -410
- package/dist/config/index.js +6 -0
- package/dist/config/sources.js +1 -0
- package/dist/core.js +3 -0
- package/dist/foundry/auth.js +40 -1
- package/dist/foundry/client.js +62 -18
- package/dist/foundry/scene-lighting.js +41 -0
- package/dist/mcp-server.js +12 -5
- package/dist/shared/config-hash.js +1 -0
- package/dist/tools/definitions.js +50 -42
- package/dist/tools/handlers/module-bridge.js +109 -21
- package/dist/tools/handlers/scenes.js +7 -2
- package/dist/tools/router.js +5 -5
- package/dist/utils/mcp-errors.js +25 -1
- package/package.json +2 -1
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Handles scene information retrieval and management.
|
|
5
5
|
*/
|
|
6
6
|
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { readSceneLighting } from '../../foundry/scene-lighting.js';
|
|
7
8
|
import { withToolError } from './utils.js';
|
|
8
9
|
/**
|
|
9
10
|
* Handles scene information requests
|
|
@@ -12,6 +13,10 @@ export async function handleGetSceneInfo(args, foundryClient) {
|
|
|
12
13
|
const { sceneId } = args;
|
|
13
14
|
return withToolError('get scene info', async () => {
|
|
14
15
|
const scene = await foundryClient.getCurrentScene(sceneId);
|
|
16
|
+
// The REST API module answers with the raw document, which keeps them under `environment`.
|
|
17
|
+
const { darkness, globalLight } = readSceneLighting(scene);
|
|
18
|
+
const lightLabel = globalLight === undefined ? 'Unknown' : globalLight ? 'Enabled' : 'Disabled';
|
|
19
|
+
const darknessLabel = darkness === undefined ? 'Unknown' : `${Math.round(darkness * 100)}%`;
|
|
15
20
|
return {
|
|
16
21
|
content: [
|
|
17
22
|
{
|
|
@@ -24,8 +29,8 @@ export async function handleGetSceneInfo(args, foundryClient) {
|
|
|
24
29
|
**Dimensions:** ${scene.width} x ${scene.height} pixels
|
|
25
30
|
**Padding:** ${scene.padding * 100}%
|
|
26
31
|
**Grid:** ${scene.grid ? `${scene.grid.size}px, distance ${scene.grid.distance}${scene.grid.units ? ` ${scene.grid.units}` : ''}` : 'Unknown'}
|
|
27
|
-
**Global Light:** ${
|
|
28
|
-
**Darkness Level:** ${
|
|
32
|
+
**Global Light:** ${lightLabel}
|
|
33
|
+
**Darkness Level:** ${darknessLabel}
|
|
29
34
|
|
|
30
35
|
**Description:** ${scene.description || 'No description available.'}`,
|
|
31
36
|
},
|
package/dist/tools/router.js
CHANGED
|
@@ -461,7 +461,7 @@ export async function routeToolRequest(name, args, foundryClient, diagnosticsCli
|
|
|
461
461
|
if (!('formula' in args) || typeof args.formula !== 'string') {
|
|
462
462
|
throw new Error('Missing required parameter: formula');
|
|
463
463
|
}
|
|
464
|
-
return handleRollAndPost(args, moduleBridge);
|
|
464
|
+
return handleRollAndPost(args, foundryClient, moduleBridge);
|
|
465
465
|
case 'import_compendium_actor':
|
|
466
466
|
if (!('compendiumId' in args) || typeof args.compendiumId !== 'string') {
|
|
467
467
|
throw new Error('Missing required parameter: compendiumId');
|
|
@@ -474,7 +474,7 @@ export async function routeToolRequest(name, args, foundryClient, diagnosticsCli
|
|
|
474
474
|
if (!('tokenIds' in args) || !Array.isArray(args.tokenIds)) {
|
|
475
475
|
throw new Error('Missing required parameter: tokenIds');
|
|
476
476
|
}
|
|
477
|
-
return handleSetTarget(args, moduleBridge);
|
|
477
|
+
return handleSetTarget(args, foundryClient, moduleBridge);
|
|
478
478
|
case 'get_actor_stats':
|
|
479
479
|
return handleGetActorStats(args, foundryClient, moduleBridge);
|
|
480
480
|
case 'get_targets':
|
|
@@ -486,9 +486,9 @@ export async function routeToolRequest(name, args, foundryClient, diagnosticsCli
|
|
|
486
486
|
if (!('y' in args) || typeof args.y !== 'number') {
|
|
487
487
|
throw new Error('Missing required parameter: y');
|
|
488
488
|
}
|
|
489
|
-
return handlePingCanvas(args, moduleBridge);
|
|
489
|
+
return handlePingCanvas(args, foundryClient, moduleBridge);
|
|
490
490
|
case 'set_pause':
|
|
491
|
-
return handleSetPause(args, moduleBridge);
|
|
491
|
+
return handleSetPause(args, foundryClient, moduleBridge);
|
|
492
492
|
case 'upload_asset':
|
|
493
493
|
if (!('targetDir' in args) || typeof args.targetDir !== 'string') {
|
|
494
494
|
throw new Error('Missing required parameter: targetDir');
|
|
@@ -496,7 +496,7 @@ export async function routeToolRequest(name, args, foundryClient, diagnosticsCli
|
|
|
496
496
|
if (!('filename' in args) || typeof args.filename !== 'string') {
|
|
497
497
|
throw new Error('Missing required parameter: filename');
|
|
498
498
|
}
|
|
499
|
-
return handleUploadAsset(args, moduleBridge);
|
|
499
|
+
return handleUploadAsset(args, foundryClient, moduleBridge);
|
|
500
500
|
// World-event tools (read-only)
|
|
501
501
|
case 'watch_events':
|
|
502
502
|
return handleWatchEvents(args, foundryClient);
|
package/dist/utils/mcp-errors.js
CHANGED
|
@@ -6,8 +6,14 @@
|
|
|
6
6
|
* client's SDK then builds its own `McpError`, which adds the prefix a second
|
|
7
7
|
* time (G33ks/foundryvtt-mcp#15). The message
|
|
8
8
|
* on the wire must therefore be the bare text.
|
|
9
|
+
*
|
|
10
|
+
* A failed tool call is not a JSON-RPC error but a result with
|
|
11
|
+
* `isError: true`, so the model reads why it failed (MCP specification,
|
|
12
|
+
* "Error Handling" of tools). No client adds a prefix to a result: the text
|
|
13
|
+
* carries the one prefix itself. An unknown tool and a failed resource read
|
|
14
|
+
* (`resources/read` has no `isError`) stay JSON-RPC errors.
|
|
9
15
|
*/
|
|
10
|
-
import { McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
16
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
11
17
|
/** McpError prefixes its message with "MCP error <code>: "; this is the text without it. */
|
|
12
18
|
export function bareMessage(error) {
|
|
13
19
|
return error.message.replace(/^MCP error -?\d+: /, '');
|
|
@@ -28,6 +34,24 @@ export class WireError extends Error {
|
|
|
28
34
|
this.data = data;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* A failed tool call as the client gets it: an `isError` result whose text
|
|
39
|
+
* is "MCP error <code>: <message>", with the McpError's code, or
|
|
40
|
+
* InternalError for any other error. An unknown tool is thrown again as a
|
|
41
|
+
* {@link WireError}, to stay a JSON-RPC error.
|
|
42
|
+
*/
|
|
43
|
+
export function toolErrorResult(error) {
|
|
44
|
+
if (error instanceof McpError && error.code === ErrorCode.MethodNotFound) {
|
|
45
|
+
throw new WireError(error.code, bareMessage(error), error.data);
|
|
46
|
+
}
|
|
47
|
+
const code = error instanceof McpError ? error.code : ErrorCode.InternalError;
|
|
48
|
+
const message = error instanceof McpError
|
|
49
|
+
? bareMessage(error)
|
|
50
|
+
: error instanceof Error
|
|
51
|
+
? error.message
|
|
52
|
+
: String(error);
|
|
53
|
+
return { isError: true, content: [{ type: 'text', text: `MCP error ${code}: ${message}` }] };
|
|
54
|
+
}
|
|
31
55
|
/**
|
|
32
56
|
* Runs a request handler; an `McpError` it throws leaves with its bare
|
|
33
57
|
* message, its code and its data, so the client shows one prefix. Any other
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g33ks/foundryvtt-mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Model Context Protocol server for FoundryVTT integration",
|
|
5
5
|
"bin": {
|
|
6
6
|
"foundryvtt-mcp": "dist/index.js"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"smoke": "node scripts/smoke-test.js",
|
|
14
14
|
"smoke:dotenv": "node scripts/smoke-dotenv.js",
|
|
15
15
|
"smoke:pack": "node scripts/smoke-pack.js",
|
|
16
|
+
"docs:tools": "node scripts/generate-tools-doc.js",
|
|
16
17
|
"stress:shared": "node scripts/stress-shared.js",
|
|
17
18
|
"check:bridge-security": "node scripts/check-bridge-security.js",
|
|
18
19
|
"bridge:package": "node scripts/package-bridge.js",
|