@softeria/ms-365-mcp-server 0.185.1 → 0.186.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 +19 -0
- package/dist/apps/file-browser.html +677 -0
- package/dist/cli.js +6 -0
- package/dist/endpoints.json +2 -1
- package/dist/graph-tools.js +4 -1
- package/dist/mcp-apps.js +68 -0
- package/dist/server.js +8 -1
- package/package.json +1 -1
- package/src/apps/file-browser.html +677 -0
- package/src/endpoints.json +2 -1
- package/tsup.config.ts +2 -1
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Files</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
font-family: var(--font-sans, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
|
|
11
|
+
font-size: var(--font-text-sm-size, 14px);
|
|
12
|
+
line-height: var(--font-text-sm-line-height, 1.4);
|
|
13
|
+
color: var(--color-text-primary, CanvasText);
|
|
14
|
+
background: var(--color-background-primary, transparent);
|
|
15
|
+
}
|
|
16
|
+
* {
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
}
|
|
19
|
+
[hidden] {
|
|
20
|
+
display: none !important;
|
|
21
|
+
}
|
|
22
|
+
body {
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 12px;
|
|
25
|
+
}
|
|
26
|
+
button {
|
|
27
|
+
font: inherit;
|
|
28
|
+
color: inherit;
|
|
29
|
+
}
|
|
30
|
+
header {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: 8px;
|
|
34
|
+
margin-bottom: 8px;
|
|
35
|
+
}
|
|
36
|
+
nav {
|
|
37
|
+
flex: 1;
|
|
38
|
+
min-width: 0;
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-wrap: wrap;
|
|
41
|
+
align-items: center;
|
|
42
|
+
gap: 2px;
|
|
43
|
+
font-weight: var(--font-weight-semibold, 600);
|
|
44
|
+
}
|
|
45
|
+
.crumb {
|
|
46
|
+
border: 0;
|
|
47
|
+
background: none;
|
|
48
|
+
padding: 2px 4px;
|
|
49
|
+
border-radius: var(--border-radius-sm, 4px);
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
color: var(--color-text-info, LinkText);
|
|
52
|
+
}
|
|
53
|
+
.crumb:disabled {
|
|
54
|
+
cursor: default;
|
|
55
|
+
color: inherit;
|
|
56
|
+
}
|
|
57
|
+
.sep {
|
|
58
|
+
color: var(--color-text-tertiary, GrayText);
|
|
59
|
+
}
|
|
60
|
+
.tool {
|
|
61
|
+
flex: none;
|
|
62
|
+
border: 1px solid var(--color-border-secondary, rgba(127, 127, 127, 0.4));
|
|
63
|
+
background: none;
|
|
64
|
+
padding: 4px 10px;
|
|
65
|
+
border-radius: var(--border-radius-sm, 4px);
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
}
|
|
68
|
+
.tool:disabled {
|
|
69
|
+
opacity: 0.5;
|
|
70
|
+
cursor: default;
|
|
71
|
+
}
|
|
72
|
+
ul {
|
|
73
|
+
list-style: none;
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding: 0;
|
|
76
|
+
max-height: 420px;
|
|
77
|
+
overflow-y: auto;
|
|
78
|
+
border-top: 1px solid var(--color-border-tertiary, rgba(127, 127, 127, 0.25));
|
|
79
|
+
}
|
|
80
|
+
li {
|
|
81
|
+
border-bottom: 1px solid var(--color-border-tertiary, rgba(127, 127, 127, 0.25));
|
|
82
|
+
}
|
|
83
|
+
.row {
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
gap: 10px;
|
|
87
|
+
width: 100%;
|
|
88
|
+
padding: 8px 6px;
|
|
89
|
+
border: 0;
|
|
90
|
+
background: none;
|
|
91
|
+
text-align: left;
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
}
|
|
94
|
+
.row:hover:not(:disabled),
|
|
95
|
+
.row:focus-visible {
|
|
96
|
+
background: var(--color-background-secondary, rgba(127, 127, 127, 0.12));
|
|
97
|
+
}
|
|
98
|
+
.row:disabled {
|
|
99
|
+
cursor: default;
|
|
100
|
+
}
|
|
101
|
+
.icon {
|
|
102
|
+
flex: none;
|
|
103
|
+
width: 20px;
|
|
104
|
+
height: 20px;
|
|
105
|
+
}
|
|
106
|
+
.icon.folder path {
|
|
107
|
+
fill: var(--color-text-warning, #d9a21b);
|
|
108
|
+
}
|
|
109
|
+
.icon.file path {
|
|
110
|
+
fill: none;
|
|
111
|
+
stroke: var(--color-text-secondary, GrayText);
|
|
112
|
+
stroke-width: 1.3;
|
|
113
|
+
stroke-linejoin: round;
|
|
114
|
+
}
|
|
115
|
+
.name {
|
|
116
|
+
flex: 1;
|
|
117
|
+
min-width: 0;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
text-overflow: ellipsis;
|
|
120
|
+
white-space: nowrap;
|
|
121
|
+
}
|
|
122
|
+
.meta {
|
|
123
|
+
flex: none;
|
|
124
|
+
color: var(--color-text-secondary, GrayText);
|
|
125
|
+
font-size: var(--font-text-xs-size, 12px);
|
|
126
|
+
}
|
|
127
|
+
#more {
|
|
128
|
+
margin-top: 8px;
|
|
129
|
+
}
|
|
130
|
+
#status {
|
|
131
|
+
margin: 8px 0 0;
|
|
132
|
+
color: var(--color-text-secondary, GrayText);
|
|
133
|
+
}
|
|
134
|
+
#status.error {
|
|
135
|
+
color: var(--color-text-danger, #c62828);
|
|
136
|
+
}
|
|
137
|
+
</style>
|
|
138
|
+
</head>
|
|
139
|
+
<body>
|
|
140
|
+
<header>
|
|
141
|
+
<nav id="crumbs" aria-label="Folder path"></nav>
|
|
142
|
+
<button id="refresh" class="tool" type="button" disabled>Refresh</button>
|
|
143
|
+
</header>
|
|
144
|
+
<ul id="items" hidden></ul>
|
|
145
|
+
<button id="more" class="tool" type="button" hidden>Load more</button>
|
|
146
|
+
<p id="status" role="status">Loading...</p>
|
|
147
|
+
<script type="application/json" id="mcp-app-config">
|
|
148
|
+
__MCP_APP_CONFIG__
|
|
149
|
+
</script>
|
|
150
|
+
<script>
|
|
151
|
+
(() => {
|
|
152
|
+
'use strict';
|
|
153
|
+
|
|
154
|
+
// MCP Apps (spec 2026-01-26): JSON-RPC 2.0 with the host over postMessage
|
|
155
|
+
const PROTOCOL_VERSION = '2026-01-26';
|
|
156
|
+
// What the view needs from each item when it lists a folder itself
|
|
157
|
+
const SELECT =
|
|
158
|
+
'id,name,size,lastModifiedDateTime,webUrl,folder,file,package,parentReference,remoteItem';
|
|
159
|
+
// Without these the view can't open folders or files (id always comes back)
|
|
160
|
+
const NEEDED = ['name', 'folder', 'file', 'webUrl'];
|
|
161
|
+
const PAGE_SIZE = 100;
|
|
162
|
+
// Like the official SDK: a request the host never answers fails instead of hanging
|
|
163
|
+
const REQUEST_TIMEOUT_MS = 60000;
|
|
164
|
+
const FOLDER_ICON =
|
|
165
|
+
'M2 5.5A1.5 1.5 0 0 1 3.5 4h4.4l1.6 2h7A1.5 1.5 0 0 1 18 7.5v7a1.5 1.5 0 0 1-1.5 1.5h-13A1.5 1.5 0 0 1 2 14.5z';
|
|
166
|
+
const FILE_ICON = 'M5 2.5h6.5L15 6v11.5H5zM11.5 2.5V6H15';
|
|
167
|
+
|
|
168
|
+
let config = {};
|
|
169
|
+
try {
|
|
170
|
+
config = JSON.parse(document.getElementById('mcp-app-config').textContent) || {};
|
|
171
|
+
} catch {
|
|
172
|
+
// Unfilled placeholder: the view can still show the result, just not navigate
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const els = {
|
|
176
|
+
crumbs: document.getElementById('crumbs'),
|
|
177
|
+
refresh: document.getElementById('refresh'),
|
|
178
|
+
items: document.getElementById('items'),
|
|
179
|
+
more: document.getElementById('more'),
|
|
180
|
+
status: document.getElementById('status'),
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const state = {
|
|
184
|
+
hostCapabilities: {},
|
|
185
|
+
locale: undefined,
|
|
186
|
+
// Arguments of the tool call the host rendered this view for
|
|
187
|
+
input: undefined,
|
|
188
|
+
// Whether that call's result has arrived
|
|
189
|
+
shown: false,
|
|
190
|
+
// { driveId, id, name } of the folders opened here, outermost first
|
|
191
|
+
crumbs: [],
|
|
192
|
+
items: [],
|
|
193
|
+
nextLink: undefined,
|
|
194
|
+
// The arguments behind the current page; the next page repeats them with skiptoken
|
|
195
|
+
lastArgs: undefined,
|
|
196
|
+
busy: false,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
let nextId = 1;
|
|
200
|
+
const pending = new Map();
|
|
201
|
+
|
|
202
|
+
function post(message) {
|
|
203
|
+
window.parent.postMessage(Object.assign({ jsonrpc: '2.0' }, message), '*');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function request(method, params) {
|
|
207
|
+
const id = nextId++;
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
const timer = setTimeout(
|
|
210
|
+
() => settle(id, new Error('The host did not answer in time.')),
|
|
211
|
+
REQUEST_TIMEOUT_MS
|
|
212
|
+
);
|
|
213
|
+
pending.set(id, { method, resolve, reject, timer });
|
|
214
|
+
post({ id, method, params });
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function settle(id, error, result) {
|
|
219
|
+
const waiter = pending.get(id);
|
|
220
|
+
if (!waiter) return;
|
|
221
|
+
pending.delete(id);
|
|
222
|
+
clearTimeout(waiter.timer);
|
|
223
|
+
if (error) waiter.reject(error);
|
|
224
|
+
else waiter.resolve(result);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function notify(method, params) {
|
|
228
|
+
post({ method, params });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
window.addEventListener('message', (event) => {
|
|
232
|
+
if (event.source !== window.parent) return;
|
|
233
|
+
const msg = event.data;
|
|
234
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') return;
|
|
235
|
+
if (typeof msg.method === 'string') {
|
|
236
|
+
if (msg.id !== undefined) answerHost(msg);
|
|
237
|
+
else onNotification(msg.method, msg.params || {});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (msg.error) settle(msg.id, new Error(msg.error.message || 'The host refused.'));
|
|
241
|
+
else settle(msg.id, undefined, msg.result);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
function answerHost(msg) {
|
|
245
|
+
if (msg.method === 'ui/resource-teardown' || msg.method === 'ping') {
|
|
246
|
+
post({ id: msg.id, result: {} });
|
|
247
|
+
} else {
|
|
248
|
+
post({ id: msg.id, error: { code: -32601, message: 'Method not found' } });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Only the first tool-input and tool-result count: they are the call that opened the
|
|
253
|
+
// view. Hosts may echo the view's own calls here too (the spec's interactive phase),
|
|
254
|
+
// and those answers already come back to load().
|
|
255
|
+
function onNotification(method, params) {
|
|
256
|
+
if (method === 'ui/notifications/tool-input') {
|
|
257
|
+
if (!state.input && !state.shown) {
|
|
258
|
+
state.input = isObject(params.arguments) ? params.arguments : {};
|
|
259
|
+
}
|
|
260
|
+
} else if (method === 'ui/notifications/tool-result') {
|
|
261
|
+
if (!state.shown) {
|
|
262
|
+
state.shown = true;
|
|
263
|
+
showToolResult(params);
|
|
264
|
+
}
|
|
265
|
+
} else if (method === 'ui/notifications/tool-cancelled') {
|
|
266
|
+
if (state.busy) {
|
|
267
|
+
for (const [id, waiter] of pending) {
|
|
268
|
+
if (waiter.method === 'tools/call') {
|
|
269
|
+
settle(id, new Error('The listing was cancelled.'));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
} else if (!state.shown) {
|
|
273
|
+
setStatus('The listing was cancelled.', true);
|
|
274
|
+
}
|
|
275
|
+
} else if (method === 'ui/notifications/host-context-changed') {
|
|
276
|
+
applyHostContext(params);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function applyHostContext(context) {
|
|
281
|
+
if (!isObject(context)) return;
|
|
282
|
+
const root = document.documentElement;
|
|
283
|
+
if (context.theme === 'light' || context.theme === 'dark') {
|
|
284
|
+
root.dataset.theme = context.theme;
|
|
285
|
+
root.style.colorScheme = context.theme;
|
|
286
|
+
}
|
|
287
|
+
const variables = context.styles && context.styles.variables;
|
|
288
|
+
if (isObject(variables)) {
|
|
289
|
+
for (const [name, value] of Object.entries(variables)) {
|
|
290
|
+
if (name.startsWith('--') && typeof value === 'string') {
|
|
291
|
+
root.style.setProperty(name, value);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (typeof context.locale === 'string') state.locale = context.locale;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// A list-folder-style result: { value: [driveItem], @odata.nextLink? } as JSON text
|
|
299
|
+
function readListing(result) {
|
|
300
|
+
const blocks = result && Array.isArray(result.content) ? result.content : [];
|
|
301
|
+
const text = blocks
|
|
302
|
+
.filter((block) => block && block.type === 'text' && typeof block.text === 'string')
|
|
303
|
+
.map((block) => block.text)
|
|
304
|
+
.join('');
|
|
305
|
+
const failed = Boolean(result && result.isError);
|
|
306
|
+
let data;
|
|
307
|
+
try {
|
|
308
|
+
data = JSON.parse(text);
|
|
309
|
+
} catch {
|
|
310
|
+
throw new Error(
|
|
311
|
+
failed
|
|
312
|
+
? text || 'The listing failed.'
|
|
313
|
+
: 'This result is not JSON, so it is not shown here.'
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
if (failed || (isObject(data) && data.error)) {
|
|
317
|
+
throw new Error(errorText(data) || 'The listing failed.');
|
|
318
|
+
}
|
|
319
|
+
if (!isObject(data) || !Array.isArray(data.value)) {
|
|
320
|
+
throw new Error('This result is not a folder listing.');
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
items: data.value.filter(isObject),
|
|
324
|
+
nextLink: str(data['@odata.nextLink']),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// { error: 'text' }, Graph's { error: { message } } or { error: 'code', message }
|
|
329
|
+
function errorText(data) {
|
|
330
|
+
if (!isObject(data)) return undefined;
|
|
331
|
+
if (typeof data.message === 'string') return data.message;
|
|
332
|
+
if (typeof data.error === 'string') return data.error;
|
|
333
|
+
if (isObject(data.error) && typeof data.error.message === 'string') {
|
|
334
|
+
return data.error.message;
|
|
335
|
+
}
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function showToolResult(result) {
|
|
340
|
+
let listing;
|
|
341
|
+
try {
|
|
342
|
+
listing = readListing(result);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
setStatus(error.message, true);
|
|
345
|
+
updateControls();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const input = state.input || {};
|
|
349
|
+
const parent = (listing.items[0] && listing.items[0].parentReference) || {};
|
|
350
|
+
const driveId = str(input.driveId) || str(parent.driveId);
|
|
351
|
+
const id = str(input.driveItemId) || str(parent.id);
|
|
352
|
+
state.crumbs = driveId && id ? [{ driveId, id, name: folderName(parent.path, id) }] : [];
|
|
353
|
+
state.lastArgs = state.input ? pageArgs(state.input) : undefined;
|
|
354
|
+
state.items = listing.items;
|
|
355
|
+
state.nextLink = listing.nextLink;
|
|
356
|
+
render();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// parentReference.path is like /drive/root:/Documents/Reports
|
|
360
|
+
function folderName(path, id) {
|
|
361
|
+
if (typeof path === 'string' && path.includes('root:')) {
|
|
362
|
+
const parts = path
|
|
363
|
+
.slice(path.indexOf('root:') + 5)
|
|
364
|
+
.split('/')
|
|
365
|
+
.filter(Boolean);
|
|
366
|
+
return parts.length ? decode(parts[parts.length - 1]) : 'Root';
|
|
367
|
+
}
|
|
368
|
+
return id === 'root' ? 'Root' : 'Folder';
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function listArgs(driveId, id) {
|
|
372
|
+
const args = { driveId, driveItemId: id, select: SELECT, top: PAGE_SIZE };
|
|
373
|
+
const account = state.input && str(state.input.account);
|
|
374
|
+
if (account) args.account = account;
|
|
375
|
+
return args;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
async function load(args, crumbs, append) {
|
|
379
|
+
if (state.busy || !canCallTools()) return;
|
|
380
|
+
state.busy = true;
|
|
381
|
+
setStatus('Loading...', false);
|
|
382
|
+
updateControls();
|
|
383
|
+
try {
|
|
384
|
+
const result = await request('tools/call', { name: config.toolName, arguments: args });
|
|
385
|
+
const listing = readListing(result);
|
|
386
|
+
state.crumbs = crumbs;
|
|
387
|
+
state.lastArgs = pageArgs(args);
|
|
388
|
+
state.items = append ? state.items.concat(listing.items) : listing.items;
|
|
389
|
+
state.nextLink = listing.nextLink;
|
|
390
|
+
state.busy = false;
|
|
391
|
+
render();
|
|
392
|
+
} catch (error) {
|
|
393
|
+
state.busy = false;
|
|
394
|
+
setStatus(error.message || String(error), true);
|
|
395
|
+
updateControls();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function openFolder(folder) {
|
|
400
|
+
load(listArgs(folder.driveId, folder.id), state.crumbs.concat([folder]), false);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function openCrumb(index) {
|
|
404
|
+
const crumb = state.crumbs[index];
|
|
405
|
+
load(listArgs(crumb.driveId, crumb.id), state.crumbs.slice(0, index + 1), false);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Lists the folder again with the fields the view needs, keeping the listing's own
|
|
409
|
+
// filter or order
|
|
410
|
+
function refresh() {
|
|
411
|
+
const crumb = current();
|
|
412
|
+
if (!crumb) return;
|
|
413
|
+
const args = pageArgs(state.lastArgs || {});
|
|
414
|
+
delete args.excludeResponse;
|
|
415
|
+
load(Object.assign(args, listArgs(crumb.driveId, crumb.id)), state.crumbs, false);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function loadMore() {
|
|
419
|
+
const crumb = current();
|
|
420
|
+
const base = state.lastArgs || (crumb && listArgs(crumb.driveId, crumb.id));
|
|
421
|
+
if (!state.nextLink || !base) return;
|
|
422
|
+
load(Object.assign(pageArgs(base), { skiptoken: state.nextLink }), state.crumbs, true);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async function openLink(url) {
|
|
426
|
+
try {
|
|
427
|
+
const result = await request('ui/open-link', { url });
|
|
428
|
+
if (result && result.isError) setStatus('The host did not open the link.', true);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
setStatus(error.message || 'The host did not open the link.', true);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function render() {
|
|
435
|
+
renderCrumbs();
|
|
436
|
+
const folders = state.items.filter(isFolder);
|
|
437
|
+
const files = state.items.filter((item) => !isFolder(item));
|
|
438
|
+
const rows = folders.concat(files).map(renderRow);
|
|
439
|
+
els.items.replaceChildren(...rows);
|
|
440
|
+
els.items.hidden = rows.length === 0;
|
|
441
|
+
setStatus(rows.length === 0 ? 'This folder is empty.' : selectHint(), false);
|
|
442
|
+
updateControls();
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Models often pick their own select and leave out fields the view needs
|
|
446
|
+
function selectHint() {
|
|
447
|
+
const select = state.lastArgs && state.lastArgs.select;
|
|
448
|
+
if (select === undefined || !canCallTools() || !current()) return '';
|
|
449
|
+
const fields = (Array.isArray(select) ? select : String(select).split(',')).map((field) =>
|
|
450
|
+
String(field).trim().toLowerCase()
|
|
451
|
+
);
|
|
452
|
+
if (NEEDED.every((field) => fields.includes(field.toLowerCase()))) return '';
|
|
453
|
+
return 'This listing leaves out details the browser needs. Refresh to load them.';
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function renderCrumbs() {
|
|
457
|
+
const parts = [];
|
|
458
|
+
state.crumbs.forEach((crumb, index) => {
|
|
459
|
+
if (index > 0) parts.push(span('sep', '/'));
|
|
460
|
+
const button = document.createElement('button');
|
|
461
|
+
button.type = 'button';
|
|
462
|
+
button.className = 'crumb';
|
|
463
|
+
button.textContent = crumb.name;
|
|
464
|
+
if (index === state.crumbs.length - 1) {
|
|
465
|
+
button.disabled = true;
|
|
466
|
+
button.setAttribute('aria-current', 'location');
|
|
467
|
+
} else if (canCallTools()) {
|
|
468
|
+
button.addEventListener('click', () => openCrumb(index));
|
|
469
|
+
} else {
|
|
470
|
+
button.disabled = true;
|
|
471
|
+
}
|
|
472
|
+
parts.push(button);
|
|
473
|
+
});
|
|
474
|
+
els.crumbs.replaceChildren(...parts);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function renderRow(item) {
|
|
478
|
+
// A shortcut to a folder shared from another drive carries the real item here
|
|
479
|
+
const target = isObject(item.remoteItem) ? item.remoteItem : item;
|
|
480
|
+
const folder = isFolder(item);
|
|
481
|
+
const name = str(item.name) || str(target.name) || '(no name)';
|
|
482
|
+
const button = document.createElement('button');
|
|
483
|
+
button.type = 'button';
|
|
484
|
+
button.className = 'row';
|
|
485
|
+
button.title = name;
|
|
486
|
+
button.append(
|
|
487
|
+
icon(folder),
|
|
488
|
+
span('name', name),
|
|
489
|
+
span('meta', describe(item, target, folder))
|
|
490
|
+
);
|
|
491
|
+
const action = rowAction(item, target, folder, name);
|
|
492
|
+
if (action) button.addEventListener('click', action);
|
|
493
|
+
else button.disabled = true;
|
|
494
|
+
const li = document.createElement('li');
|
|
495
|
+
li.append(button);
|
|
496
|
+
return li;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function rowAction(item, target, folder, name) {
|
|
500
|
+
if (folder && canCallTools()) {
|
|
501
|
+
const parent = isObject(target.parentReference) ? target.parentReference : {};
|
|
502
|
+
// A shortcut's folder is on another drive, so never borrow this one's id for it
|
|
503
|
+
const here = target === item ? current() && current().driveId : undefined;
|
|
504
|
+
const driveId = str(parent.driveId) || here;
|
|
505
|
+
const id = str(target.id);
|
|
506
|
+
if (driveId && id) return () => openFolder({ driveId, id, name });
|
|
507
|
+
}
|
|
508
|
+
const url = httpsUrl(target.webUrl) || httpsUrl(item.webUrl);
|
|
509
|
+
if (url && canOpenLinks()) return () => openLink(url);
|
|
510
|
+
return undefined;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function describe(item, target, folder) {
|
|
514
|
+
const parts = [];
|
|
515
|
+
if (folder) {
|
|
516
|
+
const count = target.folder.childCount;
|
|
517
|
+
if (typeof count === 'number') parts.push(count === 1 ? '1 item' : count + ' items');
|
|
518
|
+
} else if (typeof target.size === 'number') {
|
|
519
|
+
parts.push(formatSize(target.size));
|
|
520
|
+
}
|
|
521
|
+
const date = formatDate(target.lastModifiedDateTime || item.lastModifiedDateTime);
|
|
522
|
+
if (date) parts.push(date);
|
|
523
|
+
return parts.join(' · ');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function formatSize(bytes) {
|
|
527
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
528
|
+
let value = bytes;
|
|
529
|
+
let unit = 0;
|
|
530
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
531
|
+
value /= 1024;
|
|
532
|
+
unit++;
|
|
533
|
+
}
|
|
534
|
+
return (
|
|
535
|
+
(unit === 0 ? String(value) : value.toFixed(value < 10 ? 1 : 0)) + ' ' + units[unit]
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function formatDate(value) {
|
|
540
|
+
if (typeof value !== 'string') return '';
|
|
541
|
+
const date = new Date(value);
|
|
542
|
+
if (Number.isNaN(date.getTime())) return '';
|
|
543
|
+
try {
|
|
544
|
+
return new Intl.DateTimeFormat(state.locale, { dateStyle: 'medium' }).format(date);
|
|
545
|
+
} catch {
|
|
546
|
+
return date.toISOString().slice(0, 10);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function icon(folder) {
|
|
551
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
552
|
+
const svg = document.createElementNS(ns, 'svg');
|
|
553
|
+
svg.setAttribute('viewBox', '0 0 20 20');
|
|
554
|
+
svg.setAttribute('class', folder ? 'icon folder' : 'icon file');
|
|
555
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
556
|
+
const path = document.createElementNS(ns, 'path');
|
|
557
|
+
path.setAttribute('d', folder ? FOLDER_ICON : FILE_ICON);
|
|
558
|
+
svg.append(path);
|
|
559
|
+
return svg;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function span(className, text) {
|
|
563
|
+
const el = document.createElement('span');
|
|
564
|
+
el.className = className;
|
|
565
|
+
el.textContent = text;
|
|
566
|
+
return el;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function setStatus(text, isError) {
|
|
570
|
+
els.status.textContent = text;
|
|
571
|
+
els.status.hidden = !text;
|
|
572
|
+
els.status.classList.toggle('error', Boolean(isError));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function updateControls() {
|
|
576
|
+
els.refresh.disabled = state.busy || !current() || !canCallTools();
|
|
577
|
+
els.more.hidden = !state.nextLink || !canCallTools();
|
|
578
|
+
els.more.disabled = state.busy;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function current() {
|
|
582
|
+
return state.crumbs[state.crumbs.length - 1];
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function canCallTools() {
|
|
586
|
+
return Boolean(state.hostCapabilities.serverTools && config.toolName);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function canOpenLinks() {
|
|
590
|
+
return Boolean(state.hostCapabilities.openLinks);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function isFolder(item) {
|
|
594
|
+
const target = isObject(item.remoteItem) ? item.remoteItem : item;
|
|
595
|
+
return isObject(target.folder);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function isObject(value) {
|
|
599
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function str(value) {
|
|
603
|
+
return typeof value === 'string' && value ? value : undefined;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function decode(value) {
|
|
607
|
+
try {
|
|
608
|
+
return decodeURIComponent(value);
|
|
609
|
+
} catch {
|
|
610
|
+
return value;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// The arguments a listing repeats for its next page: no cursor, and never every
|
|
615
|
+
// page at once
|
|
616
|
+
function pageArgs(args) {
|
|
617
|
+
const copy = Object.assign({}, args);
|
|
618
|
+
delete copy.skiptoken;
|
|
619
|
+
delete copy.fetchAllPages;
|
|
620
|
+
return copy;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function httpsUrl(value) {
|
|
624
|
+
if (typeof value !== 'string') return undefined;
|
|
625
|
+
try {
|
|
626
|
+
const url = new URL(value);
|
|
627
|
+
return url.protocol === 'https:' ? url.href : undefined;
|
|
628
|
+
} catch {
|
|
629
|
+
return undefined;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// Tell the host how tall the view is, like the official App's autoResize
|
|
634
|
+
let lastWidth = 0;
|
|
635
|
+
let lastHeight = 0;
|
|
636
|
+
let sizeQueued = false;
|
|
637
|
+
function reportSize() {
|
|
638
|
+
if (sizeQueued) return;
|
|
639
|
+
sizeQueued = true;
|
|
640
|
+
requestAnimationFrame(() => {
|
|
641
|
+
sizeQueued = false;
|
|
642
|
+
const root = document.documentElement;
|
|
643
|
+
const previous = root.style.height;
|
|
644
|
+
root.style.height = 'max-content';
|
|
645
|
+
const height = Math.ceil(root.getBoundingClientRect().height);
|
|
646
|
+
root.style.height = previous;
|
|
647
|
+
const width = Math.ceil(window.innerWidth);
|
|
648
|
+
if (width === lastWidth && height === lastHeight) return;
|
|
649
|
+
lastWidth = width;
|
|
650
|
+
lastHeight = height;
|
|
651
|
+
notify('ui/notifications/size-changed', { width, height });
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
els.refresh.addEventListener('click', refresh);
|
|
656
|
+
els.more.addEventListener('click', loadMore);
|
|
657
|
+
|
|
658
|
+
request('ui/initialize', {
|
|
659
|
+
appInfo: { name: 'ms-365-file-browser', version: '1.0.0' },
|
|
660
|
+
appCapabilities: {},
|
|
661
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
662
|
+
}).then(
|
|
663
|
+
(result) => {
|
|
664
|
+
state.hostCapabilities = (result && result.hostCapabilities) || {};
|
|
665
|
+
applyHostContext(result && result.hostContext);
|
|
666
|
+
notify('ui/notifications/initialized', {});
|
|
667
|
+
const observer = new ResizeObserver(reportSize);
|
|
668
|
+
observer.observe(document.documentElement);
|
|
669
|
+
observer.observe(document.body);
|
|
670
|
+
if (state.items.length || state.crumbs.length) render();
|
|
671
|
+
},
|
|
672
|
+
(error) => setStatus('Could not connect to the host: ' + error.message, true)
|
|
673
|
+
);
|
|
674
|
+
})();
|
|
675
|
+
</script>
|
|
676
|
+
</body>
|
|
677
|
+
</html>
|
package/dist/cli.js
CHANGED
|
@@ -98,6 +98,9 @@ program.name("ms-365-mcp-server").description("Microsoft 365 MCP Server").versio
|
|
|
98
98
|
).option(
|
|
99
99
|
"--allow-unauthenticated-discovery",
|
|
100
100
|
"In HTTP mode, allow MCP discovery requests (initialize, tools/list, prompts/list, resources/list, ping) without a bearer token, so a gateway can enumerate the tool catalog before any user has authenticated. Non-discovery requests (e.g. tools/call) still require a token. Off by default."
|
|
101
|
+
).option(
|
|
102
|
+
"--enable-mcp-apps",
|
|
103
|
+
"(experimental) Show an interactive MCP Apps view for the tools that have one, starting with a OneDrive/SharePoint file browser for folder listings, in hosts that support MCP Apps. Other hosts ignore it. No effect with --toon. Equivalent env var: MS365_MCP_ENABLE_MCP_APPS=true."
|
|
101
104
|
).addOption(
|
|
102
105
|
// DEPRECATED: kept only so existing deployments that set --base-url or
|
|
103
106
|
// MS365_MCP_BASE_URL do not crash at startup. Use --public-url /
|
|
@@ -281,6 +284,9 @@ function parseArgs() {
|
|
|
281
284
|
if (process.env.MS365_MCP_ALLOW_UNAUTHENTICATED_DISCOVERY === "true" || process.env.MS365_MCP_ALLOW_UNAUTHENTICATED_DISCOVERY === "1") {
|
|
282
285
|
options.allowUnauthenticatedDiscovery = true;
|
|
283
286
|
}
|
|
287
|
+
if (process.env.MS365_MCP_ENABLE_MCP_APPS === "true" || process.env.MS365_MCP_ENABLE_MCP_APPS === "1") {
|
|
288
|
+
options.enableMcpApps = true;
|
|
289
|
+
}
|
|
284
290
|
if (options.cloud) {
|
|
285
291
|
process.env.MS365_MCP_CLOUD_TYPE = options.cloud;
|
|
286
292
|
}
|