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
.vscode
.yarn
node_modules
node_modules
config.json
+9 -10
View File
@@ -91,9 +91,7 @@ export class EwsClient {
return this.config.domain ?? "corp";
}
private async soapRequest(body: string, soapAction: string): Promise<any> {
const envelope = buildSoapEnvelope(body);
private async soapRequest(body: string, soapAction: string): Promise<any> {
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<boolean> {
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 {
</m:FolderIds>
</m:GetFolder>`);
const data = await this.soapRequest(
const data = await this.soapRequest(
soap,
"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 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,
}),
}],
};