@softeria/ms-365-mcp-server 0.145.1 → 0.145.2
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.
- package/dist/normalize-tool-schema.js +103 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import logger from "./logger.js";
|
|
3
|
+
const MAX_INLINE_GROWTH = 2;
|
|
3
4
|
function unescapePointer(token) {
|
|
4
5
|
return token.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
5
6
|
}
|
|
@@ -51,6 +52,78 @@ function repointRefs(node, nameFor) {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
function hasDef(defs, name) {
|
|
56
|
+
return Object.prototype.hasOwnProperty.call(defs, name);
|
|
57
|
+
}
|
|
58
|
+
function defRefName(value) {
|
|
59
|
+
const prefix = "#/$defs/";
|
|
60
|
+
return typeof value === "string" && value.startsWith(prefix) ? value.slice(prefix.length) : null;
|
|
61
|
+
}
|
|
62
|
+
function collectDefRefNames(node, out) {
|
|
63
|
+
if (!node || typeof node !== "object") return;
|
|
64
|
+
if (Array.isArray(node)) {
|
|
65
|
+
for (const item of node) collectDefRefNames(item, out);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const [key, value] of Object.entries(node)) {
|
|
69
|
+
const name = key === "$ref" ? defRefName(value) : null;
|
|
70
|
+
if (name === null) collectDefRefNames(value, out);
|
|
71
|
+
else out.add(name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function collectSiblingRefNames(node, out) {
|
|
75
|
+
if (!node || typeof node !== "object") return;
|
|
76
|
+
if (Array.isArray(node)) {
|
|
77
|
+
for (const item of node) collectSiblingRefNames(item, out);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const record = node;
|
|
81
|
+
const name = defRefName(record.$ref);
|
|
82
|
+
if (name !== null && Object.keys(record).length > 1) out.add(name);
|
|
83
|
+
for (const value of Object.values(record)) collectSiblingRefNames(value, out);
|
|
84
|
+
}
|
|
85
|
+
function findCyclicDefs(defs) {
|
|
86
|
+
const edges = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const [name, value] of Object.entries(defs)) {
|
|
88
|
+
const out = /* @__PURE__ */ new Set();
|
|
89
|
+
collectDefRefNames(value, out);
|
|
90
|
+
edges.set(name, out);
|
|
91
|
+
}
|
|
92
|
+
const cyclic = /* @__PURE__ */ new Set();
|
|
93
|
+
for (const start of edges.keys()) {
|
|
94
|
+
const seen = /* @__PURE__ */ new Set();
|
|
95
|
+
const stack = [...edges.get(start) ?? []];
|
|
96
|
+
while (stack.length > 0) {
|
|
97
|
+
const next = stack.pop();
|
|
98
|
+
if (next === start) {
|
|
99
|
+
cyclic.add(start);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (seen.has(next)) continue;
|
|
103
|
+
seen.add(next);
|
|
104
|
+
for (const onward of edges.get(next) ?? []) stack.push(onward);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return cyclic;
|
|
108
|
+
}
|
|
109
|
+
function inlineDefRefs(node, defs, pinned, expand) {
|
|
110
|
+
if (!node || typeof node !== "object") return node;
|
|
111
|
+
if (Array.isArray(node)) return node.map((item) => inlineDefRefs(item, defs, pinned, expand));
|
|
112
|
+
const record = node;
|
|
113
|
+
const name = defRefName(record.$ref);
|
|
114
|
+
if (name !== null && hasDef(defs, name) && !pinned.has(name)) {
|
|
115
|
+
const siblings = {};
|
|
116
|
+
for (const [key, value] of Object.entries(record)) {
|
|
117
|
+
if (key !== "$ref") siblings[key] = inlineDefRefs(value, defs, pinned, expand);
|
|
118
|
+
}
|
|
119
|
+
return { ...structuredClone(expand(name)), ...siblings };
|
|
120
|
+
}
|
|
121
|
+
const out = {};
|
|
122
|
+
for (const [key, value] of Object.entries(record)) {
|
|
123
|
+
out[key] = inlineDefRefs(value, defs, pinned, expand);
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
54
127
|
function normalizeToolSchemaRefs(schema) {
|
|
55
128
|
const targets = /* @__PURE__ */ new Set();
|
|
56
129
|
collectBadRefTargets(schema, targets);
|
|
@@ -85,8 +158,37 @@ function normalizeToolSchemaRefs(schema) {
|
|
|
85
158
|
repointRefs(clone, nameFor);
|
|
86
159
|
for (const name of Object.keys(defs)) repointRefs(defs[name], nameFor);
|
|
87
160
|
const existingDefs = clone.$defs ?? {};
|
|
161
|
+
delete clone.$defs;
|
|
162
|
+
const pinned = findCyclicDefs(defs);
|
|
163
|
+
collectSiblingRefNames(clone, pinned);
|
|
164
|
+
for (const value of Object.values(defs)) collectSiblingRefNames(value, pinned);
|
|
165
|
+
for (const value of Object.values(existingDefs)) collectSiblingRefNames(value, pinned);
|
|
166
|
+
for (const name of [...pinned]) {
|
|
167
|
+
if (!hasDef(defs, name)) pinned.delete(name);
|
|
168
|
+
}
|
|
169
|
+
if (pinned.size > 0) {
|
|
170
|
+
clone.$defs = { ...existingDefs, ...defs };
|
|
171
|
+
return clone;
|
|
172
|
+
}
|
|
173
|
+
const memo = /* @__PURE__ */ new Map();
|
|
174
|
+
const expand = (name) => {
|
|
175
|
+
if (memo.has(name)) return memo.get(name);
|
|
176
|
+
const value = inlineDefRefs(defs[name], defs, pinned, expand);
|
|
177
|
+
memo.set(name, value);
|
|
178
|
+
return value;
|
|
179
|
+
};
|
|
180
|
+
const inlined = inlineDefRefs(clone, defs, pinned, expand);
|
|
181
|
+
if (Object.keys(existingDefs).length > 0) {
|
|
182
|
+
inlined.$defs = Object.fromEntries(
|
|
183
|
+
Object.entries(existingDefs).map(([name, value]) => [
|
|
184
|
+
name,
|
|
185
|
+
inlineDefRefs(value, defs, pinned, expand)
|
|
186
|
+
])
|
|
187
|
+
);
|
|
188
|
+
}
|
|
88
189
|
clone.$defs = { ...existingDefs, ...defs };
|
|
89
|
-
|
|
190
|
+
const grewTooMuch = JSON.stringify(inlined).length > JSON.stringify(clone).length * MAX_INLINE_GROWTH;
|
|
191
|
+
return grewTooMuch ? clone : inlined;
|
|
90
192
|
}
|
|
91
193
|
function installToolSchemaRefNormalization(server) {
|
|
92
194
|
const lowLevel = server.server;
|
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.145.
|
|
4
|
+
"version": "0.145.2",
|
|
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",
|