Skip to content

Commit 44c8a41

Browse files
committed
add schema lookup resource
1 parent 552f1d4 commit 44c8a41

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

packages/mcp/src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './course.js';
33
export * from './cards.js';
44
export * from './shapes.js';
55
export * from './tags.js';
6+
export * from './schema.js';
67

78
// Resource URI patterns
89
export const RESOURCE_PATTERNS = {
@@ -20,4 +21,5 @@ export const RESOURCE_PATTERNS = {
2021
TAGS_INTERSECT: 'tags://intersect/{tags}',
2122
TAGS_EXCLUSIVE: 'tags://exclusive/{tags}',
2223
TAGS_DISTRIBUTION: 'tags://distribution',
24+
SCHEMA_SPECIFIC: 'schema://{dataShapeName}',
2325
} as const;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { CourseDBInterface } from '@vue-skuilder/db';
2+
3+
/**
4+
* Schema resource response structure
5+
*/
6+
export interface SchemaResource {
7+
dataShapeName: string;
8+
jsonSchema: object;
9+
schemaString: string;
10+
available: boolean;
11+
lastUpdated?: string;
12+
}
13+
14+
/**
15+
* Handle schema resource request for a specific DataShape
16+
* Returns the JSON Schema for the DataShape if available
17+
*/
18+
export async function handleSchemaResource(
19+
courseDB: CourseDBInterface,
20+
dataShapeName: string
21+
): Promise<SchemaResource> {
22+
const courseConfig = await courseDB.getCourseConfig();
23+
24+
// Find the DataShape in course config
25+
const dataShape = courseConfig.dataShapes.find(ds => ds.name === dataShapeName);
26+
27+
if (!dataShape) {
28+
return {
29+
dataShapeName,
30+
jsonSchema: {},
31+
schemaString: '',
32+
available: false,
33+
};
34+
}
35+
36+
if (!dataShape.serializedZodSchema) {
37+
return {
38+
dataShapeName,
39+
jsonSchema: {},
40+
schemaString: '',
41+
available: false,
42+
};
43+
}
44+
45+
let jsonSchema: object;
46+
try {
47+
jsonSchema = JSON.parse(dataShape.serializedZodSchema);
48+
} catch (error) {
49+
console.warn(`Failed to parse schema for ${dataShapeName}:`, error);
50+
return {
51+
dataShapeName,
52+
jsonSchema: {},
53+
schemaString: '',
54+
available: false,
55+
};
56+
}
57+
58+
return {
59+
dataShapeName,
60+
jsonSchema,
61+
schemaString: dataShape.serializedZodSchema,
62+
available: true,
63+
};
64+
}

0 commit comments

Comments
 (0)