@teamnetwork-nz/mailstore-spe-mcp 0.2.3 → 0.3.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.
- package/README.md +2 -0
- package/dist/strict-tools.js +39 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# MailStore SPE MCP Server
|
|
2
2
|
|
|
3
|
+
Tools accept optional `outputFormat: "json"` to return valid JSON text. The option is removed locally and is never sent to the MailStore API.
|
|
4
|
+
|
|
3
5
|
## Streamable HTTP
|
|
4
6
|
|
|
5
7
|
Set `MAILSTORE_TRANSPORT=http` to serve stateless MCP at `/mcp`. The default bind is `127.0.0.1`; remote binding requires `MAILSTORE_HTTP_BEARER_TOKEN` and `MAILSTORE_HTTP_ALLOWED_HOSTS`. Optional controls include `MAILSTORE_HTTP_PORT`, `MAILSTORE_HTTP_ALLOWED_ORIGINS`, and `MAILSTORE_HTTP_MAX_BODY_BYTES`. Each request receives an independently validated MailStore server context.
|
package/dist/strict-tools.js
CHANGED
|
@@ -17,13 +17,50 @@ function strictSchema(schema) {
|
|
|
17
17
|
return schema.strict();
|
|
18
18
|
return schema;
|
|
19
19
|
}
|
|
20
|
+
function addOutputFormat(schema) {
|
|
21
|
+
const strict = strictSchema(schema);
|
|
22
|
+
if (typeof strict.extend !== "function")
|
|
23
|
+
return strict;
|
|
24
|
+
return strict.extend({
|
|
25
|
+
outputFormat: z.enum(["json"]).optional().describe("Return the result as valid JSON text without Markdown wrappers."),
|
|
26
|
+
}).strict?.() ?? strict;
|
|
27
|
+
}
|
|
28
|
+
function toJsonValue(text) {
|
|
29
|
+
const fenced = text.match(/\x60\x60\x60json\s*([\s\S]*?)\s*\x60\x60\x60/i)?.[1];
|
|
30
|
+
const candidate = fenced ?? text;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(candidate);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
20
38
|
/** Make every tool object reject undeclared arguments, including no-argument tools. */
|
|
21
39
|
export function enforceStrictToolInputs(server) {
|
|
22
40
|
const mutable = server;
|
|
23
41
|
const createRegisteredTool = mutable._createRegisteredTool.bind(server);
|
|
24
42
|
mutable._createRegisteredTool = (...args) => {
|
|
25
|
-
//
|
|
26
|
-
args[3] =
|
|
43
|
+
// The MCP-only output option is stripped here so it cannot leak into vendor API parameters.
|
|
44
|
+
args[3] = addOutputFormat(args[3]);
|
|
45
|
+
const handler = args[8];
|
|
46
|
+
if (typeof handler === "function") {
|
|
47
|
+
args[8] = async (input, ...rest) => {
|
|
48
|
+
const values = input && typeof input === "object" ? input : {};
|
|
49
|
+
const { outputFormat, ...toolArgs } = values;
|
|
50
|
+
const result = await handler(toolArgs, ...rest);
|
|
51
|
+
if (outputFormat !== "json" || result?.isError || !Array.isArray(result?.content))
|
|
52
|
+
return result;
|
|
53
|
+
const textItems = result.content.filter((item) => item.type === "text" && typeof item.text === "string");
|
|
54
|
+
if (textItems.length === 0)
|
|
55
|
+
return result;
|
|
56
|
+
const data = result.structuredContent !== undefined
|
|
57
|
+
? result.structuredContent
|
|
58
|
+
: textItems.length === 1
|
|
59
|
+
? toJsonValue((textItems[0]?.text ?? ''))
|
|
60
|
+
: textItems.map((item) => toJsonValue(item.text));
|
|
61
|
+
return { ...result, content: [{ type: "text", text: JSON.stringify(data, null, 2) }], ...(result.structuredContent === undefined && data && typeof data === "object" ? { structuredContent: data } : {}) };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
27
64
|
return createRegisteredTool(...args);
|
|
28
65
|
};
|
|
29
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnetwork-nz/mailstore-spe-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MCP server providing a curated, safety-gated administrator interface over the MailStore Service Provider Edition (SPE) Management API. Multi-instance aware, read-only by default, with access modes, confirmation gating, capability discovery, and bounded structured output.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|