@softeria/ms-365-mcp-server 0.177.0 → 0.179.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.
@@ -0,0 +1,200 @@
1
+ import { z } from "zod";
2
+ import {
3
+ normalizeToolSchemaRefs,
4
+ tidyToolJsonSchema,
5
+ toolInputJsonSchema
6
+ } from "../normalize-tool-schema.js";
7
+ import { positiveIntFromEnv } from "./param-descriptions.js";
8
+ const CONNECTOR_DEFINITION_BUDGET = 1048576;
9
+ const DEFAULT_TOOL_DEFINITION_BUDGET = 4096;
10
+ function getToolDefinitionBudget() {
11
+ const raw = process.env.MS365_MCP_TOOL_DEFINITION_BUDGET;
12
+ if (raw === void 0 || raw === "") return void 0;
13
+ return positiveIntFromEnv("MS365_MCP_TOOL_DEFINITION_BUDGET", DEFAULT_TOOL_DEFINITION_BUDGET);
14
+ }
15
+ const PRUNE_STRATEGIES = [
16
+ { maxDepth: 4, describeDepth: 2 },
17
+ { maxDepth: 3, describeDepth: 2 },
18
+ { maxDepth: 2, describeDepth: 2 },
19
+ { maxDepth: 1, describeDepth: 2 },
20
+ { maxDepth: 1, describeDepth: 1 },
21
+ { maxDepth: 1, describeDepth: 0 },
22
+ { maxDepth: 0, describeDepth: 0 }
23
+ ];
24
+ function withDescription(rebuilt, original, keepDescription) {
25
+ const description = original.description;
26
+ return description && keepDescription ? rebuilt.describe(description) : rebuilt;
27
+ }
28
+ function collapsedKind(schema) {
29
+ const unwrapped = unwrapContainer(schema);
30
+ if (unwrapped instanceof z.ZodArray) return "array";
31
+ if (unwrapped instanceof z.ZodObject || unwrapped instanceof z.ZodRecord) return "object";
32
+ if (unwrapped instanceof z.ZodUnion) {
33
+ const kinds = new Set(unwrapped.options.map(collapsedKind));
34
+ return kinds.size === 1 ? [...kinds][0] : "other";
35
+ }
36
+ return "other";
37
+ }
38
+ function collapse(schema, keepDescription) {
39
+ switch (collapsedKind(schema)) {
40
+ case "array":
41
+ return withDescription(z.array(z.any()), schema, keepDescription);
42
+ case "object":
43
+ return withDescription(z.record(z.string(), z.any()), schema, keepDescription);
44
+ default:
45
+ return withDescription(z.any(), schema, keepDescription);
46
+ }
47
+ }
48
+ function unwrapContainer(schema) {
49
+ let current = schema;
50
+ for (let i = 0; i < 10; i++) {
51
+ if (current instanceof z.ZodOptional || current instanceof z.ZodNullable) {
52
+ current = current.unwrap();
53
+ continue;
54
+ }
55
+ if (current instanceof z.ZodLazy) {
56
+ current = current.unwrap();
57
+ continue;
58
+ }
59
+ if (current instanceof z.ZodDefault) {
60
+ current = current.def.innerType;
61
+ continue;
62
+ }
63
+ return current;
64
+ }
65
+ return current;
66
+ }
67
+ function pruneSchemaDepth(schema, maxDepth, describeDepth = Number.POSITIVE_INFINITY) {
68
+ const keepDescription = describeDepth > 0;
69
+ if (schema instanceof z.ZodOptional) {
70
+ return pruneSchemaDepth(schema.unwrap(), maxDepth, describeDepth).optional();
71
+ }
72
+ if (schema instanceof z.ZodNullable) {
73
+ return pruneSchemaDepth(schema.unwrap(), maxDepth, describeDepth).nullable();
74
+ }
75
+ if (schema instanceof z.ZodDefault) {
76
+ return pruneSchemaDepth(schema.def.innerType, maxDepth, describeDepth).default(
77
+ schema.def.defaultValue
78
+ );
79
+ }
80
+ if (schema instanceof z.ZodLazy) {
81
+ return pruneSchemaDepth(schema.unwrap(), maxDepth, describeDepth);
82
+ }
83
+ if (maxDepth <= 0) return collapse(schema, keepDescription);
84
+ if (schema instanceof z.ZodObject) {
85
+ const shape = schema.shape;
86
+ const pruned = {};
87
+ for (const [key, value] of Object.entries(shape)) {
88
+ pruned[key] = pruneSchemaDepth(value, maxDepth - 1, describeDepth - 1);
89
+ }
90
+ return withDescription(z.object(pruned).loose(), schema, keepDescription);
91
+ }
92
+ if (schema instanceof z.ZodArray) {
93
+ return withDescription(
94
+ z.array(pruneSchemaDepth(schema.element, maxDepth - 1, describeDepth - 1)),
95
+ schema,
96
+ keepDescription
97
+ );
98
+ }
99
+ if (schema instanceof z.ZodRecord) {
100
+ return withDescription(
101
+ z.record(
102
+ schema.keyType,
103
+ pruneSchemaDepth(schema.valueType, maxDepth - 1, describeDepth - 1)
104
+ ),
105
+ schema,
106
+ keepDescription
107
+ );
108
+ }
109
+ if (schema instanceof z.ZodUnion) {
110
+ const options = schema.options.map(
111
+ (option) => pruneSchemaDepth(option, maxDepth, describeDepth)
112
+ );
113
+ return withDescription(
114
+ z.union(options),
115
+ schema,
116
+ keepDescription
117
+ );
118
+ }
119
+ if (!keepDescription && schema.description) {
120
+ return collapseScalarDescription(schema);
121
+ }
122
+ return schema;
123
+ }
124
+ function collapseScalarDescription(schema) {
125
+ if (schema instanceof z.ZodString) return z.string();
126
+ if (schema instanceof z.ZodNumber) return z.number();
127
+ if (schema instanceof z.ZodBoolean) return z.boolean();
128
+ if (schema instanceof z.ZodEnum) return z.enum(schema.options);
129
+ return schema;
130
+ }
131
+ function serveToolInputSchema(paramSchema) {
132
+ return serveInputSchema(z.object(paramSchema).loose());
133
+ }
134
+ function serveInputSchema(schema) {
135
+ const served = normalizeToolSchemaRefs(toolInputJsonSchema(schema));
136
+ tidyToolJsonSchema(served);
137
+ return served;
138
+ }
139
+ function measureToolDefinitionBytes(paramSchema) {
140
+ return measureInputSchemaBytes(z.object(paramSchema).loose());
141
+ }
142
+ function measureInputSchemaBytes(schema) {
143
+ return Buffer.byteLength(JSON.stringify(serveInputSchema(schema)), "utf8");
144
+ }
145
+ const fitCache = /* @__PURE__ */ new Map();
146
+ function clearToolDefinitionBudgetCache() {
147
+ fitCache.clear();
148
+ }
149
+ function fitToolDefinitionToBudget(paramSchema, bodyParamNames, budget = DEFAULT_TOOL_DEFINITION_BUDGET, cacheKey) {
150
+ if (cacheKey !== void 0) {
151
+ const cached = fitCache.get(cacheKey);
152
+ if (cached) return cached;
153
+ }
154
+ const result = fitUncached(paramSchema, bodyParamNames, budget);
155
+ if (cacheKey !== void 0) fitCache.set(cacheKey, result);
156
+ return result;
157
+ }
158
+ function fitUncached(paramSchema, bodyParamNames, budget) {
159
+ const bytesBefore = measureToolDefinitionBytes(paramSchema);
160
+ if (bytesBefore <= budget || bodyParamNames.length === 0) {
161
+ return {
162
+ paramSchema,
163
+ appliedStrategy: null,
164
+ bytesBefore,
165
+ bytesAfter: bytesBefore,
166
+ bodyWentOpaque: false
167
+ };
168
+ }
169
+ let best = null;
170
+ for (const strategy of PRUNE_STRATEGIES) {
171
+ const candidate = { ...paramSchema };
172
+ for (const bodyName of bodyParamNames) {
173
+ const original = paramSchema[bodyName];
174
+ if (original)
175
+ candidate[bodyName] = pruneSchemaDepth(original, strategy.maxDepth, strategy.describeDepth);
176
+ }
177
+ const bytesAfter = measureToolDefinitionBytes(candidate);
178
+ best = {
179
+ paramSchema: candidate,
180
+ appliedStrategy: strategy,
181
+ bytesBefore,
182
+ bytesAfter,
183
+ bodyWentOpaque: strategy.maxDepth === 0
184
+ };
185
+ if (bytesAfter <= budget) return best;
186
+ }
187
+ return best;
188
+ }
189
+ export {
190
+ CONNECTOR_DEFINITION_BUDGET,
191
+ DEFAULT_TOOL_DEFINITION_BUDGET,
192
+ clearToolDefinitionBudgetCache,
193
+ fitToolDefinitionToBudget,
194
+ getToolDefinitionBudget,
195
+ measureInputSchemaBytes,
196
+ measureToolDefinitionBytes,
197
+ pruneSchemaDepth,
198
+ serveInputSchema,
199
+ serveToolInputSchema
200
+ };
package/dist/server.js CHANGED
@@ -236,7 +236,7 @@ class MicrosoftGraphServer {
236
236
  return `${this.secrets.clientId}/access_as_user offline_access`;
237
237
  }
238
238
  async initialize(version) {
239
- this.secrets = await getSecrets();
239
+ this.secrets = this.authManager.getAppSecrets?.() ?? await getSecrets();
240
240
  this.version = version;
241
241
  const accountRoutingAvailable = (!this.options.http || this.options.trustProxyAuth) && !this.authManager.isOAuthModeEnabled();
242
242
  if (accountRoutingAvailable) {
@@ -141,7 +141,6 @@ function presetRequiresOrgMode(preset) {
141
141
  export {
142
142
  TOOL_CATEGORIES,
143
143
  getCombinedPresetPattern,
144
- getToolsForPreset,
145
144
  listPresets,
146
145
  presetRequiresOrgMode
147
146
  };
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.177.0",
4
+ "version": "0.179.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",