@softeria/ms-365-mcp-server 0.185.1 → 0.187.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/server.js CHANGED
@@ -249,7 +249,9 @@ class MicrosoftGraphServer {
249
249
  accountNames: this.accountNames,
250
250
  allowedScopes: this.options.allowedScopes,
251
251
  httpMode: this.hidesStdioOnlyTools(),
252
- userFields: this.options.userFields
252
+ userFields: this.options.userFields,
253
+ // The views parse the tool results as JSON
254
+ mcpApps: Boolean(this.options.enableMcpApps && !this.options.toon)
253
255
  };
254
256
  if (this.options.discovery) {
255
257
  registerDiscoveryTools(server, this.graphClient, registrationOptions);
@@ -311,6 +313,11 @@ class MicrosoftGraphServer {
311
313
  "--http-local-file-tools has no effect in stdio mode, where the local file tools need no flag."
312
314
  );
313
315
  }
316
+ if (this.options.enableMcpApps && this.options.toon) {
317
+ logger.warn(
318
+ "--enable-mcp-apps has no effect with --toon: the MCP Apps views read JSON tool results."
319
+ );
320
+ }
314
321
  if (this.options.obo) {
315
322
  if (!this.options.http) {
316
323
  throw new Error("--obo requires --http (On-Behalf-Of flow only works in HTTP mode).");
package/eslint.config.js CHANGED
@@ -30,6 +30,14 @@ export default [
30
30
  'no-console': 'off',
31
31
  },
32
32
  },
33
+ {
34
+ // MCP Apps views: classic scripts the server inlines into pages in the host's iframe
35
+ files: ['src/apps/**/*.js'],
36
+ languageOptions: {
37
+ parserOptions: { sourceType: 'script' },
38
+ globals: globals.browser,
39
+ },
40
+ },
33
41
  {
34
42
  ignores: [
35
43
  'node_modules/**',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@softeria/ms-365-mcp-server",
3
3
  "mcpName": "io.github.Softeria/ms-365-mcp-server",
4
- "version": "0.185.1",
4
+ "version": "0.187.0",
5
5
  "description": " A Model Context Protocol (MCP) server for interacting with Microsoft 365 and Office services through the Graph API",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -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
+ }
@@ -0,0 +1,157 @@
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
+ __MCP_APP_BRIDGE__
152
+ </script>
153
+ <script>
154
+ __MCP_APP_SCRIPT__
155
+ </script>
156
+ </body>
157
+ </html>