feat: easier login
This commit is contained in:
+31
-8
@@ -8,6 +8,7 @@ import {
|
||||
saveConfig,
|
||||
setPassword,
|
||||
} from "../ews_client.ts";
|
||||
import type { LoginConfig } from "../types/login_config.ts";
|
||||
|
||||
export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
@@ -15,24 +16,46 @@ export function registerAuthTools(server: McpServer): void {
|
||||
{
|
||||
description: "Authenticate to Exchange EWS using NTLM credentials",
|
||||
inputSchema: z.object({
|
||||
serverUrl: z.string().describe(
|
||||
serverUrl: z.string().optional().describe(
|
||||
"EWS server URL (e.g. https://mail.example.com)",
|
||||
),
|
||||
email: z.string().describe("Email address"),
|
||||
username: z.string().describe("NTLM username"),
|
||||
email: z.string().optional().describe("Email address"),
|
||||
username: z.string().optional().describe("NTLM username"),
|
||||
password: z.string().describe("NTLM password"),
|
||||
domain: z.string().optional().describe("NTLM domain (default: corp)"),
|
||||
}),
|
||||
},
|
||||
async ({ serverUrl, email, username, password, domain }) => {
|
||||
try {
|
||||
const config = {
|
||||
serverUrl: serverUrl.replace(/\/+$/, ""),
|
||||
email,
|
||||
username,
|
||||
domain: domain ?? "corp",
|
||||
let savedConfig: Partial<LoginConfig> = {};
|
||||
try {
|
||||
savedConfig = loadConfig();
|
||||
} catch {
|
||||
// no saved config — all fields must be provided
|
||||
}
|
||||
|
||||
const config: LoginConfig = {
|
||||
serverUrl: (serverUrl ?? savedConfig.serverUrl)!,
|
||||
email: (email ?? savedConfig.email)!,
|
||||
username: (username ?? savedConfig.username)!,
|
||||
domain: domain ?? savedConfig.domain ?? "corp",
|
||||
};
|
||||
|
||||
if (!config.serverUrl || !config.email || !config.username) {
|
||||
return {
|
||||
content: [{
|
||||
type: "text" as const,
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error:
|
||||
"Missing required fields. Provide serverUrl, email, and username, or login once with all fields first.",
|
||||
}),
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
config.serverUrl = config.serverUrl.replace(/\/+$/, "");
|
||||
|
||||
const client = new EwsClient(config, password);
|
||||
const result = await client.verifyConnection();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user