@softeria/ms-365-mcp-server 0.186.0 → 0.187.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/README.md +35 -12
- package/dist/apps/bridge.js +258 -0
- package/dist/apps/file-browser.html +4 -524
- package/dist/apps/file-browser.js +362 -0
- package/dist/apps/mail-draft.html +109 -0
- package/dist/apps/mail-draft.js +341 -0
- package/dist/cli.js +1 -1
- package/dist/endpoints.json +41 -9
- package/dist/graph-tools.js +27 -3
- package/dist/mcp-apps.js +101 -44
- package/dist/normalize-tool-schema.js +38 -26
- package/eslint.config.js +8 -0
- package/package.json +1 -1
- package/src/apps/bridge.js +258 -0
- package/src/apps/file-browser.html +4 -524
- package/src/apps/file-browser.js +362 -0
- package/src/apps/mail-draft.html +109 -0
- package/src/apps/mail-draft.js +341 -0
- package/src/endpoints.json +41 -9
- package/tsup.config.ts +3 -1
package/README.md
CHANGED
|
@@ -786,16 +786,39 @@ model context. This option does not shrink individual schemas. Without
|
|
|
786
786
|
With `--enable-mcp-apps` (or `MS365_MCP_ENABLE_MCP_APPS=true`), tools that have an
|
|
787
787
|
[MCP Apps](https://github.com/modelcontextprotocol/ext-apps) view show it in hosts that
|
|
788
788
|
support MCP Apps, such as Claude, ChatGPT and VS Code. Other hosts ignore it and get the
|
|
789
|
-
same tool results as before.
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
789
|
+
same tool results as before, except with `excludeResponse` (see below).
|
|
790
|
+
|
|
791
|
+
- **File browser**, for `list-folder-files`: open folders, go back through the folder
|
|
792
|
+
path, load more items and open files in the browser.
|
|
793
|
+
- **Mail draft**, for `create-draft-email`, the reply, reply-all and forward drafts, and
|
|
794
|
+
their shared mailbox versions: the draft's subject, its recipients with every address
|
|
795
|
+
written out, and its body as the plain text Graph gives for it, which in practice writes
|
|
796
|
+
out link and image addresses. It has a Send button and a link to edit it in Outlook.
|
|
797
|
+
Ask for a draft to review a mail before it goes out; `send-mail` still sends straight away.
|
|
798
|
+
|
|
799
|
+
The views get their data through the host, which calls this server's tools again, so they
|
|
800
|
+
need no network access of their own. A click on Send is the user's confirmation, so the
|
|
801
|
+
view sends with `confirm: true`. The mail draft reads the draft itself when it opens, so it
|
|
802
|
+
shows the draft as Graph has it rather than what the model's call returned. Before it sends,
|
|
803
|
+
it reads the draft again: if the draft changed since it was shown, the view shows the new
|
|
804
|
+
version and waits for another click. With `MS365_MCP_BODY_FORMAT=html` the view shows only
|
|
805
|
+
Graph's 255-character preview of the body, and has no Send button.
|
|
806
|
+
|
|
807
|
+
When the model passes `excludeResponse`, the tool's text answer is only `{"success":true}`,
|
|
808
|
+
and the draft goes along as `structuredContent` for the view. The MCP Apps spec keeps
|
|
809
|
+
`structuredContent` out of the model's context, but ChatGPT, and clients without MCP Apps
|
|
810
|
+
that read it, give it to the model as well.
|
|
811
|
+
|
|
812
|
+
A view only offers what this server registers. The Send button needs both
|
|
813
|
+
`get-mail-message` and `send-draft-message` (for a shared mailbox,
|
|
814
|
+
`get-shared-mailbox-message` and `send-shared-mailbox-draft`); when `--enabled-tools` or the
|
|
815
|
+
allowed scopes leave one out, the mail draft has no Send button, and without the read tool
|
|
816
|
+
it shows only the start of the body.
|
|
817
|
+
|
|
818
|
+
- It has no effect with `--toon`, since the views read JSON results.
|
|
819
|
+
- With `--discovery`, only tools published directly with `--eager-tools` show a view, and
|
|
820
|
+
the Send button needs its tools published too, e.g.
|
|
821
|
+
`--discovery --eager-tools create-draft-email,get-mail-message,send-draft-message`.
|
|
799
822
|
|
|
800
823
|
## CLI Options
|
|
801
824
|
|
|
@@ -865,8 +888,8 @@ When running as an MCP server, the following options can be used:
|
|
|
865
888
|
--blob-output File download tools answer an MCP EmbeddedResource with the file instead of
|
|
866
889
|
base64 JSON in a text block (see MS365_MCP_BLOB_OUTPUT below)
|
|
867
890
|
--discovery Dynamic tool discovery: loads tools on demand to reduce initial token usage (see "Dynamic Tool Discovery" above)
|
|
868
|
-
--enable-mcp-apps (experimental) Show the interactive MCP Apps views,
|
|
869
|
-
|
|
891
|
+
--enable-mcp-apps (experimental) Show the interactive MCP Apps views, a OneDrive/SharePoint file browser
|
|
892
|
+
and a mail draft view with a Send button, in hosts that support them (see "MCP Apps" above)
|
|
870
893
|
--public-url <url> Public base URL for OAuth when behind a reverse proxy (see Open WebUI section and docs/deployment.md)
|
|
871
894
|
```
|
|
872
895
|
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/* exported createMcpAppBridge */
|
|
2
|
+
|
|
3
|
+
// MCP Apps (spec 2026-01-26): JSON-RPC 2.0 with the host over postMessage. The server inlines
|
|
4
|
+
// this into every view, before the view's own script, which calls createMcpAppBridge once.
|
|
5
|
+
function createMcpAppBridge(handlers) {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const PROTOCOL_VERSION = '2026-01-26';
|
|
9
|
+
// Like ext-apps' App: a request the host never answers fails after this, and a tool call's
|
|
10
|
+
// timer starts over on each progress notification, so a host heartbeat keeps it alive
|
|
11
|
+
const REQUEST_TIMEOUT_MS = 60000;
|
|
12
|
+
|
|
13
|
+
let nextId = 1;
|
|
14
|
+
const pending = new Map();
|
|
15
|
+
let capabilities = {};
|
|
16
|
+
let locale;
|
|
17
|
+
let inputSeen = false;
|
|
18
|
+
let resultSeen = false;
|
|
19
|
+
|
|
20
|
+
function post(message) {
|
|
21
|
+
window.parent.postMessage(Object.assign({ jsonrpc: '2.0' }, message), '*');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// options.timeout: milliseconds, 0 for none. options.progress: ask for progress notifications.
|
|
25
|
+
function request(method, params, options) {
|
|
26
|
+
const id = nextId++;
|
|
27
|
+
const timeout =
|
|
28
|
+
options && typeof options.timeout === 'number' ? options.timeout : REQUEST_TIMEOUT_MS;
|
|
29
|
+
let sent = params;
|
|
30
|
+
if (options && options.progress) {
|
|
31
|
+
const meta = Object.assign({}, params && params._meta, { progressToken: id });
|
|
32
|
+
sent = Object.assign({}, params, { _meta: meta });
|
|
33
|
+
}
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const waiter = { method, resolve, reject, timeout, timer: undefined };
|
|
36
|
+
pending.set(id, waiter);
|
|
37
|
+
arm(id, waiter);
|
|
38
|
+
post({ id, method, params: sent });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function arm(id, waiter) {
|
|
43
|
+
clearTimeout(waiter.timer);
|
|
44
|
+
if (waiter.timeout > 0) {
|
|
45
|
+
waiter.timer = setTimeout(() => {
|
|
46
|
+
// Like the SDK: tell the host the view gave up, so it can drop the request too
|
|
47
|
+
notify('notifications/cancelled', { requestId: id, reason: 'Timed out' });
|
|
48
|
+
const error = new Error('The host did not answer in time.');
|
|
49
|
+
error.name = 'TimeoutError';
|
|
50
|
+
settle(id, error);
|
|
51
|
+
}, waiter.timeout);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function settle(id, error, result) {
|
|
56
|
+
const waiter = pending.get(id);
|
|
57
|
+
if (!waiter) return;
|
|
58
|
+
pending.delete(id);
|
|
59
|
+
clearTimeout(waiter.timer);
|
|
60
|
+
if (error) waiter.reject(error);
|
|
61
|
+
else waiter.resolve(result);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function notify(method, params) {
|
|
65
|
+
post({ method, params });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
window.addEventListener('message', (event) => {
|
|
69
|
+
if (event.source !== window.parent) return;
|
|
70
|
+
const msg = event.data;
|
|
71
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0') return;
|
|
72
|
+
if (typeof msg.method === 'string') {
|
|
73
|
+
if (msg.id !== undefined) answerHost(msg);
|
|
74
|
+
else onNotification(msg.method, isObject(msg.params) ? msg.params : {});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (msg.error) settle(msg.id, new Error(msg.error.message || 'The host refused.'));
|
|
78
|
+
else settle(msg.id, undefined, msg.result);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
function answerHost(msg) {
|
|
82
|
+
if (msg.method === 'ui/resource-teardown' || msg.method === 'ping') {
|
|
83
|
+
post({ id: msg.id, result: {} });
|
|
84
|
+
} else {
|
|
85
|
+
post({ id: msg.id, error: { code: -32601, message: 'Method not found' } });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Only the first tool-input and tool-result count: they are the call that opened the view.
|
|
90
|
+
// Hosts may echo the view's own calls here too (the spec's interactive phase), and those
|
|
91
|
+
// answers already come back to the request that made them.
|
|
92
|
+
function onNotification(method, params) {
|
|
93
|
+
if (method === 'ui/notifications/tool-input') {
|
|
94
|
+
if (!inputSeen && !resultSeen) {
|
|
95
|
+
inputSeen = true;
|
|
96
|
+
handle('onToolInput', isObject(params.arguments) ? params.arguments : {});
|
|
97
|
+
}
|
|
98
|
+
} else if (method === 'ui/notifications/tool-result') {
|
|
99
|
+
if (!resultSeen) {
|
|
100
|
+
resultSeen = true;
|
|
101
|
+
handle('onToolResult', params);
|
|
102
|
+
}
|
|
103
|
+
} else if (method === 'ui/notifications/tool-cancelled') {
|
|
104
|
+
// This is about the call that opened the view, never one the view made itself, so
|
|
105
|
+
// it means nothing once that call's result is in
|
|
106
|
+
if (!resultSeen) handle('onToolCancelled', params);
|
|
107
|
+
} else if (method === 'notifications/progress') {
|
|
108
|
+
const waiter = pending.get(params.progressToken);
|
|
109
|
+
if (waiter) arm(params.progressToken, waiter);
|
|
110
|
+
} else if (method === 'ui/notifications/host-context-changed') {
|
|
111
|
+
applyHostContext(params);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function applyHostContext(context) {
|
|
116
|
+
if (!isObject(context)) return;
|
|
117
|
+
const root = document.documentElement;
|
|
118
|
+
if (context.theme === 'light' || context.theme === 'dark') {
|
|
119
|
+
root.dataset.theme = context.theme;
|
|
120
|
+
root.style.colorScheme = context.theme;
|
|
121
|
+
}
|
|
122
|
+
const variables = context.styles && context.styles.variables;
|
|
123
|
+
if (isObject(variables)) {
|
|
124
|
+
for (const [name, value] of Object.entries(variables)) {
|
|
125
|
+
if (name.startsWith('--') && typeof value === 'string') {
|
|
126
|
+
root.style.setProperty(name, value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (typeof context.locale === 'string') locale = context.locale;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Tell the host how tall the view is, like the official App's autoResize
|
|
134
|
+
let lastWidth = 0;
|
|
135
|
+
let lastHeight = 0;
|
|
136
|
+
let sizeQueued = false;
|
|
137
|
+
function reportSize() {
|
|
138
|
+
if (sizeQueued) return;
|
|
139
|
+
sizeQueued = true;
|
|
140
|
+
requestAnimationFrame(() => {
|
|
141
|
+
sizeQueued = false;
|
|
142
|
+
const root = document.documentElement;
|
|
143
|
+
const previous = root.style.height;
|
|
144
|
+
root.style.height = 'max-content';
|
|
145
|
+
const height = Math.ceil(root.getBoundingClientRect().height);
|
|
146
|
+
root.style.height = previous;
|
|
147
|
+
const width = Math.ceil(window.innerWidth);
|
|
148
|
+
if (width === lastWidth && height === lastHeight) return;
|
|
149
|
+
lastWidth = width;
|
|
150
|
+
lastHeight = height;
|
|
151
|
+
notify('ui/notifications/size-changed', { width, height });
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// This server's tool results are JSON text; a failure sets isError and has an error field.
|
|
156
|
+
// A body the model asked to leave out comes as structuredContent instead.
|
|
157
|
+
function readToolResult(result, failure) {
|
|
158
|
+
const failed = Boolean(result && result.isError);
|
|
159
|
+
let data =
|
|
160
|
+
!failed && result && isObject(result.structuredContent)
|
|
161
|
+
? result.structuredContent
|
|
162
|
+
: undefined;
|
|
163
|
+
if (data === undefined) {
|
|
164
|
+
const text = resultText(result);
|
|
165
|
+
try {
|
|
166
|
+
data = JSON.parse(text);
|
|
167
|
+
} catch {
|
|
168
|
+
throw new Error(
|
|
169
|
+
failed ? text || failure : 'This result is not JSON, so it is not shown here.'
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (failed || (isObject(data) && data.error)) throw new Error(errorText(data) || failure);
|
|
174
|
+
return data;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// The message of a failed result, undefined when it did not fail. A success need not be
|
|
178
|
+
// JSON at all: Graph answers some actions with an empty body.
|
|
179
|
+
function toolError(result, failure) {
|
|
180
|
+
const text = resultText(result);
|
|
181
|
+
let data;
|
|
182
|
+
try {
|
|
183
|
+
data = JSON.parse(text);
|
|
184
|
+
} catch {
|
|
185
|
+
return result && result.isError ? text || failure : undefined;
|
|
186
|
+
}
|
|
187
|
+
if (!(result && result.isError) && !(isObject(data) && data.error)) return undefined;
|
|
188
|
+
return errorText(data) || text || failure;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function resultText(result) {
|
|
192
|
+
const blocks = result && Array.isArray(result.content) ? result.content : [];
|
|
193
|
+
return blocks
|
|
194
|
+
.filter((block) => block && block.type === 'text' && typeof block.text === 'string')
|
|
195
|
+
.map((block) => block.text)
|
|
196
|
+
.join('');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// { error: 'text' }, Graph's { error: { message } } or { error: 'code', message }
|
|
200
|
+
function errorText(data) {
|
|
201
|
+
if (!isObject(data)) return undefined;
|
|
202
|
+
if (typeof data.message === 'string') return data.message;
|
|
203
|
+
if (typeof data.error === 'string') return data.error;
|
|
204
|
+
if (isObject(data.error) && typeof data.error.message === 'string') {
|
|
205
|
+
return data.error.message;
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function handle(name, value) {
|
|
211
|
+
if (handlers && typeof handlers[name] === 'function') handlers[name](value);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function isObject(value) {
|
|
215
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
request('ui/initialize', {
|
|
219
|
+
appInfo: { name: (handlers && handlers.name) || 'ms-365-app', version: '1.0.0' },
|
|
220
|
+
appCapabilities: {},
|
|
221
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
222
|
+
}).then(
|
|
223
|
+
(result) => {
|
|
224
|
+
capabilities = (result && isObject(result.hostCapabilities) && result.hostCapabilities) || {};
|
|
225
|
+
applyHostContext(result && result.hostContext);
|
|
226
|
+
notify('ui/notifications/initialized', {});
|
|
227
|
+
const observer = new ResizeObserver(reportSize);
|
|
228
|
+
observer.observe(document.documentElement);
|
|
229
|
+
observer.observe(document.body);
|
|
230
|
+
handle('onReady', capabilities);
|
|
231
|
+
},
|
|
232
|
+
(error) => handle('onInitError', error)
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
get capabilities() {
|
|
237
|
+
return capabilities;
|
|
238
|
+
},
|
|
239
|
+
get locale() {
|
|
240
|
+
return locale;
|
|
241
|
+
},
|
|
242
|
+
callTool(name, args, options) {
|
|
243
|
+
return request(
|
|
244
|
+
'tools/call',
|
|
245
|
+
{ name, arguments: args },
|
|
246
|
+
Object.assign({ progress: true }, options)
|
|
247
|
+
);
|
|
248
|
+
},
|
|
249
|
+
openLink(url) {
|
|
250
|
+
return request('ui/open-link', { url });
|
|
251
|
+
},
|
|
252
|
+
updateModelContext(text) {
|
|
253
|
+
return request('ui/update-model-context', { content: [{ type: 'text', text }] });
|
|
254
|
+
},
|
|
255
|
+
readToolResult,
|
|
256
|
+
toolError,
|
|
257
|
+
};
|
|
258
|
+
}
|