Skip to content

Commit 41abc25

Browse files
committed
lookup datatShape from allDataShapesRaw...
to allow correct processing by db
1 parent da59d69 commit 41abc25

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/mcp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"@modelcontextprotocol/sdk": "^1.15.1",
2525
"@vue-skuilder/common": "workspace:*",
26+
"@vue-skuilder/courseware": "workspace:*",
2627
"@vue-skuilder/db": "workspace:*",
2728
"zod": "^3.22.0"
2829
},

packages/mcp/src/tools/create-card.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type CreateCardOutput,
66
} from '../types/tools.js';
77
import { toCourseElo, NameSpacer } from '@vue-skuilder/common';
8+
import { allCourseWare } from '@vue-skuilder/courseware';
89
import {
910
MCP_AGENT_AUTHOR,
1011
handleToolError,
@@ -44,10 +45,39 @@ export async function handleCreateCard(
4445
throw new Error(errorMsg);
4546
}
4647

48+
// Get the complete DataShape definition from course config
49+
const matchingDataShape = courseConfig.dataShapes.find(
50+
(ds) => ds.name === validatedInput.datashape
51+
);
52+
if (!matchingDataShape) {
53+
const errorMsg = `DataShape not found in course configuration: ${validatedInput.datashape}`;
54+
logToolWarning(TOOL_NAME, errorMsg);
55+
throw new Error(errorMsg);
56+
}
57+
58+
// Get runtime DataShape definition from courseware
59+
const runtimeDataShape = allCourseWare
60+
.allDataShapesRaw()
61+
.find((ds) => ds.name === shapeDescriptor.dataShape);
62+
63+
if (!runtimeDataShape) {
64+
const errorMsg = `Runtime DataShape not found in courseware: ${shapeDescriptor.dataShape}`;
65+
logToolWarning(TOOL_NAME, errorMsg);
66+
throw new Error(errorMsg);
67+
}
68+
69+
logToolStart(
70+
TOOL_NAME,
71+
`Using runtime DataShape with ${runtimeDataShape.fields.length} fields`
72+
);
73+
74+
// Use complete DataShape with field definitions from courseware
75+
const dataShape = runtimeDataShape;
76+
4777
// Create the card via courseDB
4878
const result = await courseDB.addNote(
4979
shapeDescriptor.course, // Use courseware name, not courseID
50-
{ name: shapeDescriptor.dataShape as any, fields: [] },
80+
dataShape,
5181
validatedInput.data,
5282
MCP_AGENT_AUTHOR,
5383
validatedInput.tags || [],

0 commit comments

Comments
 (0)