@teamnetwork-nz/m365-mcp-server 1.3.0 → 1.4.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 +1 -1
- package/dist/tools/schemas.js +23 -3
- package/dist/tools/sharepoint/uploadFile.js +20 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -225,7 +225,7 @@ Operations always target exactly one mailbox per request, either the default or
|
|
|
225
225
|
| `get_drive_item` | Get metadata for a file or folder — always permitted, no grant required |
|
|
226
226
|
| `check_sharepoint_access` | Check whether an operation is permitted by the grant config (no network call, never errors) — use before content operations |
|
|
227
227
|
| `download_file` | Download a file as base64. Images returned as MCP image content; others as a JSON payload with `fileName`, `mimeType`, `encoding`, and `data`. Requires `read` grant |
|
|
228
|
-
| `upload_file` | Upload a file (
|
|
228
|
+
| `upload_file` | Upload a file (max 4 MB) via `sourcePath` (preferred — reads from disk) or inline `content` (`contentEncoding: "utf8"` or `"base64"`, optionally checked against `expectedBytes`/`sha256`). Creates or overwrites. Requires `create` or `update` grant |
|
|
229
229
|
| `create_folder` | Create a new folder. Requires `create` grant on the parent path |
|
|
230
230
|
| `delete_drive_item` | Permanently delete a file or folder. Requires `delete` grant |
|
|
231
231
|
| `move_drive_item` | Move a file or folder, optionally renaming. Requires `update` at source and `create` at destination |
|
package/dist/tools/schemas.js
CHANGED
|
@@ -199,9 +199,29 @@ export const UploadFileSchema = SharepointBase.extend({
|
|
|
199
199
|
content: z
|
|
200
200
|
.string()
|
|
201
201
|
.optional()
|
|
202
|
-
.describe('
|
|
203
|
-
'for anything larger, or
|
|
204
|
-
'instead.
|
|
202
|
+
.describe('Inline file content, interpreted per contentEncoding (default base64). Only use this for ' +
|
|
203
|
+
'small files supplied inline — for anything larger, or a file that already exists on disk, ' +
|
|
204
|
+
'use sourcePath instead. For text files, prefer contentEncoding "utf8" so no base64 is ' +
|
|
205
|
+
'needed. Exactly one of sourcePath or content must be provided. Maximum 4 MB.'),
|
|
206
|
+
contentEncoding: z
|
|
207
|
+
.enum(['base64', 'utf8'])
|
|
208
|
+
.default('base64')
|
|
209
|
+
.describe('How to interpret content. "utf8" = plain text sent as-is (recommended for .md, .txt, .csv, ' +
|
|
210
|
+
'.json etc. — avoids error-prone base64). "base64" = binary files. Ignored for sourcePath.'),
|
|
211
|
+
expectedBytes: z
|
|
212
|
+
.number()
|
|
213
|
+
.int()
|
|
214
|
+
.nonnegative()
|
|
215
|
+
.optional()
|
|
216
|
+
.describe('Optional integrity check: the exact size in bytes the file should have after decoding. ' +
|
|
217
|
+
'If the received content decodes to a different size, the upload is rejected before ' +
|
|
218
|
+
'anything is written — this catches truncated or corrupted inline content.'),
|
|
219
|
+
sha256: z
|
|
220
|
+
.string()
|
|
221
|
+
.regex(/^[0-9a-fA-F]{64}$/, 'sha256 must be a 64-character hex string')
|
|
222
|
+
.optional()
|
|
223
|
+
.describe('Optional integrity check: hex SHA-256 of the file bytes. If the received content does not ' +
|
|
224
|
+
'match, the upload is rejected before anything is written.'),
|
|
205
225
|
contentType: z
|
|
206
226
|
.string()
|
|
207
227
|
.optional()
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { readFile } from 'node:fs/promises';
|
|
2
3
|
import { UploadFileSchema } from '../schemas.js';
|
|
3
4
|
import { createGraphClient } from '../../graph/clientFactory.js';
|
|
@@ -13,10 +14,11 @@ export function registerUploadFile(server, config, auth) {
|
|
|
13
14
|
server.tool('upload_file', 'Upload a file to a SharePoint document library. Creates the file if it does not exist; ' +
|
|
14
15
|
'overwrites it if it does (SharePoint manages version history). ' +
|
|
15
16
|
'Provide exactly one of sourcePath or content: sourcePath (preferred) reads an existing ' +
|
|
16
|
-
'local file directly from disk; content is
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
17
|
+
'local file directly from disk; content is for small inline payloads only — use ' +
|
|
18
|
+
'contentEncoding "utf8" for text files (no base64), "base64" for binary. Long base64 ' +
|
|
19
|
+
'emitted inline can be truncated or corrupted by the caller with no error, so pass ' +
|
|
20
|
+
'expectedBytes and/or sha256 with inline content: a mismatch rejects the upload before ' +
|
|
21
|
+
'anything is written. Prefer sourcePath for anything above a few KB. ' +
|
|
20
22
|
'Maximum 4 MB. Requires a grant with "create" OR "update" in allowedOperations for the path ' +
|
|
21
23
|
'and filename. Call check_sharepoint_access first to verify permissions.', UploadFileSchema.shape, async (params) => {
|
|
22
24
|
try {
|
|
@@ -43,7 +45,20 @@ export function registerUploadFile(server, config, auth) {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
else {
|
|
46
|
-
buf = Buffer.from(params.content, 'base64');
|
|
48
|
+
buf = Buffer.from(params.content, params.contentEncoding === 'utf8' ? 'utf8' : 'base64');
|
|
49
|
+
}
|
|
50
|
+
// Integrity checks — reject before any Graph call if the decoded bytes are wrong.
|
|
51
|
+
if (params.expectedBytes !== undefined && buf.byteLength !== params.expectedBytes) {
|
|
52
|
+
throw new ToolError(`Integrity check failed: expected ${params.expectedBytes} bytes but received ` +
|
|
53
|
+
`${buf.byteLength}. The content was likely truncated or corrupted in transit — ` +
|
|
54
|
+
'nothing was uploaded.', 'INTEGRITY_CHECK_FAILED');
|
|
55
|
+
}
|
|
56
|
+
if (params.sha256 !== undefined) {
|
|
57
|
+
const actual = createHash('sha256').update(buf).digest('hex');
|
|
58
|
+
if (actual !== params.sha256.toLowerCase()) {
|
|
59
|
+
throw new ToolError(`Integrity check failed: SHA-256 mismatch (received ${actual}). The content was ` +
|
|
60
|
+
'likely truncated or corrupted in transit — nothing was uploaded.', 'INTEGRITY_CHECK_FAILED');
|
|
61
|
+
}
|
|
47
62
|
}
|
|
48
63
|
if (buf.byteLength > MAX_BYTES) {
|
|
49
64
|
throw new ToolError(`File is ${(buf.byteLength / 1024 / 1024).toFixed(1)} MB which exceeds the 4 MB ` +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnetwork-nz/m365-mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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",
|