This commit is contained in:
2026-07-09 02:19:40 +03:00
parent 9697d8724d
commit 653eaecf2e
3 changed files with 17 additions and 16 deletions
+2 -1
View File
@@ -9,4 +9,5 @@
.tmp .tmp
.vscode .vscode
.yarn .yarn
node_modules node_modules
config.json
+9 -10
View File
@@ -91,9 +91,7 @@ export class EwsClient {
return this.config.domain ?? "corp"; return this.config.domain ?? "corp";
} }
private async soapRequest(body: string, soapAction: string): Promise<any> { private async soapRequest(body: string, soapAction: string): Promise<any> {
const envelope = buildSoapEnvelope(body);
const res = await postAsync({ const res = await postAsync({
url: this.ewsUrl, url: this.ewsUrl,
username: this.config.username, username: this.config.username,
@@ -104,14 +102,15 @@ export class EwsClient {
"Content-Type": "text/xml; charset=utf-8", "Content-Type": "text/xml; charset=utf-8",
SOAPAction: soapAction, SOAPAction: soapAction,
}, },
body: envelope, body,
}); });
if (typeof res.body !== "string") { if (typeof res.body !== "string") {
throw new Error(`NTLM request failed, status=${res.statusCode}`); 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[] { private extractResponseMessages(data: any): any[] {
@@ -131,12 +130,12 @@ export class EwsClient {
return Array.isArray(msgs) ? msgs : [msgs]; return Array.isArray(msgs) ? msgs : [msgs];
} }
async verifyConnection(): Promise<boolean> { async verifyConnection(): Promise<{ ok: boolean; error?: string }> {
try { try {
await this.getFolderId("inbox"); await this.getFolderId("inbox");
return true; return { ok: true };
} catch { } catch (error: any) {
return false; return { ok: false, error: error.message ?? String(error) };
} }
} }
@@ -155,7 +154,7 @@ export class EwsClient {
</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",
); );
+6 -5
View File
@@ -26,11 +26,11 @@ export function registerAuthTools(server: McpServer): void {
}; };
const client = new EwsClient(config); const client = new EwsClient(config);
const ok = await client.verifyConnection(); const result = await client.verifyConnection();
if (!ok) { if (!result.ok) {
return { 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 { try {
const config = loadConfig(); const config = loadConfig();
const client = new EwsClient(config); const client = new EwsClient(config);
const ok = await client.verifyConnection(); const result = await client.verifyConnection();
return { return {
content: [{ content: [{
type: "text" as const, type: "text" as const,
text: JSON.stringify({ text: JSON.stringify({
authenticated: ok, authenticated: result.ok,
email: config.email, email: config.email,
serverUrl: config.serverUrl, serverUrl: config.serverUrl,
error: result.error,
}), }),
}], }],
}; };