w
This commit is contained in:
@@ -80,10 +80,11 @@ Get a single email with full body and details.
|
|||||||
Search emails by text.
|
Search emails by text.
|
||||||
|
|
||||||
| Parameter | Type | Default | Description |
|
| Parameter | Type | Default | Description |
|
||||||
| ------------- | ------ | -------- | --------------------------------------- |
|
| ------------- | ------ | -------- | ------------------------------------------- |
|
||||||
| `query` | string | — | Text to search for |
|
| `query` | string | — | Text to search for |
|
||||||
| `folderId` | string | optional | Folder ID to limit search |
|
| `folderId` | string | optional | Folder ID to limit search; omitted = all |
|
||||||
| `maxResults` | number | `20` | Max results (max 100) |
|
| `limit` | number | `10` | Max emails (max 50) |
|
||||||
|
| `offset` | number | `0` | Pagination offset |
|
||||||
| `searchScope` | enum | `"all"` | Scope: `all`, `subject`, `body`, `from` |
|
| `searchScope` | enum | `"all"` | Scope: `all`, `subject`, `body`, `from` |
|
||||||
|
|
||||||
#### `mark_email_read`
|
#### `mark_email_read`
|
||||||
|
|||||||
+9
-1
@@ -250,6 +250,14 @@ export class EwsClient {
|
|||||||
traversal = "Shallow",
|
traversal = "Shallow",
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const isDistinguished =
|
||||||
|
DISTINGUISHED_FOLDERS[folderId.toLowerCase()] !== undefined
|
||||||
|
|| ["msgfolderroot"].includes(folderId.toLowerCase());
|
||||||
|
|
||||||
|
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>
|
||||||
@@ -257,7 +265,7 @@ export class EwsClient {
|
|||||||
</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">
|
||||||
|
|||||||
+16
-46
@@ -148,14 +148,17 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
folderId: z.string().optional().describe(
|
folderId: z.string().optional().describe(
|
||||||
"Optional folder ID to limit the search. When omitted, searches all mail folders",
|
"Optional folder ID to limit the search. When omitted, searches all mail folders",
|
||||||
),
|
),
|
||||||
maxResults: z.number().default(20).describe(
|
limit: z.number().default(10).describe(
|
||||||
"Maximum number of results (default 20, max 100)",
|
"Maximum number of emails to return (default 10, max 50)",
|
||||||
|
),
|
||||||
|
offset: z.number().default(0).describe(
|
||||||
|
"Number of emails to skip for pagination",
|
||||||
),
|
),
|
||||||
searchScope: z.enum(["all", "subject", "body", "from"]).default("all")
|
searchScope: z.enum(["all", "subject", "body", "from"]).default("all")
|
||||||
.describe("Where to search"),
|
.describe("Where to search"),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
async ({ query, folderId, maxResults, searchScope }) => {
|
async ({ query, folderId, limit, offset, searchScope }) => {
|
||||||
try {
|
try {
|
||||||
const client = getClient();
|
const client = getClient();
|
||||||
|
|
||||||
@@ -171,7 +174,8 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
maxResults = Math.max(1, Math.min(maxResults, 100));
|
limit = Math.max(1, Math.min(limit, 50));
|
||||||
|
offset = Math.max(0, offset);
|
||||||
|
|
||||||
const fieldUriMap: Record<string, string> = {
|
const fieldUriMap: Record<string, string> = {
|
||||||
subject: "item:Subject",
|
subject: "item:Subject",
|
||||||
@@ -220,15 +224,16 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
</m:Restriction>`;
|
</m:Restriction>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const targetFolder = folderId || "msgfolderroot";
|
||||||
const traversal = folderId ? "Shallow" : "Deep";
|
const traversal = folderId ? "Shallow" : "Deep";
|
||||||
|
|
||||||
if (folderId) {
|
const items = await client.findItems(targetFolder, {
|
||||||
const items = await client.findItems(folderId, {
|
limit,
|
||||||
limit: maxResults,
|
offset,
|
||||||
restriction,
|
restriction,
|
||||||
traversal,
|
traversal,
|
||||||
});
|
});
|
||||||
const results = formatSearchResults(items, client, maxResults);
|
const results = formatSearchResults(items, client);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{
|
content: [{
|
||||||
@@ -236,47 +241,14 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
text: JSON.stringify({
|
text: JSON.stringify({
|
||||||
query,
|
query,
|
||||||
searchScope,
|
searchScope,
|
||||||
folderId,
|
folderId: folderId || "all",
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
totalResults: results.length,
|
totalResults: results.length,
|
||||||
results,
|
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: [{
|
content: [{
|
||||||
@@ -448,11 +420,9 @@ export function registerEmailTools(server: McpServer): void {
|
|||||||
function formatSearchResults(
|
function formatSearchResults(
|
||||||
items: any[],
|
items: any[],
|
||||||
client: EwsClient,
|
client: EwsClient,
|
||||||
maxResults: number,
|
|
||||||
): any[] {
|
): any[] {
|
||||||
const results: any[] = [];
|
const results: any[] = [];
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (results.length >= maxResults) break;
|
|
||||||
const summary = client.extractEmailSummary(item);
|
const summary = client.extractEmailSummary(item);
|
||||||
|
|
||||||
const bodyHtml = item.Body?.Value ?? item.Body?.["#text"] ?? "";
|
const bodyHtml = item.Body?.Value ?? item.Body?.["#text"] ?? "";
|
||||||
|
|||||||
Reference in New Issue
Block a user