File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
packages/mcp/src/resources Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ export * from './course.js';
33export * from './cards.js' ;
44export * from './shapes.js' ;
55export * from './tags.js' ;
6+ export * from './schema.js' ;
67
78// Resource URI patterns
89export 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 ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments