From 0efecad60e05e1d368ab223f18e86f679067306b Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Wed, 16 Jul 2025 16:27:57 -0600 Subject: [PATCH] route edits --- src/app/api/mcp/[transport]/route.ts | 74 ++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/app/api/mcp/[transport]/route.ts b/src/app/api/mcp/[transport]/route.ts index b94473f..823a09a 100644 --- a/src/app/api/mcp/[transport]/route.ts +++ b/src/app/api/mcp/[transport]/route.ts @@ -1,6 +1,7 @@ import { LocalCourseSettings } from "@/models/local/localCourseSettings"; import { groupByStartDate } from "@/models/local/utils/timeUtils"; import { fileStorageService } from "@/services/fileStorage/fileStorageService"; +import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js"; import { createMcpHandler } from "mcp-handler"; import { z } from "zod"; @@ -31,6 +32,79 @@ const handler = createMcpHandler( }; } ); + server.tool( + "get_assignments_for_course", + "gets assignments and modules for a course", + { + courseName: z.string(), + }, + async ({ courseName }) => { + const modules = await fileStorageService.modules.getModuleNames( + courseName + ); + const assignments = ( + await Promise.all( + modules.map(async (moduleName) => { + const assignments = + await fileStorageService.assignments.getAssignments( + courseName, + moduleName + ); + return assignments.map((assignment) => ({ + assignmentName: assignment.name, + moduleName, + })); + }) + ) + ).flat(); + + return { + content: assignments.map((a) => ({ + type: "resource_link", + uri: `canvas:///courses/${courseName}/module/${a.moduleName}/assignments/${a.assignmentName}`, + name: `${a.assignmentName}.md`, + mimeType: "text/markdown", + description: "An canvas assignment", + })), + }; + } + ); + + server.registerResource( + "course_assignment", + new ResourceTemplate( + "canvas:///courses/{courseName}/module/{moduleName}/assignments/{assignmentName}", + { list: undefined } + ), + { + title: "Course Assignment", + description: "Markdown representation of a course assignment", + }, + async (uri, { courseName, moduleName, assignmentName }) => { + if ( + typeof courseName !== "string" || + typeof moduleName !== "string" || + typeof assignmentName !== "string" + ) { + throw new Error( + "courseName, moduleName, and assignmentName must be strings" + ); + } + const assignment = await fileStorageService.assignments.getAssignment( + courseName, + moduleName, + assignmentName + ); + return { + contents: [ + { + uri: uri.href, + text: assignment.description, + }, + ], + }; + } + ); }, { serverInfo: {