@teamnetwork-nz/m365-mcp-server 1.2.2 → 1.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/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ async function main() {
|
|
|
16
16
|
// 3. Create MCP server and register all tools
|
|
17
17
|
const server = new McpServer({
|
|
18
18
|
name: '@teamnetwork/m365-mcp-server',
|
|
19
|
-
version: '1.0
|
|
19
|
+
version: '1.3.0',
|
|
20
20
|
}, {
|
|
21
21
|
instructions: `
|
|
22
22
|
Microsoft 365 MCP server — email, calendar, and To Do via the Microsoft Graph API.
|
package/dist/tools/schemas.js
CHANGED
|
@@ -189,11 +189,24 @@ export const UploadFileSchema = SharepointBase.extend({
|
|
|
189
189
|
.string()
|
|
190
190
|
.describe('Full destination path including filename (e.g. "/Finance/Reports/Q1.pdf"). ' +
|
|
191
191
|
'Requires a grant with "create" OR "update" in allowedOperations.'),
|
|
192
|
-
|
|
192
|
+
sourcePath: z
|
|
193
|
+
.string()
|
|
194
|
+
.optional()
|
|
195
|
+
.describe('Preferred over content: an absolute local file path to upload. The server reads the file ' +
|
|
196
|
+
'directly from disk, so no base64 payload needs to be embedded in the tool call. Overwrites ' +
|
|
197
|
+
'the destination if it already exists; SharePoint manages version history. Exactly one of ' +
|
|
198
|
+
'sourcePath or content must be provided.'),
|
|
199
|
+
content: z
|
|
200
|
+
.string()
|
|
201
|
+
.optional()
|
|
202
|
+
.describe('Base64-encoded file content. Only use this for small files (a few KB) supplied inline — ' +
|
|
203
|
+
'for anything larger, or to upload a file that already exists on disk, use sourcePath ' +
|
|
204
|
+
'instead. Exactly one of sourcePath or content must be provided. Maximum 4 MB.'),
|
|
193
205
|
contentType: z
|
|
194
206
|
.string()
|
|
195
|
-
.
|
|
196
|
-
.describe('MIME type of the file (e.g. "application/pdf", "image/png").'
|
|
207
|
+
.optional()
|
|
208
|
+
.describe('MIME type of the file (e.g. "application/pdf", "image/png"). Inferred from the ' +
|
|
209
|
+
'destination path\'s extension when omitted.'),
|
|
197
210
|
});
|
|
198
211
|
export const CreateFolderSchema = SharepointBase.extend({
|
|
199
212
|
parentPath: z
|
|
@@ -6,22 +6,10 @@ import { errorResponse } from '../../utils/errors.js';
|
|
|
6
6
|
import { logger } from '../../utils/logger.js';
|
|
7
7
|
import { resolveSharepointLibrary } from '../../utils/resolveSharepointLibrary.js';
|
|
8
8
|
import { splitPath } from '../../utils/pathUtils.js';
|
|
9
|
+
import { mimeFromExtension } from '../../utils/mimeTypes.js';
|
|
9
10
|
const IMAGE_MIME_TYPES = new Set([
|
|
10
11
|
'image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml',
|
|
11
12
|
]);
|
|
12
|
-
function mimeFromExtension(filename) {
|
|
13
|
-
const ext = filename.split('.').pop()?.toLowerCase() ?? '';
|
|
14
|
-
const map = {
|
|
15
|
-
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg',
|
|
16
|
-
gif: 'image/gif', webp: 'image/webp', svg: 'image/svg+xml',
|
|
17
|
-
pdf: 'application/pdf',
|
|
18
|
-
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
19
|
-
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
20
|
-
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
21
|
-
txt: 'text/plain', csv: 'text/csv', json: 'application/json',
|
|
22
|
-
};
|
|
23
|
-
return map[ext] ?? 'application/octet-stream';
|
|
24
|
-
}
|
|
25
13
|
export function registerDownloadFile(server, config, auth) {
|
|
26
14
|
server.tool('download_file', 'Download a file from a SharePoint document library as base64-encoded content. ' +
|
|
27
15
|
'Images are returned as MCP image content; all other files are returned as a JSON ' +
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
1
2
|
import { UploadFileSchema } from '../schemas.js';
|
|
2
3
|
import { createGraphClient } from '../../graph/clientFactory.js';
|
|
3
4
|
import { uploadFile } from '../../graph/sharepoint.js';
|
|
@@ -6,12 +7,18 @@ import { ToolError, errorResponse } from '../../utils/errors.js';
|
|
|
6
7
|
import { logger } from '../../utils/logger.js';
|
|
7
8
|
import { resolveSharepointLibrary } from '../../utils/resolveSharepointLibrary.js';
|
|
8
9
|
import { splitPath } from '../../utils/pathUtils.js';
|
|
10
|
+
import { mimeFromExtension } from '../../utils/mimeTypes.js';
|
|
9
11
|
const MAX_BYTES = 4 * 1024 * 1024; // 4 MB
|
|
10
12
|
export function registerUploadFile(server, config, auth) {
|
|
11
|
-
server.tool('upload_file', 'Upload a file to a SharePoint document library.
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
13
|
+
server.tool('upload_file', 'Upload a file to a SharePoint document library. Creates the file if it does not exist; ' +
|
|
14
|
+
'overwrites it if it does (SharePoint manages version history). ' +
|
|
15
|
+
'Provide exactly one of sourcePath or content: sourcePath (preferred) reads an existing ' +
|
|
16
|
+
'local file directly from disk; content is a base64 string for small inline payloads only. ' +
|
|
17
|
+
'Passing large content inline has been observed to silently truncate with no error — the ' +
|
|
18
|
+
'response still reports success with a truncated size — so prefer sourcePath for anything ' +
|
|
19
|
+
'above a few KB, and verify with download_file + checksum after uploading via content. ' +
|
|
20
|
+
'Maximum 4 MB. Requires a grant with "create" OR "update" in allowedOperations for the path ' +
|
|
21
|
+
'and filename. Call check_sharepoint_access first to verify permissions.', UploadFileSchema.shape, async (params) => {
|
|
15
22
|
try {
|
|
16
23
|
const library = resolveSharepointLibrary(config, params.libraryId);
|
|
17
24
|
const { folderPath, filename } = splitPath(params.path);
|
|
@@ -23,14 +30,29 @@ export function registerUploadFile(server, config, auth) {
|
|
|
23
30
|
// Report whichever gives a more relevant message (create is the more common intent)
|
|
24
31
|
throw new ToolError(createResult.reason, 'ACCESS_DENIED');
|
|
25
32
|
}
|
|
26
|
-
|
|
33
|
+
if (!params.sourcePath === !params.content) {
|
|
34
|
+
throw new ToolError('Provide exactly one of sourcePath or content, not both or neither.', 'INVALID_PARAMS');
|
|
35
|
+
}
|
|
36
|
+
let buf;
|
|
37
|
+
if (params.sourcePath) {
|
|
38
|
+
try {
|
|
39
|
+
buf = await readFile(params.sourcePath);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
throw new ToolError(`Could not read local file "${params.sourcePath}": ${err.message}`, 'SOURCE_FILE_NOT_FOUND');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
buf = Buffer.from(params.content, 'base64');
|
|
47
|
+
}
|
|
27
48
|
if (buf.byteLength > MAX_BYTES) {
|
|
28
49
|
throw new ToolError(`File is ${(buf.byteLength / 1024 / 1024).toFixed(1)} MB which exceeds the 4 MB ` +
|
|
29
50
|
'simple upload limit. For larger files, chunked upload (resumable sessions) is required.', 'PAYLOAD_TOO_LARGE');
|
|
30
51
|
}
|
|
52
|
+
const contentType = params.contentType ?? mimeFromExtension(filename);
|
|
31
53
|
const token = await auth.getAccessToken(config.accounts[0].id);
|
|
32
54
|
const client = createGraphClient(token);
|
|
33
|
-
const result = await uploadFile(client, library.driveId, params.path, buf,
|
|
55
|
+
const result = await uploadFile(client, library.driveId, params.path, buf, contentType);
|
|
34
56
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
35
57
|
}
|
|
36
58
|
catch (err) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const EXTENSION_MIME_MAP = {
|
|
2
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg',
|
|
3
|
+
gif: 'image/gif', webp: 'image/webp', svg: 'image/svg+xml',
|
|
4
|
+
pdf: 'application/pdf',
|
|
5
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
6
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
7
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
8
|
+
txt: 'text/plain', csv: 'text/csv', json: 'application/json',
|
|
9
|
+
md: 'text/markdown',
|
|
10
|
+
};
|
|
11
|
+
/** Infer a MIME type from a filename's extension, defaulting to application/octet-stream. */
|
|
12
|
+
export function mimeFromExtension(filename) {
|
|
13
|
+
const ext = filename.split('.').pop()?.toLowerCase() ?? '';
|
|
14
|
+
return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnetwork-nz/m365-mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|