refactor: drop skill file, rework client
This commit was merged in pull request #3.
This commit is contained in:
+51
-18
@@ -1,28 +1,29 @@
|
||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { z } from "zod/v4";
|
||||
import {
|
||||
clearConfig,
|
||||
EwsClient,
|
||||
hasPassword,
|
||||
loadConfig,
|
||||
saveConfig,
|
||||
setPassword,
|
||||
} from "../ews_client.ts";
|
||||
import type { LoginConfig } from "../types/login_config.ts";
|
||||
import { clearConfig, hasPassword, loadConfig, saveConfig, setPassword } from "../utils/login.ts";
|
||||
import { EwsClient } from "../client/ews_client.ts";
|
||||
import { type LoginConfig } from "../utils/login.ts";
|
||||
|
||||
export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"login",
|
||||
{
|
||||
description: "Authenticate to Exchange EWS using NTLM credentials",
|
||||
description: "Authenticate to Exchange EWS using NTLM credentials."
|
||||
+ " On first use all fields except domain are required."
|
||||
+ " On subsequent logins only password is needed — previously saved"
|
||||
+ " serverUrl, email, username, and domain are reused"
|
||||
+ " automatically from config.",
|
||||
inputSchema: z.object({
|
||||
serverUrl: z.string().optional().describe(
|
||||
"EWS server URL (e.g. https://mail.example.com)",
|
||||
),
|
||||
serverUrl: z.string().optional().describe("EWS server URL"),
|
||||
email: z.string().optional().describe("Email address"),
|
||||
username: z.string().optional().describe("NTLM username"),
|
||||
password: z.string().describe("NTLM password"),
|
||||
domain: z.string().optional().describe("NTLM domain (default: corp)"),
|
||||
domain: z.string().optional().describe("NTLM domain"),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
success: z.boolean(),
|
||||
message: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async ({ serverUrl, email, username, password, domain }) => {
|
||||
@@ -47,8 +48,9 @@ export function registerAuthTools(server: McpServer): void {
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error:
|
||||
"Missing required fields. Provide serverUrl, email, and username, or login once with all fields first.",
|
||||
error: "Missing required fields."
|
||||
+ " Provide serverUrl, email, and username, or"
|
||||
+ " login once with all fields first.",
|
||||
}),
|
||||
}],
|
||||
};
|
||||
@@ -99,8 +101,15 @@ export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"check_session",
|
||||
{
|
||||
description: "Check whether the current EWS session is authenticated",
|
||||
description:
|
||||
"Check whether the current EWS session is authenticated. No parameters.",
|
||||
inputSchema: z.object({}),
|
||||
outputSchema: z.object({
|
||||
authenticated: z.boolean(),
|
||||
email: z.string().optional(),
|
||||
serverUrl: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async () => {
|
||||
try {
|
||||
@@ -113,6 +122,10 @@ export function registerAuthTools(server: McpServer): void {
|
||||
error: "Not logged in. Password not found in memory.",
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
authenticated: false,
|
||||
error: "Not logged in. Password not found in memory.",
|
||||
},
|
||||
};
|
||||
}
|
||||
const config = loadConfig();
|
||||
@@ -129,6 +142,12 @@ export function registerAuthTools(server: McpServer): void {
|
||||
error: result.error,
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
authenticated: result.ok,
|
||||
email: config.email,
|
||||
serverUrl: config.serverUrl,
|
||||
error: result.error,
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -139,6 +158,10 @@ export function registerAuthTools(server: McpServer): void {
|
||||
error: error.message ?? String(error),
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
authenticated: false,
|
||||
error: error.message ?? String(error),
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
@@ -147,8 +170,14 @@ export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"logout",
|
||||
{
|
||||
description: "Clear stored credentials",
|
||||
description:
|
||||
"Clear stored credentials (serverUrl, email, username, domain, password)."
|
||||
+ " No parameters.",
|
||||
inputSchema: z.object({}),
|
||||
outputSchema: z.object({
|
||||
success: z.boolean(),
|
||||
message: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async () => {
|
||||
clearConfig();
|
||||
@@ -160,6 +189,10 @@ export function registerAuthTools(server: McpServer): void {
|
||||
message: "Logged out. Credentials cleared.",
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: true,
|
||||
message: "Logged out. Credentials cleared.",
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
+52
-11
@@ -1,25 +1,38 @@
|
||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
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 registerAvailabilityTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"find_free_time",
|
||||
{
|
||||
description: "Find free time slots in your own calendar",
|
||||
description: "Find free time slots in your own calendar."
|
||||
+ " Queries your free/busy status and returns available slots"
|
||||
+ " within working hours that meet the minimum duration.",
|
||||
inputSchema: z.object({
|
||||
startDate: z.string().describe("Start date in YYYY-MM-DD format"),
|
||||
endDate: z.string().optional().describe(
|
||||
"End date in YYYY-MM-DD format (defaults to startDate)",
|
||||
"End date in YYYY-MM-DD format",
|
||||
),
|
||||
durationMinutes: z.number().default(30).describe(
|
||||
"Minimum slot duration in minutes (default 30)",
|
||||
"Minimum slot duration in minutes",
|
||||
),
|
||||
startHour: z.number().default(9).describe(
|
||||
"Working day start hour (0-23, default 9)",
|
||||
"Working day start hour (0-23)",
|
||||
),
|
||||
endHour: z.number().default(18).describe(
|
||||
"Working day end hour (0-23, default 18)",
|
||||
"Working day end hour (0-23)",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
freeSlots: z.record(
|
||||
z.string(),
|
||||
z.array(z.object({
|
||||
start: z.string(),
|
||||
end: z.string(),
|
||||
durationMinutes: z.number(),
|
||||
})),
|
||||
),
|
||||
}),
|
||||
},
|
||||
@@ -79,6 +92,7 @@ export function registerAvailabilityTools(server: McpServer): void {
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({ freeSlots }),
|
||||
}],
|
||||
structuredContent: { freeSlots },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -94,23 +108,45 @@ export function registerAvailabilityTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"find_meeting_time",
|
||||
{
|
||||
description: "Find meeting times that work for multiple people",
|
||||
description: "Find common free time for multiple attendees."
|
||||
+ " Queries free/busy for all attendees"
|
||||
+ " and returns slots where everyone is available.",
|
||||
inputSchema: z.object({
|
||||
emails: z.string().describe(
|
||||
"Comma-separated email addresses of attendees",
|
||||
),
|
||||
startDate: z.string().describe("Start date in YYYY-MM-DD format"),
|
||||
endDate: z.string().optional().describe(
|
||||
"End date in YYYY-MM-DD format (defaults to startDate)",
|
||||
"End date in YYYY-MM-DD format",
|
||||
),
|
||||
durationMinutes: z.number().default(30).describe(
|
||||
"Minimum slot duration in minutes (default 30)",
|
||||
"Minimum slot duration in minutes",
|
||||
),
|
||||
startHour: z.number().default(9).describe(
|
||||
"Working day start hour (0-23, default 9)",
|
||||
"Working day start hour (0-23)",
|
||||
),
|
||||
endHour: z.number().default(18).describe(
|
||||
"Working day end hour (0-23, default 18)",
|
||||
"Working day end hour (0-23)",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
period: z.object({
|
||||
start: z.string(),
|
||||
end: z.string(),
|
||||
}),
|
||||
attendees: z.array(z.object({
|
||||
email: z.string(),
|
||||
busySlots: z.number().optional(),
|
||||
freeSlots: z.number().optional(),
|
||||
calendarEvents: z.number().optional(),
|
||||
})),
|
||||
freeSlots: z.record(
|
||||
z.string(),
|
||||
z.array(z.object({
|
||||
start: z.string(),
|
||||
end: z.string(),
|
||||
durationMinutes: z.number(),
|
||||
})),
|
||||
),
|
||||
}),
|
||||
},
|
||||
@@ -192,6 +228,11 @@ export function registerAvailabilityTools(server: McpServer): void {
|
||||
freeSlots: freeByDate,
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
period: { start: startDate, end: ed },
|
||||
attendees: attendeeInfo,
|
||||
freeSlots: freeByDate,
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
|
||||
+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 {
|
||||
|
||||
+106
-53
@@ -2,7 +2,8 @@ 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";
|
||||
|
||||
function getClient(): EwsClient {
|
||||
return new EwsClient(loadConfig());
|
||||
@@ -12,31 +13,41 @@ export function registerEmailTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"get_emails",
|
||||
{
|
||||
description: "Get emails from a mailbox folder",
|
||||
description: "Get emails from a mailbox folder."
|
||||
+ " Supports optional text search via query/queryScope.",
|
||||
inputSchema: z.object({
|
||||
folder: z.string().default("Inbox").describe(
|
||||
"Folder name (Inbox, Sent, Drafts, Deleted, Junk, or custom)",
|
||||
"Folder name (Inbox, Sent, Drafts, Deleted, Junk, or custom)."
|
||||
+ " Supports Russian folder names",
|
||||
),
|
||||
limit: z.number().default(10).describe(
|
||||
"Maximum number of emails to return (default 10, max 50)",
|
||||
"Maximum number of emails to return",
|
||||
),
|
||||
offset: z.number().default(0).describe(
|
||||
"Number of emails to skip for pagination",
|
||||
),
|
||||
includeBody: z.boolean().default(false).describe(
|
||||
"If True, fetch full body for each email (slower)",
|
||||
"If true, fetches full email body for each email (slower)",
|
||||
),
|
||||
unreadOnly: z.boolean().default(false).describe(
|
||||
"If True, only return unread emails",
|
||||
),
|
||||
idsOnly: z.boolean().default(false).describe(
|
||||
"If True, return only item IDs and dates (max limit 500)",
|
||||
"If true, only return unread emails",
|
||||
),
|
||||
query: z.string().optional().describe(
|
||||
"Optional text to search for within the folder",
|
||||
),
|
||||
queryScope: z.enum(["all", "subject", "body", "from"]).default("all")
|
||||
.describe("Where to search (only used when query is set)"),
|
||||
.describe("Search scope: all, subject, body, or from"),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
emails: z.array(z.object({
|
||||
itemId: z.string(),
|
||||
subject: z.string(),
|
||||
from: z.string(),
|
||||
date: z.string(),
|
||||
isRead: z.boolean(),
|
||||
hasAttachments: z.boolean(),
|
||||
})),
|
||||
count: z.number(),
|
||||
}),
|
||||
},
|
||||
async (
|
||||
@@ -46,19 +57,18 @@ export function registerEmailTools(server: McpServer): void {
|
||||
offset,
|
||||
includeBody,
|
||||
unreadOnly,
|
||||
idsOnly,
|
||||
query,
|
||||
queryScope,
|
||||
},
|
||||
) => {
|
||||
try {
|
||||
const client = getClient();
|
||||
const maxLimit = idsOnly ? 500 : 50;
|
||||
const maxLimit = 50;
|
||||
if (limit > maxLimit) limit = maxLimit;
|
||||
offset = Math.max(0, offset);
|
||||
|
||||
const folderId = await client.getFolderId(folder);
|
||||
const baseShape = idsOnly ? "IdOnly" : "AllProperties";
|
||||
const baseShape = "AllProperties";
|
||||
|
||||
if (query && !query.trim()) query = undefined;
|
||||
|
||||
@@ -109,16 +119,16 @@ export function registerEmailTools(server: McpServer): void {
|
||||
let restriction = "";
|
||||
if (restrictions.length === 1) {
|
||||
restriction = `\
|
||||
<m:Restriction>
|
||||
${restrictions[0]}
|
||||
</m:Restriction>`;
|
||||
<m:Restriction>
|
||||
${restrictions[0]}
|
||||
</m:Restriction>`;
|
||||
} else if (restrictions.length > 1) {
|
||||
restriction = `\
|
||||
<m:Restriction>
|
||||
<t:And>
|
||||
${restrictions.join("\n")}
|
||||
</t:And>
|
||||
</m:Restriction>`;
|
||||
<m:Restriction>
|
||||
<t:And>
|
||||
${restrictions.join("\n")}
|
||||
</t:And>
|
||||
</m:Restriction>`;
|
||||
}
|
||||
|
||||
const items = await client.findItems(folderId, {
|
||||
@@ -128,33 +138,9 @@ export function registerEmailTools(server: McpServer): void {
|
||||
restriction,
|
||||
});
|
||||
|
||||
if (idsOnly) {
|
||||
const result = items.map((item: any) => ({
|
||||
itemId: item.ItemId?.["@_Id"] ?? "",
|
||||
date: item.DateTimeReceived ?? "",
|
||||
subject: item.Subject ?? "",
|
||||
}));
|
||||
return {
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({ itemIds: result, count: result.length }),
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
const emails = [];
|
||||
for (const item of items) {
|
||||
const email = client.extractEmailSummary(item);
|
||||
|
||||
if (includeBody && email.itemId) {
|
||||
const details = client.extractEmailDetails(item);
|
||||
email.to = details.to;
|
||||
email.cc = details.cc;
|
||||
email.body = details.body;
|
||||
email.hasLinks = details.hasLinks;
|
||||
}
|
||||
|
||||
emails.push(email);
|
||||
emails.push(client.extractEmail(item));
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -162,6 +148,7 @@ export function registerEmailTools(server: McpServer): void {
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({ emails, count: emails.length }),
|
||||
}],
|
||||
structuredContent: { emails, count: emails.length },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -177,21 +164,43 @@ export function registerEmailTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"get_email",
|
||||
{
|
||||
description: "Get a single email with full body and details",
|
||||
description:
|
||||
"Get a single email with full body and details by Exchange ItemId.",
|
||||
inputSchema: z.object({
|
||||
itemId: z.string().describe(
|
||||
"The Exchange ItemId of the email to retrieve",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
itemId: z.string(),
|
||||
subject: z.string(),
|
||||
from: z.string(),
|
||||
fromName: z.string().optional(),
|
||||
to: z.array(z.string()).optional(),
|
||||
cc: z.array(z.string()).optional(),
|
||||
date: z.string(),
|
||||
body: z.string().optional(),
|
||||
isRead: z.boolean().optional(),
|
||||
hasAttachments: z.boolean().optional(),
|
||||
hasLinks: z.boolean().optional(),
|
||||
attachments: z.array(z.object({
|
||||
name: z.string(),
|
||||
size: z.number(),
|
||||
contentType: z.string(),
|
||||
attachmentId: z.string().optional(),
|
||||
isInline: z.boolean().optional(),
|
||||
})).optional(),
|
||||
}),
|
||||
},
|
||||
async ({ itemId }) => {
|
||||
try {
|
||||
const client = getClient();
|
||||
const item = await client.getItem(itemId);
|
||||
const email = client.extractEmailDetails(item);
|
||||
const email = client.extractEmail(item);
|
||||
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(email) }],
|
||||
structuredContent: { emails: [email] },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -207,15 +216,21 @@ export function registerEmailTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"mark_email_read",
|
||||
{
|
||||
description: "Mark one or more emails as read or unread",
|
||||
description:
|
||||
"Mark one or more emails as read or unread by their Exchange ItemIds.",
|
||||
inputSchema: z.object({
|
||||
itemIds: z.array(z.string()).describe(
|
||||
"List of Exchange ItemIds to update",
|
||||
),
|
||||
isRead: z.boolean().default(true).describe(
|
||||
"True to mark as read, False to mark as unread",
|
||||
"True to mark as read, false to mark as unread",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
success: z.boolean(),
|
||||
message: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async ({ itemIds, isRead }) => {
|
||||
try {
|
||||
@@ -234,6 +249,10 @@ export function registerEmailTools(server: McpServer): void {
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({ error: errors.join("; ") }),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: false,
|
||||
error: errors.join("; "),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -246,6 +265,10 @@ export function registerEmailTools(server: McpServer): void {
|
||||
message: `Marked ${itemIds.length} email(s) as ${status}.`,
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: true,
|
||||
message: `Marked ${itemIds.length} email(s) as ${status}.`,
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -253,6 +276,10 @@ export function registerEmailTools(server: McpServer): void {
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: false,
|
||||
error: error.message ?? String(error),
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
@@ -261,19 +288,36 @@ export function registerEmailTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"download_attachments",
|
||||
{
|
||||
description: "Download all file attachments from an email to disk",
|
||||
description: "Download all file attachments from an email 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 email"),
|
||||
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(
|
||||
@@ -291,6 +335,12 @@ export function registerEmailTools(server: McpServer): void {
|
||||
message: "No downloadable file attachments.",
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: true,
|
||||
downloaded: [],
|
||||
count: 0,
|
||||
message: "No downloadable file attachments.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -348,6 +398,9 @@ export function registerEmailTools(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 {
|
||||
|
||||
+16
-4
@@ -1,20 +1,31 @@
|
||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
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 registerFolderTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"get_folders",
|
||||
{
|
||||
description: "List mail folders from the Exchange mailbox",
|
||||
description: "List mailbox folders from the Exchange mailbox.",
|
||||
inputSchema: z.object({
|
||||
parentFolderId: z.string().default("msgfolderroot").describe(
|
||||
"Parent folder to list children of (default: msgfolderroot)",
|
||||
"Parent folder to list children of."
|
||||
+ " Supports distinguished names (e.g. inbox, calendar)",
|
||||
),
|
||||
recursive: z.boolean().default(false).describe(
|
||||
"If True, traverse all subfolders recursively",
|
||||
"If true, recursively traverse all subfolders",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
folders: z.array(z.object({
|
||||
name: z.string(),
|
||||
id: z.string(),
|
||||
totalCount: z.number(),
|
||||
unreadCount: z.number(),
|
||||
childFolderCount: z.number(),
|
||||
})),
|
||||
}),
|
||||
},
|
||||
async ({ parentFolderId, recursive }) => {
|
||||
try {
|
||||
@@ -23,6 +34,7 @@ export function registerFolderTools(server: McpServer): void {
|
||||
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(folders) }],
|
||||
structuredContent: { folders },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
|
||||
+27
-3
@@ -1,22 +1,45 @@
|
||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
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 registerPeopleTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"find_person",
|
||||
{
|
||||
description: "Search for people in the corporate directory",
|
||||
description:
|
||||
"Search for people in the corporate directory (Active Directory)"
|
||||
+ " by name, email, or keyword.",
|
||||
inputSchema: z.object({
|
||||
query: z.string().describe(
|
||||
"Name, email address, or keyword to search for",
|
||||
),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
mailboxType: z.string(),
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
jobTitle: z.string(),
|
||||
department: z.string(),
|
||||
company: z.string(),
|
||||
office: z.string(),
|
||||
alias: z.string(),
|
||||
manager: z.string(),
|
||||
managerEmail: z.string(),
|
||||
phones: z.record(z.string(), z.string()),
|
||||
address: z.string(),
|
||||
directReports: z.array(z.object({
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
})),
|
||||
}),
|
||||
},
|
||||
async ({ query }) => {
|
||||
try {
|
||||
const client = new EwsClient(loadConfig());
|
||||
const resolutions = await client.resolveNames(query, true);
|
||||
const resolutions = await client.resolveNames(query);
|
||||
|
||||
const people = resolutions.map((r: any) => {
|
||||
const mailbox = r.Mailbox ?? {};
|
||||
@@ -84,6 +107,7 @@ export function registerPeopleTools(server: McpServer): void {
|
||||
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify(people) }],
|
||||
structuredContent: { people },
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user