feat: basics #1
@@ -10,3 +10,4 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.yarn
|
.yarn
|
||||||
node_modules
|
node_modules
|
||||||
|
config.json
|
||||||
+7
-8
@@ -92,8 +92,6 @@ export class EwsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -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,
|
||||||
}),
|
}),
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user