UNPKG

@softeria/ms-365-mcp-server

Version:

A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API

70 lines (69 loc) 2.39 kB
import { zodToJsonSchema } from "zod-to-json-schema"; import { isDestructiveOperation } from "./destructive-ops.js"; function unwrapOptional(schema) { const def = schema._def; const typeName = def?.typeName; if (typeName === "ZodOptional" || typeName === "ZodDefault" || typeName === "ZodNullable") { return { inner: def.innerType, optional: true }; } return { inner: schema, optional: false }; } function describeToolSchema(tool, config) { const params = (tool.parameters ?? []).map((p) => { const { inner, optional } = unwrapOptional(p.schema); const isPath = p.type === "Path"; const jsonSchema = zodToJsonSchema(inner, { target: "jsonSchema7", $refStrategy: "none" }); const { $schema: _s, ...schema } = jsonSchema; return { name: p.name, in: p.type, required: isPath || !optional, description: p.description, schema }; }); if (isDestructiveOperation(tool.method, config)) { params.push({ name: "confirm", in: "Query", required: false, description: 'For destructive operations when the confirm gate is enabled (MS365_MCP_REQUIRE_CONFIRM=true; off by default). Set to true only after the user has explicitly approved this action. When the gate is on, calls without confirm: true return { error: "confirmation_required" } without touching user data.', schema: { type: "boolean" } }); } const llmTip = config?.llmTip; return { name: tool.alias, method: tool.method.toUpperCase(), path: tool.path, description: config?.descriptionOverride ?? tool.description ?? "", ...llmTip ? { llmTip } : {}, parameters: params }; } function describeUtilityToolSchema(utility, ctx) { const schemaMap = utility.buildSchema(ctx); const params = Object.entries(schemaMap).map(([name, zodSchema]) => { const { inner, optional } = unwrapOptional(zodSchema); const jsonSchema = zodToJsonSchema(inner, { target: "jsonSchema7", $refStrategy: "none" }); const { $schema: _s, ...schema } = jsonSchema; return { name, in: "Query", required: !optional, description: zodSchema.description, schema }; }); return { name: utility.name, method: utility.method, path: utility.path, description: utility.description, parameters: params }; } export { describeToolSchema, describeUtilityToolSchema };