feat: easier login

This commit is contained in:
2026-07-09 16:54:31 +03:00
parent 6fefd17400
commit d2de768878
2 changed files with 40 additions and 12 deletions
+9 -4
View File
@@ -31,16 +31,21 @@ Gmail, Outlook.com.
#### `login` #### `login`
Authenticate to Exchange EWS via NTLM. Authenticate to Exchange EWS via NTLM. On first use, all fields except `domain`
are required. On subsequent logins, only `password` is needed — previously saved
`serverUrl`, `email`, `username`, and `domain` are reused automatically.
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| ----------- | ------ | -------- | ------------------------------------------------ | | ----------- | ------ | -------- | ------------------------------------------------ |
| `serverUrl` | string | yes | EWS server URL (e.g. `https://mail.example.com`) | | `serverUrl` | string | no* | EWS server URL (e.g. `https://mail.example.com`) |
| `email` | string | yes | Email address | | `email` | string | no* | Email address |
| `username` | string | yes | NTLM username | | `username` | string | no* | NTLM username |
| `password` | string | yes | NTLM password | | `password` | string | yes | NTLM password |
| `domain` | string | no | NTLM domain (default: `corp`) | | `domain` | string | no | NTLM domain (default: `corp`) |
\* Required only on first login; skipped on subsequent logins (loaded from saved
config).
#### `check_session` #### `check_session`
Check if the current session is authenticated. No parameters. Returns Check if the current session is authenticated. No parameters. Returns
+31 -8
View File
@@ -8,6 +8,7 @@ import {
saveConfig, saveConfig,
setPassword, setPassword,
} from "../ews_client.ts"; } from "../ews_client.ts";
import type { LoginConfig } from "../types/login_config.ts";
export function registerAuthTools(server: McpServer): void { export function registerAuthTools(server: McpServer): void {
server.registerTool( server.registerTool(
@@ -15,24 +16,46 @@ export function registerAuthTools(server: McpServer): void {
{ {
description: "Authenticate to Exchange EWS using NTLM credentials", description: "Authenticate to Exchange EWS using NTLM credentials",
inputSchema: z.object({ inputSchema: z.object({
serverUrl: z.string().describe( serverUrl: z.string().optional().describe(
"EWS server URL (e.g. https://mail.example.com)", "EWS server URL (e.g. https://mail.example.com)",
), ),
email: z.string().describe("Email address"), email: z.string().optional().describe("Email address"),
username: z.string().describe("NTLM username"), username: z.string().optional().describe("NTLM username"),
password: z.string().describe("NTLM password"), password: z.string().describe("NTLM password"),
domain: z.string().optional().describe("NTLM domain (default: corp)"), domain: z.string().optional().describe("NTLM domain (default: corp)"),
}), }),
}, },
async ({ serverUrl, email, username, password, domain }) => { async ({ serverUrl, email, username, password, domain }) => {
try { try {
const config = { let savedConfig: Partial<LoginConfig> = {};
serverUrl: serverUrl.replace(/\/+$/, ""), try {
email, savedConfig = loadConfig();
username, } catch {
domain: domain ?? "corp", // 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 client = new EwsClient(config, password);
const result = await client.verifyConnection(); const result = await client.verifyConnection();