w
This commit is contained in:
+46
-9
@@ -1,6 +1,11 @@
|
||||
import { z } from "zod/v4";
|
||||
import { EwsClient, loadConfig, saveConfig, clearConfig } from "../ews_client.ts";
|
||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { z } from "zod/v4";
|
||||
import {
|
||||
clearConfig,
|
||||
EwsClient,
|
||||
loadConfig,
|
||||
saveConfig,
|
||||
} from "../ews_client.ts";
|
||||
|
||||
export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
@@ -8,7 +13,9 @@ export function registerAuthTools(server: McpServer): void {
|
||||
{
|
||||
description: "Authenticate to Exchange EWS using NTLM credentials",
|
||||
inputSchema: z.object({
|
||||
serverUrl: z.string().describe("EWS server URL (e.g. https://mail.example.com)"),
|
||||
serverUrl: z.string().describe(
|
||||
"EWS server URL (e.g. https://mail.example.com)",
|
||||
),
|
||||
email: z.string().describe("Email address"),
|
||||
username: z.string().describe("NTLM username"),
|
||||
password: z.string().describe("NTLM password"),
|
||||
@@ -30,18 +37,36 @@ export function registerAuthTools(server: McpServer): void {
|
||||
|
||||
if (!result.ok) {
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: result.error ?? "Connection verification failed" }) }],
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: result.error ?? "Connection verification failed",
|
||||
}),
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
saveConfig(config);
|
||||
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify({ success: true, message: `Logged in as ${email} to ${serverUrl}` }) }],
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
message: `Logged in as ${email} to ${serverUrl}`,
|
||||
}),
|
||||
}],
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: error.message ?? String(error) }) }],
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: error.message ?? String(error),
|
||||
}),
|
||||
}],
|
||||
};
|
||||
}
|
||||
},
|
||||
@@ -72,7 +97,13 @@ export function registerAuthTools(server: McpServer): void {
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify({ authenticated: false, error: error.message ?? String(error) }) }],
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
authenticated: false,
|
||||
error: error.message ?? String(error),
|
||||
}),
|
||||
}],
|
||||
};
|
||||
}
|
||||
},
|
||||
@@ -87,8 +118,14 @@ export function registerAuthTools(server: McpServer): void {
|
||||
async () => {
|
||||
clearConfig();
|
||||
return {
|
||||
content: [{ type: "text" as const, text: JSON.stringify({ success: true, message: "Logged out. Credentials cleared." }) }],
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
success: true,
|
||||
message: "Logged out. Credentials cleared.",
|
||||
}),
|
||||
}],
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user