mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
got one mcp endpoint
This commit is contained in:
@@ -1,38 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useLocalCoursesSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
import { useLocalCoursesSettingsQuery } from "@/hooks/localCourse/localCoursesHooks";
|
||||||
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
import { getDateKey, getTermName, groupByStartDate } from "@/models/local/utils/timeUtils";
|
||||||
import { getCourseUrl } from "@/services/urlUtils";
|
import { getCourseUrl } from "@/services/urlUtils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
function getDateKey(dateString: string) {
|
|
||||||
return dateString.split("T")[0];
|
|
||||||
}
|
|
||||||
function groupByStartDate(courses: LocalCourseSettings[]): {
|
|
||||||
[key: string]: LocalCourseSettings[];
|
|
||||||
} {
|
|
||||||
return courses.reduce(
|
|
||||||
(acc, course) => {
|
|
||||||
const { startDate } = course;
|
|
||||||
const key = getDateKey(startDate);
|
|
||||||
if (!acc[key]) {
|
|
||||||
acc[key] = [];
|
|
||||||
}
|
|
||||||
acc[key].push(course);
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{} as {
|
|
||||||
[key: string]: LocalCourseSettings[];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTermName(startDate: string) {
|
|
||||||
const [year, month, ..._rest] = startDate.split("-");
|
|
||||||
if (month < "04") return "Spring " + year;
|
|
||||||
if (month < "07") return "Summer " + year;
|
|
||||||
return "Fall " + year;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function CourseList() {
|
export default function CourseList() {
|
||||||
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
const { data: allSettings } = useLocalCoursesSettingsQuery();
|
||||||
|
|
||||||
@@ -67,4 +38,4 @@ export default function CourseList() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,47 @@
|
|||||||
|
import { LocalCourseSettings } from "@/models/local/localCourseSettings";
|
||||||
|
import { groupByStartDate } from "@/models/local/utils/timeUtils";
|
||||||
|
import { fileStorageService } from "@/services/fileStorage/fileStorageService";
|
||||||
import { createMcpHandler } from "mcp-handler";
|
import { createMcpHandler } from "mcp-handler";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const handler = createMcpHandler(
|
const handler = createMcpHandler(
|
||||||
(server) => {
|
(server) => {
|
||||||
server.tool(
|
server.tool(
|
||||||
"roll_dice",
|
"get_current_courses",
|
||||||
"Rolls an N-sided die",
|
"gets courses for the current term",
|
||||||
{
|
{},
|
||||||
sides: z.number().int().min(2),
|
async () => {
|
||||||
},
|
const settingsList =
|
||||||
async ({ sides }) => {
|
await fileStorageService.settings.getAllCoursesSettings();
|
||||||
const value = 1 + Math.floor(Math.random() * sides);
|
|
||||||
|
const coursesByStartDate = groupByStartDate(settingsList);
|
||||||
|
|
||||||
|
const sortedDates = Object.keys(coursesByStartDate).sort().reverse();
|
||||||
|
|
||||||
|
const mostRecentStartDate = sortedDates[0];
|
||||||
|
|
||||||
|
const courseNames = coursesByStartDate[mostRecentStartDate].map(
|
||||||
|
(settings) => settings.name
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: `🎲 You rolled a ${value}!` }],
|
content: courseNames.map((name) => ({
|
||||||
|
type: "text",
|
||||||
|
text: name,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Optional server options
|
serverInfo: {
|
||||||
|
name: "Canvas Management MCP Server",
|
||||||
|
version: "2.0.0",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Optional redis config
|
basePath: "/api/mcp",
|
||||||
redisUrl: process.env.REDIS_URL,
|
|
||||||
basePath: "/api/mcp", // this needs to match where the [transport] is located.
|
|
||||||
maxDuration: 60,
|
maxDuration: 60,
|
||||||
verboseLogs: true,
|
verboseLogs: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
export { handler as GET, handler as POST };
|
export { handler as GET, handler as POST };
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { LocalCourseSettings } from "../localCourseSettings";
|
||||||
|
|
||||||
const _getDateFromAMPM = (
|
const _getDateFromAMPM = (
|
||||||
datePart: string,
|
datePart: string,
|
||||||
timePart: string,
|
timePart: string,
|
||||||
@@ -57,7 +59,8 @@ export const getDateFromString = (value: string): Date | undefined => {
|
|||||||
} else if (militaryDateRegex.test(value)) {
|
} else if (militaryDateRegex.test(value)) {
|
||||||
const [datePart, timePart] = value.split(" ");
|
const [datePart, timePart] = value.split(" ");
|
||||||
return _getDateFromMilitary(datePart, timePart);
|
return _getDateFromMilitary(datePart, timePart);
|
||||||
} if (dateOnlyRegex.test(value)) {
|
}
|
||||||
|
if (dateOnlyRegex.test(value)) {
|
||||||
return _getDateFromDateOnly(value);
|
return _getDateFromDateOnly(value);
|
||||||
} else {
|
} else {
|
||||||
if (value) console.log("invalid date format", value);
|
if (value) console.log("invalid date format", value);
|
||||||
@@ -104,3 +107,32 @@ export const dateToMarkdownString = (date: Date) => {
|
|||||||
export const getDateOnlyMarkdownString = (date: Date) => {
|
export const getDateOnlyMarkdownString = (date: Date) => {
|
||||||
return dateToMarkdownString(date).split(" ")[0];
|
return dateToMarkdownString(date).split(" ")[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getTermName(startDate: string) {
|
||||||
|
const [year, month, ..._rest] = startDate.split("-");
|
||||||
|
if (month < "04") return "Spring " + year;
|
||||||
|
if (month < "07") return "Summer " + year;
|
||||||
|
return "Fall " + year;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDateKey(dateString: string) {
|
||||||
|
return dateString.split("T")[0];
|
||||||
|
}
|
||||||
|
export function groupByStartDate(courses: LocalCourseSettings[]): {
|
||||||
|
[key: string]: LocalCourseSettings[];
|
||||||
|
} {
|
||||||
|
return courses.reduce(
|
||||||
|
(acc, course) => {
|
||||||
|
const { startDate } = course;
|
||||||
|
const key = getDateKey(startDate);
|
||||||
|
if (!acc[key]) {
|
||||||
|
acc[key] = [];
|
||||||
|
}
|
||||||
|
acc[key].push(course);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as {
|
||||||
|
[key: string]: LocalCourseSettings[];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user