emailengine-app 2.79.0 → 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.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +79 -0
- package/bin/emailengine.js +8 -1
- package/config/default.toml +6 -0
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +137 -19
- package/lib/api-routes/account-routes.js +13 -1
- package/lib/api-routes/index.js +12 -0
- package/lib/api-routes/mailbox-routes.js +6 -0
- package/lib/api-routes/mcp-oauth-routes.js +259 -0
- package/lib/api-routes/mcp-routes.js +172 -0
- package/lib/api-routes/message-routes.js +125 -4
- package/lib/api-routes/outbox-routes.js +7 -0
- package/lib/api-routes/permission-map.js +101 -1
- package/lib/api-routes/route-helpers.js +87 -4
- package/lib/api-routes/route-metadata.js +24 -4
- package/lib/api-routes/settings-routes.js +37 -14
- package/lib/api-routes/submit-routes.js +41 -0
- package/lib/api-routes/template-routes.js +7 -0
- package/lib/api-routes/token-routes.js +292 -122
- package/lib/arf-detect.js +17 -4
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +36 -1
- package/lib/db.js +6 -0
- package/lib/email-client/base-client.js +102 -117
- package/lib/email-client/gmail-client.js +91 -29
- package/lib/email-client/imap/mailbox.js +175 -101
- package/lib/email-client/imap-client.js +49 -2
- package/lib/email-client/outlook-client.js +20 -24
- package/lib/enum-descriptions.js +2 -1
- package/lib/field-usage.js +17 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/lua/s-list-accounts.lua +5 -2
- package/lib/mcp/index.js +29 -0
- package/lib/mcp/inject.js +70 -0
- package/lib/mcp/json-schema.js +120 -0
- package/lib/mcp/listen.js +171 -0
- package/lib/mcp/oauth.js +324 -0
- package/lib/mcp/protocol.js +489 -0
- package/lib/mcp/resources.js +139 -0
- package/lib/mcp/tools.js +655 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/oauth2-apps.js +84 -15
- package/lib/openapi/build-document.js +5 -1
- package/lib/openapi/index.js +3 -1
- package/lib/response-stream.js +52 -21
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +26 -5
- package/lib/settings.js +23 -9
- package/lib/token-audit-log.js +32 -9
- package/lib/token-permission-view.js +104 -8
- package/lib/tokens.js +194 -68
- package/lib/tools.js +96 -0
- package/lib/ui-routes/account-routes.js +55 -6
- package/lib/ui-routes/admin-config-routes.js +114 -1
- package/lib/ui-routes/admin-entities-routes.js +103 -19
- package/lib/ui-routes/auth-routes.js +13 -0
- package/lib/ui-routes/mcp-consent-routes.js +330 -0
- package/lib/ui-routes/oauth-config-routes.js +7 -7
- package/lib/ui-routes/route-helpers.js +143 -1
- package/lib/ui-routes/suppression-list-routes.js +14 -9
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +9 -1
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +61 -0
- package/lib/webhook-routing.js +6 -2
- package/lib/webhooks.js +31 -8
- package/package.json +9 -8
- package/sbom.json +1 -1
- package/scripts/README.md +25 -0
- package/scripts/build-icon.js +77 -0
- package/server.js +39 -17
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +98 -0
- package/static/emailengine.ico +0 -0
- package/static/js/ui.js +465 -1
- package/static/licenses.html +42 -22
- package/translations/messages.pot +57 -57
- package/views/accounts/account.hbs +8 -8
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +2 -2
- package/views/config/mcp.hbs +361 -0
- package/views/config/oauth/index.hbs +7 -0
- package/views/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/layout/prompt.hbs +62 -0
- package/views/mcp/authorize.hbs +136 -0
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/head_assets.hbs +3 -3
- package/views/partials/mcp_access_levels.hbs +13 -0
- package/views/partials/mcp_account_limit.hbs +14 -0
- package/views/partials/mcp_tool_count.hbs +19 -0
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/account-picker.hbs +59 -0
- package/views/partials/ui/code-block.hbs +26 -0
- package/views/partials/ui/menu-item.hbs +5 -0
- package/views/partials/ui/radio.hbs +41 -0
- package/views/partials/ui/tab.hbs +15 -10
- package/views/partials/ui/tabs.hbs +8 -5
- package/views/suppression-lists/list.hbs +1 -1
- package/views/templates/index.hbs +2 -2
- package/views/templates/template.hbs +5 -4
- package/views/tokens/index.hbs +30 -4
- package/views/tokens/new.hbs +517 -239
- package/winconf.js +148 -48
- package/workers/api.js +239 -95
- package/workers/imap.js +65 -72
- package/workers/webhooks.js +21 -1
|
@@ -8,6 +8,7 @@ const { failAction } = require('../tools');
|
|
|
8
8
|
const { handleError, maskSecrets, MASK_NOTE } = require('./route-helpers');
|
|
9
9
|
const { outboxEntrySchema, apiResponses } = require('../schemas');
|
|
10
10
|
const { IMPACT } = require('./operation-impact');
|
|
11
|
+
const { MCP_MAX_PAGE_SIZE } = require('../consts');
|
|
11
12
|
|
|
12
13
|
async function init(args) {
|
|
13
14
|
const { server, CORS_CONFIG } = args;
|
|
@@ -38,6 +39,12 @@ async function init(args) {
|
|
|
38
39
|
tags: ['api', 'Outbox'],
|
|
39
40
|
|
|
40
41
|
plugins: {
|
|
42
|
+
mcp: {
|
|
43
|
+
name: 'get_outbox',
|
|
44
|
+
title: 'List outbox',
|
|
45
|
+
description: 'List messages queued for delivery, paged, including scheduled sends and their delivery progress.',
|
|
46
|
+
bounds: { pageSize: MCP_MAX_PAGE_SIZE }
|
|
47
|
+
},
|
|
41
48
|
openapi: {
|
|
42
49
|
responses: apiResponses('Returns the messages currently queued for delivery.', 400, 401, 403, 429, 500)
|
|
43
50
|
}
|
|
@@ -145,9 +145,101 @@ const SURFACE_GRANTS = {
|
|
|
145
145
|
],
|
|
146
146
|
// Not a submission surface: /metrics is an ordinary api-token route, so this mirrors its entry in
|
|
147
147
|
// GROUP_ROUTES below. Listed with the others because the admin form shows all three together.
|
|
148
|
-
metrics: [{ action: ACTION.READ, group: GROUP.DIAGNOSTICS }]
|
|
148
|
+
metrics: [{ action: ACTION.READ, group: GROUP.DIAGNOSTICS }],
|
|
149
|
+
|
|
150
|
+
// The MCP endpoint. Unlike smtp and imap-proxy this surface is checked per request, not once
|
|
151
|
+
// at login (see PER_REQUEST_SURFACES below): an mcp-scoped token opens /mcp, and each tool
|
|
152
|
+
// call is re-authenticated as the API request it dispatches, admitted only when that route's
|
|
153
|
+
// grant is in this list - the surfaceAdmits() predicate below is the one place that rule is
|
|
154
|
+
// written. The list must therefore cover every grant a tool the MCP registry exposes can
|
|
155
|
+
// require - test/mcp-tools-test.js asserts exactly that, so a new plugins.mcp block on a
|
|
156
|
+
// route outside these grants fails the build rather than shipping a tool that mcp-scoped
|
|
157
|
+
// tokens cannot call.
|
|
158
|
+
mcp: [
|
|
159
|
+
{ action: ACTION.READ, group: GROUP.ACCOUNT },
|
|
160
|
+
{ action: ACTION.READ, group: GROUP.MAILBOX },
|
|
161
|
+
{ action: ACTION.READ, group: GROUP.MESSAGE },
|
|
162
|
+
{ action: ACTION.WRITE, group: GROUP.MESSAGE },
|
|
163
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.MESSAGE },
|
|
164
|
+
{ action: ACTION.SEND, group: GROUP.SUBMIT },
|
|
165
|
+
{ action: ACTION.READ, group: GROUP.OUTBOX },
|
|
166
|
+
{ action: ACTION.READ, group: GROUP.TEMPLATE }
|
|
167
|
+
]
|
|
149
168
|
};
|
|
150
169
|
|
|
170
|
+
// The quantifier over SURFACE_GRANTS differs by surface, and consumers must not hard-code their
|
|
171
|
+
// own: the login-time surfaces (smtp, imap-proxy, metrics) admit a token only if it holds ALL of
|
|
172
|
+
// their grants, because they are checked once and then hand over a session; a per-request
|
|
173
|
+
// surface admits a request when ANY single grant covers it, because every request is checked on
|
|
174
|
+
// its own. The admin token form renders its scope warning from this distinction too.
|
|
175
|
+
const PER_REQUEST_SURFACES = new Set(['mcp']);
|
|
176
|
+
|
|
177
|
+
function grantListAdmits(grants, grant) {
|
|
178
|
+
return (grants || []).some(entry => entry.action === grant.action && entry.group === grant.group);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether one operation is inside a surface's grant list. This is the per-request quantifier -
|
|
183
|
+
* the api-token strategy asks it for the `mcp` scope, and test/mcp-tools-test.js asserts every
|
|
184
|
+
* exposed tool against it, so the guardrail and the enforcement share one predicate.
|
|
185
|
+
*
|
|
186
|
+
* @param {String} scope - a SURFACE_GRANTS key
|
|
187
|
+
* @param {{action: String, group: String}} grant - the operation, from routeGrant()
|
|
188
|
+
* @returns {Boolean}
|
|
189
|
+
*/
|
|
190
|
+
function surfaceAdmits(scope, grant) {
|
|
191
|
+
return grantListAdmits(SURFACE_GRANTS[scope], grant);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* What a `sess_` session token may reach.
|
|
196
|
+
*
|
|
197
|
+
* Deliberately not a SURFACE_GRANTS entry: those are token scopes an operator picks on the token
|
|
198
|
+
* form, and this is not one. A session token is minted by the message browser page for its own
|
|
199
|
+
* fetches (lib/ui-routes/account-routes.js), lives in the page HTML where any script on it can read
|
|
200
|
+
* it, and is bound to the account whose page issued it.
|
|
201
|
+
*
|
|
202
|
+
* The list is exactly what static/js/ee-client.js calls: read the account and its folders, read,
|
|
203
|
+
* flag, move, upload and delete messages, and submit. Before it existed the credential skipped the
|
|
204
|
+
* permission check entirely, which let a page-readable token reach every api-tagged route naming
|
|
205
|
+
* its account - including `PUT /v1/account/{account}`, which rewrites the account's webhook target
|
|
206
|
+
* and credentials, and `GET /v1/account/{account}/oauth-token`, which hands out the account's live
|
|
207
|
+
* provider access token. Both are in the never-grantable ADMIN group that no issued token may hold,
|
|
208
|
+
* and this is what makes that true of session tokens too.
|
|
209
|
+
*
|
|
210
|
+
* Per-request, like the mcp surface: the browser calls one route at a time.
|
|
211
|
+
*/
|
|
212
|
+
const SESSION_TOKEN_GRANTS = [
|
|
213
|
+
{ action: ACTION.READ, group: GROUP.ACCOUNT },
|
|
214
|
+
{ action: ACTION.READ, group: GROUP.MAILBOX },
|
|
215
|
+
{ action: ACTION.READ, group: GROUP.MESSAGE },
|
|
216
|
+
{ action: ACTION.WRITE, group: GROUP.MESSAGE },
|
|
217
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.MESSAGE },
|
|
218
|
+
{ action: ACTION.SEND, group: GROUP.SUBMIT }
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Whether a session token may perform one operation on one account.
|
|
223
|
+
*
|
|
224
|
+
* The account is half the rule rather than a detail of it. A session token is bound to the account
|
|
225
|
+
* whose page minted it, so a route that names no account is outside its scope by construction - and
|
|
226
|
+
* `GET /v1/accounts`, which lists every account on the instance, resolves to the same read/account
|
|
227
|
+
* grant as the account page the browser does need. The grant list cannot tell those two apart, so
|
|
228
|
+
* the binding is what separates them, and both halves live here so the enforcement and the
|
|
229
|
+
* guardrail ask one question.
|
|
230
|
+
*
|
|
231
|
+
* @param {{action: String, group: String}} grant - the operation, from routeGrant()
|
|
232
|
+
* @param {Object} [opts]
|
|
233
|
+
* @param {String} [opts.account] - the account the request names, from request.params
|
|
234
|
+
* @returns {Boolean}
|
|
235
|
+
*/
|
|
236
|
+
function sessionTokenAdmits(grant, opts) {
|
|
237
|
+
if (!opts || !opts.account) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
return grantListAdmits(SESSION_TOKEN_GRANTS, grant);
|
|
241
|
+
}
|
|
242
|
+
|
|
151
243
|
// Membership sets for the two vocabularies. lib/token-permissions.js rejects a record naming
|
|
152
244
|
// anything outside them, which is what makes an unknown value a denial rather than something a
|
|
153
245
|
// reader silently drops.
|
|
@@ -293,6 +385,10 @@ const GROUP_ROUTES = {
|
|
|
293
385
|
// as the requests in it, and a narrowed token has no business reading its own audit record.
|
|
294
386
|
'GET /v1/tokens/{token}',
|
|
295
387
|
'GET /v1/tokens/{token}/log',
|
|
388
|
+
// Deprecated pre-2.79 aliases of the three above (see lib/api-routes/token-routes.js)
|
|
389
|
+
'POST /v1/token',
|
|
390
|
+
'DELETE /v1/token/{token}',
|
|
391
|
+
'GET /v1/tokens/account/{account}',
|
|
296
392
|
|
|
297
393
|
// Returns a live OAuth2 access token for the account: a mail credential in its own right,
|
|
298
394
|
// which outlives any narrowing on the token that fetched it
|
|
@@ -386,6 +482,10 @@ module.exports = {
|
|
|
386
482
|
ACTION,
|
|
387
483
|
GROUP,
|
|
388
484
|
SURFACE_GRANTS,
|
|
485
|
+
PER_REQUEST_SURFACES,
|
|
486
|
+
surfaceAdmits,
|
|
487
|
+
SESSION_TOKEN_GRANTS,
|
|
488
|
+
sessionTokenAdmits,
|
|
389
489
|
GRANTABLE_GROUPS,
|
|
390
490
|
ACTION_VALUES,
|
|
391
491
|
GROUP_VALUES,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Boom = require('@hapi/boom');
|
|
4
|
+
const { isDeepStrictEqual } = require('node:util');
|
|
4
5
|
const tokenPermissions = require('../token-permissions');
|
|
5
6
|
|
|
6
7
|
// Shared helpers for the extracted API route modules under lib/api-routes/.
|
|
@@ -226,6 +227,74 @@ function maskSecrets(entry) {
|
|
|
226
227
|
return entry;
|
|
227
228
|
}
|
|
228
229
|
|
|
230
|
+
// Compares header lists on the two fields a client round-trips, so an echo check is not thrown
|
|
231
|
+
// off by incidental extra properties on either side
|
|
232
|
+
function normalizedHeaderList(headers) {
|
|
233
|
+
return [].concat(headers || []).map(header => ({ key: (header && header.key) || '', value: (header && header.value) || '' }));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Whether an incoming value carries the mask maskSecrets() writes into responses where a
|
|
238
|
+
* credential should be.
|
|
239
|
+
*
|
|
240
|
+
* A write-side guard for the masking convention: a masked value passes the joi schemas (it is a
|
|
241
|
+
* well-formed URL / header list), so without this check a read-modify-write client silently
|
|
242
|
+
* replaces the stored credential with the literal mask. Keys outside the two secret lists are
|
|
243
|
+
* never masked on the way out, so they report false.
|
|
244
|
+
*
|
|
245
|
+
* Currently wired into POST /v1/settings only. The account and gateway update routes share the
|
|
246
|
+
* read-side masking but still follow the documented MASK_NOTE contract on writes ("leave the
|
|
247
|
+
* field out of an update rather than writing it back") - closing them the same way is an open
|
|
248
|
+
* follow-up, and needs a shape this helper does not cover yet (the gateway password is a bare
|
|
249
|
+
* masked string, not a URL or header list).
|
|
250
|
+
*
|
|
251
|
+
* @param {String} key - the setting/field name
|
|
252
|
+
* @param {*} value - the incoming value
|
|
253
|
+
* @returns {Boolean} true when the value carries the mask placeholder
|
|
254
|
+
*/
|
|
255
|
+
function containsMaskedSecret(key, value) {
|
|
256
|
+
if (URL_SECRET_KEYS.includes(key)) {
|
|
257
|
+
if (!value || typeof value !== 'string') {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
let parsed;
|
|
261
|
+
try {
|
|
262
|
+
parsed = new URL(value);
|
|
263
|
+
} catch (err) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return parsed.username === MASKED || parsed.password === MASKED;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (HEADER_SECRET_KEYS.includes(key)) {
|
|
270
|
+
return Array.isArray(value) && value.some(header => header && typeof header === 'object' && header.value === MASKED);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Whether an incoming masked value is exactly what a read of the stored value returns - i.e. a
|
|
278
|
+
* read-modify-write client posting back what GET handed it, with this key untouched. Such an echo
|
|
279
|
+
* is not an update at all, so the caller can skip the write instead of refusing it.
|
|
280
|
+
*
|
|
281
|
+
* @param {String} key - the setting/field name
|
|
282
|
+
* @param {*} incoming - the incoming value
|
|
283
|
+
* @param {*} stored - the currently stored value
|
|
284
|
+
* @returns {Boolean} true when the incoming value is the masked echo of the stored one
|
|
285
|
+
*/
|
|
286
|
+
function isMaskedRoundTrip(key, incoming, stored) {
|
|
287
|
+
if (URL_SECRET_KEYS.includes(key)) {
|
|
288
|
+
return !!stored && typeof incoming === 'string' && maskUrlPassword(stored) === incoming;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (HEADER_SECRET_KEYS.includes(key)) {
|
|
292
|
+
return Array.isArray(incoming) && isDeepStrictEqual(normalizedHeaderList(maskCustomHeaders(stored)), normalizedHeaderList(incoming));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
|
|
229
298
|
/**
|
|
230
299
|
* Refuses a submission that redirects the connection, when the credential making it is narrowed.
|
|
231
300
|
*
|
|
@@ -240,9 +309,15 @@ function maskSecrets(entry) {
|
|
|
240
309
|
* reading a stored credential back is masked, sending it somewhere is not. It applies here because
|
|
241
310
|
* `submit` is a grantable group, so the narrowing has to hold the line the route grant cannot.
|
|
242
311
|
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
312
|
+
* Refused for two kinds of credential. A narrowed token, for the reason above. And a browse-page
|
|
313
|
+
* session token, which is bounded by SESSION_TOKEN_GRANTS rather than by a permissions record and
|
|
314
|
+
* so reads as unnarrowed here - it holds `send/submit` but is refused `PUT /v1/account/{account}`,
|
|
315
|
+
* which is exactly the shape this guard exists for. Without it the one credential that lives in
|
|
316
|
+
* page HTML could still post the account's SMTP session to an address of its choosing.
|
|
317
|
+
*
|
|
318
|
+
* Everything else is left alone: an unnarrowed API token already reaches PUT /v1/account/{account}
|
|
319
|
+
* and can point the account's own proxy wherever it likes, so refusing it here would cost a
|
|
320
|
+
* documented capability and buy nothing.
|
|
246
321
|
*
|
|
247
322
|
* The refusal is not written to the per-token audit log, deliberately. That trail records what a
|
|
248
323
|
* credential was ADMITTED to attempt - it is written by the auth strategy, before payload validation
|
|
@@ -257,10 +332,16 @@ function assertNoNetworkOverride(request) {
|
|
|
257
332
|
return;
|
|
258
333
|
}
|
|
259
334
|
|
|
335
|
+
// Set by the api-token strategy for a `sess_` credential. Marked on the request rather than
|
|
336
|
+
// faked into a permissions record: the session bound is a grant list, which the two axes cannot
|
|
337
|
+
// express without widening it, and a record that says more than the rule would be read as
|
|
338
|
+
// policy by the next thing that looks at it.
|
|
339
|
+
const sessionToken = !!(request.app && request.app.sessionToken);
|
|
340
|
+
|
|
260
341
|
// Asked of the module that enforces the narrowing rather than by testing `permissions` for
|
|
261
342
|
// truthiness, so `{}` and an unreadable record are read here exactly as they are at the
|
|
262
343
|
// strategy. `artifacts` is the token record the api-token strategy resolved.
|
|
263
|
-
if (!tokenPermissions.inspect(request.auth && request.auth.artifacts).narrowed) {
|
|
344
|
+
if (!sessionToken && !tokenPermissions.inspect(request.auth && request.auth.artifacts).narrowed) {
|
|
264
345
|
return;
|
|
265
346
|
}
|
|
266
347
|
|
|
@@ -275,6 +356,8 @@ module.exports = {
|
|
|
275
356
|
maskCustomHeaders,
|
|
276
357
|
maskUrlPassword,
|
|
277
358
|
maskSecrets,
|
|
359
|
+
containsMaskedSecret,
|
|
360
|
+
isMaskedRoundTrip,
|
|
278
361
|
assertNoNetworkOverride,
|
|
279
362
|
MASKED,
|
|
280
363
|
MASK_NOTE
|
|
@@ -15,14 +15,34 @@
|
|
|
15
15
|
|
|
16
16
|
const PLUGIN_OPTIONS_KEY = 'openapi';
|
|
17
17
|
|
|
18
|
+
// The shared no-metadata answer. This accessor runs in the api-token strategy on every API
|
|
19
|
+
// request, and nearly every route declares no plugins.mcp block, so allocating a fresh empty
|
|
20
|
+
// object per call would be steady-state garbage. Frozen so a caller that tries to write into
|
|
21
|
+
// it fails loudly instead of poisoning every other route's answer.
|
|
22
|
+
const NO_OPTIONS = Object.freeze({});
|
|
23
|
+
|
|
18
24
|
/**
|
|
19
25
|
* The documentation and permission metadata a route declares.
|
|
20
26
|
*
|
|
21
27
|
* @param {Object} route - a `server.table()` entry, or a live `request.route`
|
|
22
|
-
* @
|
|
28
|
+
* @param {String} [namespace] - which plugins block to read; defaults to `plugins.openapi`
|
|
29
|
+
* @returns {Object} the route's plugins block, or an empty object when it declares none
|
|
30
|
+
*/
|
|
31
|
+
function pluginOptions(route, namespace) {
|
|
32
|
+
return (route && route.settings && route.settings.plugins && route.settings.plugins[namespace || PLUGIN_OPTIONS_KEY]) || NO_OPTIONS;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The MCP metadata a route declares (`plugins.mcp`): a tool definition block on wrapped routes,
|
|
37
|
+
* `{ endpoint: true }` on the /mcp door itself. Three readers - the tool registry, the api-token
|
|
38
|
+
* strategy's door carve-outs, and the route-table guardrail - and this accessor is what keeps a
|
|
39
|
+
* renamed key from turning into an empty object for exactly one of them.
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} route - a `server.table()` entry, or a live `request.route`
|
|
42
|
+
* @returns {Object} the route's `plugins.mcp`, or an empty object when it declares none
|
|
23
43
|
*/
|
|
24
|
-
function
|
|
25
|
-
return (route
|
|
44
|
+
function mcpOptions(route) {
|
|
45
|
+
return pluginOptions(route, 'mcp');
|
|
26
46
|
}
|
|
27
47
|
|
|
28
|
-
module.exports = { pluginOptions };
|
|
48
|
+
module.exports = { pluginOptions, mcpOptions };
|
|
@@ -6,7 +6,8 @@ const settings = require('../settings');
|
|
|
6
6
|
const consts = require('../consts');
|
|
7
7
|
const { failAction } = require('../tools');
|
|
8
8
|
const { queueStats } = require('../queue-stats');
|
|
9
|
-
const
|
|
9
|
+
const Boom = require('@hapi/boom');
|
|
10
|
+
const { handleError, maskSecrets, containsMaskedSecret, isMaskedRoundTrip, MASKED } = require('./route-helpers');
|
|
10
11
|
const { settingsSchema, settingsQuerySchema, apiResponses, ENUM_DESCRIPTIONS } = require('../schemas');
|
|
11
12
|
|
|
12
13
|
// Response variant of the settings schema. Secret values are masked and returned as booleans,
|
|
@@ -72,7 +73,7 @@ async function init(args) {
|
|
|
72
73
|
},
|
|
73
74
|
options: {
|
|
74
75
|
description: 'List specific settings',
|
|
75
|
-
notes:
|
|
76
|
+
notes: `List setting values for specific keys. Credentials are masked: the credentials in any proxy or webhook URL and the values of custom webhook headers read back as "${MASKED}", and encrypted secrets are returned as booleans. A masked value is not the stored one - POST /v1/settings skips it when it matches the stored value and refuses it otherwise.`,
|
|
76
77
|
tags: ['api', 'Settings'],
|
|
77
78
|
|
|
78
79
|
plugins: {
|
|
@@ -110,25 +111,47 @@ async function init(args) {
|
|
|
110
111
|
path: '/v1/settings',
|
|
111
112
|
|
|
112
113
|
async handler(request) {
|
|
113
|
-
let
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
let applied = {};
|
|
115
|
+
try {
|
|
116
|
+
for (let key of Object.keys(request.payload)) {
|
|
117
|
+
let value = request.payload[key];
|
|
118
|
+
|
|
119
|
+
// GET /v1/settings masks stored credentials ("******"), and the masked values
|
|
120
|
+
// pass the schemas here - they are well-formed URLs and header lists - so a
|
|
121
|
+
// read-modify-write client would silently replace the stored credential with
|
|
122
|
+
// the literal mask. The unchanged masked echo of the stored value is skipped
|
|
123
|
+
// as "not an update"; a mask anywhere else is refused, because the credential
|
|
124
|
+
// it stands for cannot be reconstructed.
|
|
125
|
+
if (containsMaskedSecret(key, value)) {
|
|
126
|
+
if (isMaskedRoundTrip(key, value, await settings.get(key))) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
throw Boom.badRequest(
|
|
130
|
+
`The value for "${key}" carries the masked placeholder "${MASKED}" instead of a credential. Send the real value, or leave the key out to keep the stored one`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
119
133
|
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
if (key === 'webhooksEnabled' && !value) {
|
|
135
|
+
// clear error message (if exists)
|
|
136
|
+
await settings.clear('webhookErrorFlag');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
await settings.set(key, value);
|
|
140
|
+
applied[key] = value;
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
handleError(request, err);
|
|
122
144
|
}
|
|
123
145
|
|
|
124
146
|
// Broadcast to all workers (including this one); each reloads its HTTP proxy agent via
|
|
125
|
-
// the 'settings' message handler, so no inline reload is needed here.
|
|
126
|
-
|
|
127
|
-
|
|
147
|
+
// the 'settings' message handler, so no inline reload is needed here. Only the keys
|
|
148
|
+
// that were actually written: a skipped masked echo must not trigger reloads either.
|
|
149
|
+
notify('settings', applied);
|
|
150
|
+
return { updated: Object.keys(applied) };
|
|
128
151
|
},
|
|
129
152
|
options: {
|
|
130
153
|
description: 'Set setting values',
|
|
131
|
-
notes:
|
|
154
|
+
notes: `Set setting values for specific keys. Masked credential values ("${MASKED}") read from GET /v1/settings are not accepted: a masked value that matches the stored one is skipped as unchanged, any other value carrying the mask is refused. Send the real credential, or leave the key out to keep the stored value.`,
|
|
132
155
|
tags: ['api', 'Settings'],
|
|
133
156
|
|
|
134
157
|
plugins: {
|
|
@@ -124,6 +124,47 @@ async function init(args) {
|
|
|
124
124
|
tags: ['api', 'Submit'],
|
|
125
125
|
|
|
126
126
|
plugins: {
|
|
127
|
+
mcp: {
|
|
128
|
+
name: 'send_message',
|
|
129
|
+
title: 'Send message',
|
|
130
|
+
description:
|
|
131
|
+
'Send an email from the account to real recipients - confirm with the user before calling this. Takes structured fields (to, subject, text, html). ' +
|
|
132
|
+
'To answer or pass on a message the user is looking at, set `reference.message` to its id and `reference.action` to reply, reply-all or forward, ' +
|
|
133
|
+
'and write only the new text: the subject, the recipients (for a reply) and the threading headers come from the referenced message. ' +
|
|
134
|
+
'Add `reference.inline` to quote the original under it, and `reference.forwardAttachments` to carry its attachments along when forwarding. ' +
|
|
135
|
+
'Delivery is queued; the response carries the queue id for get_outbox.',
|
|
136
|
+
// An allowlist, not a deny list. The submit payload is the widest one in the
|
|
137
|
+
// API and it grows; with `omit` a field added here later would join the
|
|
138
|
+
// agent-facing schema by default, which fails open on the one tool that
|
|
139
|
+
// reaches people outside the mailbox.
|
|
140
|
+
//
|
|
141
|
+
// What is kept is the message an agent composes: who it goes to, what it
|
|
142
|
+
// says, what it answers, what it carries and when it leaves. What is not is a
|
|
143
|
+
// decision the operator made when they connected the account - routing,
|
|
144
|
+
// tracking, bounce handling, whether the sent copy is filed - plus every way
|
|
145
|
+
// around the structured fields (`raw` replaces the whole message, `envelope`
|
|
146
|
+
// overrides the SMTP conversation, `headers`/`messageId` set headers
|
|
147
|
+
// EmailEngine derives) and `mailMerge`, which would turn one call into a bulk
|
|
148
|
+
// send to a recipient list - not what "confirm before sending" protects
|
|
149
|
+
// against. An agent that should mail several people calls the tool several
|
|
150
|
+
// times, where each send is visible as a send.
|
|
151
|
+
keep: [
|
|
152
|
+
'account',
|
|
153
|
+
'reference',
|
|
154
|
+
'from',
|
|
155
|
+
'replyTo',
|
|
156
|
+
'to',
|
|
157
|
+
'cc',
|
|
158
|
+
'bcc',
|
|
159
|
+
'subject',
|
|
160
|
+
'text',
|
|
161
|
+
'html',
|
|
162
|
+
'template',
|
|
163
|
+
'render',
|
|
164
|
+
'attachments',
|
|
165
|
+
'sendAt'
|
|
166
|
+
]
|
|
167
|
+
},
|
|
127
168
|
openapi: {
|
|
128
169
|
'x-ee-impact': IMPACT.SENDS,
|
|
129
170
|
'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
|
|
@@ -10,6 +10,7 @@ const { handleError, throwNotFound } = require('./route-helpers');
|
|
|
10
10
|
|
|
11
11
|
const { templateSchemas, accountIdSchema, apiResponses } = require('../schemas');
|
|
12
12
|
const { IMPACT } = require('./operation-impact');
|
|
13
|
+
const { MCP_MAX_PAGE_SIZE } = require('../consts');
|
|
13
14
|
|
|
14
15
|
// Template owner field shared by all template response schemas
|
|
15
16
|
const templateAccountIdSchema = accountIdSchema.required().allow(null).description('Account ID. Null for public templates');
|
|
@@ -226,6 +227,12 @@ async function init(args) {
|
|
|
226
227
|
tags: ['api', 'Templates'],
|
|
227
228
|
|
|
228
229
|
plugins: {
|
|
230
|
+
mcp: {
|
|
231
|
+
name: 'list_templates',
|
|
232
|
+
title: 'List templates',
|
|
233
|
+
description: 'List stored email templates, paged. Pass an account id for account-specific templates or omit it for shared ones.',
|
|
234
|
+
bounds: { pageSize: MCP_MAX_PAGE_SIZE }
|
|
235
|
+
},
|
|
229
236
|
openapi: {
|
|
230
237
|
responses: apiResponses('Returns a page of stored templates for the account.', 400, 401, 403, 404, 429, 500)
|
|
231
238
|
}
|