@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.
- package/LICENSE +22 -0
- package/README.md +468 -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 +410 -0
- package/dist/cli/prompt.js +117 -0
- package/dist/cli/snippets.js +49 -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 +415 -0
- package/dist/diagnostics/client.js +353 -0
- package/dist/diagnostics/types.js +94 -0
- package/dist/foundry/auth.js +220 -0
- package/dist/foundry/browser-detect.js +170 -0
- package/dist/foundry/client.js +5555 -0
- package/dist/foundry/dice-formula.js +154 -0
- package/dist/foundry/event-log.js +299 -0
- package/dist/foundry/headless-gm-session.js +740 -0
- package/dist/foundry/journal-history.js +90 -0
- package/dist/foundry/journal-integrity.js +306 -0
- package/dist/foundry/module-bridge.js +413 -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 +63 -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 +255 -0
- package/dist/shared/daemon-link.js +135 -0
- package/dist/shared/daemon.js +313 -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 +36 -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 +438 -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 +47 -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/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/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,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview General-purpose ActiveEffect tool handlers (create/update/delete/list).
|
|
3
|
+
*
|
|
4
|
+
* `apply_status_effect` (token-mutations.ts) stays a separate, simpler
|
|
5
|
+
* contract — toggle a condition by status id, idempotent — and is not
|
|
6
|
+
* superseded by these; these exist for mechanical buffs/debuffs carrying
|
|
7
|
+
* real `changes`/`duration`.
|
|
8
|
+
*/
|
|
9
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
+
import { withToolError } from './utils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the `ActiveEffect` parent UUID from an actor reference.
|
|
13
|
+
*
|
|
14
|
+
* `actorId` is always required. `sceneId` and `tokenId` are an optional
|
|
15
|
+
* pair — supplying only one of the two is rejected — that, when present,
|
|
16
|
+
* select the unlinked-token-actor UUID form instead of the plain
|
|
17
|
+
* `Actor.<actorId>` form.
|
|
18
|
+
*/
|
|
19
|
+
function resolveActorUuid(ref) {
|
|
20
|
+
if (!ref.actorId || typeof ref.actorId !== 'string') {
|
|
21
|
+
throw new McpError(ErrorCode.InvalidParams, 'actorId is required and must be a string');
|
|
22
|
+
}
|
|
23
|
+
const hasScene = ref.sceneId !== undefined;
|
|
24
|
+
const hasToken = ref.tokenId !== undefined;
|
|
25
|
+
if (hasScene !== hasToken) {
|
|
26
|
+
throw new McpError(ErrorCode.InvalidParams, 'sceneId and tokenId must be supplied together (for an unlinked token actor) or not at all');
|
|
27
|
+
}
|
|
28
|
+
return hasScene
|
|
29
|
+
? `Scene.${ref.sceneId}.Token.${ref.tokenId}.Actor.${ref.actorId}`
|
|
30
|
+
: `Actor.${ref.actorId}`;
|
|
31
|
+
}
|
|
32
|
+
function formatEffect(effect) {
|
|
33
|
+
const parts = [`**ID:** ${effect._id}`, `**Name:** ${effect.name}`];
|
|
34
|
+
if (effect.statuses && effect.statuses.length > 0) {
|
|
35
|
+
parts.push(`**Statuses:** ${effect.statuses.join(', ')}`);
|
|
36
|
+
}
|
|
37
|
+
if (effect.changes && effect.changes.length > 0) {
|
|
38
|
+
parts.push(`**Changes:** ${JSON.stringify(effect.changes)}`);
|
|
39
|
+
}
|
|
40
|
+
if (effect.duration && Object.keys(effect.duration).length > 0) {
|
|
41
|
+
parts.push(`**Duration:** ${JSON.stringify(effect.duration)}`);
|
|
42
|
+
}
|
|
43
|
+
return parts.join('\n');
|
|
44
|
+
}
|
|
45
|
+
export async function handleCreateActorEffect(args, foundryClient) {
|
|
46
|
+
const parentActorUuid = resolveActorUuid(args);
|
|
47
|
+
if (!args.name || typeof args.name !== 'string') {
|
|
48
|
+
throw new McpError(ErrorCode.InvalidParams, 'name is required and must be a string');
|
|
49
|
+
}
|
|
50
|
+
return withToolError('create actor effect', async () => {
|
|
51
|
+
const effect = await foundryClient.createActorEffect(parentActorUuid, args);
|
|
52
|
+
return {
|
|
53
|
+
content: [{ type: 'text', text: `✨ **Effect Created**\n${formatEffect(effect)}` }],
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export async function handleUpdateActorEffect(args, foundryClient) {
|
|
58
|
+
const parentActorUuid = resolveActorUuid(args);
|
|
59
|
+
if (!args.effectId || typeof args.effectId !== 'string') {
|
|
60
|
+
throw new McpError(ErrorCode.InvalidParams, 'effectId is required and must be a string');
|
|
61
|
+
}
|
|
62
|
+
return withToolError('update actor effect', async () => {
|
|
63
|
+
const effect = await foundryClient.updateActorEffect(parentActorUuid, args.effectId, args);
|
|
64
|
+
return {
|
|
65
|
+
content: [{ type: 'text', text: `✨ **Effect Updated**\n${formatEffect(effect)}` }],
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export async function handleDeleteActorEffect(args, foundryClient) {
|
|
70
|
+
const parentActorUuid = resolveActorUuid(args);
|
|
71
|
+
if (!args.effectId || typeof args.effectId !== 'string') {
|
|
72
|
+
throw new McpError(ErrorCode.InvalidParams, 'effectId is required and must be a string');
|
|
73
|
+
}
|
|
74
|
+
return withToolError('delete actor effect', async () => {
|
|
75
|
+
await foundryClient.deleteActorEffect(parentActorUuid, args.effectId);
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: 'text', text: `🗑️ **Effect Deleted**\n**ID:** ${args.effectId}` }],
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export async function handleListActorEffects(args, foundryClient) {
|
|
82
|
+
if (!args.actorId || typeof args.actorId !== 'string') {
|
|
83
|
+
throw new McpError(ErrorCode.InvalidParams, 'actorId is required and must be a string');
|
|
84
|
+
}
|
|
85
|
+
return withToolError('list actor effects', async () => {
|
|
86
|
+
const effects = foundryClient.listActorEffects(args.actorId);
|
|
87
|
+
if (effects.length === 0) {
|
|
88
|
+
return {
|
|
89
|
+
content: [{ type: 'text', text: '✨ **No active effects on this actor.**' }],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const lines = effects.map((effect) => `- ${formatEffect(effect)}`.replace(/\n/g, ' | '));
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: 'text',
|
|
97
|
+
text: `✨ **Active Effects** (${effects.length})\n${lines.join('\n')}`,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* World-event tool handler (`watch_events`).
|
|
3
|
+
*/
|
|
4
|
+
import { config } from '../../config/index.js';
|
|
5
|
+
import { withToolError } from './utils.js';
|
|
6
|
+
/** Clamps `waitMs` into the range the tool description promises. */
|
|
7
|
+
function clampWaitMs(value) {
|
|
8
|
+
const fallback = config.events.defaultWaitMs;
|
|
9
|
+
const raw = value ?? fallback;
|
|
10
|
+
return Math.min(Math.max(raw, 0), 120000);
|
|
11
|
+
}
|
|
12
|
+
/** Clamps `limit` into the range the tool description promises. */
|
|
13
|
+
function clampLimit(value) {
|
|
14
|
+
return Math.min(Math.max(value ?? 50, 1), 200);
|
|
15
|
+
}
|
|
16
|
+
export async function handleWatchEvents(args, foundryClient) {
|
|
17
|
+
return withToolError('watch events', async () => {
|
|
18
|
+
const waitMs = clampWaitMs(args.waitMs);
|
|
19
|
+
const limit = clampLimit(args.limit);
|
|
20
|
+
const result = await foundryClient.watchEvents({
|
|
21
|
+
...(args.cursor !== undefined ? { cursor: args.cursor } : {}),
|
|
22
|
+
waitMs,
|
|
23
|
+
limit,
|
|
24
|
+
...(args.kinds ? { kinds: args.kinds } : {}),
|
|
25
|
+
...(args.types ? { types: args.types } : {}),
|
|
26
|
+
...(args.actions ? { actions: args.actions } : {}),
|
|
27
|
+
...(args.sceneId ? { sceneId: args.sceneId } : {}),
|
|
28
|
+
...(args.excludeSelf !== undefined ? { excludeSelf: args.excludeSelf } : {}),
|
|
29
|
+
});
|
|
30
|
+
const lines = [];
|
|
31
|
+
if (result.dropped > 0) {
|
|
32
|
+
lines.push(`⚠️ **${result.dropped} events were dropped** before your cursor (buffer holds a limited window). Cached world data may be behind — run \`refresh_world_data\`.`, '');
|
|
33
|
+
}
|
|
34
|
+
if (result.events.length === 0) {
|
|
35
|
+
lines.push(`👁️ **World Events** (none)`, `No world activity in the last ${waitMs}ms.`, '', `**nextCursor:** ${result.nextCursor} — pass this back as \`cursor\` on the next call.`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const first = result.events[0];
|
|
39
|
+
const last = result.events[result.events.length - 1];
|
|
40
|
+
lines.push(`👁️ **World Events** (${result.events.length} new)`, `**Cursor:** ${first ? first.seq - 1 : 0} → ${last?.seq ?? result.nextCursor}`, '', ...result.events.map((event, index) => `${index + 1}. [${event.seq}] ${event.summary}`), '', `**nextCursor:** ${result.nextCursor} — pass this back as \`cursor\` on the next call.`);
|
|
41
|
+
if (result.more) {
|
|
42
|
+
lines.push(`**more:** true — more matching events are already buffered; call again with this cursor.`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Content generation tool handlers
|
|
3
|
+
*
|
|
4
|
+
* Handles NPC generation, loot generation, and rule lookups.
|
|
5
|
+
*/
|
|
6
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { stripHtml } from '../../utils/sanitize.js';
|
|
8
|
+
import { withToolError } from './utils.js';
|
|
9
|
+
/**
|
|
10
|
+
* Handles NPC generation requests
|
|
11
|
+
*/
|
|
12
|
+
export async function handleGenerateNPC(args, _foundryClient) {
|
|
13
|
+
const { level = 1, race, class: characterClass } = args;
|
|
14
|
+
return withToolError('generate NPC', async () => {
|
|
15
|
+
// Generate basic NPC data
|
|
16
|
+
const npcName = generateRandomName();
|
|
17
|
+
const npcRace = race || getRandomRace();
|
|
18
|
+
const npcClass = characterClass || getRandomClass();
|
|
19
|
+
const stats = generateAbilityScores();
|
|
20
|
+
const hp = Math.max(1, Math.floor(Math.random() * (level * 8)) + level);
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: 'text',
|
|
25
|
+
text: `🧙 **Generated NPC**
|
|
26
|
+
**Name:** ${npcName}
|
|
27
|
+
**Race:** ${npcRace}
|
|
28
|
+
**Class:** ${npcClass}
|
|
29
|
+
**Level:** ${level}
|
|
30
|
+
**Hit Points:** ${hp}
|
|
31
|
+
|
|
32
|
+
**Ability Scores:**
|
|
33
|
+
**STR:** ${stats.str} | **DEX:** ${stats.dex} | **CON:** ${stats.con}
|
|
34
|
+
**INT:** ${stats.int} | **WIS:** ${stats.wis} | **CHA:** ${stats.cha}
|
|
35
|
+
|
|
36
|
+
**Background:** ${generateBackground(npcRace, npcClass)}`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Handles loot generation requests
|
|
44
|
+
*/
|
|
45
|
+
export async function handleGenerateLoot(args, _foundryClient) {
|
|
46
|
+
const { challengeRating = 1, treasureType = 'individual' } = args;
|
|
47
|
+
return withToolError('generate loot', async () => {
|
|
48
|
+
const loot = generateLootForCR(challengeRating, treasureType);
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: 'text',
|
|
53
|
+
text: `💰 **Generated Loot**
|
|
54
|
+
**Challenge Rating:** ${challengeRating}
|
|
55
|
+
**Treasure Type:** ${treasureType}
|
|
56
|
+
|
|
57
|
+
**Currency:**
|
|
58
|
+
${loot.currency.map((c) => `- ${c.amount} ${c.type}`).join('\n')}
|
|
59
|
+
|
|
60
|
+
**Items:**
|
|
61
|
+
${loot.items.map((item) => `- ${item.name} (${item.rarity})`).join('\n')}
|
|
62
|
+
|
|
63
|
+
**Total Estimated Value:** ${loot.totalValue} gp`,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Handles rule lookup requests across world journals and compendium journal packs.
|
|
71
|
+
*/
|
|
72
|
+
export async function handleLookupRule(args, foundryClient, moduleBridge = null) {
|
|
73
|
+
const { query } = args;
|
|
74
|
+
if (!query || typeof query !== 'string') {
|
|
75
|
+
throw new McpError(ErrorCode.InvalidParams, 'query is required and must be a string');
|
|
76
|
+
}
|
|
77
|
+
return withToolError('lookup rule', async () => {
|
|
78
|
+
const hits = [];
|
|
79
|
+
// 1. Search world journals
|
|
80
|
+
const worldJournals = foundryClient.searchJournals(query);
|
|
81
|
+
for (const j of worldJournals) {
|
|
82
|
+
for (const page of j.pages ?? []) {
|
|
83
|
+
const text = page.text?.content ?? '';
|
|
84
|
+
const plain = stripHtml(text).replace(/\s+/g, ' ');
|
|
85
|
+
const idx = plain.toLowerCase().indexOf(query.toLowerCase());
|
|
86
|
+
if (idx !== -1) {
|
|
87
|
+
const start = Math.max(0, idx - 60);
|
|
88
|
+
const end = Math.min(plain.length, idx + query.length + 60);
|
|
89
|
+
const snippet = (start > 0 ? '...' : '') +
|
|
90
|
+
plain.slice(start, end).trim() +
|
|
91
|
+
(end < plain.length ? '...' : '');
|
|
92
|
+
hits.push({ title: `${j.name} > ${page.name}`, source: 'World Journal', snippet });
|
|
93
|
+
}
|
|
94
|
+
else if (page.name.toLowerCase().includes(query.toLowerCase()) ||
|
|
95
|
+
j.name.toLowerCase().includes(query.toLowerCase())) {
|
|
96
|
+
hits.push({ title: `${j.name} > ${page.name}`, source: 'World Journal' });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 2. Search compendium journal packs via module bridge if available
|
|
101
|
+
let compendiumSearched = false;
|
|
102
|
+
if (moduleBridge) {
|
|
103
|
+
try {
|
|
104
|
+
const compResult = (await moduleBridge.send('search_compendium_content', {
|
|
105
|
+
query,
|
|
106
|
+
packType: 'JournalEntry',
|
|
107
|
+
limit: 10,
|
|
108
|
+
}));
|
|
109
|
+
if (Array.isArray(compResult?.results)) {
|
|
110
|
+
compendiumSearched = true;
|
|
111
|
+
for (const r of compResult.results) {
|
|
112
|
+
hits.push({
|
|
113
|
+
title: r.documentName,
|
|
114
|
+
source: `Compendium: ${r.packLabel}`,
|
|
115
|
+
...(r.snippet ? { snippet: r.snippet } : {}),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Module bridge failed or unavailable
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (hits.length === 0) {
|
|
125
|
+
const note = !compendiumSearched
|
|
126
|
+
? '\n\n_Note: Compendium rules packs were not searched (companion module not connected)._'
|
|
127
|
+
: '';
|
|
128
|
+
return {
|
|
129
|
+
content: [{ type: 'text', text: `📖 **No rules found matching "${query}".**${note}` }],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const lines = hits.map((h) => {
|
|
133
|
+
const snip = h.snippet ? `\n > "${h.snippet}"` : '';
|
|
134
|
+
return `- **${h.title}** [_${h.source}_]${snip}`;
|
|
135
|
+
});
|
|
136
|
+
const bridgeNotice = !compendiumSearched
|
|
137
|
+
? '\n\n_Note: Compendium rules packs were not searched (companion module not connected)._'
|
|
138
|
+
: '';
|
|
139
|
+
return {
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
type: 'text',
|
|
143
|
+
text: `📖 **Rule Search Results: "${query}"** (${hits.length})\n\n${lines.join('\n')}${bridgeNotice}`,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// Helper functions for content generation
|
|
150
|
+
function generateRandomName() {
|
|
151
|
+
const firstNames = [
|
|
152
|
+
'Aerdrie',
|
|
153
|
+
'Berris',
|
|
154
|
+
'Cithreth',
|
|
155
|
+
'Drannor',
|
|
156
|
+
'Enna',
|
|
157
|
+
'Galinndan',
|
|
158
|
+
'Halimath',
|
|
159
|
+
'Immeral',
|
|
160
|
+
'Jallarzi',
|
|
161
|
+
'Keth',
|
|
162
|
+
];
|
|
163
|
+
const lastNames = [
|
|
164
|
+
'Amakir',
|
|
165
|
+
'Amakiir',
|
|
166
|
+
'Galanodel',
|
|
167
|
+
'Holimion',
|
|
168
|
+
'Liadon',
|
|
169
|
+
'Meliamne',
|
|
170
|
+
'Nailo',
|
|
171
|
+
'Siannodel',
|
|
172
|
+
'Xiloscient',
|
|
173
|
+
'Yellowleaf',
|
|
174
|
+
];
|
|
175
|
+
return `${firstNames[Math.floor(Math.random() * firstNames.length)]} ${lastNames[Math.floor(Math.random() * lastNames.length)]}`;
|
|
176
|
+
}
|
|
177
|
+
function getRandomRace() {
|
|
178
|
+
const races = [
|
|
179
|
+
'Human',
|
|
180
|
+
'Elf',
|
|
181
|
+
'Dwarf',
|
|
182
|
+
'Halfling',
|
|
183
|
+
'Dragonborn',
|
|
184
|
+
'Gnome',
|
|
185
|
+
'Half-Elf',
|
|
186
|
+
'Half-Orc',
|
|
187
|
+
'Tiefling',
|
|
188
|
+
];
|
|
189
|
+
return races[Math.floor(Math.random() * races.length)] || 'Human';
|
|
190
|
+
}
|
|
191
|
+
function getRandomClass() {
|
|
192
|
+
const classes = [
|
|
193
|
+
'Fighter',
|
|
194
|
+
'Wizard',
|
|
195
|
+
'Cleric',
|
|
196
|
+
'Rogue',
|
|
197
|
+
'Ranger',
|
|
198
|
+
'Paladin',
|
|
199
|
+
'Barbarian',
|
|
200
|
+
'Bard',
|
|
201
|
+
'Druid',
|
|
202
|
+
'Monk',
|
|
203
|
+
'Sorcerer',
|
|
204
|
+
'Warlock',
|
|
205
|
+
];
|
|
206
|
+
return classes[Math.floor(Math.random() * classes.length)] || 'Fighter';
|
|
207
|
+
}
|
|
208
|
+
function generateAbilityScores() {
|
|
209
|
+
const rollStat = () => {
|
|
210
|
+
const rolls = Array.from({ length: 4 }, () => Math.floor(Math.random() * 6) + 1);
|
|
211
|
+
rolls.sort((a, b) => b - a);
|
|
212
|
+
return rolls.slice(0, 3).reduce((sum, roll) => sum + roll, 0);
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
str: rollStat(),
|
|
216
|
+
dex: rollStat(),
|
|
217
|
+
con: rollStat(),
|
|
218
|
+
int: rollStat(),
|
|
219
|
+
wis: rollStat(),
|
|
220
|
+
cha: rollStat(),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function generateBackground(race, characterClass) {
|
|
224
|
+
const backgrounds = [
|
|
225
|
+
`A former ${characterClass.toLowerCase()} who seeks redemption for past mistakes.`,
|
|
226
|
+
`A ${race.toLowerCase()} ${characterClass.toLowerCase()} from a distant land, traveling to spread their knowledge.`,
|
|
227
|
+
`Once a member of a secret organization, now working independently.`,
|
|
228
|
+
`A scholar turned adventurer after discovering an ancient mystery.`,
|
|
229
|
+
`A protector of the innocent, dedicated to fighting against evil.`,
|
|
230
|
+
];
|
|
231
|
+
return (backgrounds[Math.floor(Math.random() * backgrounds.length)] ||
|
|
232
|
+
'A mysterious wanderer with an unknown past.');
|
|
233
|
+
}
|
|
234
|
+
function generateLootForCR(cr, _type) {
|
|
235
|
+
const baseValue = Math.floor(cr * 100 * (0.5 + Math.random()));
|
|
236
|
+
return {
|
|
237
|
+
currency: [
|
|
238
|
+
{ amount: Math.floor(baseValue * 0.1), type: 'gp' },
|
|
239
|
+
{ amount: Math.floor(baseValue * 0.05), type: 'sp' },
|
|
240
|
+
{ amount: Math.floor(baseValue * 0.02), type: 'cp' },
|
|
241
|
+
],
|
|
242
|
+
items: [
|
|
243
|
+
{ name: 'Healing Potion', rarity: 'Common' },
|
|
244
|
+
{ name: 'Silver Ring', rarity: 'Common' },
|
|
245
|
+
],
|
|
246
|
+
totalValue: baseValue,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function _lookupGameRule(query, system) {
|
|
250
|
+
// Mock rule lookup - in a real implementation, this would query actual rule databases
|
|
251
|
+
return {
|
|
252
|
+
title: `${query} Rule`,
|
|
253
|
+
description: `Rules and mechanics for ${query} in ${system}.`,
|
|
254
|
+
mechanics: `Detailed explanation of how ${query} works mechanically.`,
|
|
255
|
+
source: `${system} Core Rulebook`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=generation.js.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Actor item mutation tool handlers (create / update / delete)
|
|
3
|
+
*
|
|
4
|
+
* WRITE operations — require FOUNDRY_WRITE_ENABLED=true and an active Socket.IO
|
|
5
|
+
* connection (mutations use the core `modifyDocument` protocol). The canonical
|
|
6
|
+
* mutation target is the D&D 5e v4+ activity schema; item `system` patches
|
|
7
|
+
* honour JSON-merge-patch semantics on nested paths such as
|
|
8
|
+
* `activities.{id}.consumption.targets`.
|
|
9
|
+
*/
|
|
10
|
+
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
11
|
+
import { withToolError } from './utils.js';
|
|
12
|
+
/**
|
|
13
|
+
* Handles creating an item on an actor from a compendium reference or an inline
|
|
14
|
+
* item document.
|
|
15
|
+
*/
|
|
16
|
+
export async function handleCreateActorItem(args, foundryClient, moduleBridge = null) {
|
|
17
|
+
const { actorId, source } = args;
|
|
18
|
+
if (!actorId || typeof actorId !== 'string') {
|
|
19
|
+
throw new McpError(ErrorCode.InvalidParams, 'actorId is required and must be a string');
|
|
20
|
+
}
|
|
21
|
+
if (!source || typeof source !== 'object') {
|
|
22
|
+
throw new McpError(ErrorCode.InvalidParams, 'source is required and must be an object');
|
|
23
|
+
}
|
|
24
|
+
if (source.type === 'compendium') {
|
|
25
|
+
if (typeof source.compendiumId !== 'string' || typeof source.itemId !== 'string') {
|
|
26
|
+
throw new McpError(ErrorCode.InvalidParams, 'compendium source requires compendiumId and itemId strings');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (source.type === 'inline') {
|
|
30
|
+
if (!source.item || typeof source.item !== 'object') {
|
|
31
|
+
throw new McpError(ErrorCode.InvalidParams, 'inline source requires an item object');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new McpError(ErrorCode.InvalidParams, 'source.type must be "compendium" or "inline"');
|
|
36
|
+
}
|
|
37
|
+
return withToolError('create item', async () => {
|
|
38
|
+
let effectiveSource = source;
|
|
39
|
+
if (source.type === 'compendium') {
|
|
40
|
+
if (!moduleBridge) {
|
|
41
|
+
throw new McpError(ErrorCode.InvalidRequest, 'Creating an item from a compendium source requires the companion Foundry module. Set FOUNDRY_MODULE_BRIDGE_ENABLED=true and install the module, or provide an inline item.');
|
|
42
|
+
}
|
|
43
|
+
const rawDoc = (await moduleBridge.send('get_compendium_document', {
|
|
44
|
+
packId: source.compendiumId,
|
|
45
|
+
documentId: source.itemId,
|
|
46
|
+
}));
|
|
47
|
+
const cleanDoc = { ...rawDoc };
|
|
48
|
+
delete cleanDoc._id;
|
|
49
|
+
delete cleanDoc._stats;
|
|
50
|
+
effectiveSource = { type: 'inline', item: cleanDoc };
|
|
51
|
+
}
|
|
52
|
+
const newItem = await foundryClient.createActorItem(actorId, effectiveSource);
|
|
53
|
+
const origin = source.type === 'compendium'
|
|
54
|
+
? `compendium ${source.compendiumId} / ${source.itemId}`
|
|
55
|
+
: 'inline definition';
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
text: `⚔️ **Item Created**
|
|
61
|
+
**Actor:** ${actorId}
|
|
62
|
+
**Item:** ${newItem.name} (${newItem.type})
|
|
63
|
+
**Item ID:** ${newItem._id}
|
|
64
|
+
**Source:** ${origin}
|
|
65
|
+
|
|
66
|
+
_Canonical target: D&D 5e v4+ activity schema._`,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Handles applying a JSON merge patch to an item's `system` data. Supports
|
|
74
|
+
* nested paths (e.g. `activities.{id}.consumption.targets`).
|
|
75
|
+
*/
|
|
76
|
+
export async function handleUpdateActorItem(args, foundryClient) {
|
|
77
|
+
const { actorId, itemId, patch } = args;
|
|
78
|
+
if (!actorId || typeof actorId !== 'string') {
|
|
79
|
+
throw new McpError(ErrorCode.InvalidParams, 'actorId is required and must be a string');
|
|
80
|
+
}
|
|
81
|
+
if (!itemId || typeof itemId !== 'string') {
|
|
82
|
+
throw new McpError(ErrorCode.InvalidParams, 'itemId is required and must be a string');
|
|
83
|
+
}
|
|
84
|
+
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
|
|
85
|
+
throw new McpError(ErrorCode.InvalidParams, 'patch is required and must be an object');
|
|
86
|
+
}
|
|
87
|
+
return withToolError('update item', async () => {
|
|
88
|
+
const updatedItem = await foundryClient.updateActorItem(actorId, itemId, patch);
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: 'text',
|
|
93
|
+
text: `⚔️ **Item Updated**
|
|
94
|
+
**Actor:** ${actorId}
|
|
95
|
+
**Item:** ${updatedItem.name} (${updatedItem.type})
|
|
96
|
+
**Item ID:** ${updatedItem._id}
|
|
97
|
+
**Patched keys:** ${Object.keys(patch).join(', ') || '(none)'}
|
|
98
|
+
|
|
99
|
+
_JSON merge patch applied to item.system. Canonical target: D&D 5e v4+ activity schema (e.g. activities.{id}.consumption.targets)._`,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Handles deleting an item owned by an actor.
|
|
107
|
+
*/
|
|
108
|
+
export async function handleDeleteActorItem(args, foundryClient) {
|
|
109
|
+
const { actorId, itemId } = args;
|
|
110
|
+
if (!actorId || typeof actorId !== 'string') {
|
|
111
|
+
throw new McpError(ErrorCode.InvalidParams, 'actorId is required and must be a string');
|
|
112
|
+
}
|
|
113
|
+
if (!itemId || typeof itemId !== 'string') {
|
|
114
|
+
throw new McpError(ErrorCode.InvalidParams, 'itemId is required and must be a string');
|
|
115
|
+
}
|
|
116
|
+
return withToolError('delete item', async () => {
|
|
117
|
+
await foundryClient.deleteActorItem(actorId, itemId);
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: 'text',
|
|
122
|
+
text: `🗑️ **Item Deleted**
|
|
123
|
+
**Actor:** ${actorId}
|
|
124
|
+
**Item ID:** ${itemId}
|
|
125
|
+
|
|
126
|
+
_Canonical target: D&D 5e v4+ activity schema._`,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=item-mutations.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Item management tool handlers
|
|
3
|
+
*
|
|
4
|
+
* Handles searching for items and retrieving detailed item information.
|
|
5
|
+
*/
|
|
6
|
+
import { withToolError } from './utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* Handles item search requests
|
|
9
|
+
*/
|
|
10
|
+
export async function handleSearchItems(args, foundryClient) {
|
|
11
|
+
const { query, type, rarity, limit = 10, cursor } = args;
|
|
12
|
+
return withToolError('search items', async () => {
|
|
13
|
+
const searchParams = {
|
|
14
|
+
query: query || '',
|
|
15
|
+
limit,
|
|
16
|
+
};
|
|
17
|
+
if (type) {
|
|
18
|
+
searchParams.type = type;
|
|
19
|
+
}
|
|
20
|
+
if (rarity) {
|
|
21
|
+
searchParams.rarity = rarity;
|
|
22
|
+
}
|
|
23
|
+
if (cursor) {
|
|
24
|
+
searchParams.cursor = cursor;
|
|
25
|
+
}
|
|
26
|
+
const result = await foundryClient.searchItems(searchParams);
|
|
27
|
+
const itemList = result.items
|
|
28
|
+
.map((item) => {
|
|
29
|
+
const price = item.price
|
|
30
|
+
? `${item.price.value} ${item.price.denomination}`
|
|
31
|
+
: 'Unknown price';
|
|
32
|
+
return `- **${item.name}** (${item.type}) - ${item.rarity || 'Common'} - ${price}`;
|
|
33
|
+
})
|
|
34
|
+
.join('\n');
|
|
35
|
+
return {
|
|
36
|
+
content: [
|
|
37
|
+
{
|
|
38
|
+
type: 'text',
|
|
39
|
+
text: `⚔️ **Item Search Results**
|
|
40
|
+
**Query:** ${query || 'All items'}
|
|
41
|
+
**Type Filter:** ${type || 'All types'}
|
|
42
|
+
**Rarity Filter:** ${rarity || 'All rarities'}
|
|
43
|
+
**Results:** ${result.items.length}/${result.total} total
|
|
44
|
+
|
|
45
|
+
${itemList || 'No items found matching the criteria.'}
|
|
46
|
+
|
|
47
|
+
**Page:** ${result.page} | **Limit:** ${result.limit}${result.nextCursor ? `\n\n_More results available. Pass cursor: "${result.nextCursor}" to retrieve the next page._` : ''}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=items.js.map
|