From 653eaecf2e81b929f1730b7d02c16f826f364054 Mon Sep 17 00:00:00 2001 From: albnnc Date: Thu, 9 Jul 2026 02:19:40 +0300 Subject: [PATCH] w --- .gitignore | 3 ++- ews_client.ts | 19 +++++++++---------- tools/auth.ts | 11 ++++++----- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index c46c3e7..d59519f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ .tmp .vscode .yarn -node_modules \ No newline at end of file +node_modules +config.json \ No newline at end of file diff --git a/ews_client.ts b/ews_client.ts index f0f6620..7c09d35 100644 --- a/ews_client.ts +++ b/ews_client.ts @@ -91,9 +91,7 @@ export class EwsClient { return this.config.domain ?? "corp"; } - private async soapRequest(body: string, soapAction: string): Promise { - const envelope = buildSoapEnvelope(body); - +private async soapRequest(body: string, soapAction: string): Promise { const res = await postAsync({ url: this.ewsUrl, username: this.config.username, @@ -104,14 +102,15 @@ export class EwsClient { "Content-Type": "text/xml; charset=utf-8", SOAPAction: soapAction, }, - body: envelope, + body, }); if (typeof res.body !== "string") { throw new Error(`NTLM request failed, status=${res.statusCode}`); } - return PARSER.parse(res.body); + const parsed = PARSER.parse(res.body); + return parsed; } private extractResponseMessages(data: any): any[] { @@ -131,12 +130,12 @@ export class EwsClient { return Array.isArray(msgs) ? msgs : [msgs]; } - async verifyConnection(): Promise { + async verifyConnection(): Promise<{ ok: boolean; error?: string }> { try { await this.getFolderId("inbox"); - return true; - } catch { - return false; + return { ok: true }; + } catch (error: any) { + return { ok: false, error: error.message ?? String(error) }; } } @@ -155,7 +154,7 @@ export class EwsClient { `); - const data = await this.soapRequest( +const data = await this.soapRequest( soap, "http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder", ); diff --git a/tools/auth.ts b/tools/auth.ts index 0694814..d467e4d 100644 --- a/tools/auth.ts +++ b/tools/auth.ts @@ -26,11 +26,11 @@ export function registerAuthTools(server: McpServer): void { }; const client = new EwsClient(config); - const ok = await client.verifyConnection(); + const result = await client.verifyConnection(); - if (!ok) { + if (!result.ok) { return { - content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: "Connection verification failed. Check credentials and server URL." }) }], + content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: result.error ?? "Connection verification failed" }) }], }; } @@ -57,15 +57,16 @@ export function registerAuthTools(server: McpServer): void { try { const config = loadConfig(); const client = new EwsClient(config); - const ok = await client.verifyConnection(); + const result = await client.verifyConnection(); return { content: [{ type: "text" as const, text: JSON.stringify({ - authenticated: ok, + authenticated: result.ok, email: config.email, serverUrl: config.serverUrl, + error: result.error, }), }], };