Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 33da3cba1a | |||
| 8fce57800f | |||
| 91d9befa1e | |||
| 509e49e374 | |||
| 91f83da567 | |||
| 92942a3bcd | |||
| af3da35179 |
+2
-1
@@ -10,4 +10,5 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.yarn
|
.yarn
|
||||||
node_modules
|
node_modules
|
||||||
config.json
|
config.json
|
||||||
|
data/
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
---
|
||||||
|
name: exchange-mcp
|
||||||
|
description: >-
|
||||||
|
Use this skill when the user talks about
|
||||||
|
email, calendar, contacts, Exchange, EWS, corporate mail,
|
||||||
|
or scheduling meetings.
|
||||||
|
---
|
||||||
|
|
||||||
|
# exchange-mcp — MCP server for Microsoft Exchange
|
||||||
|
|
||||||
|
This MCP server provides access to **Microsoft Exchange Server** via **Exchange
|
||||||
|
Web Services (EWS)** with NTLM authentication. Supports email, calendar,
|
||||||
|
contacts, and free/busy scheduling.
|
||||||
|
|
||||||
|
**Use this server when the user talks about:**
|
||||||
|
|
||||||
|
- Email, inbox, sent items, drafts
|
||||||
|
- Calendar, events, meetings, availability
|
||||||
|
- Contacts, people, colleagues, employees
|
||||||
|
- Attachments, files in emails
|
||||||
|
- Exchange, EWS, corporate mail
|
||||||
|
|
||||||
|
**Does not support:** Microsoft 365 / Exchange Online (OAuth), IMAP/POP3/SMTP,
|
||||||
|
Gmail, Outlook.com.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
### Auth
|
||||||
|
|
||||||
|
#### `login`
|
||||||
|
|
||||||
|
Authenticate to Exchange EWS via NTLM.
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| ----------- | ------ | -------- | ------------------------------------------------ |
|
||||||
|
| `serverUrl` | string | yes | EWS server URL (e.g. `https://mail.example.com`) |
|
||||||
|
| `email` | string | yes | Email address |
|
||||||
|
| `username` | string | yes | NTLM username |
|
||||||
|
| `password` | string | yes | NTLM password |
|
||||||
|
| `domain` | string | no | NTLM domain (default: `corp`) |
|
||||||
|
|
||||||
|
#### `check_session`
|
||||||
|
|
||||||
|
Check if the current session is authenticated. No parameters. Returns
|
||||||
|
`{authenticated, email, serverUrl}`.
|
||||||
|
|
||||||
|
#### `logout`
|
||||||
|
|
||||||
|
Clear stored credentials. No parameters.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Email
|
||||||
|
|
||||||
|
#### `get_emails`
|
||||||
|
|
||||||
|
Get emails from a folder. Supports optional text search via
|
||||||
|
`query`/`queryScope`.
|
||||||
|
|
||||||
|
| Parameter | Type | Default | Description |
|
||||||
|
| ------------- | ------- | --------- | ----------------------------------------------------------------------------------- |
|
||||||
|
| `folder` | string | `"Inbox"` | Folder name (Inbox, Sent, Drafts, Deleted, Junk, or custom; supports Russian names) |
|
||||||
|
| `limit` | number | `10` | Max emails (max 50; max 500 if `idsOnly=true`) |
|
||||||
|
| `offset` | number | `0` | Pagination offset |
|
||||||
|
| `includeBody` | boolean | `false` | If `true`, fetches full email body |
|
||||||
|
| `unreadOnly` | boolean | `false` | Only unread emails |
|
||||||
|
| `idsOnly` | boolean | `false` | Return only IDs + dates + subjects (faster, higher limit) |
|
||||||
|
| `query` | string | — | Text to search for within the folder |
|
||||||
|
| `queryScope` | enum | `"all"` | Scope: `all`, `subject`, `body`, `from` (only when `query` is set) |
|
||||||
|
|
||||||
|
#### `get_email`
|
||||||
|
|
||||||
|
Get a single email with full body and details.
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ------ | -------- | ---------------------------- |
|
||||||
|
| `itemId` | string | yes | Exchange ItemId of the email |
|
||||||
|
|
||||||
|
#### `mark_email_read`
|
||||||
|
|
||||||
|
Mark emails as read or unread.
|
||||||
|
|
||||||
|
| Parameter | Type | Default | Description |
|
||||||
|
| --------- | -------- | ------- | ------------------------------- |
|
||||||
|
| `itemIds` | string[] | — | List of Exchange ItemIds |
|
||||||
|
| `isRead` | boolean | `true` | `true` = read, `false` = unread |
|
||||||
|
|
||||||
|
#### `download_attachments`
|
||||||
|
|
||||||
|
Download all file attachments from an email to disk.
|
||||||
|
|
||||||
|
| Parameter | Type | Default | Description |
|
||||||
|
| -------------- | ------ | -------------------- | --------------- |
|
||||||
|
| `itemId` | string | — | Exchange ItemId |
|
||||||
|
| `targetFolder` | string | `"/tmp/attachments"` | Local folder |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Folders
|
||||||
|
|
||||||
|
#### `get_folders`
|
||||||
|
|
||||||
|
List mailbox folders.
|
||||||
|
|
||||||
|
| Parameter | Type | Default | Description |
|
||||||
|
| ---------------- | ------- | ----------------- | ----------------------------------------------------------------- |
|
||||||
|
| `parentFolderId` | string | `"msgfolderroot"` | Parent folder (supports distinguished names: `inbox`, `calendar`) |
|
||||||
|
| `recursive` | boolean | `false` | Recursively traverse subfolders |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Calendar
|
||||||
|
|
||||||
|
#### `get_calendar_events`
|
||||||
|
|
||||||
|
Get calendar events within a date range.
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| ------------- | ------- | -------- | ----------------------------------------- |
|
||||||
|
| `startDate` | string | yes | Start (`YYYY-MM-DD`) |
|
||||||
|
| `endDate` | string | yes | End (`YYYY-MM-DD`) |
|
||||||
|
| `includeBody` | boolean | `false` | Full details (organizer, attendees, body) |
|
||||||
|
|
||||||
|
#### `download_event_attachments`
|
||||||
|
|
||||||
|
Download attachments from a calendar event. Same parameters as
|
||||||
|
`download_attachments`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Availability
|
||||||
|
|
||||||
|
#### `find_free_time`
|
||||||
|
|
||||||
|
Find free time slots in your calendar.
|
||||||
|
|
||||||
|
| Parameter | Type | Default | Description |
|
||||||
|
| ----------------- | ------ | ----------- | -------------------------- |
|
||||||
|
| `startDate` | string | — | Start (`YYYY-MM-DD`) |
|
||||||
|
| `endDate` | string | = startDate | End |
|
||||||
|
| `durationMinutes` | number | `30` | Minimum slot duration |
|
||||||
|
| `startHour` | number | `9` | Work day start hour (0-23) |
|
||||||
|
| `endHour` | number | `18` | Work day end hour (0-23) |
|
||||||
|
|
||||||
|
#### `find_meeting_time`
|
||||||
|
|
||||||
|
Find common free time for multiple people.
|
||||||
|
|
||||||
|
| Parameter | Type | Default | Description |
|
||||||
|
| ----------------- | ------ | ----------- | --------------------------------- |
|
||||||
|
| `emails` | string | — | Attendee emails (comma-separated) |
|
||||||
|
| `startDate` | string | — | Start |
|
||||||
|
| `endDate` | string | = startDate | End |
|
||||||
|
| `durationMinutes` | number | `30` | Minimum slot duration |
|
||||||
|
| `startHour` | number | `9` | Work day start hour |
|
||||||
|
| `endHour` | number | `18` | Work day end hour |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### People
|
||||||
|
|
||||||
|
#### `find_person`
|
||||||
|
|
||||||
|
Search for people in the corporate directory (Active Directory).
|
||||||
|
|
||||||
|
| Parameter | Type | Required | Description |
|
||||||
|
| --------- | ------ | -------- | ----------------------- |
|
||||||
|
| `query` | string | yes | Name, email, or keyword |
|
||||||
|
|
||||||
|
Returns: name, email, job title, department, company, office, phone, manager,
|
||||||
|
direct reports.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
FROM node:26-slim
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . .
|
||||||
|
RUN npm install
|
||||||
|
CMD ["npm", "start"]
|
||||||
+8
-4
@@ -5,14 +5,18 @@
|
|||||||
"module.sortImportDeclarations": "caseInsensitive",
|
"module.sortImportDeclarations": "caseInsensitive",
|
||||||
"module.sortExportDeclarations": "caseInsensitive"
|
"module.sortExportDeclarations": "caseInsensitive"
|
||||||
},
|
},
|
||||||
|
"markdown": {
|
||||||
|
"lineWidth": 80,
|
||||||
|
"textWrap": "always"
|
||||||
|
},
|
||||||
"excludes": [
|
"excludes": [
|
||||||
"**/.git",
|
"**/.git",
|
||||||
"**/.target"
|
"**/.target"
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"https://plugins.dprint.dev/typescript-0.91.1.wasm",
|
"https://plugins.dprint.dev/typescript-0.96.1.wasm",
|
||||||
"https://plugins.dprint.dev/json-0.17.4.wasm",
|
"https://plugins.dprint.dev/json-0.23.0.wasm",
|
||||||
"https://plugins.dprint.dev/markdown-0.15.3.wasm",
|
"https://plugins.dprint.dev/markdown-0.22.1.wasm",
|
||||||
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm"
|
"https://plugins.dprint.dev/dockerfile-0.4.1.wasm"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+285
-27
@@ -1,11 +1,36 @@
|
|||||||
import { XMLParser } from "fast-xml-parser";
|
import { XMLParser } from "fast-xml-parser";
|
||||||
import { promisify } from "node:util";
|
|
||||||
import { createRequire } from "node:module";
|
|
||||||
import https from "node:https";
|
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import https from "node:https";
|
||||||
|
import { createRequire } from "node:module";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { promisify } from "node:util";
|
||||||
import type { Email, Folder, LoginConfig } from "./models.ts";
|
import type { Email } from "./types/email.ts";
|
||||||
|
import type { Folder } from "./types/folder.ts";
|
||||||
|
import type { LoginConfig } from "./types/login_config.ts";
|
||||||
|
|
||||||
|
let inMemoryPassword: string | null = null;
|
||||||
|
let dataDir: string = "./data";
|
||||||
|
|
||||||
|
export function initDataDir(dir: string): void {
|
||||||
|
dataDir = path.resolve(dir);
|
||||||
|
fs.mkdirSync(dataDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setPassword(password: string): void {
|
||||||
|
inMemoryPassword = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPassword(): string | null {
|
||||||
|
return inMemoryPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hasPassword(): boolean {
|
||||||
|
return inMemoryPassword !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearPassword(): void {
|
||||||
|
inMemoryPassword = null;
|
||||||
|
}
|
||||||
|
|
||||||
const ntlm: any = createRequire(import.meta.url)("httpntlm");
|
const ntlm: any = createRequire(import.meta.url)("httpntlm");
|
||||||
const postAsync = promisify(ntlm.post.bind(ntlm));
|
const postAsync = promisify(ntlm.post.bind(ntlm));
|
||||||
@@ -54,8 +79,7 @@ ${body}
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configFilePath(): string {
|
function configFilePath(): string {
|
||||||
const dir = path.dirname(fileURLToPath(import.meta.url));
|
return path.join(dataDir, "config.json");
|
||||||
return path.join(dir, "config.json");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadConfig(): LoginConfig {
|
export function loadConfig(): LoginConfig {
|
||||||
@@ -76,27 +100,38 @@ export function clearConfig(): void {
|
|||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
fs.unlinkSync(filePath);
|
fs.unlinkSync(filePath);
|
||||||
}
|
}
|
||||||
|
clearPassword();
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EwsClient {
|
export class EwsClient {
|
||||||
private config: LoginConfig;
|
private config: LoginConfig;
|
||||||
private ewsUrl: string;
|
private ewsUrl: string;
|
||||||
|
|
||||||
constructor(config: LoginConfig) {
|
constructor(config: LoginConfig, password?: string) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.ewsUrl = `${config.serverUrl.replace(/\/+$/, "")}/EWS/Exchange.asmx`;
|
this.ewsUrl = `${config.serverUrl.replace(/\/+$/, "")}/EWS/Exchange.asmx`;
|
||||||
|
|
||||||
|
if (password) {
|
||||||
|
setPassword(password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private get domain(): string {
|
private get domain(): string {
|
||||||
return this.config.domain ?? "corp";
|
return this.config.domain ?? "corp";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async soapRequest(body: string, soapAction: string): Promise<any> {
|
private get password(): string {
|
||||||
|
const pw = getPassword();
|
||||||
|
if (!pw) throw new Error("Not logged in. Password not found in memory.");
|
||||||
|
return pw;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async soapRequest(body: string, soapAction: string): Promise<any> {
|
||||||
const res = await postAsync({
|
const res = await postAsync({
|
||||||
url: this.ewsUrl,
|
url: this.ewsUrl,
|
||||||
username: this.config.username,
|
username: this.config.username,
|
||||||
domain: this.domain,
|
domain: this.domain,
|
||||||
password: this.config.password,
|
password: this.password,
|
||||||
agent: AGENT,
|
agent: AGENT,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/xml; charset=utf-8",
|
"Content-Type": "text/xml; charset=utf-8",
|
||||||
@@ -154,7 +189,7 @@ private async soapRequest(body: string, soapAction: string): Promise<any> {
|
|||||||
</m:FolderIds>
|
</m:FolderIds>
|
||||||
</m:GetFolder>`);
|
</m:GetFolder>`);
|
||||||
|
|
||||||
const data = await this.soapRequest(
|
const data = await this.soapRequest(
|
||||||
soap,
|
soap,
|
||||||
"http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder",
|
"http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder",
|
||||||
);
|
);
|
||||||
@@ -215,6 +250,13 @@ const data = await this.soapRequest(
|
|||||||
traversal = "Shallow",
|
traversal = "Shallow",
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const isDistinguished =
|
||||||
|
DISTINGUISHED_FOLDERS[folderId.toLowerCase()] !== undefined;
|
||||||
|
|
||||||
|
const folderIdXml = isDistinguished
|
||||||
|
? `<t:DistinguishedFolderId Id="${folderId}"/>`
|
||||||
|
: `<t:FolderId Id="${folderId}"/>`;
|
||||||
|
|
||||||
const soap = buildSoapEnvelope(`\
|
const soap = buildSoapEnvelope(`\
|
||||||
<m:FindItem Traversal="${traversal}">
|
<m:FindItem Traversal="${traversal}">
|
||||||
<m:ItemShape>
|
<m:ItemShape>
|
||||||
@@ -222,7 +264,7 @@ const data = await this.soapRequest(
|
|||||||
</m:ItemShape>
|
</m:ItemShape>
|
||||||
<m:IndexedPageItemView MaxEntriesReturned="${limit}" Offset="${offset}" BasePoint="Beginning"/>
|
<m:IndexedPageItemView MaxEntriesReturned="${limit}" Offset="${offset}" BasePoint="Beginning"/>
|
||||||
<m:ParentFolderIds>
|
<m:ParentFolderIds>
|
||||||
<t:FolderId Id="${folderId}"/>
|
${folderIdXml}
|
||||||
</m:ParentFolderIds>
|
</m:ParentFolderIds>
|
||||||
<m:SortOrder>
|
<m:SortOrder>
|
||||||
<t:FieldOrder Order="Descending">
|
<t:FieldOrder Order="Descending">
|
||||||
@@ -238,7 +280,8 @@ ${restriction}
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const msg of this.extractResponseMessages(data)) {
|
for (const msg of this.extractResponseMessages(data)) {
|
||||||
const items = msg?.RootFolder?.Items?.Message ?? msg?.RootFolder?.Items?.CalendarItem;
|
const items = msg?.RootFolder?.Items?.Message
|
||||||
|
?? msg?.RootFolder?.Items?.CalendarItem;
|
||||||
if (!items) continue;
|
if (!items) continue;
|
||||||
return Array.isArray(items) ? items : [items];
|
return Array.isArray(items) ? items : [items];
|
||||||
}
|
}
|
||||||
@@ -268,7 +311,13 @@ ${restriction}
|
|||||||
if (!items) continue;
|
if (!items) continue;
|
||||||
|
|
||||||
const itemKey = Object.keys(items).find((k) =>
|
const itemKey = Object.keys(items).find((k) =>
|
||||||
["Message", "CalendarItem", "MeetingRequest", "MeetingResponse", "MeetingCancellation"].includes(k)
|
[
|
||||||
|
"Message",
|
||||||
|
"CalendarItem",
|
||||||
|
"MeetingRequest",
|
||||||
|
"MeetingResponse",
|
||||||
|
"MeetingCancellation",
|
||||||
|
].includes(k)
|
||||||
);
|
);
|
||||||
if (itemKey) {
|
if (itemKey) {
|
||||||
return items[itemKey];
|
return items[itemKey];
|
||||||
@@ -283,7 +332,8 @@ ${restriction}
|
|||||||
recursive: boolean = false,
|
recursive: boolean = false,
|
||||||
): Promise<Folder[]> {
|
): Promise<Folder[]> {
|
||||||
const traversal = recursive ? "Deep" : "Shallow";
|
const traversal = recursive ? "Deep" : "Shallow";
|
||||||
const isDistinguished = DISTINGUISHED_FOLDERS[parentFolderId.toLowerCase()] !== undefined
|
const isDistinguished =
|
||||||
|
DISTINGUISHED_FOLDERS[parentFolderId.toLowerCase()] !== undefined
|
||||||
|| ["msgfolderroot"].includes(parentFolderId.toLowerCase());
|
|| ["msgfolderroot"].includes(parentFolderId.toLowerCase());
|
||||||
|
|
||||||
const folderIdXml = isDistinguished
|
const folderIdXml = isDistinguished
|
||||||
@@ -329,7 +379,10 @@ ${restriction}
|
|||||||
|
|
||||||
extractEmailSummary(item: any): Email {
|
extractEmailSummary(item: any): Email {
|
||||||
const itemType = item["@_xsi_type"] ?? item.__type ?? "";
|
const itemType = item["@_xsi_type"] ?? item.__type ?? "";
|
||||||
const isMeeting = /MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(itemType);
|
const isMeeting =
|
||||||
|
/MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(
|
||||||
|
itemType,
|
||||||
|
);
|
||||||
|
|
||||||
const fromMailbox = item.From?.Mailbox
|
const fromMailbox = item.From?.Mailbox
|
||||||
?? item.Organizer?.Mailbox
|
?? item.Organizer?.Mailbox
|
||||||
@@ -340,9 +393,11 @@ ${restriction}
|
|||||||
subject: item.Subject ?? "(No subject)",
|
subject: item.Subject ?? "(No subject)",
|
||||||
from: fromMailbox.EmailAddress ?? "",
|
from: fromMailbox.EmailAddress ?? "",
|
||||||
fromName: fromMailbox.Name ?? "",
|
fromName: fromMailbox.Name ?? "",
|
||||||
date: item.DateTimeSent ?? item.DateTimeReceived ?? item.DateTimeCreated ?? "",
|
date: item.DateTimeSent ?? item.DateTimeReceived ?? item.DateTimeCreated
|
||||||
|
?? "",
|
||||||
isRead: item.IsRead === "true" || item.IsRead === true,
|
isRead: item.IsRead === "true" || item.IsRead === true,
|
||||||
hasAttachments: item.HasAttachments === "true" || item.HasAttachments === true,
|
hasAttachments: item.HasAttachments === "true"
|
||||||
|
|| item.HasAttachments === true,
|
||||||
hasLinks: false,
|
hasLinks: false,
|
||||||
itemId: item.ItemId?.["@_Id"] ?? "",
|
itemId: item.ItemId?.["@_Id"] ?? "",
|
||||||
size: item.Size ? Number(item.Size) : 0,
|
size: item.Size ? Number(item.Size) : 0,
|
||||||
@@ -357,15 +412,20 @@ ${restriction}
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (item.DisplayTo) {
|
if (item.DisplayTo) {
|
||||||
email.to = item.DisplayTo.split(";").map((t: string) => t.trim()).filter(Boolean);
|
email.to = item.DisplayTo.split(";").map((t: string) => t.trim()).filter(
|
||||||
|
Boolean,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (item.DisplayCc) {
|
if (item.DisplayCc) {
|
||||||
email.cc = item.DisplayCc.split(";").map((c: string) => c.trim()).filter(Boolean);
|
email.cc = item.DisplayCc.split(";").map((c: string) => c.trim()).filter(
|
||||||
|
Boolean,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMeeting) {
|
if (isMeeting) {
|
||||||
email.location = item.Location ?? "";
|
email.location = item.Location ?? "";
|
||||||
email.start = item.Start ?? item.StartWallClock ?? item.ReminderDueBy ?? "";
|
email.start = item.Start ?? item.StartWallClock ?? item.ReminderDueBy
|
||||||
|
?? "";
|
||||||
email.end = item.End ?? item.EndWallClock ?? "";
|
email.end = item.End ?? item.EndWallClock ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,11 +476,13 @@ ${restriction}
|
|||||||
isInline: a.IsInline === "true" || a.IsInline === true,
|
isInline: a.IsInline === "true" || a.IsInline === true,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const isMeeting = /MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(
|
const isMeeting =
|
||||||
item["@_xsi_type"] ?? "",
|
/MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(
|
||||||
);
|
item["@_xsi_type"] ?? "",
|
||||||
|
);
|
||||||
if (isMeeting) {
|
if (isMeeting) {
|
||||||
email.location = item.Location ?? item.EnhancedLocation?.DisplayName ?? "";
|
email.location = item.Location ?? item.EnhancedLocation?.DisplayName
|
||||||
|
?? "";
|
||||||
email.start = item.Start ?? "";
|
email.start = item.Start ?? "";
|
||||||
email.end = item.End ?? "";
|
email.end = item.End ?? "";
|
||||||
|
|
||||||
@@ -462,10 +524,206 @@ ${restriction}
|
|||||||
text = text.replace(/&/g, "&");
|
text = text.replace(/&/g, "&");
|
||||||
text = text.replace(/</g, "<");
|
text = text.replace(/</g, "<");
|
||||||
text = text.replace(/>/g, ">");
|
text = text.replace(/>/g, ">");
|
||||||
text = text.replace(/"/g, '"');
|
text = text.replace(/"/g, "\"");
|
||||||
text = text.replace(/'/g, "'");
|
text = text.replace(/'/g, "'");
|
||||||
text = text.replace(/\n\s*\n/g, "\n\n");
|
text = text.replace(/\n\s*\n/g, "\n\n");
|
||||||
text = text.replace(/[ \t]+/g, " ");
|
text = text.replace(/[ \t]+/g, " ");
|
||||||
return text.trim();
|
return text.trim();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// ── UpdateItem (for marking read/unread, etc.) ──────────────────────────
|
||||||
|
|
||||||
|
async updateItems(
|
||||||
|
itemIds: string[],
|
||||||
|
updates: { fieldUri: string; value: string | boolean }[],
|
||||||
|
): Promise<any[]> {
|
||||||
|
const propName = (fieldUri: string): string => {
|
||||||
|
const parts = fieldUri.split(":");
|
||||||
|
return parts[parts.length - 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
const changesXml = itemIds.map((id) => {
|
||||||
|
const updatesXml = updates.map((u) => {
|
||||||
|
const val = typeof u.value === "boolean"
|
||||||
|
? (u.value ? "true" : "false")
|
||||||
|
: u.value;
|
||||||
|
return `\
|
||||||
|
<t:SetItemField>
|
||||||
|
<t:FieldURI FieldURI="${u.fieldUri}"/>
|
||||||
|
<t:Message>
|
||||||
|
<t:${propName(u.fieldUri)}>${String(val)}</t:${
|
||||||
|
propName(u.fieldUri)
|
||||||
|
}>
|
||||||
|
</t:Message>
|
||||||
|
</t:SetItemField>`;
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
|
return `\
|
||||||
|
<t:ItemChange>
|
||||||
|
<t:ItemId Id="${id}"/>
|
||||||
|
<t:Updates>
|
||||||
|
${updatesXml}
|
||||||
|
</t:Updates>
|
||||||
|
</t:ItemChange>`;
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
|
const soap = buildSoapEnvelope(`\
|
||||||
|
<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AutoResolve">
|
||||||
|
<m:ItemChanges>
|
||||||
|
${changesXml}
|
||||||
|
</m:ItemChanges>
|
||||||
|
</m:UpdateItem>`);
|
||||||
|
|
||||||
|
const data = await this.soapRequest(
|
||||||
|
soap,
|
||||||
|
"http://schemas.microsoft.com/exchange/services/2006/messages/UpdateItem",
|
||||||
|
);
|
||||||
|
|
||||||
|
return this.extractResponseMessages(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── GetAttachment ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
async getAttachment(
|
||||||
|
attachmentId: string,
|
||||||
|
): Promise<{ content: Buffer; name: string; contentType: string }> {
|
||||||
|
const soap = buildSoapEnvelope(`\
|
||||||
|
<m:GetAttachment>
|
||||||
|
<m:AttachmentIds>
|
||||||
|
<t:AttachmentId Id="${attachmentId}"/>
|
||||||
|
</m:AttachmentIds>
|
||||||
|
</m:GetAttachment>`);
|
||||||
|
|
||||||
|
const data = await this.soapRequest(
|
||||||
|
soap,
|
||||||
|
"http://schemas.microsoft.com/exchange/services/2006/messages/GetAttachment",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const msg of this.extractResponseMessages(data)) {
|
||||||
|
const attachments = msg?.Attachments?.FileAttachment;
|
||||||
|
if (!attachments) continue;
|
||||||
|
const list = Array.isArray(attachments) ? attachments : [attachments];
|
||||||
|
for (const a of list) {
|
||||||
|
const contentBase64 = a.Content ?? "";
|
||||||
|
const content = Buffer.from(contentBase64, "base64");
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
name: a.Name ?? "attachment",
|
||||||
|
contentType: a.ContentType ?? "application/octet-stream",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Attachment '${attachmentId}' not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── FindItem with CalendarView ──────────────────────────────────────────
|
||||||
|
|
||||||
|
async findCalendarItems(
|
||||||
|
folderId: string,
|
||||||
|
startDate: string,
|
||||||
|
endDate: string,
|
||||||
|
): Promise<any[]> {
|
||||||
|
const soap = buildSoapEnvelope(`\
|
||||||
|
<m:FindItem Traversal="Shallow">
|
||||||
|
<m:ItemShape>
|
||||||
|
<t:BaseShape>AllProperties</t:BaseShape>
|
||||||
|
<t:BodyType>HTML</t:BodyType>
|
||||||
|
</m:ItemShape>
|
||||||
|
<m:ParentFolderIds>
|
||||||
|
<t:FolderId Id="${folderId}"/>
|
||||||
|
</m:ParentFolderIds>
|
||||||
|
<m:CalendarView MaxEntriesReturned="200" StartDate="${startDate}" EndDate="${endDate}"/>
|
||||||
|
</m:FindItem>`);
|
||||||
|
|
||||||
|
const data = await this.soapRequest(
|
||||||
|
soap,
|
||||||
|
"http://schemas.microsoft.com/exchange/services/2006/messages/FindItem",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const msg of this.extractResponseMessages(data)) {
|
||||||
|
const items = msg?.RootFolder?.Items?.CalendarItem;
|
||||||
|
if (!items) continue;
|
||||||
|
return Array.isArray(items) ? items : [items];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── GetUserAvailability ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
async getUserAvailability(
|
||||||
|
emails: string[],
|
||||||
|
startDate: string,
|
||||||
|
endDate: string,
|
||||||
|
requestedView: string = "DetailedMerged",
|
||||||
|
): Promise<any> {
|
||||||
|
const mailboxDataXml = emails.map((email) =>
|
||||||
|
`\
|
||||||
|
<t:MailboxData>
|
||||||
|
<t:Email>
|
||||||
|
<t:Address>${
|
||||||
|
email.replace(/&/g, "&").replace(/</g, "<")
|
||||||
|
}</t:Address>
|
||||||
|
</t:Email>
|
||||||
|
<t:AttendeeType>Required</t:AttendeeType>
|
||||||
|
</t:MailboxData>`
|
||||||
|
).join("\n");
|
||||||
|
|
||||||
|
const soap = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
|
||||||
|
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
|
||||||
|
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
|
||||||
|
<s:Body>
|
||||||
|
<m:GetUserAvailabilityRequest>
|
||||||
|
<m:MailboxDataArray>
|
||||||
|
${mailboxDataXml}
|
||||||
|
</m:MailboxDataArray>
|
||||||
|
<m:FreeBusyViewOptions>
|
||||||
|
<t:TimeWindow>
|
||||||
|
<t:StartTime>${startDate}T00:00:00</t:StartTime>
|
||||||
|
<t:EndTime>${endDate}T23:59:59</t:EndTime>
|
||||||
|
</t:TimeWindow>
|
||||||
|
<t:MergedFreeBusyIntervalInMinutes>30</t:MergedFreeBusyIntervalInMinutes>
|
||||||
|
<t:RequestedView>${requestedView}</t:RequestedView>
|
||||||
|
</m:FreeBusyViewOptions>
|
||||||
|
</m:GetUserAvailabilityRequest>
|
||||||
|
</s:Body>
|
||||||
|
</s:Envelope>`;
|
||||||
|
|
||||||
|
const data = await this.soapRequest(
|
||||||
|
soap,
|
||||||
|
"http://schemas.microsoft.com/exchange/services/2006/messages/GetUserAvailability",
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── ResolveNames (directory search) ─────────────────────────────────────
|
||||||
|
|
||||||
|
async resolveNames(
|
||||||
|
query: string,
|
||||||
|
fullContact: boolean = true,
|
||||||
|
): Promise<any[]> {
|
||||||
|
const soap = buildSoapEnvelope(`\
|
||||||
|
<m:ResolveNames ReturnFullContactData="${fullContact}" SearchScope="ActiveDirectoryContacts">
|
||||||
|
<m:UnresolvedEntry>${
|
||||||
|
query.replace(/&/g, "&").replace(/</g, "<")
|
||||||
|
}</m:UnresolvedEntry>
|
||||||
|
</m:ResolveNames>`);
|
||||||
|
|
||||||
|
const data = await this.soapRequest(
|
||||||
|
soap,
|
||||||
|
"http://schemas.microsoft.com/exchange/services/2006/messages/ResolveNames",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const msg of this.extractResponseMessages(data)) {
|
||||||
|
const resolutions = msg?.ResolutionSet?.Resolution;
|
||||||
|
if (resolutions) {
|
||||||
|
return Array.isArray(resolutions) ? resolutions : [resolutions];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
||||||
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
||||||
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import http from "node:http";
|
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
|
import http from "node:http";
|
||||||
|
import { initDataDir } from "./ews_client.ts";
|
||||||
import { registerAuthTools } from "./tools/auth.ts";
|
import { registerAuthTools } from "./tools/auth.ts";
|
||||||
|
import { registerAvailabilityTools } from "./tools/availability.ts";
|
||||||
|
import { registerCalendarTools } from "./tools/calendar.ts";
|
||||||
import { registerEmailTools } from "./tools/email.ts";
|
import { registerEmailTools } from "./tools/email.ts";
|
||||||
import { registerFolderTools } from "./tools/folders.ts";
|
import { registerFolderTools } from "./tools/folders.ts";
|
||||||
|
import { registerPeopleTools } from "./tools/people.ts";
|
||||||
|
|
||||||
const program = new Command()
|
const program = new Command()
|
||||||
.name("exchange-mcp")
|
.name("exchange-mcp")
|
||||||
.description("Exchange MCP Server — EWS integration via MCP")
|
.description("Exchange MCP Server — EWS integration via MCP")
|
||||||
.option("--transport <type>", "Transport: stdio or sse", "stdio")
|
.option("--transport <type>", "Transport: stdio or sse", "stdio")
|
||||||
.option("--token-hash <hash>", "SHA-256 hash of bearer token for HTTP transport auth")
|
.option(
|
||||||
|
"--token-hash <hash>",
|
||||||
|
"SHA-256 hash of bearer token for HTTP transport auth",
|
||||||
|
)
|
||||||
.option("--host <host>", "HTTP host", "127.0.0.1")
|
.option("--host <host>", "HTTP host", "127.0.0.1")
|
||||||
.option("--port <port>", "HTTP port", "8000");
|
.option("--port <port>", "HTTP port", "8000")
|
||||||
|
.option("--data-dir <path>", "Data directory for config.json", "./data");
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
const options = program.opts();
|
const options = program.opts();
|
||||||
|
|
||||||
|
initDataDir(options.dataDir);
|
||||||
|
|
||||||
function buildServer(): McpServer {
|
function buildServer(): McpServer {
|
||||||
const server = new McpServer({
|
const server = new McpServer({
|
||||||
name: "exchange-mcp",
|
name: "exchange-mcp",
|
||||||
@@ -28,6 +38,9 @@ function buildServer(): McpServer {
|
|||||||
registerAuthTools(server);
|
registerAuthTools(server);
|
||||||
registerEmailTools(server);
|
registerEmailTools(server);
|
||||||
registerFolderTools(server);
|
registerFolderTools(server);
|
||||||
|
registerCalendarTools(server);
|
||||||
|
registerAvailabilityTools(server);
|
||||||
|
registerPeopleTools(server);
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
@@ -55,7 +68,10 @@ async function runSSE() {
|
|||||||
|
|
||||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
||||||
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
res.setHeader(
|
||||||
|
"Access-Control-Allow-Headers",
|
||||||
|
"Content-Type, Authorization",
|
||||||
|
);
|
||||||
|
|
||||||
if (req.method === "OPTIONS") {
|
if (req.method === "OPTIONS") {
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
@@ -66,7 +82,7 @@ async function runSSE() {
|
|||||||
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
||||||
|
|
||||||
if (req.method === "GET") {
|
if (req.method === "GET") {
|
||||||
const transport = new SSEServerTransport("/message", res);
|
const transport = new SSEServerTransport("/sse", res);
|
||||||
const server = buildServer();
|
const server = buildServer();
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
|
|
||||||
@@ -77,7 +93,7 @@ async function runSSE() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === "POST" && url.pathname === "/message") {
|
if (req.method === "POST" && url.pathname === "/sse") {
|
||||||
const sessionId = url.searchParams.get("sessionId") || "";
|
const sessionId = url.searchParams.get("sessionId") || "";
|
||||||
const transport = transports.get(sessionId);
|
const transport = transports.get(sessionId);
|
||||||
if (!transport) {
|
if (!transport) {
|
||||||
@@ -113,7 +129,9 @@ async function main() {
|
|||||||
await runSSE();
|
await runSSE();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error(`Unsupported transport: "${transportType}". Use "stdio" or "sse".`);
|
console.error(
|
||||||
|
`Unsupported transport: "${transportType}". Use "stdio" or "sse".`,
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,4 +139,4 @@ async function main() {
|
|||||||
main().catch((error) => {
|
main().catch((error) => {
|
||||||
console.error("Fatal error:", error);
|
console.error("Fatal error:", error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
export interface LoginConfig {
|
|
||||||
serverUrl: string;
|
|
||||||
email: string;
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
domain?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Email {
|
|
||||||
subject: string;
|
|
||||||
from: string;
|
|
||||||
fromName: string;
|
|
||||||
date: string;
|
|
||||||
isRead: boolean;
|
|
||||||
hasAttachments: boolean;
|
|
||||||
hasLinks: boolean;
|
|
||||||
itemId: string;
|
|
||||||
size: number;
|
|
||||||
isMeeting: boolean;
|
|
||||||
itemType: string;
|
|
||||||
to: string[];
|
|
||||||
cc: string[];
|
|
||||||
body: string;
|
|
||||||
bodyType: string;
|
|
||||||
attachments: Attachment[];
|
|
||||||
preview: string;
|
|
||||||
location?: string;
|
|
||||||
start?: string;
|
|
||||||
end?: string;
|
|
||||||
requiredAttendees?: string[];
|
|
||||||
optionalAttendees?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Attachment {
|
|
||||||
name: string;
|
|
||||||
size: number;
|
|
||||||
contentType: string;
|
|
||||||
attachmentId: string;
|
|
||||||
isInline: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Folder {
|
|
||||||
name: string;
|
|
||||||
id: string;
|
|
||||||
totalCount: number;
|
|
||||||
unreadCount: number;
|
|
||||||
childFolderCount: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Person {
|
|
||||||
name: string;
|
|
||||||
email: string;
|
|
||||||
mailboxType: string;
|
|
||||||
firstName: string;
|
|
||||||
lastName: string;
|
|
||||||
jobTitle: string;
|
|
||||||
department: string;
|
|
||||||
company: string;
|
|
||||||
office: string;
|
|
||||||
alias: string;
|
|
||||||
manager: string;
|
|
||||||
managerEmail: string;
|
|
||||||
phones: Record<string, string>;
|
|
||||||
address: string;
|
|
||||||
directReports: Array<{ name: string; email: string }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CalendarEvent {
|
|
||||||
subject: string;
|
|
||||||
start: string;
|
|
||||||
end: string;
|
|
||||||
location: string;
|
|
||||||
isAllDay: boolean;
|
|
||||||
isCancelled: boolean;
|
|
||||||
isMeeting: boolean;
|
|
||||||
isRecurring: boolean;
|
|
||||||
organizer: string;
|
|
||||||
organizerEmail: string;
|
|
||||||
myResponse: string;
|
|
||||||
itemId: string;
|
|
||||||
body: string;
|
|
||||||
requiredAttendees: string[];
|
|
||||||
optionalAttendees: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FreeSlot {
|
|
||||||
date: string;
|
|
||||||
start: string;
|
|
||||||
end: string;
|
|
||||||
durationMinutes: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MeetingResult {
|
|
||||||
success: boolean;
|
|
||||||
subject: string;
|
|
||||||
date: string;
|
|
||||||
startTime: string;
|
|
||||||
endTime: string;
|
|
||||||
location: string;
|
|
||||||
requiredAttendees: string[];
|
|
||||||
optionalAttendees: string[];
|
|
||||||
error: string;
|
|
||||||
}
|
|
||||||
Generated
-519
@@ -16,452 +16,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.20.1",
|
"@types/node": "^22.20.1",
|
||||||
"tsx": "^4.23.0",
|
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@esbuild/aix-ppc64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==",
|
|
||||||
"cpu": [
|
|
||||||
"ppc64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"aix"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/android-arm": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==",
|
|
||||||
"cpu": [
|
|
||||||
"arm"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"android"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/android-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"android"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/android-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"android"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/darwin-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"darwin"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/darwin-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"darwin"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/freebsd-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"freebsd"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/freebsd-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"freebsd"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-arm": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==",
|
|
||||||
"cpu": [
|
|
||||||
"arm"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-ia32": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==",
|
|
||||||
"cpu": [
|
|
||||||
"ia32"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-loong64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==",
|
|
||||||
"cpu": [
|
|
||||||
"loong64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-mips64el": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==",
|
|
||||||
"cpu": [
|
|
||||||
"mips64el"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-ppc64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==",
|
|
||||||
"cpu": [
|
|
||||||
"ppc64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-riscv64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==",
|
|
||||||
"cpu": [
|
|
||||||
"riscv64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-s390x": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==",
|
|
||||||
"cpu": [
|
|
||||||
"s390x"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/linux-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/netbsd-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"netbsd"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/netbsd-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"netbsd"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/openbsd-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"openbsd"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/openbsd-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"openbsd"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/openharmony-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"openharmony"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/sunos-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"sunos"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/win32-arm64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==",
|
|
||||||
"cpu": [
|
|
||||||
"arm64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"win32"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/win32-ia32": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==",
|
|
||||||
"cpu": [
|
|
||||||
"ia32"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"win32"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@esbuild/win32-x64": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==",
|
|
||||||
"cpu": [
|
|
||||||
"x64"
|
|
||||||
],
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"win32"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@hono/node-server": {
|
"node_modules/@hono/node-server": {
|
||||||
"version": "1.19.14",
|
"version": "1.19.14",
|
||||||
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.14.tgz",
|
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.14.tgz",
|
||||||
@@ -844,48 +401,6 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/esbuild": {
|
|
||||||
"version": "0.28.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz",
|
|
||||||
"integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==",
|
|
||||||
"dev": true,
|
|
||||||
"hasInstallScript": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"bin": {
|
|
||||||
"esbuild": "bin/esbuild"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"@esbuild/aix-ppc64": "0.28.1",
|
|
||||||
"@esbuild/android-arm": "0.28.1",
|
|
||||||
"@esbuild/android-arm64": "0.28.1",
|
|
||||||
"@esbuild/android-x64": "0.28.1",
|
|
||||||
"@esbuild/darwin-arm64": "0.28.1",
|
|
||||||
"@esbuild/darwin-x64": "0.28.1",
|
|
||||||
"@esbuild/freebsd-arm64": "0.28.1",
|
|
||||||
"@esbuild/freebsd-x64": "0.28.1",
|
|
||||||
"@esbuild/linux-arm": "0.28.1",
|
|
||||||
"@esbuild/linux-arm64": "0.28.1",
|
|
||||||
"@esbuild/linux-ia32": "0.28.1",
|
|
||||||
"@esbuild/linux-loong64": "0.28.1",
|
|
||||||
"@esbuild/linux-mips64el": "0.28.1",
|
|
||||||
"@esbuild/linux-ppc64": "0.28.1",
|
|
||||||
"@esbuild/linux-riscv64": "0.28.1",
|
|
||||||
"@esbuild/linux-s390x": "0.28.1",
|
|
||||||
"@esbuild/linux-x64": "0.28.1",
|
|
||||||
"@esbuild/netbsd-arm64": "0.28.1",
|
|
||||||
"@esbuild/netbsd-x64": "0.28.1",
|
|
||||||
"@esbuild/openbsd-arm64": "0.28.1",
|
|
||||||
"@esbuild/openbsd-x64": "0.28.1",
|
|
||||||
"@esbuild/openharmony-arm64": "0.28.1",
|
|
||||||
"@esbuild/sunos-x64": "0.28.1",
|
|
||||||
"@esbuild/win32-arm64": "0.28.1",
|
|
||||||
"@esbuild/win32-ia32": "0.28.1",
|
|
||||||
"@esbuild/win32-x64": "0.28.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/escape-html": {
|
"node_modules/escape-html": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||||
@@ -1083,21 +598,6 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fsevents": {
|
|
||||||
"version": "2.3.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
|
||||||
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
|
||||||
"dev": true,
|
|
||||||
"hasInstallScript": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"optional": true,
|
|
||||||
"os": [
|
|
||||||
"darwin"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/function-bind": {
|
"node_modules/function-bind": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||||
@@ -1768,25 +1268,6 @@
|
|||||||
"node": ">=0.6"
|
"node": ">=0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/tsx": {
|
|
||||||
"version": "4.23.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.0.tgz",
|
|
||||||
"integrity": "sha512-eUdUIaCr963q2h5u3+QwvYp0+eqPvn+egeqZUm0hwERCqqx1E3kK5ehbGCvqSE5MQAULr67ww0cA3jKc3YkM1w==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"esbuild": "~0.28.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"tsx": "dist/cli.mjs"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18.0.0"
|
|
||||||
},
|
|
||||||
"optionalDependencies": {
|
|
||||||
"fsevents": "~2.3.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/type-is": {
|
"node_modules/type-is": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz",
|
||||||
|
|||||||
+1
-2
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "tsx main.ts",
|
"start": "node main.ts",
|
||||||
"format": "dprint fmt"
|
"format": "dprint fmt"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.20.1",
|
"@types/node": "^22.20.1",
|
||||||
"tsx": "^4.23.0",
|
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-11
@@ -1,6 +1,13 @@
|
|||||||
import { z } from "zod/v4";
|
|
||||||
import { EwsClient, loadConfig, saveConfig, clearConfig } from "../ews_client.ts";
|
|
||||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
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";
|
||||||
|
|
||||||
export function registerAuthTools(server: McpServer): void {
|
export function registerAuthTools(server: McpServer): void {
|
||||||
server.registerTool(
|
server.registerTool(
|
||||||
@@ -8,7 +15,9 @@ export function registerAuthTools(server: McpServer): void {
|
|||||||
{
|
{
|
||||||
description: "Authenticate to Exchange EWS using NTLM credentials",
|
description: "Authenticate to Exchange EWS using NTLM credentials",
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
serverUrl: z.string().describe("EWS server URL (e.g. https://mail.example.com)"),
|
serverUrl: z.string().describe(
|
||||||
|
"EWS server URL (e.g. https://mail.example.com)",
|
||||||
|
),
|
||||||
email: z.string().describe("Email address"),
|
email: z.string().describe("Email address"),
|
||||||
username: z.string().describe("NTLM username"),
|
username: z.string().describe("NTLM username"),
|
||||||
password: z.string().describe("NTLM password"),
|
password: z.string().describe("NTLM password"),
|
||||||
@@ -21,27 +30,44 @@ export function registerAuthTools(server: McpServer): void {
|
|||||||
serverUrl: serverUrl.replace(/\/+$/, ""),
|
serverUrl: serverUrl.replace(/\/+$/, ""),
|
||||||
email,
|
email,
|
||||||
username,
|
username,
|
||||||
password,
|
|
||||||
domain: domain ?? "corp",
|
domain: domain ?? "corp",
|
||||||
};
|
};
|
||||||
|
|
||||||
const client = new EwsClient(config);
|
const client = new EwsClient(config, password);
|
||||||
const result = await client.verifyConnection();
|
const result = await client.verifyConnection();
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: result.error ?? "Connection verification failed" }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
error: result.error ?? "Connection verification failed",
|
||||||
|
}),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
saveConfig(config);
|
saveConfig(config);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ success: true, message: `Logged in as ${email} to ${serverUrl}` }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
message: `Logged in as ${email} to ${serverUrl}`,
|
||||||
|
}),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: error.message ?? String(error) }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
error: error.message ?? String(error),
|
||||||
|
}),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -55,6 +81,17 @@ export function registerAuthTools(server: McpServer): void {
|
|||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
try {
|
try {
|
||||||
|
if (!hasPassword()) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
authenticated: false,
|
||||||
|
error: "Not logged in. Password not found in memory.",
|
||||||
|
}),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
const client = new EwsClient(config);
|
const client = new EwsClient(config);
|
||||||
const result = await client.verifyConnection();
|
const result = await client.verifyConnection();
|
||||||
@@ -72,7 +109,13 @@ export function registerAuthTools(server: McpServer): void {
|
|||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ authenticated: false, error: error.message ?? String(error) }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
authenticated: false,
|
||||||
|
error: error.message ?? String(error),
|
||||||
|
}),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -87,8 +130,14 @@ export function registerAuthTools(server: McpServer): void {
|
|||||||
async () => {
|
async () => {
|
||||||
clearConfig();
|
clearConfig();
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ success: true, message: "Logged out. Credentials cleared." }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
message: "Logged out. Credentials cleared.",
|
||||||
|
}),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,331 @@
|
|||||||
|
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
import { z } from "zod/v4";
|
||||||
|
import { EwsClient, loadConfig } from "../ews_client.ts";
|
||||||
|
|
||||||
|
export function registerAvailabilityTools(server: McpServer): void {
|
||||||
|
server.registerTool(
|
||||||
|
"find_free_time",
|
||||||
|
{
|
||||||
|
description: "Find free time slots in your own calendar",
|
||||||
|
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)",
|
||||||
|
),
|
||||||
|
durationMinutes: z.number().default(30).describe(
|
||||||
|
"Minimum slot duration in minutes (default 30)",
|
||||||
|
),
|
||||||
|
startHour: z.number().default(9).describe(
|
||||||
|
"Working day start hour (0-23, default 9)",
|
||||||
|
),
|
||||||
|
endHour: z.number().default(18).describe(
|
||||||
|
"Working day end hour (0-23, default 18)",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
async ({ startDate, endDate, durationMinutes, startHour, endHour }) => {
|
||||||
|
try {
|
||||||
|
const client = new EwsClient(loadConfig());
|
||||||
|
const config = loadConfig();
|
||||||
|
const ed = endDate || startDate;
|
||||||
|
|
||||||
|
const data = await client.getUserAvailability(
|
||||||
|
[config.email],
|
||||||
|
startDate,
|
||||||
|
ed,
|
||||||
|
);
|
||||||
|
|
||||||
|
const body = data?.Envelope?.Body?.GetUserAvailabilityResponse
|
||||||
|
?? data?.Envelope?.Body ?? {};
|
||||||
|
const freeBusyArray = body?.FreeBusyResponseArray?.FreeBusyResponse
|
||||||
|
?? [];
|
||||||
|
const responses = Array.isArray(freeBusyArray)
|
||||||
|
? freeBusyArray
|
||||||
|
: [freeBusyArray];
|
||||||
|
|
||||||
|
const busyPeriods: { start: Date; end: Date }[] = [];
|
||||||
|
|
||||||
|
for (const fbResp of responses) {
|
||||||
|
const fbView = fbResp?.FreeBusyView ?? {};
|
||||||
|
const calEvents = fbView?.CalendarEventArray?.CalendarEvent ?? [];
|
||||||
|
const evList = Array.isArray(calEvents) ? calEvents : [calEvents];
|
||||||
|
|
||||||
|
for (const ev of evList) {
|
||||||
|
const bt = ev.BusyType ?? "";
|
||||||
|
if (bt === "Free" || bt === "NoData") continue;
|
||||||
|
const startStr = ev.StartTime ?? "";
|
||||||
|
const endStr = ev.EndTime ?? "";
|
||||||
|
if (startStr && endStr) {
|
||||||
|
busyPeriods.push({
|
||||||
|
start: new Date(startStr),
|
||||||
|
end: new Date(endStr),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const merged = mergeBusyPeriods(busyPeriods);
|
||||||
|
const freeSlots = findFreeSlots(
|
||||||
|
merged,
|
||||||
|
new Date(startDate),
|
||||||
|
ed ? new Date(ed) : new Date(startDate),
|
||||||
|
startHour,
|
||||||
|
endHour,
|
||||||
|
durationMinutes,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ freeSlots }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
server.registerTool(
|
||||||
|
"find_meeting_time",
|
||||||
|
{
|
||||||
|
description: "Find meeting times that work for multiple people",
|
||||||
|
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)",
|
||||||
|
),
|
||||||
|
durationMinutes: z.number().default(30).describe(
|
||||||
|
"Minimum slot duration in minutes (default 30)",
|
||||||
|
),
|
||||||
|
startHour: z.number().default(9).describe(
|
||||||
|
"Working day start hour (0-23, default 9)",
|
||||||
|
),
|
||||||
|
endHour: z.number().default(18).describe(
|
||||||
|
"Working day end hour (0-23, default 18)",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
async (
|
||||||
|
{ emails, startDate, endDate, durationMinutes, startHour, endHour },
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const client = new EwsClient(loadConfig());
|
||||||
|
const emailList = emails.split(",").map((e) => e.trim()).filter(
|
||||||
|
Boolean,
|
||||||
|
);
|
||||||
|
const ed = endDate || startDate;
|
||||||
|
|
||||||
|
const data = await client.getUserAvailability(emailList, startDate, ed);
|
||||||
|
|
||||||
|
const body = data?.Envelope?.Body?.GetUserAvailabilityResponse
|
||||||
|
?? data?.Envelope?.Body ?? {};
|
||||||
|
const freeBusyArray = body?.FreeBusyResponseArray?.FreeBusyResponse
|
||||||
|
?? [];
|
||||||
|
const responses = Array.isArray(freeBusyArray)
|
||||||
|
? freeBusyArray
|
||||||
|
: [freeBusyArray];
|
||||||
|
|
||||||
|
const allBusy: { start: Date; end: Date }[] = [];
|
||||||
|
const attendeeInfo: any[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < responses.length; i++) {
|
||||||
|
const fbResp = responses[i];
|
||||||
|
const fbView = fbResp?.FreeBusyView ?? {};
|
||||||
|
const email = emailList[i] || `Person ${i + 1}`;
|
||||||
|
|
||||||
|
const mergedFb = fbView.MergedFreeBusy ?? "";
|
||||||
|
if (mergedFb) {
|
||||||
|
const startTime = new Date(`${startDate}T00:00:00`);
|
||||||
|
const busyPeriods = parseFreeBusyString(mergedFb, startTime);
|
||||||
|
const busyCount = busyPeriods.length;
|
||||||
|
const freeCount = mergedFb.split("").filter((c: string) =>
|
||||||
|
c === "0"
|
||||||
|
).length;
|
||||||
|
attendeeInfo.push({
|
||||||
|
email,
|
||||||
|
busySlots: busyCount,
|
||||||
|
freeSlots: freeCount,
|
||||||
|
});
|
||||||
|
allBusy.push(...busyPeriods);
|
||||||
|
} else {
|
||||||
|
const calEvents = fbView?.CalendarEventArray?.CalendarEvent ?? [];
|
||||||
|
const evList = Array.isArray(calEvents) ? calEvents : [calEvents];
|
||||||
|
attendeeInfo.push({ email, calendarEvents: evList.length });
|
||||||
|
for (const ev of evList) {
|
||||||
|
const startStr = ev.StartTime ?? "";
|
||||||
|
const endStr = ev.EndTime ?? "";
|
||||||
|
if (startStr && endStr) {
|
||||||
|
allBusy.push({
|
||||||
|
start: new Date(startStr),
|
||||||
|
end: new Date(endStr),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const merged = mergeBusyPeriods(allBusy);
|
||||||
|
const freeByDate = findFreeSlots(
|
||||||
|
merged,
|
||||||
|
new Date(startDate),
|
||||||
|
new Date(ed),
|
||||||
|
startHour,
|
||||||
|
endHour,
|
||||||
|
durationMinutes,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
period: { start: startDate, end: ed },
|
||||||
|
attendees: attendeeInfo,
|
||||||
|
freeSlots: freeByDate,
|
||||||
|
}),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Helpers ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function parseFreeBusyString(
|
||||||
|
fbStr: string,
|
||||||
|
startTime: Date,
|
||||||
|
intervalMinutes: number = 30,
|
||||||
|
): { start: Date; end: Date }[] {
|
||||||
|
const periods: { start: Date; end: Date }[] = [];
|
||||||
|
const current = new Date(startTime);
|
||||||
|
|
||||||
|
for (const char of fbStr) {
|
||||||
|
const next = new Date(current.getTime() + intervalMinutes * 60000);
|
||||||
|
if (char !== "0") {
|
||||||
|
periods.push({ start: new Date(current), end: next });
|
||||||
|
}
|
||||||
|
current.setTime(next.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
return periods;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeBusyPeriods(
|
||||||
|
periods: { start: Date; end: Date }[],
|
||||||
|
): { start: Date; end: Date }[] {
|
||||||
|
if (!periods.length) return [];
|
||||||
|
|
||||||
|
const sorted = [...periods].sort((a, b) =>
|
||||||
|
a.start.getTime() - b.start.getTime()
|
||||||
|
);
|
||||||
|
const merged: { start: Date; end: Date }[] = [{ ...sorted[0] }];
|
||||||
|
|
||||||
|
for (let i = 1; i < sorted.length; i++) {
|
||||||
|
const last = merged[merged.length - 1];
|
||||||
|
if (sorted[i].start <= last.end) {
|
||||||
|
last.end = sorted[i].end > last.end ? sorted[i].end : last.end;
|
||||||
|
} else {
|
||||||
|
merged.push({ ...sorted[i] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findFreeSlots(
|
||||||
|
busyPeriods: { start: Date; end: Date }[],
|
||||||
|
startDate: Date,
|
||||||
|
endDate: Date,
|
||||||
|
startHour: number,
|
||||||
|
endHour: number,
|
||||||
|
durationMinutes: number,
|
||||||
|
): Record<string, { start: string; end: string; durationMinutes: number }[]> {
|
||||||
|
const result: Record<
|
||||||
|
string,
|
||||||
|
{ start: string; end: string; durationMinutes: number }[]
|
||||||
|
> = {};
|
||||||
|
|
||||||
|
const current = new Date(startDate);
|
||||||
|
current.setDate(current.getDate());
|
||||||
|
current.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const end = new Date(endDate);
|
||||||
|
end.setDate(end.getDate() + 1);
|
||||||
|
end.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
while (current < end) {
|
||||||
|
if (current.getDay() !== 0 && current.getDay() !== 6) {
|
||||||
|
const dayStart = new Date(current);
|
||||||
|
dayStart.setHours(startHour, 0, 0, 0);
|
||||||
|
|
||||||
|
const dayEnd = new Date(current);
|
||||||
|
dayEnd.setHours(endHour, 0, 0, 0);
|
||||||
|
|
||||||
|
const dayBusy = busyPeriods
|
||||||
|
.filter((p) => p.start < dayEnd && p.end > dayStart)
|
||||||
|
.map((p) => ({
|
||||||
|
start: p.start < dayStart ? dayStart : p.start,
|
||||||
|
end: p.end > dayEnd ? dayEnd : p.end,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const merged = mergeBusyPeriods(dayBusy);
|
||||||
|
|
||||||
|
const slots: { start: string; end: string; durationMinutes: number }[] =
|
||||||
|
[];
|
||||||
|
let cursor = new Date(dayStart);
|
||||||
|
|
||||||
|
for (const bp of merged) {
|
||||||
|
if (cursor < bp.start) {
|
||||||
|
const gap = (bp.start.getTime() - cursor.getTime()) / 60000;
|
||||||
|
if (gap >= durationMinutes) {
|
||||||
|
slots.push({
|
||||||
|
start: formatTime(cursor),
|
||||||
|
end: formatTime(bp.start),
|
||||||
|
durationMinutes: gap,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor = bp.end > cursor ? bp.end : cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor < dayEnd) {
|
||||||
|
const gap = (dayEnd.getTime() - cursor.getTime()) / 60000;
|
||||||
|
if (gap >= durationMinutes) {
|
||||||
|
slots.push({
|
||||||
|
start: formatTime(cursor),
|
||||||
|
end: formatTime(dayEnd),
|
||||||
|
durationMinutes: gap,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slots.length) {
|
||||||
|
result[current.toISOString().slice(0, 10)] = slots;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
current.setDate(current.getDate() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(d: Date): string {
|
||||||
|
return d.toTimeString().slice(0, 5);
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
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";
|
||||||
|
|
||||||
|
export function registerCalendarTools(server: McpServer): void {
|
||||||
|
server.registerTool(
|
||||||
|
"get_calendar_events",
|
||||||
|
{
|
||||||
|
description: "Get calendar events within a date range",
|
||||||
|
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",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
async ({ startDate, endDate, includeBody }) => {
|
||||||
|
try {
|
||||||
|
const client = new EwsClient(loadConfig());
|
||||||
|
const folderId = await client.getFolderId("calendar");
|
||||||
|
const items = await client.findCalendarItems(
|
||||||
|
folderId,
|
||||||
|
`${startDate}T00:00:00`,
|
||||||
|
`${endDate}T23:59:59`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const events = [];
|
||||||
|
for (const item of items) {
|
||||||
|
const event: any = {
|
||||||
|
subject: item.Subject ?? "(No subject)",
|
||||||
|
start: item.Start ?? "",
|
||||||
|
end: item.End ?? "",
|
||||||
|
location: item.Location ?? item.EnhancedLocation?.DisplayName ?? "",
|
||||||
|
isAllDay: item.IsAllDayEvent === "true"
|
||||||
|
|| item.IsAllDayEvent === true,
|
||||||
|
isCancelled: item.IsCancelled === "true"
|
||||||
|
|| item.IsCancelled === true,
|
||||||
|
isMeeting: true,
|
||||||
|
isRecurring: item.IsRecurring === "true"
|
||||||
|
|| item.IsRecurring === true,
|
||||||
|
organizer: "",
|
||||||
|
organizerEmail: "",
|
||||||
|
myResponse: item.MyResponseType ?? "",
|
||||||
|
itemId: item.ItemId?.["@_Id"] ?? "",
|
||||||
|
body: "",
|
||||||
|
requiredAttendees: [],
|
||||||
|
optionalAttendees: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (includeBody && event.itemId) {
|
||||||
|
const details = client.extractEmailDetails(item);
|
||||||
|
event.body = details.body;
|
||||||
|
event.requiredAttendees = details.requiredAttendees ?? [];
|
||||||
|
event.optionalAttendees = details.optionalAttendees ?? [];
|
||||||
|
event.organizer = details.fromName;
|
||||||
|
event.organizerEmail = details.from;
|
||||||
|
event.location = details.location || event.location;
|
||||||
|
}
|
||||||
|
|
||||||
|
events.push(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ events, count: events.length }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
server.registerTool(
|
||||||
|
"download_event_attachments",
|
||||||
|
{
|
||||||
|
description:
|
||||||
|
"Download all file attachments from a calendar event to disk",
|
||||||
|
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)",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
async ({ itemId, targetFolder }) => {
|
||||||
|
try {
|
||||||
|
const client = new EwsClient(loadConfig());
|
||||||
|
const item = await client.getItem(itemId);
|
||||||
|
const email = client.extractEmailDetails(item);
|
||||||
|
const attachments = email.attachments ?? [];
|
||||||
|
|
||||||
|
const fileAttachments = attachments.filter(
|
||||||
|
(a: any) => a.attachmentId && !a.isInline,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!fileAttachments.length) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
downloaded: [],
|
||||||
|
count: 0,
|
||||||
|
message: "No downloadable file attachments.",
|
||||||
|
}),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.mkdirSync(targetFolder, { recursive: true });
|
||||||
|
|
||||||
|
const downloaded = [];
|
||||||
|
const errors = [];
|
||||||
|
const usedNames = new Set<string>();
|
||||||
|
|
||||||
|
for (const att of fileAttachments) {
|
||||||
|
try {
|
||||||
|
const result = await client.getAttachment(att.attachmentId);
|
||||||
|
let filename = path.basename(result.name);
|
||||||
|
if (!filename) filename = att.name || "attachment";
|
||||||
|
|
||||||
|
const baseName = filename;
|
||||||
|
const dotIdx = baseName.lastIndexOf(".");
|
||||||
|
const namePart = dotIdx > 0 ? baseName.slice(0, dotIdx) : baseName;
|
||||||
|
const extPart = dotIdx > 0 ? baseName.slice(dotIdx) : "";
|
||||||
|
|
||||||
|
let counter = 1;
|
||||||
|
let finalName = filename;
|
||||||
|
while (usedNames.has(finalName.toLowerCase())) {
|
||||||
|
finalName = extPart
|
||||||
|
? `${namePart}_${counter}${extPart}`
|
||||||
|
: `${namePart}_${counter}`;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
usedNames.add(finalName.toLowerCase());
|
||||||
|
|
||||||
|
const filepath = path.join(targetFolder, finalName);
|
||||||
|
fs.writeFileSync(filepath, result.content);
|
||||||
|
|
||||||
|
downloaded.push({
|
||||||
|
name: finalName,
|
||||||
|
path: filepath,
|
||||||
|
size: result.content.length,
|
||||||
|
contentType: result.contentType,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
errors.push({
|
||||||
|
name: att.name || "unknown",
|
||||||
|
error: e.message ?? String(e),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: errors.length === 0,
|
||||||
|
downloaded,
|
||||||
|
count: downloaded.length,
|
||||||
|
...(errors.length ? { errors } : {}),
|
||||||
|
}),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
+253
-119
@@ -1,6 +1,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 { z } from "zod/v4";
|
||||||
import { EwsClient, loadConfig } from "../ews_client.ts";
|
import { EwsClient, loadConfig } from "../ews_client.ts";
|
||||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
||||||
|
|
||||||
function getClient(): EwsClient {
|
function getClient(): EwsClient {
|
||||||
return new EwsClient(loadConfig());
|
return new EwsClient(loadConfig());
|
||||||
@@ -12,37 +14,119 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
{
|
{
|
||||||
description: "Get emails from a mailbox folder",
|
description: "Get emails from a mailbox folder",
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
folder: z.string().default("Inbox").describe("Folder name (Inbox, Sent, Drafts, Deleted, Junk, or custom)"),
|
folder: z.string().default("Inbox").describe(
|
||||||
limit: z.number().default(10).describe("Maximum number of emails to return (default 10, max 50)"),
|
"Folder name (Inbox, Sent, Drafts, Deleted, Junk, or custom)",
|
||||||
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)"),
|
limit: z.number().default(10).describe(
|
||||||
unreadOnly: z.boolean().default(false).describe("If True, only return unread emails"),
|
"Maximum number of emails to return (default 10, max 50)",
|
||||||
idsOnly: z.boolean().default(false).describe("If True, return only item IDs and dates (max limit 500)"),
|
),
|
||||||
|
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)",
|
||||||
|
),
|
||||||
|
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)",
|
||||||
|
),
|
||||||
|
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)"),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
async ({ folder, limit, offset, includeBody, unreadOnly, idsOnly }) => {
|
async (
|
||||||
|
{
|
||||||
|
folder,
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
includeBody,
|
||||||
|
unreadOnly,
|
||||||
|
idsOnly,
|
||||||
|
query,
|
||||||
|
queryScope,
|
||||||
|
},
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const client = getClient();
|
const client = getClient();
|
||||||
const maxLimit = idsOnly ? 500 : 50;
|
const maxLimit = idsOnly ? 500 : 50;
|
||||||
if (limit > maxLimit) limit = maxLimit;
|
if (limit > maxLimit) limit = maxLimit;
|
||||||
|
offset = Math.max(0, offset);
|
||||||
|
|
||||||
const folderId = await client.getFolderId(folder);
|
const folderId = await client.getFolderId(folder);
|
||||||
const baseShape = idsOnly ? "IdOnly" : "AllProperties";
|
const baseShape = idsOnly ? "IdOnly" : "AllProperties";
|
||||||
|
|
||||||
let restriction = "";
|
if (query && !query.trim()) query = undefined;
|
||||||
|
|
||||||
|
const restrictions: string[] = [];
|
||||||
|
|
||||||
if (unreadOnly) {
|
if (unreadOnly) {
|
||||||
restriction = `\
|
restrictions.push(`\
|
||||||
<m:Restriction>
|
|
||||||
<t:IsEqualTo>
|
<t:IsEqualTo>
|
||||||
<t:FieldURI FieldURI="message:IsRead"/>
|
<t:FieldURI FieldURI="message:IsRead"/>
|
||||||
<t:FieldURIOrConstant>
|
<t:FieldURIOrConstant>
|
||||||
<t:Constant Value="false"/>
|
<t:Constant Value="false"/>
|
||||||
</t:FieldURIOrConstant>
|
</t:FieldURIOrConstant>
|
||||||
</t:IsEqualTo>
|
</t:IsEqualTo>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
function containsExpression(fieldUri: string, value: string): string {
|
||||||
|
return `\
|
||||||
|
<t:Contains ContainmentMode="Substring" ContainmentComparison="IgnoreCase">
|
||||||
|
<t:FieldURI FieldURI="${fieldUri}"/>
|
||||||
|
<t:Constant Value="${
|
||||||
|
value.replace(/&/g, "&").replace(/</g, "<").replace(
|
||||||
|
/>/g,
|
||||||
|
">",
|
||||||
|
).replace(/"/g, """)
|
||||||
|
}"/>
|
||||||
|
</t:Contains>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldUriMap: Record<string, string> = {
|
||||||
|
subject: "item:Subject",
|
||||||
|
body: "item:Body",
|
||||||
|
from: "message:From",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (queryScope === "all") {
|
||||||
|
restrictions.push(`\
|
||||||
|
<t:Or>
|
||||||
|
${containsExpression("item:Subject", query)}
|
||||||
|
${containsExpression("item:Body", query)}
|
||||||
|
</t:Or>`);
|
||||||
|
} else {
|
||||||
|
const fieldUri = fieldUriMap[queryScope];
|
||||||
|
restrictions.push(containsExpression(fieldUri, query));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let restriction = "";
|
||||||
|
if (restrictions.length === 1) {
|
||||||
|
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>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = await client.findItems(folderId, { limit, offset, baseShape, restriction });
|
const items = await client.findItems(folderId, {
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
baseShape,
|
||||||
|
restriction,
|
||||||
|
});
|
||||||
|
|
||||||
if (idsOnly) {
|
if (idsOnly) {
|
||||||
const result = items.map((item: any) => ({
|
const result = items.map((item: any) => ({
|
||||||
@@ -51,7 +135,10 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
subject: item.Subject ?? "",
|
subject: item.Subject ?? "",
|
||||||
}));
|
}));
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ itemIds: result, count: result.length }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ itemIds: result, count: result.length }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +158,17 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ emails, count: emails.length }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ emails, count: emails.length }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ error: error.message ?? String(error) }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -86,7 +179,9 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
{
|
{
|
||||||
description: "Get a single email with full body and details",
|
description: "Get a single email with full body and details",
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
itemId: z.string().describe("The Exchange ItemId of the email to retrieve"),
|
itemId: z.string().describe(
|
||||||
|
"The Exchange ItemId of the email to retrieve",
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
async ({ itemId }) => {
|
async ({ itemId }) => {
|
||||||
@@ -100,129 +195,168 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ error: error.message ?? String(error) }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
server.registerTool(
|
server.registerTool(
|
||||||
"search_emails",
|
"mark_email_read",
|
||||||
{
|
{
|
||||||
description: "Search emails by text across one or all folders",
|
description: "Mark one or more emails as read or unread",
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
query: z.string().describe("The text to search for"),
|
itemIds: z.array(z.string()).describe(
|
||||||
folderId: z.string().optional().describe("Optional folder ID to limit the search. When omitted, searches all mail folders"),
|
"List of Exchange ItemIds to update",
|
||||||
maxResults: z.number().default(20).describe("Maximum number of results (default 20, max 100)"),
|
),
|
||||||
searchScope: z.enum(["all", "subject", "body", "from"]).default("all").describe("Where to search"),
|
isRead: z.boolean().default(true).describe(
|
||||||
|
"True to mark as read, False to mark as unread",
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
async ({ query, folderId, maxResults, searchScope }) => {
|
async ({ itemIds, isRead }) => {
|
||||||
try {
|
try {
|
||||||
const client = getClient();
|
const client = new EwsClient(loadConfig());
|
||||||
|
const responses = await client.updateItems(itemIds, [
|
||||||
|
{ fieldUri: "message:IsRead", value: isRead },
|
||||||
|
]);
|
||||||
|
|
||||||
if (!query.trim()) {
|
const errors = responses
|
||||||
|
.filter((r: any) => r.ResponseClass === "Error")
|
||||||
|
.map((r: any) => r.MessageText ?? "Unknown error");
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ error: "query must not be empty", results: [] }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: errors.join("; ") }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
maxResults = Math.max(1, Math.min(maxResults, 100));
|
const status = isRead ? "read" : "unread";
|
||||||
|
return {
|
||||||
const fieldUriMap: Record<string, string> = {
|
content: [{
|
||||||
subject: "item:Subject",
|
type: "text" as const,
|
||||||
body: "item:Body",
|
text: JSON.stringify({
|
||||||
from: "message:From",
|
success: true,
|
||||||
|
message: `Marked ${itemIds.length} email(s) as ${status}.`,
|
||||||
|
}),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
function containsExpression(fieldUri: string, value: string): string {
|
|
||||||
return `\
|
|
||||||
<t:Contains ContainmentMode="Substring" ContainmentComparison="IgnoreCase">
|
|
||||||
<t:FieldURI FieldURI="${fieldUri}"/>
|
|
||||||
<t:Constant Value="${value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """)}"/>
|
|
||||||
</t:Contains>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let restriction: string;
|
|
||||||
if (searchScope === "all") {
|
|
||||||
restriction = `\
|
|
||||||
<m:Restriction>
|
|
||||||
<t:Or>
|
|
||||||
${containsExpression("item:Subject", query)}
|
|
||||||
${containsExpression("item:Body", query)}
|
|
||||||
</t:Or>
|
|
||||||
</m:Restriction>`;
|
|
||||||
} else {
|
|
||||||
const fieldUri = fieldUriMap[searchScope];
|
|
||||||
if (!fieldUri) {
|
|
||||||
return {
|
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ error: `unsupported search_scope: ${searchScope}`, results: [] }) }],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
restriction = `\
|
|
||||||
<m:Restriction>
|
|
||||||
${containsExpression(fieldUri, query)}
|
|
||||||
</m:Restriction>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const traversal = folderId ? "Shallow" : "Deep";
|
|
||||||
|
|
||||||
if (folderId) {
|
|
||||||
const items = await client.findItems(folderId, { limit: maxResults, restriction, traversal });
|
|
||||||
const results = formatSearchResults(items, client, maxResults);
|
|
||||||
|
|
||||||
return {
|
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ query, searchScope, folderId, totalResults: results.length, results }) }],
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const folders = await client.findFolders("msgfolderroot", true);
|
|
||||||
const allResults = [];
|
|
||||||
|
|
||||||
for (const f of folders) {
|
|
||||||
if (allResults.length >= maxResults) break;
|
|
||||||
const remaining = maxResults - allResults.length;
|
|
||||||
const items = await client.findItems(f.id, { limit: remaining, restriction, traversal: "Shallow" });
|
|
||||||
const formatted = formatSearchResults(items, client, remaining);
|
|
||||||
|
|
||||||
for (const r of formatted) {
|
|
||||||
r.folderId = f.id;
|
|
||||||
r.folderName = f.name;
|
|
||||||
allResults.push(r);
|
|
||||||
if (allResults.length >= maxResults) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ query, searchScope, folderId: "all", totalResults: allResults.length, results: allResults }) }],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ error: error.message ?? String(error) }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
server.registerTool(
|
||||||
|
"download_attachments",
|
||||||
|
{
|
||||||
|
description: "Download all file attachments from an email to disk",
|
||||||
|
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)",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
async ({ itemId, targetFolder }) => {
|
||||||
|
try {
|
||||||
|
const client = new EwsClient(loadConfig());
|
||||||
|
const item = await client.getItem(itemId);
|
||||||
|
const email = client.extractEmailDetails(item);
|
||||||
|
const attachments = email.attachments ?? [];
|
||||||
|
|
||||||
|
const fileAttachments = attachments.filter(
|
||||||
|
(a: any) => a.attachmentId && !a.isInline,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!fileAttachments.length) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
downloaded: [],
|
||||||
|
count: 0,
|
||||||
|
message: "No downloadable file attachments.",
|
||||||
|
}),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.mkdirSync(targetFolder, { recursive: true });
|
||||||
|
|
||||||
|
const downloaded = [];
|
||||||
|
const errors = [];
|
||||||
|
const usedNames = new Set<string>();
|
||||||
|
|
||||||
|
for (const att of fileAttachments) {
|
||||||
|
try {
|
||||||
|
const result = await client.getAttachment(att.attachmentId);
|
||||||
|
let filename = path.basename(result.name);
|
||||||
|
if (!filename) filename = att.name || "attachment";
|
||||||
|
|
||||||
|
const baseName = filename;
|
||||||
|
const dotIdx = baseName.lastIndexOf(".");
|
||||||
|
const namePart = dotIdx > 0 ? baseName.slice(0, dotIdx) : baseName;
|
||||||
|
const extPart = dotIdx > 0 ? baseName.slice(dotIdx) : "";
|
||||||
|
|
||||||
|
let counter = 1;
|
||||||
|
let finalName = filename;
|
||||||
|
while (usedNames.has(finalName.toLowerCase())) {
|
||||||
|
finalName = extPart
|
||||||
|
? `${namePart}_${counter}${extPart}`
|
||||||
|
: `${namePart}_${counter}`;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
usedNames.add(finalName.toLowerCase());
|
||||||
|
|
||||||
|
const filepath = path.join(targetFolder, finalName);
|
||||||
|
fs.writeFileSync(filepath, result.content);
|
||||||
|
|
||||||
|
downloaded.push({
|
||||||
|
name: finalName,
|
||||||
|
path: filepath,
|
||||||
|
size: result.content.length,
|
||||||
|
contentType: result.contentType,
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
errors.push({
|
||||||
|
name: att.name || "unknown",
|
||||||
|
error: e.message ?? String(e),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({
|
||||||
|
success: errors.length === 0,
|
||||||
|
downloaded,
|
||||||
|
count: downloaded.length,
|
||||||
|
...(errors.length ? { errors } : {}),
|
||||||
|
}),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatSearchResults(items: any[], client: EwsClient, maxResults: number): any[] {
|
|
||||||
const results: any[] = [];
|
|
||||||
for (const item of items) {
|
|
||||||
if (results.length >= maxResults) break;
|
|
||||||
const summary = client.extractEmailSummary(item);
|
|
||||||
|
|
||||||
const bodyHtml = item.Body?.Value ?? item.Body?.["#text"] ?? "";
|
|
||||||
const bodyType = item.Body?.["@_BodyType"] ?? "HTML";
|
|
||||||
let bodyPreview = "";
|
|
||||||
if (bodyType === "HTML" && bodyHtml) {
|
|
||||||
bodyPreview = bodyHtml.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim().slice(0, 200);
|
|
||||||
} else {
|
|
||||||
bodyPreview = bodyHtml.slice(0, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
summary.preview = bodyPreview;
|
|
||||||
|
|
||||||
results.push(summary);
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
+12
-5
@@ -1,6 +1,6 @@
|
|||||||
|
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
import { EwsClient, loadConfig } from "../ews_client.ts";
|
import { EwsClient, loadConfig } from "../ews_client.ts";
|
||||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
||||||
|
|
||||||
export function registerFolderTools(server: McpServer): void {
|
export function registerFolderTools(server: McpServer): void {
|
||||||
server.registerTool(
|
server.registerTool(
|
||||||
@@ -8,8 +8,12 @@ export function registerFolderTools(server: McpServer): void {
|
|||||||
{
|
{
|
||||||
description: "List mail folders from the Exchange mailbox",
|
description: "List mail folders from the Exchange mailbox",
|
||||||
inputSchema: z.object({
|
inputSchema: z.object({
|
||||||
parentFolderId: z.string().default("msgfolderroot").describe("Parent folder to list children of (default: msgfolderroot)"),
|
parentFolderId: z.string().default("msgfolderroot").describe(
|
||||||
recursive: z.boolean().default(false).describe("If True, traverse all subfolders recursively"),
|
"Parent folder to list children of (default: msgfolderroot)",
|
||||||
|
),
|
||||||
|
recursive: z.boolean().default(false).describe(
|
||||||
|
"If True, traverse all subfolders recursively",
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
async ({ parentFolderId, recursive }) => {
|
async ({ parentFolderId, recursive }) => {
|
||||||
@@ -22,9 +26,12 @@ export function registerFolderTools(server: McpServer): void {
|
|||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text" as const, text: JSON.stringify({ error: error.message ?? String(error) }) }],
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
import { z } from "zod/v4";
|
||||||
|
import { EwsClient, loadConfig } from "../ews_client.ts";
|
||||||
|
|
||||||
|
export function registerPeopleTools(server: McpServer): void {
|
||||||
|
server.registerTool(
|
||||||
|
"find_person",
|
||||||
|
{
|
||||||
|
description: "Search for people in the corporate directory",
|
||||||
|
inputSchema: z.object({
|
||||||
|
query: z.string().describe(
|
||||||
|
"Name, email address, or keyword to search for",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
async ({ query }) => {
|
||||||
|
try {
|
||||||
|
const client = new EwsClient(loadConfig());
|
||||||
|
const resolutions = await client.resolveNames(query, true);
|
||||||
|
|
||||||
|
const people = resolutions.map((r: any) => {
|
||||||
|
const mailbox = r.Mailbox ?? {};
|
||||||
|
const contact = r.Contact ?? {};
|
||||||
|
|
||||||
|
const person: any = {
|
||||||
|
name: mailbox.Name ?? contact.DisplayName ?? "",
|
||||||
|
email: mailbox.EmailAddress ?? "",
|
||||||
|
mailboxType: mailbox.MailboxType ?? "",
|
||||||
|
firstName: contact.GivenName ?? "",
|
||||||
|
lastName: contact.Surname ?? "",
|
||||||
|
jobTitle: contact.JobTitle ?? "",
|
||||||
|
department: contact.Department ?? "",
|
||||||
|
company: contact.CompanyName ?? "",
|
||||||
|
office: contact.OfficeLocation ?? "",
|
||||||
|
alias: contact.Alias ?? "",
|
||||||
|
manager: "",
|
||||||
|
managerEmail: "",
|
||||||
|
phones: {},
|
||||||
|
address: "",
|
||||||
|
directReports: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const phones = contact.PhoneNumbers?.PhoneNumber ?? [];
|
||||||
|
const phoneList = Array.isArray(phones) ? phones : [phones];
|
||||||
|
for (const p of phoneList) {
|
||||||
|
if (p?.Key && p?.PhoneNumber) {
|
||||||
|
person.phones[p.Key] = p.PhoneNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const addrs = contact.PhysicalAddresses?.PhysicalAddress ?? [];
|
||||||
|
const addrList = Array.isArray(addrs) ? addrs : [addrs];
|
||||||
|
for (const a of addrList) {
|
||||||
|
if (a?.Key === "Business") {
|
||||||
|
const parts = [a.Street, a.City, a.PostalCode, a.CountryOrRegion]
|
||||||
|
.filter(Boolean);
|
||||||
|
if (parts.length) {
|
||||||
|
person.address = parts.join(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const managerData = contact.ManagerMailbox?.Mailbox ?? {};
|
||||||
|
if (managerData.Name || managerData.EmailAddress) {
|
||||||
|
person.manager = managerData.Name ?? "";
|
||||||
|
person.managerEmail = managerData.EmailAddress ?? "";
|
||||||
|
} else if (contact.Manager) {
|
||||||
|
person.manager = contact.Manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reports = contact.DirectReports?.DirectReport ?? [];
|
||||||
|
const reportList = Array.isArray(reports) ? reports : [reports];
|
||||||
|
for (const rp of reportList) {
|
||||||
|
if (rp?.Name || rp?.EmailAddress) {
|
||||||
|
person.directReports.push({
|
||||||
|
name: rp.Name ?? "",
|
||||||
|
email: rp.EmailAddress ?? "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return person;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [{ type: "text" as const, text: JSON.stringify(people) }],
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text" as const,
|
||||||
|
text: JSON.stringify({ error: error.message ?? String(error) }),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
+1
-1
@@ -39,4 +39,4 @@
|
|||||||
"useUnknownInCatchVariables": true,
|
"useUnknownInCatchVariables": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export interface CalendarEvent {
|
||||||
|
subject: string;
|
||||||
|
start: string;
|
||||||
|
end: string;
|
||||||
|
location: string;
|
||||||
|
isAllDay: boolean;
|
||||||
|
isCancelled: boolean;
|
||||||
|
isMeeting: boolean;
|
||||||
|
isRecurring: boolean;
|
||||||
|
organizer: string;
|
||||||
|
organizerEmail: string;
|
||||||
|
myResponse: string;
|
||||||
|
itemId: string;
|
||||||
|
body: string;
|
||||||
|
requiredAttendees: string[];
|
||||||
|
optionalAttendees: string[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
export interface Email {
|
||||||
|
subject: string;
|
||||||
|
from: string;
|
||||||
|
fromName: string;
|
||||||
|
date: string;
|
||||||
|
isRead: boolean;
|
||||||
|
hasAttachments: boolean;
|
||||||
|
hasLinks: boolean;
|
||||||
|
itemId: string;
|
||||||
|
size: number;
|
||||||
|
isMeeting: boolean;
|
||||||
|
itemType: string;
|
||||||
|
to: string[];
|
||||||
|
cc: string[];
|
||||||
|
body: string;
|
||||||
|
bodyType: string;
|
||||||
|
attachments: Attachment[];
|
||||||
|
preview: string;
|
||||||
|
location?: string;
|
||||||
|
start?: string;
|
||||||
|
end?: string;
|
||||||
|
requiredAttendees?: string[];
|
||||||
|
optionalAttendees?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Attachment {
|
||||||
|
name: string;
|
||||||
|
size: number;
|
||||||
|
contentType: string;
|
||||||
|
attachmentId: string;
|
||||||
|
isInline: boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export interface Folder {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
totalCount: number;
|
||||||
|
unreadCount: number;
|
||||||
|
childFolderCount: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export interface FreeSlot {
|
||||||
|
date: string;
|
||||||
|
start: string;
|
||||||
|
end: string;
|
||||||
|
durationMinutes: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export interface LoginConfig {
|
||||||
|
serverUrl: string;
|
||||||
|
email: string;
|
||||||
|
username: string;
|
||||||
|
domain?: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export interface MeetingResult {
|
||||||
|
success: boolean;
|
||||||
|
subject: string;
|
||||||
|
date: string;
|
||||||
|
startTime: string;
|
||||||
|
endTime: string;
|
||||||
|
location: string;
|
||||||
|
requiredAttendees: string[];
|
||||||
|
optionalAttendees: string[];
|
||||||
|
error: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export interface Person {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
mailboxType: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
jobTitle: string;
|
||||||
|
department: string;
|
||||||
|
company: string;
|
||||||
|
office: string;
|
||||||
|
alias: string;
|
||||||
|
manager: string;
|
||||||
|
managerEmail: string;
|
||||||
|
phones: Record<string, string>;
|
||||||
|
address: string;
|
||||||
|
directReports: Array<{ name: string; email: string }>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user