emailengine-app 2.79.1 → 2.79.2

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.
Files changed (81) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +40 -0
  3. package/bin/emailengine.js +8 -1
  4. package/config/default.toml +6 -0
  5. package/data/google-crawlers.json +1 -1
  6. package/lib/account.js +95 -18
  7. package/lib/api-routes/account-routes.js +13 -1
  8. package/lib/api-routes/index.js +12 -0
  9. package/lib/api-routes/mailbox-routes.js +6 -0
  10. package/lib/api-routes/mcp-oauth-routes.js +259 -0
  11. package/lib/api-routes/mcp-routes.js +172 -0
  12. package/lib/api-routes/message-routes.js +125 -4
  13. package/lib/api-routes/outbox-routes.js +7 -0
  14. package/lib/api-routes/permission-map.js +97 -1
  15. package/lib/api-routes/route-helpers.js +16 -4
  16. package/lib/api-routes/route-metadata.js +24 -4
  17. package/lib/api-routes/submit-routes.js +41 -0
  18. package/lib/api-routes/template-routes.js +7 -0
  19. package/lib/api-routes/token-routes.js +4 -2
  20. package/lib/consts.js +30 -1
  21. package/lib/email-client/base-client.js +102 -117
  22. package/lib/email-client/gmail-client.js +87 -22
  23. package/lib/email-client/imap/mailbox.js +140 -66
  24. package/lib/email-client/outlook-client.js +17 -14
  25. package/lib/enum-descriptions.js +2 -1
  26. package/lib/field-usage.js +17 -1
  27. package/lib/lua/s-list-accounts.lua +5 -2
  28. package/lib/mcp/index.js +29 -0
  29. package/lib/mcp/inject.js +70 -0
  30. package/lib/mcp/json-schema.js +120 -0
  31. package/lib/mcp/listen.js +171 -0
  32. package/lib/mcp/oauth.js +324 -0
  33. package/lib/mcp/protocol.js +489 -0
  34. package/lib/mcp/resources.js +139 -0
  35. package/lib/mcp/tools.js +655 -0
  36. package/lib/openapi/index.js +3 -1
  37. package/lib/response-stream.js +52 -21
  38. package/lib/routes-ui.js +4 -0
  39. package/lib/schemas.js +24 -3
  40. package/lib/token-permission-view.js +104 -8
  41. package/lib/tokens.js +34 -5
  42. package/lib/tools.js +96 -0
  43. package/lib/ui-routes/account-routes.js +43 -1
  44. package/lib/ui-routes/admin-config-routes.js +114 -1
  45. package/lib/ui-routes/admin-entities-routes.js +54 -5
  46. package/lib/ui-routes/auth-routes.js +13 -0
  47. package/lib/ui-routes/mcp-consent-routes.js +330 -0
  48. package/lib/ui-routes/route-helpers.js +116 -1
  49. package/lib/utils/network.js +9 -1
  50. package/lib/web-safe-html.js +61 -0
  51. package/lib/webhooks.js +3 -8
  52. package/package.json +9 -8
  53. package/sbom.json +1 -1
  54. package/scripts/README.md +25 -0
  55. package/scripts/build-icon.js +77 -0
  56. package/static/css/flyonui.css +1 -1
  57. package/static/css/src/app.tailwind.css +98 -0
  58. package/static/emailengine.ico +0 -0
  59. package/static/js/ui.js +465 -1
  60. package/static/licenses.html +42 -22
  61. package/translations/messages.pot +57 -57
  62. package/views/config/mcp.hbs +361 -0
  63. package/views/config/oauth/index.hbs +7 -0
  64. package/views/layout/prompt.hbs +62 -0
  65. package/views/mcp/authorize.hbs +136 -0
  66. package/views/partials/head_assets.hbs +3 -3
  67. package/views/partials/mcp_access_levels.hbs +13 -0
  68. package/views/partials/mcp_account_limit.hbs +14 -0
  69. package/views/partials/mcp_tool_count.hbs +19 -0
  70. package/views/partials/side_menu.hbs +1 -0
  71. package/views/partials/ui/account-picker.hbs +59 -0
  72. package/views/partials/ui/code-block.hbs +26 -0
  73. package/views/partials/ui/menu-item.hbs +5 -0
  74. package/views/partials/ui/radio.hbs +41 -0
  75. package/views/partials/ui/tab.hbs +15 -10
  76. package/views/partials/ui/tabs.hbs +8 -5
  77. package/views/templates/template.hbs +4 -3
  78. package/views/tokens/index.hbs +8 -2
  79. package/views/tokens/new.hbs +514 -243
  80. package/winconf.js +148 -48
  81. package/workers/api.js +198 -48
@@ -0,0 +1,361 @@
1
+ {{> ui/page-header title="MCP" icon="icon-[tabler--plug-connected]" badgeLabel="Beta" badgeVariant="info" class="mb-1"}}
2
+
3
+ <p class="mb-6">
4
+ Let AI agents work with the connected email accounts over the Model Context Protocol. The MCP endpoint exposes a
5
+ curated tool set (list and search messages, read content, organize and delete messages, create drafts, send mail)
6
+ and accepts the same access tokens as the REST API.
7
+ </p>
8
+
9
+ <div class="mb-6 alert alert-soft alert-info">
10
+ <span class="icon-[tabler--flask] size-5 shrink-0"></span>
11
+ <span>MCP support is in beta. The endpoint is off by default and the tool set may still change between releases -
12
+ feedback is welcome.</span>
13
+ </div>
14
+
15
+ {{#unless mcpFeatureEnabled}}
16
+ <div class="mb-6 alert alert-soft alert-warning">
17
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
18
+ <span>The MCP endpoint is disabled for this deployment (<code>EENGINE_MCP_ENABLED</code> or <code>[mcp]
19
+ enabled</code> in the configuration file), so the settings below have no effect until that gate is turned
20
+ back on and EmailEngine is restarted.</span>
21
+ </div>
22
+ {{/unless}}
23
+
24
+ {{!-- Two jobs share this page: configuring the instance (a settings form, done once) and
25
+ connecting agents (done every time a new client shows up). Tabbed so each reads as the
26
+ other settings pages do - the form's Save sits at the bottom of its own content instead
27
+ of mid-page above a wall of unrelated cards. Settings stays the default tab so a
28
+ validation-error re-render can never hide the errors behind the other tab. --}}
29
+ {{#> ui/tabs label="MCP configuration sections" class="mb-6"}}
30
+ {{> ui/tab target="mcp-settings" label="Settings" active=true}}
31
+ {{> ui/tab target="mcp-connect" label="Connect an agent"}}
32
+ {{/ui/tabs}}
33
+
34
+ <div id="mcp-settings" role="tabpanel" aria-labelledby="mcp-settings-tab">
35
+
36
+ <form method="post" action="/admin/config/mcp">
37
+ {{!-- no id: the layout already renders the #crumb element scripts read --}}
38
+ <input type="hidden" name="crumb" value="{{crumb}}" />
39
+
40
+ {{#> ui/card bodyClass="space-y-4"}}
41
+ <div>
42
+ {{> ui/setting-ref name="mcpEnabled"}}
43
+ {{> ui/checkbox id="settingsMcpEnabled" name="mcpEnabled" label="Enable the MCP endpoint"
44
+ checked=values.mcpEnabled error=errors.mcpEnabled}}
45
+ <span class="helper-text">Serves the Model Context Protocol at <code>/mcp</code>. The
46
+ <button type="button" class="link cursor-pointer" data-goto-tab="mcp-connect">Connect an agent</button> tab
47
+ generates access tokens and ready-to-paste setup for clients; a token with the <code>mcp</code> scope works
48
+ only here and not against the REST API.</span>
49
+ </div>
50
+
51
+ {{!-- Nested rather than a peer: OAuth is a sub-option of an endpoint that is already on,
52
+ not a second decision of equal weight. It adds the sign-in path for clients that
53
+ cannot hold a static token, so with the endpoint off it decides nothing. The nesting
54
+ is presentational only - the checkbox is never disabled, so toggling the endpoint off
55
+ and back on cannot silently clear the stored setting. --}}
56
+ <div class="ps-6">
57
+ {{> ui/setting-ref name="mcpOAuthEnabled"}}
58
+ {{> ui/checkbox id="settingsMcpOAuthEnabled" name="mcpOAuthEnabled" label="Enable OAuth sign-in for MCP clients"
59
+ checked=values.mcpOAuthEnabled error=errors.mcpOAuthEnabled}}
60
+ <span class="helper-text">For web connectors and other MCP clients that cannot be configured with a static
61
+ token. Requires the Service URL to be set under General. The
62
+ <button type="button" class="link cursor-pointer" data-goto-tab="mcp-connect-oauth">Connect an agent</button>
63
+ tab shows exactly what to enter in the client's connector form.</span>
64
+ </div>
65
+ {{/ui/card}}
66
+
67
+ <div class="mb-6">
68
+ {{> ui/btn label="Save Changes" type="submit" icon="icon-[tabler--settings]"}}
69
+ </div>
70
+ </form>
71
+
72
+ </div>
73
+
74
+ <div id="mcp-connect" class="hidden" role="tabpanel" aria-labelledby="mcp-connect-tab">
75
+
76
+ {{!-- Only the "gate on, setting off" state: with the deployment gate off, the page-level
77
+ warning above already says the settings are inert, and telling the operator to flip a
78
+ switch that will not help would contradict it --}}
79
+ {{#if mcpFeatureEnabled}}
80
+ {{#unless values.mcpEnabled}}
81
+ <div class="mb-6 alert alert-soft alert-warning">
82
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
83
+ <span>The MCP endpoint is not enabled yet, so a connected client would get nothing to talk to. Turn it on under
84
+ <button type="button" class="link cursor-pointer" data-goto-tab="mcp-settings">Settings</button> first.</span>
85
+ </div>
86
+ {{/unless}}
87
+ {{/if}}
88
+
89
+ {{!-- The two connection methods are mutually exclusive per client, so they are a segmented
90
+ switch (labeled by client type - "which one am I connecting" is the question the operator
91
+ arrives with), not stacked cards to scroll past. Deliberately vendor-neutral: EmailEngine
92
+ is a generic MCP server, so specific clients appear only as examples inside the panels.
93
+ The badge and the OAuth panel's warnings all key on the one route-supplied
94
+ oauthMethodBlocker, which also owns the rationale for keeping a blocked method's tab
95
+ clickable. --}}
96
+ {{#> ui/tabs label="Connection methods" variant="segment" class="mb-4"}}
97
+ {{> ui/tab target="mcp-connect-token" label="Desktop and self-hosted agents" active=true}}
98
+ {{> ui/tab target="mcp-connect-oauth" label="Web connectors"
99
+ badgeLabel=(when oauthMethodBlocker "not enabled" "") badgeVariant="warning"}}
100
+ {{/ui/tabs}}
101
+
102
+ <div id="mcp-connect-token" role="tabpanel" aria-labelledby="mcp-connect-token-tab">
103
+
104
+ {{#> ui/card bodyClass="space-y-4"}}
105
+
106
+ <p class="text-sm">Generate an access token and ready-to-paste client configuration in one step. The token gets the
107
+ <code>mcp</code> scope, so it works against the MCP endpoint and nothing else.</p>
108
+
109
+ {{#unless canProvision}}
110
+ <div class="alert alert-soft alert-warning text-sm">
111
+ <span class="icon-[tabler--lock] size-5 shrink-0"></span>
112
+ <span>Generating a token requires an authenticated admin session. Set an admin password and sign in first.</span>
113
+ </div>
114
+ {{/unless}}
115
+
116
+ <div id="mcpTokenGen" data-presets="{{json mcpAccessPresets}}" data-mcp-url="{{mcpUrl}}" class="space-y-4">
117
+ {{!-- One column on purpose: two-up put the account field a full screen away from its
118
+ label-mate on wide displays, and the form reads as one top-to-bottom flow --}}
119
+ {{> ui/form-field id="mcpGenLabel" label="What is this token for?" placeholder="for example Cursor or Claude"
120
+ hint="Shows up as the token description, so you can tell agents apart on the Access Tokens page."}}
121
+
122
+ {{> mcp_account_limit id="mcpGenAccount"}}
123
+
124
+ <fieldset class="space-y-2">
125
+ <legend class="label-text mb-1">Access level</legend>
126
+ {{> mcp_access_levels name="mcpGenAccess" idPrefix="mcpGenAccess" selected="read"}}
127
+
128
+ {{!-- What the selected level actually leaves the client able to call, which the level
129
+ names alone cannot say: the count follows both the level and the account limit
130
+ above, exactly as tools/list will --}}
131
+ {{> mcp_tool_count id="mcpGenToolCount" levelName="mcpGenAccess" accountId="mcpGenAccount" class="pt-1"}}
132
+
133
+ {{!-- At the decision point rather than only in the collapsed manual-config block: the
134
+ level chosen here is what decides whether injected instructions can act --}}
135
+ <p class="text-base-content/60 text-sm">Email content flows into whatever model the connected client runs, and
136
+ instructions inside received mail can steer it - grant sending and deleting rights deliberately.</p>
137
+ </fieldset>
138
+
139
+ <div class="flex items-center gap-3">
140
+ {{#if canProvision}}
141
+ <button type="button" id="mcpGenSubmit" class="btn btn-primary">
142
+ <span class="icon-[tabler--key] size-4 shrink-0"></span>Generate connection command
143
+ </button>
144
+ {{/if}}
145
+ <span id="mcpGenError" class="text-error text-sm hidden"></span>
146
+ </div>
147
+
148
+ <div id="mcpGenResult" class="hidden space-y-4">
149
+ <div class="alert alert-soft alert-warning text-sm">
150
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
151
+ {{!-- Just the one-time warning: the standing footer below already carries the
152
+ Access Tokens review/revoke pointer --}}
153
+ <span>The token below is shown only once.</span>
154
+ </div>
155
+
156
+ {{#> ui/code-block id="mcpGenJsonCfg" label="JSON configuration" copy=true}}
157
+ For clients configured through a JSON file, for example Cursor or a project-level <code>.mcp.json</code>. Some
158
+ clients name the top-level key <code>servers</code> instead of <code>mcpServers</code>.
159
+ {{/ui/code-block}}
160
+
161
+ {{#> ui/code-block id="mcpGenClaudeCmd" label="Command-line example (Claude Code)" copy=true}}
162
+ Other command-line clients register MCP servers with a similar command - check the client's documentation.
163
+ {{/ui/code-block}}
164
+ </div>
165
+
166
+ <div class="text-sm text-base-content/60">
167
+ Every connected agent is an ordinary access token with the <code>mcp</code> scope - review or revoke them on
168
+ the <a href="/admin/tokens?scope=mcp" class="link">Access Tokens</a> page.
169
+ </div>
170
+ </div>
171
+
172
+ {{/ui/card}}
173
+
174
+ {{#> ui/details summary="Manual configuration" class="card bg-base-100 shadow-md mb-6"}}
175
+ <div class="space-y-4">
176
+
177
+ <div>
178
+ <label class="label-text" for="mcpEndpointUrl">MCP endpoint</label>
179
+ {{> ui/copy-field id="mcpEndpointUrl" value=mcpUrl ariaLabel="MCP endpoint URL"}}
180
+ </div>
181
+
182
+ {{#unless serviceUrlConfigured}}
183
+ <div class="alert alert-soft alert-info text-sm">
184
+ <span class="icon-[tabler--info-circle] size-5 shrink-0"></span>
185
+ <span>No Service URL is configured, so the address above is how this browser reached the instance. Set the
186
+ Service URL on the <a href="/admin/config/service" class="link">General</a> page to pin the public
187
+ endpoint address.</span>
188
+ </div>
189
+ {{/unless}}
190
+
191
+ {{> ui/code-block id="mcpManualJsonCfg" label="JSON configuration"}}
192
+
193
+ {{> ui/code-block id="mcpManualClaudeCmd" label="Command-line example (Claude Code)"}}
194
+
195
+ {{!-- No prompt-injection sentence here: the generator fieldset in this same panel already
196
+ carries it, at the point where the access level is chosen --}}
197
+ <div class="text-sm text-base-content/60">
198
+ Any access token from the <a href="/admin/tokens" class="link">Access Tokens</a> page works. For an AI agent,
199
+ prefer a token bound to a single account, with the <code>mcp</code> scope.
200
+ </div>
201
+
202
+ </div>
203
+ {{/ui/details}}
204
+
205
+ </div>
206
+
207
+ <div id="mcp-connect-oauth" class="hidden" role="tabpanel" aria-labelledby="mcp-connect-oauth-tab">
208
+
209
+ {{#> ui/card bodyClass="space-y-4"}}
210
+
211
+ <p class="text-sm">Web-based agents (for example a claude.ai connector) cannot store a pre-made token, so the
212
+ client signs itself in with OAuth instead. In the client, fill the connector form like this:</p>
213
+
214
+ {{!-- One blocking precondition at a time, keyed on the same oauthMethodBlocker the tab badge
215
+ reads, so the badge and its "matching warning" cannot disagree --}}
216
+ {{#equals oauthMethodBlocker 'setting'}}
217
+ <div class="alert alert-soft alert-warning text-sm">
218
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
219
+ <span>OAuth sign-in is not enabled yet, so a connector cannot sign itself in. Turn on "Enable OAuth sign-in for
220
+ MCP clients" under <button type="button" class="link cursor-pointer" data-goto-tab="mcp-settings">Settings</button>
221
+ first.</span>
222
+ </div>
223
+ {{/equals}}
224
+ {{#equals oauthMethodBlocker 'serviceUrl'}}
225
+ <div class="alert alert-soft alert-warning text-sm">
226
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
227
+ <span>No Service URL is configured, and OAuth sign-in stays inactive without one - the sign-in flow has to
228
+ publish a fixed public address. Set it on the <a href="/admin/config/service" class="link">General</a>
229
+ page.</span>
230
+ </div>
231
+ {{/equals}}
232
+
233
+ <div>
234
+ <span class="label-text">Name</span>
235
+ <p class="text-base-content/60 text-sm">Anything that identifies this instance in the client, for example
236
+ "EmailEngine".</p>
237
+ </div>
238
+
239
+ <div>
240
+ <label class="label-text" for="mcpOAuthUrl">Remote MCP server URL</label>
241
+ {{> ui/copy-field id="mcpOAuthUrl" value=mcpUrl ariaLabel="MCP endpoint URL for OAuth connectors"}}
242
+ <span class="helper-text">The full endpoint address, including the <code>/mcp</code> path.</span>
243
+ </div>
244
+
245
+ <div>
246
+ <span class="label-text">OAuth Client ID and Client Secret</span>
247
+ <p class="text-base-content/60 text-sm">Leave both empty - there is no pre-made client ID to copy. EmailEngine
248
+ supports automatic client registration, so the connector creates its own credentials when it first connects.
249
+ Some clients, claude.ai among them, keep these fields behind an "Advanced settings" toggle.</p>
250
+ </div>
251
+
252
+ <div>
253
+ <span class="label-text">What happens next</span>
254
+ <ol class="text-base-content/80 ms-4 mt-1 list-decimal space-y-1 text-sm">
255
+ <li>When you connect, the client opens this instance's authorization prompt in the browser. Sign in with the
256
+ admin credentials if asked.</li>
257
+ <li>On the prompt, pick the access level (read-only is the default) and optionally limit the connector to a
258
+ single account, then approve.</li>
259
+ <li>The connector receives its own access token with the <code>mcp</code> scope - review or revoke it at any
260
+ time on the <a href="/admin/tokens?scope=mcp" class="link">Access Tokens</a> page.</li>
261
+ </ol>
262
+ </div>
263
+
264
+ <div class="text-base-content/60 text-sm">Approval happens on the admin interface, so it works wherever admin access
265
+ works - if admin access is limited to specific IP addresses (<code>EENGINE_ADMIN_ACCESS_ADDRESSES</code>), connect
266
+ new clients from one of those addresses.</div>
267
+
268
+ {{/ui/card}}
269
+
270
+ </div>
271
+
272
+ {{!-- Outside the method panels: what a connected agent receives is the same either way --}}
273
+ {{#> ui/details summary="Exposed tools" summarySmall=(concat toolCatalog.length " tools") class="card bg-base-100 shadow-md mb-6"}}
274
+ <div>
275
+ <p class="text-sm text-base-content/60 mb-4">This is exactly what a connected agent receives from
276
+ <code>tools/list</code>. Whether a given token can call a tool also depends on its account binding and
277
+ permission restrictions.</p>
278
+ <div class="space-y-3">
279
+ {{#each toolCatalog}}
280
+ <div class="flex flex-wrap items-baseline gap-2">
281
+ <code>{{name}}</code>
282
+ {{> ui/badge label=badge.label variant=badge.variant soft=true}}
283
+ <span class="text-sm text-base-content/60 basis-full sm:basis-auto sm:grow">{{description}}</span>
284
+ </div>
285
+ {{/each}}
286
+ </div>
287
+ </div>
288
+ {{/ui/details}}
289
+
290
+ </div>
291
+
292
+ <script>
293
+ (() => {
294
+ let container = document.getElementById('mcpTokenGen');
295
+ let presets = JSON.parse(container.dataset.presets || '{}');
296
+ let mcpUrl = container.dataset.mcpUrl;
297
+
298
+ // The one place each artifact is written; the manual block shows them with a
299
+ // placeholder, the generator repeats them with the real token. The mcpServers shape
300
+ // is what most JSON-configured clients read (Cursor, project-level .mcp.json files);
301
+ // "type" disambiguates the transport for clients that ask.
302
+ let claudeCommand = token => 'claude mcp add --transport http emailengine ' + mcpUrl + ' \\\n --header "Authorization: Bearer ' + token + '"';
303
+ let jsonConfig = token =>
304
+ JSON.stringify({ mcpServers: { emailengine: { type: 'http', url: mcpUrl, headers: { Authorization: 'Bearer ' + token } } } }, null, 4);
305
+
306
+ document.getElementById('mcpManualJsonCfg').textContent = jsonConfig('<access token>');
307
+ document.getElementById('mcpManualClaudeCmd').textContent = claudeCommand('<access token>');
308
+
309
+ // Cross-tab pointers on this page use data-goto-tab, handled centrally in ui.js
310
+
311
+ let submitElm = document.getElementById('mcpGenSubmit');
312
+ if (!submitElm) {
313
+ return;
314
+ }
315
+
316
+ let errorElm = document.getElementById('mcpGenError');
317
+
318
+ submitElm.addEventListener('click', async () => {
319
+ errorElm.classList.add('hidden');
320
+ uiButtonBusy(submitElm, true);
321
+
322
+ let label = (document.getElementById('mcpGenLabel').value || '').trim() || 'MCP agent';
323
+ let account = (document.getElementById('mcpGenAccount').value || '').trim();
324
+ let accessElm = document.querySelector('input[name="mcpGenAccess"]:checked');
325
+ let access = (accessElm && accessElm.value) || 'read';
326
+
327
+ try {
328
+ if (!Object.prototype.hasOwnProperty.call(presets, access)) {
329
+ // A missing preset must not silently mint a wider credential than the
330
+ // selected level promises
331
+ throw new Error('The access preset failed to load. Reload the page and try again.');
332
+ }
333
+
334
+ let data = await uiPostJson('/admin/tokens/new', {
335
+ description: 'MCP: ' + label,
336
+ scopes: ['mcp'],
337
+ // The empty string, not null: accountIdSchema is `Joi.string().empty('')`,
338
+ // which converts '' to the schema default and refuses an explicit null
339
+ account: account,
340
+ // The access-level table maps 'full' to null: the absence of a permissions
341
+ // record, because the mcp scope already bounds the token to the MCP surface
342
+ permissions: presets[access]
343
+ });
344
+
345
+ if (!data.success) {
346
+ throw new Error(data.message || data.error || 'Failed to generate the token');
347
+ }
348
+
349
+ document.getElementById('mcpGenJsonCfg').textContent = jsonConfig(data.token);
350
+ document.getElementById('mcpGenClaudeCmd').textContent = claudeCommand(data.token);
351
+
352
+ document.getElementById('mcpGenResult').classList.remove('hidden');
353
+ } catch (err) {
354
+ errorElm.textContent = err.message;
355
+ errorElm.classList.remove('hidden');
356
+ } finally {
357
+ uiButtonBusy(submitElm, false);
358
+ }
359
+ });
360
+ })();
361
+ </script>
@@ -40,6 +40,13 @@
40
40
  {{> ui/row-link href=(concat "/admin/config/oauth/app/" id) label="Open OAuth2 app"}}
41
41
  <div><strong>{{name}}</strong></div>
42
42
  {{> ui/entity-id id=id prefix="Provider ID"}}
43
+ {{!-- The provider-issued client id, which for Azure Entra is the same
44
+ value the portal lists as "Application (client) ID" - showing it
45
+ here is what lets an operator match this row against the Entra
46
+ app list without opening every app --}}
47
+ {{#if clientId}}
48
+ <div>{{> ui/entity-id id=clientId prefix="Client ID"}}</div>
49
+ {{/if}}
43
50
  </td>
44
51
 
45
52
  <td class="relative">
@@ -0,0 +1,62 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+
6
+ <meta charset="utf-8">
7
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
9
+ <meta name="description" content="EmailEngine Application page; The Ultimate Email API for Developers" />
10
+ <meta name="author" content="Postal Systems OÜ">
11
+
12
+ <title>{{#if pageTitleFull}}{{pageTitleFull}}{{else}}{{pageBrandName}}{{#if pageTitle}} &ndash;
13
+ {{pageTitle}}{{/if}}{{/if}}</title>
14
+
15
+ {{> head_assets}}
16
+
17
+ <link href="/static/css/flyonui.css" rel="stylesheet">
18
+
19
+ </head>
20
+
21
+ {{!-- Focused single-decision pages (the MCP consent prompt): one centered card with no
22
+ navigation chrome, so the page reads as a dialog rather than a place in the admin app.
23
+ Still an admin-surface layout - same design system, assets and session handling as the
24
+ login layout it mirrors - NOT one of the framework-free public pages. --}}
25
+
26
+ <body class="from-primary to-secondary min-h-screen bg-gradient-to-br">
27
+
28
+ <div class="container mx-auto px-4">
29
+
30
+ <div class="flex justify-center">
31
+
32
+ <div class="w-full max-w-xl">
33
+
34
+ <div class="card bg-base-100 my-12 overflow-hidden shadow-lg">
35
+ <div class="alert-margin">
36
+ {{> alerts}}
37
+
38
+ <div class="p-8 sm:p-10">
39
+
40
+ <div class="mb-8 flex justify-center">
41
+ <img src="/static/logo/EmailEngine_logo_horiz.png" alt="EmailEngine" class="max-h-7">
42
+ </div>
43
+
44
+ {{{content}}}
45
+ </div>
46
+ </div>
47
+ </div>
48
+
49
+ </div>
50
+
51
+ </div>
52
+
53
+ </div>
54
+
55
+ <script src="/static/js/flyonui.js"></script>
56
+ <script src="/static/js/ui.js"></script>
57
+
58
+ <script src="/static/js/app.js"></script>
59
+
60
+ </body>
61
+
62
+ </html>
@@ -0,0 +1,136 @@
1
+ {{!-- The human decision point of the MCP OAuth flow, rendered in the chrome-free `prompt`
2
+ layout so it reads as a consent dialog rather than a settings page. The operator arrives
3
+ here from an MCP client, decides, and leaves - the admin navigation would only suggest
4
+ this is a place to stay. --}}
5
+
6
+ {{#if errorMessage}}
7
+
8
+ <div class="text-center">
9
+ <div class="bg-warning/10 text-warning mx-auto mb-4 flex size-12 items-center justify-center rounded-full">
10
+ <span class="icon-[tabler--plug-connected-x] size-6"></span>
11
+ </div>
12
+ <h1 class="text-base-content mb-2 text-xl font-semibold">Cannot authorize this client</h1>
13
+ <p class="text-base-content/60 mb-6 text-sm">{{errorMessage}}</p>
14
+ <a href="/admin" class="link link-animated text-sm">Go to the EmailEngine dashboard</a>
15
+ </div>
16
+
17
+ {{else}}
18
+
19
+ <div class="mb-6 text-center">
20
+ <div class="bg-primary/10 text-primary mx-auto mb-4 flex size-12 items-center justify-center rounded-full">
21
+ <span class="icon-[tabler--plug-connected] size-6"></span>
22
+ </div>
23
+ <h1 class="text-base-content text-xl font-semibold">{{clientName}} wants to connect
24
+ {{!-- The same Beta label the config page, the side menu and the token form carry. This is
25
+ the one MCP surface a person can reach without passing one of those first, so it is
26
+ also the one where the label would otherwise be missing. --}}
27
+ {{> ui/badge label="Beta" variant="info" soft=true class="badge-sm align-middle"}}</h1>
28
+ <p class="text-base-content/60 mt-2 text-sm">An MCP client is asking for access to the email accounts on this
29
+ EmailEngine instance. Once you decide, the browser returns to <code>{{redirectHost}}</code>.</p>
30
+ </div>
31
+
32
+ {{#unless canProvision}}
33
+ <div class="alert alert-soft alert-warning mb-6 text-sm">
34
+ <span class="icon-[tabler--lock] size-5 shrink-0"></span>
35
+ <span>Authorizing a client requires an authenticated admin session.
36
+ <a href="/admin/account/password" target="_blank" rel="noopener noreferrer" class="link">Set an admin
37
+ password</a> and sign in first - otherwise this request can only be denied.</span>
38
+ </div>
39
+ {{/unless}}
40
+
41
+ <form method="post" action="/admin/mcp/authorize">
42
+ <input type="hidden" name="crumb" value="{{crumb}}" />
43
+ <input type="hidden" name="client_id" value="{{values.client_id}}" />
44
+ <input type="hidden" name="redirect_uri" value="{{values.redirect_uri}}" />
45
+ <input type="hidden" name="state" value="{{values.state}}" />
46
+ <input type="hidden" name="code_challenge" value="{{values.code_challenge}}" />
47
+ <input type="hidden" name="resource" value="{{values.resource}}" />
48
+
49
+ <div class="space-y-4">
50
+
51
+ <fieldset class="space-y-2">
52
+ <legend class="label-text mb-1">Access level</legend>
53
+ {{> mcp_access_levels name="access" idPrefix="access" selected=accessLevel}}
54
+ </fieldset>
55
+
56
+ {{!-- The grant word lists come from MCP_GRANT_WORDING (derived from SURFACE_GRANTS.mcp,
57
+ never written out here), so this screen cannot promise less than the token grants
58
+ after the tool set changes. The framing prose around them is bespoke per level - a
59
+ level added to MCP_ACCESS_LEVELS needs its own alert block here. One is visible at
60
+ a time - the one describing the selected access level. --}}
61
+ <div data-access="read" class="consent-grant alert alert-soft alert-info text-sm{{#equals accessLevel 'read'}}{{else}} hidden{{/equals}}">
62
+ <span class="icon-[tabler--info-circle] size-5 shrink-0"></span>
63
+ <span>Through the MCP tool set the client will be able to <strong>{{grantWording.read.actions}}</strong>
64
+ {{grantWording.read.groups}} on the accounts its token can reach. It cannot send email, delete anything,
65
+ change anything, read stored credentials, or change instance settings.</span>
66
+ </div>
67
+
68
+ <div data-access="mail" class="consent-grant alert alert-soft alert-warning text-sm{{#equals accessLevel 'mail'}}{{else}} hidden{{/equals}}">
69
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
70
+ <span>Through the MCP tool set the client will be able to <strong>{{grantWording.mail.actions}}</strong>
71
+ across {{grantWording.mail.groups}} on the accounts its token can reach - everything except the delete
72
+ tool. Instructions inside received mail are a real prompt-injection risk once sending is granted. It
73
+ cannot read stored credentials or change instance settings.</span>
74
+ </div>
75
+
76
+ <div data-access="full" class="consent-grant alert alert-soft alert-warning text-sm{{#equals accessLevel 'full'}}{{else}} hidden{{/equals}}">
77
+ <span class="icon-[tabler--alert-triangle] size-5 shrink-0"></span>
78
+ <span>Through the MCP tool set the client will be able to <strong>{{grantWording.full.actions}}</strong>
79
+ across {{grantWording.full.groups}} on the accounts its token can reach. Instructions inside received
80
+ mail are a real prompt-injection risk once sending is granted. It cannot read stored credentials or
81
+ change instance settings.</span>
82
+ </div>
83
+
84
+ <div>
85
+ {{> mcp_account_limit id="account" value=values.account selected=selectedAccount error=errors.account}}
86
+ </div>
87
+
88
+ {{!-- The grant sentences above say what a level allows in the permission vocabulary; this
89
+ says which tools the client ends up holding, which is closer to the thing being
90
+ approved. Follows the account field too, because limiting the client to one account
91
+ takes the instance-wide tools away from it. --}}
92
+ {{> mcp_tool_count id="consentToolCount" levelName="access" accountId="account"}}
93
+
94
+ <div class="flex gap-3 pt-2">
95
+ <button type="submit" name="decision" value="deny" class="btn btn-neutral btn-outline grow">
96
+ <span class="icon-[tabler--x] size-4 shrink-0"></span>Deny
97
+ </button>
98
+ {{!-- Denying needs no admin session, so that button works in every state the page
99
+ renders in --}}
100
+ {{#if canProvision}}
101
+ <button type="submit" name="decision" value="approve" class="btn btn-primary grow">
102
+ <span class="icon-[tabler--check] size-4 shrink-0"></span>Approve
103
+ </button>
104
+ {{/if}}
105
+ </div>
106
+
107
+ {{!-- The lifecycle is revocation, not expiry: this flow issues no refresh token and sets no
108
+ TTL, so an approved client holds its token until someone takes it away. Said here
109
+ because this is the screen where the decision is made, and the person making it has
110
+ no other place to learn it. --}}
111
+ <p class="text-base-content/60 text-center text-xs">Approving creates an access token with the <code>mcp</code>
112
+ scope. It does not expire - it appears on the <a href="/admin/tokens?scope=mcp" class="link">Access
113
+ Tokens</a> page and stays valid until you revoke it there.</p>
114
+
115
+ </div>
116
+ </form>
117
+
118
+ <script>
119
+ (() => {
120
+ // The grant sentences describe the same token under each setting of the radio, so
121
+ // whichever is showing is the one the operator is about to approve
122
+ let radios = Array.from(document.querySelectorAll('input[name="access"]'));
123
+ let grants = Array.from(document.querySelectorAll('.consent-grant'));
124
+
125
+ let sync = () => {
126
+ let selected = radios.find(radio => radio.checked);
127
+ let access = (selected && selected.value) || 'read';
128
+ grants.forEach(grant => grant.classList.toggle('hidden', grant.dataset.access !== access));
129
+ };
130
+
131
+ radios.forEach(radio => radio.addEventListener('change', sync));
132
+ sync();
133
+ })();
134
+ </script>
135
+
136
+ {{/if}}
@@ -1,6 +1,6 @@
1
- {{!-- Shared head assets for the admin layouts (app/login/main): favicons, the
2
- pre-paint theme script, and the self-hosted PT Sans font. Stylesheets stay
3
- in the layouts - their order relative to page-specific CSS matters. --}}
1
+ {{!-- Shared head assets for the admin layouts (app/login/main/prompt): favicons,
2
+ the pre-paint theme script, and the self-hosted PT Sans font. Stylesheets
3
+ stay in the layouts - their order relative to page-specific CSS matters. --}}
4
4
  <link rel="apple-touch-icon" href="/static/favicon/apple-touch-icon.png" sizes="180x180" />
5
5
  <link rel="icon" href="/static/favicon/favicon-32x32.png" sizes="32x32" type="image/png" />
6
6
  <link rel="icon" href="/static/favicon/favicon-16x16.png" sizes="16x16" type="image/png" />
@@ -0,0 +1,13 @@
1
+ {{!--
2
+ The MCP access-level radio group, rendered identically by the OAuth consent prompt and the
3
+ admin token generator so the two cannot drift on what each level promises. The options come
4
+ from MCP_ACCESS_LEVEL_OPTIONS (lib/token-permission-view.js) through the accessOptions
5
+ context value.
6
+ Params:
7
+ name - input name shared by the radio group (required)
8
+ idPrefix - per-page prefix for the input ids (required)
9
+ selected - the selected value (required; pass "read" for the static default)
10
+ --}}
11
+ {{#each accessOptions}}
12
+ {{> ui/radio id=(concat ../idPrefix value) name=../name value=value label=label selected=../selected hint=hint}}
13
+ {{/each}}
@@ -0,0 +1,14 @@
1
+ {{!--
2
+ The "Limit to one account" field, offered identically by the OAuth consent prompt and the
3
+ admin token generator so the two cannot drift on the wording - the same reason
4
+ mcp_access_levels.hbs exists. The control itself is the shared ui/account-picker; only the
5
+ label and the hint, which are about what the binding means for an MCP client, live here.
6
+ Params:
7
+ id - input id, also the posted field name (required)
8
+ value - current value, for validation re-renders (optional)
9
+ selected - picker entry for that value (optional)
10
+ error - validation error message (optional)
11
+ --}}
12
+ {{> ui/account-picker id=id value=value selected=selected error=error label="Limit to one account"
13
+ placeholder="Search by name, address or account id"
14
+ hint="Recommended. The client then only reaches this account, and its tools stop asking which account to act on. Leave empty to allow every account on the instance."}}
@@ -0,0 +1,19 @@
1
+ {{!--
2
+ The "N of M MCP tools available" line, shown by every page that mints an mcp-scoped token so
3
+ the three cannot disagree about what a credential will actually be offered. The counting rule
4
+ is uiMcpToolCount() in static/js/ui.js - the browser's copy of toolVisibleTo(), pinned to it by
5
+ test/mcp-tools-test.js. Reads mcpTools (and mcpAccessPresets, when auto-wired) from the
6
+ page context.
7
+
8
+ Pass levelName to have ui.js drive the count from a named access level (the MCP config
9
+ generator and the consent prompt); leave it out and the page repaints the element itself,
10
+ which is what the access-token form does for its custom-permissions option.
11
+ Params:
12
+ id - element id (required; the page's own script needs it, and so does nothing else)
13
+ levelName - the radio group name to follow, for the auto-wired pages (optional)
14
+ accountId - id of the "limit to one account" field to follow (optional, with levelName)
15
+ class - extra classes on the wrapper (optional)
16
+ --}}
17
+ <div id="{{id}}" class="text-sm space-y-1{{#if class}} {{class}}{{/if}}" data-mcp-tools="{{json mcpTools}}"
18
+ {{#if levelName}}data-mcp-level-name="{{levelName}}" data-mcp-account-id="{{accountId}}"
19
+ data-mcp-presets="{{json mcpAccessPresets}}"{{/if}}></div>
@@ -27,6 +27,7 @@
27
27
  {{> ui/menu-item href="/admin/config/email-processing" label="Email Processing" active=menuConfigEmailProcessing}}
28
28
  {{> ui/menu-item href="/admin/config/webhooks" label="Webhooks" active=menuConfigWebhooks}}
29
29
  {{> ui/menu-item href="/admin/config/ai" label="AI Processing" active=menuConfigAi}}
30
+ {{> ui/menu-item href="/admin/config/mcp" label="MCP" badge="Beta" active=menuConfigMcp}}
30
31
  {{> ui/menu-item href="/admin/config/network" label="Network" active=menuConfigNetwork}}
31
32
  {{> ui/menu-item href="/admin/config/smtp" label="SMTP Server" active=menuConfigSmtp}}
32
33
  {{> ui/menu-item href="/admin/config/imap-proxy" label="IMAP Proxy" active=menuConfigImapProxy}}