@teamnetwork-nz/m365-mcp-server 1.7.0 → 1.7.1

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/env.js ADDED
@@ -0,0 +1,12 @@
1
+ export function parsePositiveInt(name, raw, fallback, maximum) {
2
+ if (raw === undefined || raw.trim() === '')
3
+ return fallback;
4
+ if (!/^\d+$/.test(raw.trim())) {
5
+ throw new Error(`${name} must be an integer from 1 to ${maximum}`);
6
+ }
7
+ const value = Number(raw);
8
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
9
+ throw new Error(`${name} must be an integer from 1 to ${maximum}`);
10
+ }
11
+ return value;
12
+ }
@@ -64,9 +64,10 @@ export function createHttpServer(factory, o) {
64
64
  return error(res, 405, -32000, "Method not allowed");
65
65
  }
66
66
  const server = factory();
67
- const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
67
+ const transport = new StreamableHTTPServerTransport();
68
68
  try {
69
69
  const body = await readBody(req, o.maxBodyBytes ?? 1048576);
70
+ // SDK 1.29's class getter types conflict with Transport only under exactOptionalPropertyTypes.
70
71
  await server.connect(transport);
71
72
  await transport.handleRequest(req, res, body);
72
73
  res.once("close", () => { void transport.close(); void server.close(); });
package/dist/index.js CHANGED
@@ -7,6 +7,9 @@ import { AuthManager } from './auth/AuthManager.js';
7
7
  import { registerAllTools } from './tools/registry.js';
8
8
  import { logger } from './utils/logger.js';
9
9
  import { createHttpServer } from './http-server.js';
10
+ import { packageName, packageVersion } from './package-info.js';
11
+ import { enforceStrictToolInputs } from './strict-tools.js';
12
+ import { parsePositiveInt } from './env.js';
10
13
  async function main() {
11
14
  // 1. Load and validate config — aborts if invalid
12
15
  const config = loadConfig();
@@ -17,8 +20,8 @@ async function main() {
17
20
  // 3. Create MCP server and register all tools
18
21
  const createConfiguredServer = () => {
19
22
  const server = new McpServer({
20
- name: '@teamnetwork/m365-mcp-server',
21
- version: '1.7.0',
23
+ name: packageName,
24
+ version: packageVersion,
22
25
  }, {
23
26
  instructions: `
24
27
  Microsoft 365 MCP server — email, calendar, and To Do via the Microsoft Graph API.
@@ -49,14 +52,15 @@ Microsoft 365 MCP server — email, calendar, and To Do via the Microsoft Graph
49
52
  - delete_todo_task is permanent and irreversible. Confirm with the user before calling it.
50
53
  `.trim(),
51
54
  });
55
+ enforceStrictToolInputs(server);
52
56
  registerAllTools(server, config, auth);
53
57
  return server;
54
58
  };
55
59
  // 4. Connect via stdio transport (Claude Desktop / Claude Code)
56
60
  if ((process.env['M365_TRANSPORT'] ?? 'stdio') === 'http') {
57
61
  const host = process.env['M365_HTTP_HOST'] ?? '127.0.0.1';
58
- const port = Number.parseInt(process.env['M365_HTTP_PORT'] ?? '3000', 10);
59
- createHttpServer(createConfiguredServer, { host, port, serverName: '@teamnetwork/m365-mcp-server', bearerToken: process.env['M365_HTTP_BEARER_TOKEN'], allowedHosts: process.env['M365_HTTP_ALLOWED_HOSTS']?.split(',').map(v => v.trim()).filter(Boolean), allowedOrigins: process.env['M365_HTTP_ALLOWED_ORIGINS']?.split(',').map(v => v.trim()).filter(Boolean), maxBodyBytes: Number.parseInt(process.env['M365_HTTP_MAX_BODY_BYTES'] ?? '1048576', 10) }).listen(port, host, () => logger.info(`M365 MCP server listening on ${host}:${port}/mcp`));
62
+ const port = parsePositiveInt('M365_HTTP_PORT', process.env['M365_HTTP_PORT'], 3000, 65535);
63
+ createHttpServer(createConfiguredServer, { host, port, serverName: packageName, bearerToken: process.env['M365_HTTP_BEARER_TOKEN'], allowedHosts: process.env['M365_HTTP_ALLOWED_HOSTS']?.split(',').map(v => v.trim()).filter(Boolean), allowedOrigins: process.env['M365_HTTP_ALLOWED_ORIGINS']?.split(',').map(v => v.trim()).filter(Boolean), maxBodyBytes: parsePositiveInt('M365_HTTP_MAX_BODY_BYTES', process.env['M365_HTTP_MAX_BODY_BYTES'], 1_048_576, 16_777_216) }).listen(port, host, () => logger.info(`M365 MCP server listening on ${host}:${port}/mcp`));
60
64
  }
61
65
  else {
62
66
  await createConfiguredServer().connect(new StdioServerTransport());
@@ -0,0 +1,6 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ const packageJson = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8'));
5
+ export const packageName = packageJson.name ?? 'm365-mcp-server';
6
+ export const packageVersion = packageJson.version ?? '0.0.0';
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ function isSchema(value) {
3
+ return typeof value === "object" && value !== null && "_def" in value;
4
+ }
5
+ function isRawShape(value) {
6
+ if (typeof value !== "object" || value === null || isSchema(value))
7
+ return false;
8
+ const values = Object.values(value);
9
+ return values.length === 0 || values.some(isSchema);
10
+ }
11
+ function strictSchema(schema) {
12
+ if (schema === undefined)
13
+ return z.object({}).strict();
14
+ if (isRawShape(schema))
15
+ return z.object(schema).strict();
16
+ if (isSchema(schema) && typeof schema.strict === "function")
17
+ return schema.strict();
18
+ return schema;
19
+ }
20
+ /** Make every tool object reject undeclared arguments, including no-argument tools. */
21
+ export function enforceStrictToolInputs(server) {
22
+ const mutable = server;
23
+ const createRegisteredTool = mutable._createRegisteredTool.bind(server);
24
+ mutable._createRegisteredTool = (...args) => {
25
+ // SDK 1.29 funnels both tool() and registerTool() through this method.
26
+ args[3] = strictSchema(args[3]);
27
+ return createRegisteredTool(...args);
28
+ };
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnetwork-nz/m365-mcp-server",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "MCP server for Microsoft 365 — Email, Calendar, To Do, SharePoint document libraries, and Teams — using client credentials (app-only auth). Supports multiple accounts, shared mailboxes, per-mailbox read-only access, and grant-based SharePoint access control.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@azure/msal-node": "^2.16.0",
39
39
  "@microsoft/microsoft-graph-client": "^3.0.7",
40
- "@modelcontextprotocol/sdk": "^1.10.0",
41
- "zod": "^3.23.0"
40
+ "@modelcontextprotocol/sdk": "^1.29.0",
41
+ "zod": "^3.25.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^20.0.0",