8000 fix(character-manage): preserve cantrips through MCP schema by Mnehmos · Pull Request #98 · Mnehmos/mnehmos.rpg.mcp · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/server/consolidated/character-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const CreateSchema = z.object({
characterType: CharacterTypeSchema.optional().default('pc'),
factionId: z.string().optional(),
behavior: z.string().optional(),
cantripsKnown: z.array(z.string()).optional().default([]),
knownSpells: z.array(z.string()).optional().default([]),
preparedSpells: z.array(z.string()).optional().default([]),
resistances: z.array(z.string()).optional().default([]),
Expand Down Expand Up @@ -142,6 +143,7 @@ const UpdateSchema = z.object({
level: z.number().int().min(1).optional(),
characterType: CharacterTypeSchema.optional(),
stats: StatsSchema.partial().optional(),
cantripsKnown: z.array(z.string()).optional(),
knownSpells: z.array(z.string()).optional(),
preparedSpells: z.array(z.string()).optional(),
skillProficiencies: z.array(SkillProficiencySchema).optional(),
Expand Down Expand Up @@ -325,7 +327,7 @@ export async function handleCreate(args: z.infer<typeof CreateSchema>): Promise<
factionId: args.factionId,
behavior: args.behavior,
knownSpells: args.knownSpells || [],
cantripsKnown: [],
cantripsKnown: args.cantripsKnown || [],
// Known spells are immediately usable after creation unless the caller
// explicitly supplies a prepared list.
preparedSpells: args.preparedSpells?.length
Expand Down Expand Up @@ -379,7 +381,9 @@ export async function handleCreate(args: z.infer<typeof CreateSchema>): Promise<
character.preparedSpells = args.preparedSpells?.length
? [...new Set(args.preparedSpells)]
: [...new Set(character.knownSpells as string[])];
character.cantripsKnown = provisioningResult.cantripsGranted || [];
character.cantripsKnown = args.cantripsKnown?.length
? [...new Set(args.cantripsKnown)]
: provisioningResult.cantripsGranted || [];
Comment on lines +384 to +386
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep provisioning metadata aligned with selected cantrips

When a caller creates an auto-provisioned spellcaster with an explicit cantripsKnown list, the provisioner is still called without its supported customCantrips option, so provisioningResult.cantripsGranted contains the class defaults while these lines store the caller's selection. The response later exposes the untouched result as _provisioning.cantripsGranted; for example, a wizard created with only ['Fire Bolt'] reports that all four default wizard cantrips were granted even though the character contains one. Pass the selection into provisioning or report the final persisted list so the response is not contradictory.

Useful? React with 👍 / 👎.

character.spellSlots = convertSpellSlotsToObject(provisioningResult.spellSlots ?? null);
character.pactMagicSlots = provisioningResult.pactMagicSlots || undefined;

Expand Down Expand Up @@ -480,6 +484,7 @@ async function handleUpdate(args: z.infer<typeof UpdateSchema>): Promise<object>
if (args.alignment !== undefined) updateData.alignment = args.alignment;
if (args.origin !== undefined) updateData.origin = args.origin;
if (args.stats !== undefined) updateData.stats = args.stats;
if (args.cantripsKnown !== undefined) updateData.cantripsKnown = args.cantripsKnown;
if (args.knownSpells !== undefined) updateData.knownSpells = args.knownSpells;
if (args.preparedSpells !== undefined) updateData.preparedSpells = args.preparedSpells;
if (args.skillProficiencies !== undefined) updateData.skillProficiencies = args.skillProficiencies;
Expand Down Expand Up @@ -778,6 +783,7 @@ Aliases: new/add/spawn->create, fetch/find->get, modify/edit->update`,
characterType: CharacterTypeSchema.optional(),
factionId: z.string().optional(),
behavior: z.string().optional(),
cantripsKnown: z.array(z.string()).optional(),
knownSpells: z.array(z.string()).optional(),
preparedSpells: z.array(z.string()).optional(),
skillProficiencies: z.array(SkillProficiencySchema).optional(),
Expand Down
33 changes: 33 additions & 0 deletions tests/server/consolidated/character-manage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ describe('character_manage consolidated tool', () => {
expect(CharacterManageTool.description).toContain('add_xp');
expect(CharacterManageTool.description).toContain('level_up');
});

it('exposes cantripsKnown through the MCP registration schema', () => {
const parsed = CharacterManageTool.inputSchema.parse({
action: 'update',
characterId: randomUUID(),
cantripsKnown: ['Guidance'],
});

expect(parsed.cantripsKnown).toEqual(['Guidance']);
});
});

describe('action: create', () => {
Expand Down 9223 Expand Up @@ -92,6 +102,29 @@ describe('character_manage consolidated tool', () => {
expect(parsed.toolProficiencies).toEqual(['vehicles (land)']);
});

it('persists explicit cantrips on create and update', async () => {
const createdResult = await handleCharacterManage({
action: 'create',
name: 'Spellbook Test',
class: 'Wizard',
cantripsKnown: ['Fire Bolt'],
knownSpells: ['Magic Missile'],
preparedSpells: ['Magic Missile'],
}, ctx);
const created = extractJson(createdResult.content[0].text);

expect(created.cantripsKnown).toEqual(['Fire Bolt']);

const updatedResult = await handleCharacterManage({
action: 'update',
characterId: created.id,
cantripsKnown: ['Ray of Frost'],
}, ctx);
const updated = extractJson(updatedResult.content[0].text);

expect(updated.cantripsKnown).toEqual(['Ray of Frost']);
});

it('round-trips all character proficiency fields through get and update', async () => {
const createdResult = await handleCharacterManage({
action: 'create',
Expand Down
Loading
0