mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
adding mcp tools
This commit is contained in:
@@ -47,7 +47,7 @@ services:
|
|||||||
--api-key "$MCP_TOKEN" \
|
--api-key "$MCP_TOKEN" \
|
||||||
--server-type "streamable_http" \
|
--server-type "streamable_http" \
|
||||||
--cors-allow-origins "*" \
|
--cors-allow-origins "*" \
|
||||||
-- http://canvas-dev:3000/api/mcp/mcp
|
-- http://canvas-dev:3000/api/mcp
|
||||||
'
|
'
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { assignmentMarkdownSerializer } from "@/models/local/assignment/utils/assignmentMarkdownSerializer";
|
||||||
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||||
import { groupByStartDate } from "@/models/local/utils/timeUtils";
|
import { groupByStartDate } from "@/models/local/utils/timeUtils";
|
||||||
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||||
@@ -8,7 +9,7 @@ import { z } from "zod";
|
|||||||
const handler = createMcpHandler(
|
const handler = createMcpHandler(
|
||||||
(server) => {
|
(server) => {
|
||||||
server.tool(
|
server.tool(
|
||||||
"get_current_courses",
|
"list_current_courses",
|
||||||
"gets courses for the current term",
|
"gets courses for the current term",
|
||||||
{},
|
{},
|
||||||
async () => {
|
async () => {
|
||||||
@@ -27,13 +28,15 @@ const handler = createMcpHandler(
|
|||||||
return {
|
return {
|
||||||
content: courseNames.map((name) => ({
|
content: courseNames.map((name) => ({
|
||||||
type: "text",
|
type: "text",
|
||||||
text: name,
|
text: JSON.stringify({
|
||||||
|
courseName: name,
|
||||||
|
}),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
server.tool(
|
server.tool(
|
||||||
"get_assignments_for_course",
|
"list_assignments_for_course",
|
||||||
"gets assignments and modules for a course",
|
"gets assignments and modules for a course",
|
||||||
{
|
{
|
||||||
courseName: z.string(),
|
courseName: z.string(),
|
||||||
@@ -57,19 +60,65 @@ const handler = createMcpHandler(
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
).flat();
|
).flat();
|
||||||
|
console.log("mcp got assignments", assignments);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
//doesn't seem to work with many clients
|
||||||
|
// 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",
|
||||||
|
// })),
|
||||||
|
|
||||||
content: assignments.map((a) => ({
|
content: assignments.map((a) => ({
|
||||||
type: "resource_link",
|
type: "text",
|
||||||
uri: `canvas:///courses/${courseName}/module/${a.moduleName}/assignments/${a.assignmentName}`,
|
text: JSON.stringify({
|
||||||
name: `${a.assignmentName}.md`,
|
assignmentName: a.assignmentName,
|
||||||
mimeType: "text/markdown",
|
moduleName: a.moduleName,
|
||||||
description: "An canvas assignment",
|
}),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
server.tool(
|
||||||
|
"get_assignment",
|
||||||
|
"gets a markdown file defining the assignment",
|
||||||
|
{
|
||||||
|
courseName: z.string(),
|
||||||
|
moduleName: z.string(),
|
||||||
|
assignmentName: z.string(),
|
||||||
|
},
|
||||||
|
async ({ 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
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("mcp assignment", assignment);
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: assignmentMarkdownSerializer.toMarkdown(assignment),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
server.registerResource(
|
server.registerResource(
|
||||||
"course_assignment",
|
"course_assignment",
|
||||||
new ResourceTemplate(
|
new ResourceTemplate(
|
||||||
@@ -75,6 +75,7 @@ export const assignmentsFileStorageService = {
|
|||||||
|
|
||||||
await fs.writeFile(filePath, assignmentMarkdown);
|
await fs.writeFile(filePath, assignmentMarkdown);
|
||||||
},
|
},
|
||||||
|
|
||||||
async delete({
|
async delete({
|
||||||
courseName,
|
courseName,
|
||||||
moduleName,
|
moduleName,
|
||||||
|
|||||||
Reference in New Issue
Block a user