Skip to content

Commit b331f9c

Browse files
committed
fix handling in mcp
1 parent a5b1fa8 commit b331f9c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/app/api/mcp/route.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,10 @@ async function callTool(
670670
? new Date(args.graduationDate as string)
671671
: undefined,
672672
subtitle: (args.subtitle as string) ?? undefined,
673-
semesters: (args.semesters as number) ?? undefined,
673+
semesters: args.semesters !== undefined ? Number(args.semesters) : undefined,
674674
tags: (args.tags as string) ?? undefined,
675675
excludeFromExport: (args.excludeFromExport as boolean) ?? undefined,
676-
webId: (args.webId as number) ?? undefined,
676+
webId: args.webId !== undefined ? Number(args.webId) : undefined,
677677
},
678678
select: {
679679
id: true,
@@ -712,6 +712,7 @@ async function callTool(
712712
select: { id: true },
713713
});
714714
if (!existing) return toolError(`No user found with email ${email}`);
715+
715716
const member = await db.user.update({
716717
where: { email },
717718
data: {
@@ -743,13 +744,13 @@ async function callTool(
743744
subtitle: args.subtitle as string,
744745
}),
745746
...(args.semesters !== undefined && {
746-
semesters: args.semesters as number,
747+
semesters: Number(args.semesters),
747748
}),
748749
...(args.tags !== undefined && { tags: args.tags as string }),
749750
...(args.excludeFromExport !== undefined && {
750751
excludeFromExport: args.excludeFromExport as boolean,
751752
}),
752-
...(args.webId !== undefined && { webId: args.webId as number }),
753+
...(args.webId !== undefined && { webId: Number(args.webId) }),
753754
},
754755
select: {
755756
id: true,
@@ -869,7 +870,7 @@ async function callTool(
869870
semesterId: args.semesterId as string,
870871
name: args.name as string,
871872
description: (args.description as string) ?? undefined,
872-
points: args.points as number,
873+
points: Number(args.points),
873874
isMandatory: (args.isMandatory as boolean) ?? false,
874875
},
875876
});
@@ -882,7 +883,7 @@ async function callTool(
882883
const data: Record<string, unknown> = {};
883884
if (args.name !== undefined) data.name = args.name;
884885
if (args.description !== undefined) data.description = args.description;
885-
if (args.points !== undefined) data.points = args.points;
886+
if (args.points !== undefined) data.points = Number(args.points);
886887
if (args.isMandatory !== undefined) data.isMandatory = args.isMandatory;
887888
const activity = await db.workPlanActivity.update({
888889
where: { id: args.activityId as string },
@@ -1041,8 +1042,16 @@ export async function POST(request: Request) {
10411042
name: string;
10421043
arguments?: Record<string, unknown>;
10431044
};
1044-
const result = await callTool(name, args, user);
1045-
return rpcResponse(id, result);
1045+
try {
1046+
const result = await callTool(name, args, user);
1047+
return rpcResponse(id, result);
1048+
} catch (err) {
1049+
const message = err instanceof Error ? err.message : String(err);
1050+
return rpcResponse(id, {
1051+
content: [{ type: "text", text: `Error: ${message}` }],
1052+
isError: true,
1053+
});
1054+
}
10461055
}
10471056

10481057
case "ping":

0 commit comments

Comments
 (0)