@softeria/ms-365-mcp-server 0.176.0 → 0.177.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,142 @@
1
1
  import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
2
+ import { z } from "zod";
2
3
  import logger from "./logger.js";
4
+ function dropZodOnlyChecks(node) {
5
+ if (!node || typeof node !== "object") return;
6
+ if (Array.isArray(node)) {
7
+ for (const item of node) dropZodOnlyChecks(item);
8
+ return;
9
+ }
10
+ const record = node;
11
+ const allOf = record.allOf;
12
+ if (typeof record.format === "string" && Array.isArray(allOf) && allOf.length > 0 && allOf.every(
13
+ (item) => isPlainObject(item) && Object.keys(item).every((key) => key === "type" || key === "pattern")
14
+ )) {
15
+ record.pattern = allOf[0].pattern;
16
+ delete record.allOf;
17
+ }
18
+ if (record.type === "integer") {
19
+ if (record.maximum === Number.MAX_SAFE_INTEGER) delete record.maximum;
20
+ if (record.minimum === Number.MIN_SAFE_INTEGER) delete record.minimum;
21
+ }
22
+ for (const value of Object.values(record)) dropZodOnlyChecks(value);
23
+ }
24
+ function closesUnknownKeys(schema) {
25
+ const def = schema._zod?.def;
26
+ return def?.type === "object" && def.catchall === void 0;
27
+ }
28
+ function zodToToolJsonSchema(schema, reused = "ref") {
29
+ const json = z.toJSONSchema(schema, {
30
+ target: "draft-07",
31
+ io: "input",
32
+ unrepresentable: "any",
33
+ reused,
34
+ override: ({ zodSchema, jsonSchema }) => {
35
+ if (closesUnknownKeys(zodSchema)) jsonSchema.additionalProperties = false;
36
+ }
37
+ });
38
+ dropZodOnlyChecks(json);
39
+ return json;
40
+ }
41
+ const parameterJsonCache = /* @__PURE__ */ new WeakMap();
42
+ function parameterJson(schema) {
43
+ let json = parameterJsonCache.get(schema);
44
+ if (!json) {
45
+ json = zodToToolJsonSchema(schema);
46
+ delete json.$schema;
47
+ parameterJsonCache.set(schema, json);
48
+ }
49
+ return structuredClone(json);
50
+ }
51
+ function anchorRefs(node, base) {
52
+ if (!node || typeof node !== "object") return;
53
+ if (Array.isArray(node)) {
54
+ for (const item of node) anchorRefs(item, base);
55
+ return;
56
+ }
57
+ const record = node;
58
+ for (const [key, value] of Object.entries(record)) {
59
+ if (key === "$ref" && typeof value === "string" && value.startsWith("#")) {
60
+ record.$ref = `#${base}${value.slice(1)}`;
61
+ } else {
62
+ anchorRefs(value, base);
63
+ }
64
+ }
65
+ }
66
+ function toolInputJsonSchema(schema) {
67
+ const { shape, catchall } = schema._zod.def;
68
+ const properties = {};
69
+ const required = [];
70
+ for (const [name, parameter] of Object.entries(shape)) {
71
+ const json = parameterJson(parameter);
72
+ anchorRefs(json, `/properties/${escapePointer(name)}`);
73
+ properties[name] = json;
74
+ if (inputOptin(parameter) === void 0) required.push(name);
75
+ }
76
+ return {
77
+ $schema: "http://json-schema.org/draft-07/schema#",
78
+ type: "object",
79
+ properties,
80
+ ...required.length > 0 ? { required } : {},
81
+ // .loose() tools take flattened body fields at the top level (#569). A tool with no
82
+ // parameters says nothing, like the SDK's empty schema did.
83
+ ...catchall === void 0 && Object.keys(shape).length === 0 ? {} : { additionalProperties: !(catchall === void 0 || catchall._zod.def.type === "never") }
84
+ };
85
+ }
86
+ function inputOptin(schema) {
87
+ const def = schema._zod.def;
88
+ if (def.type === "pipe" && def.in?._zod.def.type === "transform" && def.out) {
89
+ return inputOptin(def.out);
90
+ }
91
+ if (def.type === "catch" && def.innerType) return inputOptin(def.innerType);
92
+ return schema._zod.optin;
93
+ }
94
+ function tidyToolJsonSchema(node) {
95
+ if (!node || typeof node !== "object") return;
96
+ if (Array.isArray(node)) {
97
+ for (const item of node) tidyToolJsonSchema(item);
98
+ return;
99
+ }
100
+ const record = node;
101
+ for (const value of Object.values(record)) tidyToolJsonSchema(value);
102
+ const allOf = record.allOf;
103
+ if (Array.isArray(allOf) && allOf.length === 1 && isPlainObject(allOf[0])) {
104
+ const only = allOf[0];
105
+ const clashes = Object.keys(only).filter((key) => key !== "description" && key in record);
106
+ const keepsWrapper = "$ref" in only && Object.keys(record).length > 1;
107
+ if (clashes.length === 0 && !keepsWrapper) {
108
+ delete record.allOf;
109
+ for (const [key, value] of Object.entries(only)) {
110
+ if (!(key in record)) record[key] = value;
111
+ }
112
+ }
113
+ }
114
+ const anyOf = record.anyOf;
115
+ if (Array.isArray(anyOf) && anyOf.length === 2 && !("type" in record)) {
116
+ const [value, nullable] = anyOf;
117
+ if (isPlainObject(value) && typeof value.type === "string" && Object.keys(value).every((key) => key === "type" || key === "description") && isPlainObject(nullable) && Object.keys(nullable).length === 1 && nullable.type === "null") {
118
+ delete record.anyOf;
119
+ record.type = [value.type, "null"];
120
+ if (value.description !== void 0 && record.description === void 0) {
121
+ record.description = value.description;
122
+ }
123
+ }
124
+ }
125
+ const extra = record.additionalProperties;
126
+ if (isPlainObject(extra) && Object.keys(extra).length === 0) {
127
+ record.additionalProperties = true;
128
+ }
129
+ const names = record.propertyNames;
130
+ if (isPlainObject(names) && Object.keys(names).length === 1 && names.type === "string") {
131
+ delete record.propertyNames;
132
+ }
133
+ }
134
+ function isPlainObject(value) {
135
+ return !!value && typeof value === "object" && !Array.isArray(value);
136
+ }
137
+ function escapePointer(token) {
138
+ return token.replace(/~/g, "~0").replace(/\//g, "~1");
139
+ }
3
140
  const MAX_INLINE_GROWTH = 2;
4
141
  function unescapePointer(token) {
5
142
  return token.replace(/~1/g, "/").replace(/~0/g, "~");
@@ -157,6 +294,18 @@ function normalizeToolSchemaRefs(schema) {
157
294
  }
158
295
  repointRefs(clone, nameFor);
159
296
  for (const name of Object.keys(defs)) repointRefs(defs[name], nameFor);
297
+ const definitionOwners = /* @__PURE__ */ new Set();
298
+ for (const pointer of slots.keys()) {
299
+ const match = /^(.*)\/definitions\/[^/]+$/.exec(pointer);
300
+ if (match) definitionOwners.add(match[1]);
301
+ }
302
+ for (const owner of definitionOwners) {
303
+ const holder = owner === "" ? clone : resolvePointer(clone, owner)?.obj;
304
+ const block = isPlainObject(holder) ? holder.definitions : void 0;
305
+ if (isPlainObject(holder) && isPlainObject(block) && Object.keys(block).every((name) => slots.has(`${owner}/definitions/${escapePointer(name)}`))) {
306
+ delete holder.definitions;
307
+ }
308
+ }
160
309
  const existingDefs = clone.$defs ?? {};
161
310
  delete clone.$defs;
162
311
  const pinned = findCyclicDefs(defs);
@@ -198,17 +347,37 @@ function installToolSchemaRefNormalization(server) {
198
347
  logger.warn("Skipping tool-schema $ref normalization: tools/list handler not found");
199
348
  return;
200
349
  }
350
+ const registered = server._registeredTools;
201
351
  lowLevel.setRequestHandler(ListToolsRequestSchema, async (request, extra) => {
352
+ for (const [name, tool] of Object.entries(registered ?? {})) {
353
+ if (tool.inputSchema instanceof z.core.$ZodObject) useOwnConversion(name, tool.inputSchema);
354
+ }
202
355
  const result = await original(request, extra);
203
356
  for (const tool of result.tools ?? []) {
204
357
  if (tool.inputSchema && typeof tool.inputSchema === "object") {
205
358
  tool.inputSchema = normalizeToolSchemaRefs(tool.inputSchema);
359
+ tidyToolJsonSchema(tool.inputSchema);
206
360
  }
207
361
  }
208
362
  return result;
209
363
  });
210
364
  }
365
+ function useOwnConversion(name, schema) {
366
+ const internals = schema._zod;
367
+ if (internals.toJSONSchema) return;
368
+ internals.toJSONSchema = () => {
369
+ try {
370
+ return toolInputJsonSchema(schema);
371
+ } catch (error) {
372
+ logger.warn(`Could not convert the input schema of ${name}: ${error}`);
373
+ return void 0;
374
+ }
375
+ };
376
+ }
211
377
  export {
212
378
  installToolSchemaRefNormalization,
213
- normalizeToolSchemaRefs
379
+ normalizeToolSchemaRefs,
380
+ tidyToolJsonSchema,
381
+ toolInputJsonSchema,
382
+ zodToToolJsonSchema
214
383
  };
package/dist/server.js CHANGED
@@ -192,12 +192,13 @@ class MicrosoftGraphServer {
192
192
  discovery: Boolean(this.options.discovery),
193
193
  eagerTools: this.options.eagerTools,
194
194
  orgMode: Boolean(this.options.orgMode),
195
+ appMode: Boolean(this.options.appMode),
195
196
  readOnly: Boolean(this.options.readOnly),
196
197
  multiAccount: this.multiAccount
197
198
  })
198
199
  }
199
200
  );
200
- const shouldRegisterAuthTools = !this.options.http || this.options.enableAuthTools;
201
+ const shouldRegisterAuthTools = !this.options.appMode && (!this.options.http || this.options.enableAuthTools);
201
202
  if (shouldRegisterAuthTools) {
202
203
  registerAuthTools(server, this.authManager);
203
204
  }
@@ -207,6 +208,7 @@ class MicrosoftGraphServer {
207
208
  onUnavailableEagerTool: this.reportUnavailableEagerTool,
208
209
  enabledTools: this.options.enabledTools,
209
210
  orgMode: this.options.orgMode,
211
+ appMode: this.options.appMode,
210
212
  authManager: this.authManager,
211
213
  multiAccount: this.multiAccount,
212
214
  accountNames: this.accountNames,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@softeria/ms-365-mcp-server",
3
3
  "mcpName": "io.github.Softeria/ms-365-mcp-server",
4
- "version": "0.176.0",
4
+ "version": "0.177.0",
5
5
  "description": " A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -47,8 +47,7 @@
47
47
  "open": "^11.0.0",
48
48
  "parse5": "^8.0.1",
49
49
  "winston": "^3.17.0",
50
- "zod": "^3.24.2",
51
- "zod-to-json-schema": "^3.25.1"
50
+ "zod": "^4.6.7"
52
51
  },
53
52
  "optionalDependencies": {
54
53
  "@azure/identity": "^4.5.0",