refactor: drop skill file, rework client
This commit was merged in pull request #3.
This commit is contained in:
+57
-7
@@ -2,20 +2,43 @@ import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { z } from "zod/v4";
|
||||
import { EwsClient, loadConfig } from "../ews_client.ts";
|
||||
import { loadConfig } from "../utils/login.ts";
|
||||
import { EwsClient } from "../client/ews_client.ts";
|
||||
|
||||
export function registerCalendarTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"get_calendar_events",
|
||||
{
|
||||
description: "Get calendar events within a date range",
|
||||
description: "Get calendar events within a date range."
|
||||
+ " Set includeBody=true to fetch organizer, attendees, and body via GetItem.",
|
||||
inputSchema: z.object({
|
||||
startDate: z.string().describe("Start date in YYYY-MM-DD format"),
|
||||
endDate: z.string().describe("End date in YYYY-MM-DD format"),
|
||||
includeBody: z.boolean().default(false).describe(
|
||||
"If True, fetch full event details (organizer, attendees, body) via GetItem",
|
||||
"If true, fetch full event details (organizer, attendees, body)"
|
||||
+ " via GetItem",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
events: z.array(z.object({
|
||||
subject: z.string(),
|
||||
start: z.string(),
|
||||
end: z.string(),
|
||||
location: z.string(),
|
||||
isAllDay: z.boolean(),
|
||||
isCancelled: z.boolean(),
|
||||
isMeeting: z.boolean(),
|
||||
isRecurring: z.boolean(),
|
||||
organizer: z.string(),
|
||||
organizerEmail: z.string(),
|
||||
myResponse: z.string(),
|
||||
itemId: z.string(),
|
||||
body: z.string(),
|
||||
requiredAttendees: z.array(z.string()),
|
||||
optionalAttendees: z.array(z.string()),
|
||||
})),
|
||||
count: z.number(),
|
||||
}),
|
||||
},
|
||||
async ({ startDate, endDate, includeBody }) => {
|
||||
try {
|
||||
@@ -51,7 +74,7 @@ export function registerCalendarTools(server: McpServer): void {
|
||||
};
|
||||
|
||||
if (includeBody && event.itemId) {
|
||||
const details = client.extractEmailDetails(item);
|
||||
const details = client.extractEmail(item);
|
||||
event.body = details.body;
|
||||
event.requiredAttendees = details.requiredAttendees ?? [];
|
||||
event.optionalAttendees = details.optionalAttendees ?? [];
|
||||
@@ -68,6 +91,7 @@ export function registerCalendarTools(server: McpServer): void {
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({ events, count: events.length }),
|
||||
}],
|
||||
structuredContent: { events, count: events.length },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -84,21 +108,38 @@ export function registerCalendarTools(server: McpServer): void {
|
||||
"download_event_attachments",
|
||||
{
|
||||
description:
|
||||
"Download all file attachments from a calendar event to disk",
|
||||
"Download all file attachments from a calendar event to disk."
|
||||
+ " Inline (embedded) attachments are skipped —"
|
||||
+ " only standalone file attachments are downloaded.",
|
||||
inputSchema: z.object({
|
||||
itemId: z.string().describe(
|
||||
"The Exchange ItemId of the calendar event",
|
||||
),
|
||||
targetFolder: z.string().default("/tmp/attachments").describe(
|
||||
"Local directory to save files (default /tmp/attachments)",
|
||||
"Local directory to save files",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
success: z.boolean(),
|
||||
downloaded: z.array(z.object({
|
||||
name: z.string(),
|
||||
path: z.string(),
|
||||
size: z.number(),
|
||||
contentType: z.string(),
|
||||
})),
|
||||
count: z.number(),
|
||||
errors: z.array(z.object({
|
||||
name: z.string(),
|
||||
error: z.string(),
|
||||
})).optional(),
|
||||
message: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async ({ itemId, targetFolder }) => {
|
||||
try {
|
||||
const client = new EwsClient(loadConfig());
|
||||
const item = await client.getItem(itemId);
|
||||
const email = client.extractEmailDetails(item);
|
||||
const email = client.extractEmail(item);
|
||||
const attachments = email.attachments ?? [];
|
||||
|
||||
const fileAttachments = attachments.filter(
|
||||
@@ -116,6 +157,12 @@ export function registerCalendarTools(server: McpServer): void {
|
||||
message: "No downloadable file attachments.",
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: true,
|
||||
downloaded: [],
|
||||
count: 0,
|
||||
message: "No downloadable file attachments.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -173,6 +220,9 @@ export function registerCalendarTools(server: McpServer): void {
|
||||
...(errors.length ? { errors } : {}),
|
||||
}),
|
||||
}],
|
||||
structuredContent: errors.length === 0
|
||||
? { success: true, downloaded, count: downloaded.length }
|
||||
: { success: false, downloaded, count: downloaded.length, errors },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user