refactor: drop skill file, rework client
This commit was merged in pull request #3.
This commit is contained in:
+51
-18
@@ -1,28 +1,29 @@
|
||||
import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { z } from "zod/v4";
|
||||
import {
|
||||
clearConfig,
|
||||
EwsClient,
|
||||
hasPassword,
|
||||
loadConfig,
|
||||
saveConfig,
|
||||
setPassword,
|
||||
} from "../ews_client.ts";
|
||||
import type { LoginConfig } from "../types/login_config.ts";
|
||||
import { clearConfig, hasPassword, loadConfig, saveConfig, setPassword } from "../utils/login.ts";
|
||||
import { EwsClient } from "../client/ews_client.ts";
|
||||
import { type LoginConfig } from "../utils/login.ts";
|
||||
|
||||
export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"login",
|
||||
{
|
||||
description: "Authenticate to Exchange EWS using NTLM credentials",
|
||||
description: "Authenticate to Exchange EWS using NTLM credentials."
|
||||
+ " 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 from config.",
|
||||
inputSchema: z.object({
|
||||
serverUrl: z.string().optional().describe(
|
||||
"EWS server URL (e.g. https://mail.example.com)",
|
||||
),
|
||||
serverUrl: z.string().optional().describe("EWS server URL"),
|
||||
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)"),
|
||||
domain: z.string().optional().describe("NTLM domain"),
|
||||
}),
|
||||
outputSchema: z.object({
|
||||
success: z.boolean(),
|
||||
message: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async ({ serverUrl, email, username, password, domain }) => {
|
||||
@@ -47,8 +48,9 @@ export function registerAuthTools(server: McpServer): void {
|
||||
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.",
|
||||
error: "Missing required fields."
|
||||
+ " Provide serverUrl, email, and username, or"
|
||||
+ " login once with all fields first.",
|
||||
}),
|
||||
}],
|
||||
};
|
||||
@@ -99,8 +101,15 @@ export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"check_session",
|
||||
{
|
||||
description: "Check whether the current EWS session is authenticated",
|
||||
description:
|
||||
"Check whether the current EWS session is authenticated. No parameters.",
|
||||
inputSchema: z.object({}),
|
||||
outputSchema: z.object({
|
||||
authenticated: z.boolean(),
|
||||
email: z.string().optional(),
|
||||
serverUrl: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async () => {
|
||||
try {
|
||||
@@ -113,6 +122,10 @@ export function registerAuthTools(server: McpServer): void {
|
||||
error: "Not logged in. Password not found in memory.",
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
authenticated: false,
|
||||
error: "Not logged in. Password not found in memory.",
|
||||
},
|
||||
};
|
||||
}
|
||||
const config = loadConfig();
|
||||
@@ -129,6 +142,12 @@ export function registerAuthTools(server: McpServer): void {
|
||||
error: result.error,
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
authenticated: result.ok,
|
||||
email: config.email,
|
||||
serverUrl: config.serverUrl,
|
||||
error: result.error,
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
@@ -139,6 +158,10 @@ export function registerAuthTools(server: McpServer): void {
|
||||
error: error.message ?? String(error),
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
authenticated: false,
|
||||
error: error.message ?? String(error),
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
@@ -147,8 +170,14 @@ export function registerAuthTools(server: McpServer): void {
|
||||
server.registerTool(
|
||||
"logout",
|
||||
{
|
||||
description: "Clear stored credentials",
|
||||
description:
|
||||
"Clear stored credentials (serverUrl, email, username, domain, password)."
|
||||
+ " No parameters.",
|
||||
inputSchema: z.object({}),
|
||||
outputSchema: z.object({
|
||||
success: z.boolean(),
|
||||
message: z.string().optional(),
|
||||
}),
|
||||
},
|
||||
async () => {
|
||||
clearConfig();
|
||||
@@ -160,6 +189,10 @@ export function registerAuthTools(server: McpServer): void {
|
||||
message: "Logged out. Credentials cleared.",
|
||||
}),
|
||||
}],
|
||||
structuredContent: {
|
||||
success: true,
|
||||
message: "Logged out. Credentials cleared.",
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user