vantage-peers-mcp 4.0.0 → 4.1.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/CHANGELOG.md +25 -0
- package/README.md +49 -6
- package/dist/server-http.js +49 -31
- package/dist/src/auth.d.ts +24 -1
- package/dist/src/auth.js +46 -1
- package/dist/src/authenticatedConvexClient.d.ts +19 -3
- package/dist/src/authenticatedConvexClient.js +67 -1
- package/dist/src/backendContract.d.ts +1 -1
- package/dist/src/backendContract.js +4 -1
- package/dist/src/doorScope.d.ts +17 -0
- package/dist/src/doorScope.js +40 -2
- package/dist/src/registerTool.d.ts +7 -0
- package/dist/src/registerTool.js +23 -3
- package/dist/src/toolUsage.d.ts +33 -0
- package/dist/src/toolUsage.js +99 -0
- package/dist/src/tools/kbIngest.js +10 -2
- package/dist/src/tools.d.ts +4 -1
- package/dist/src/tools.js +219 -29
- package/dist/src/ui-resources/apps.d.ts +41 -0
- package/dist/src/ui-resources/apps.js +288 -0
- package/dist/src/ui-resources/index.d.ts +4 -0
- package/dist/src/ui-resources/index.js +4 -0
- package/dist/src/ui-resources/register.d.ts +38 -0
- package/dist/src/ui-resources/register.js +77 -0
- package/dist/src/verifiedActor.js +9 -0
- package/package.json +1 -1
- package/tool-exposure.json +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [4.1.0] — 2026-11-03
|
|
6
|
+
|
|
7
|
+
Customer-facing summary of every `mcp-server/` change since 4.0.0. Each entry says which product it concerns (VantagePeers Cloud, the hosted service; VantagePeers Self-host, the separate product) and links the README section that documents it.
|
|
8
|
+
|
|
9
|
+
### Action required
|
|
10
|
+
|
|
11
|
+
- Self-host: the server requires backend contract version 17 and 144 backend functions (4.0.0: 10 and 141) and refuses to start against an older backend. Deploy the backend of this release first, then upgrade this package. ([Backend compatibility check](README.md#backend-compatibility-check))
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Cloud and Self-host: new tools `get_tool_usage` and `get_owner_tool_usage`: which MCP tools a caller, or all the agents a person owns, has called, with first call, last call and call count. ([Tool inputs and outputs](README.md#tool-inputs-and-outputs))
|
|
16
|
+
- Cloud and Self-host: `list_tasks`, `list_messages`, `list_missions`, `list_memories`, `get_diary` and `get_briefing_note` name an interactive MCP Apps view; a client without MCP Apps support shows the unchanged text result. ([MCP Apps](README.md#mcp-apps-interactive-views))
|
|
17
|
+
- Cloud: a native client's loopback `redirect_uri` (`http://127.0.0.1`, `http://localhost`, `http://[::1]`) may vary its port, so VS Code can connect (RFC 8252 section 7.3). ([Security](README.md#security))
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Cloud: `pause_recurring_task`, `resume_recurring_task` and `delete_recurring_task` are no longer refused to every non-operator caller; an agent manages the schedules it created. ([Tool inputs and outputs](README.md#tool-inputs-and-outputs))
|
|
22
|
+
- Cloud and Self-host: a refused `send_message` carries `RBAC_DENIED` or `INVALID_RECIPIENTS`, a missing message `MESSAGE_NOT_FOUND`, and a refused `store_memory` / `store_episode` write names the namespaces the caller may write. ([Tool inputs and outputs](README.md#tool-inputs-and-outputs))
|
|
23
|
+
|
|
24
|
+
### Security and fixes
|
|
25
|
+
|
|
26
|
+
- Cloud: every call an OAuth bearer makes runs inside its own verified organisation, keyed by the permanent organisation ID, so a bearer no longer reads another organisation's diaries, mandate bindings, tasks or UI resources (cross-tenant leak, #1639). ([Security](README.md#security))
|
|
27
|
+
- Cloud: a seat reads and writes its own `orchestrator/<agent ID>` and `project/<org>` on every path into the server, whatever its token was minted with; a token's rights follow its scope profile as it is now; a one-agent seat resolves its agent by ID only. ([Agent identity](README.md#agent-identity))
|
|
28
|
+
- Cloud and Self-host: `add_task_dependency` and `block_task` append to a task's dependencies instead of replacing them, and `link_commit_to_issue` no longer records a SHA twice. ([Tool inputs and outputs](README.md#tool-inputs-and-outputs))
|
|
29
|
+
|
|
5
30
|
## [4.0.0] — 2026-11-01
|
|
6
31
|
|
|
7
32
|
Customer-facing summary of every `mcp-server/` change since 3.0.0. Each entry says which product it concerns (VantagePeers Cloud, the hosted service; VantagePeers Self-host, the separate product) and links the README section that documents it. The repository changelog carries the full engineering record of the same release.
|
package/README.md
CHANGED
|
@@ -98,6 +98,23 @@ _Applies to: Cloud._
|
|
|
98
98
|
|
|
99
99
|
Ask your agent who it is (`whoami`), to list your peers (`list_peers`), or to store and then recall a short note (`store_memory`, then `recall`). `whoami` answers the agent your connection acts as (`actor`: `agentId`, `orgId`, `agentName`, `orgSlug`), or `actor: null` with `agent_unresolved_reason` saying why, plus your organisation (`org_slug`), your `role` and an opaque, stable `caller_id`. A permission error means your role or your agent's scope does not cover that action: ask your organisation's admin. You do not need new credentials for that.
|
|
100
100
|
|
|
101
|
+
### MCP Apps (interactive views)
|
|
102
|
+
|
|
103
|
+
_Applies to: Cloud._
|
|
104
|
+
|
|
105
|
+
Six tools can show their result as an interactive view in clients that support [MCP Apps](https://github.com/modelcontextprotocol/ext-apps) (the MCP UI extension, protocol `2025-11-21`):
|
|
106
|
+
|
|
107
|
+
- `list_tasks`: a task table (`ui://vp/apps/v1/tasks-table`).
|
|
108
|
+
- `list_messages`: a message feed (`ui://vp/apps/v1/messages-feed`).
|
|
109
|
+
- `list_missions`: a mission list (`ui://vp/apps/v1/mission-timeline`).
|
|
110
|
+
- `list_memories`: a memory list (`ui://vp/apps/v1/memory-quote`).
|
|
111
|
+
- `get_diary`: a diary entry (`ui://vp/apps/v1/diary-entry`).
|
|
112
|
+
- `get_briefing_note`: a briefing note (`ui://vp/apps/v1/briefing-note`).
|
|
113
|
+
|
|
114
|
+
Each of these tools names its view in `tools/list` (`_meta.ui.resourceUri`), and the view is served by `resources/read` as `text/html;profile=mcp-app`. The view holds no data and calls nothing: your client hands it the tool's own result, so it shows exactly the rows the tool returned to you, after your scope was applied. A refusal is shown as a refusal, not as an empty list.
|
|
115
|
+
|
|
116
|
+
You turn nothing on. A client without MCP Apps support (Claude Code in a terminal, for example) shows the tool's text result, which is the same as before the views existed.
|
|
117
|
+
|
|
101
118
|
## Authentication
|
|
102
119
|
|
|
103
120
|
_Applies to: Cloud._
|
|
@@ -157,7 +174,7 @@ An agent is identified by its **agent ID** (the `agentId` that `list_peers` retu
|
|
|
157
174
|
_Applies to: Cloud and Self-host._
|
|
158
175
|
|
|
159
176
|
<!-- tools:start -->
|
|
160
|
-
|
|
177
|
+
90 tools are advertised to clients. This reference is generated from the server's own `tools/list` by `scripts/print-tools.mjs`; do not edit it by hand.
|
|
161
178
|
|
|
162
179
|
### Memory and search (9)
|
|
163
180
|
|
|
@@ -271,7 +288,7 @@ _Applies to: Cloud and Self-host._
|
|
|
271
288
|
- `export_okf_bundle` (write) — Export a VantagePeers namespace as an OKF v0.1 bundle (tarball).
|
|
272
289
|
- `import_okf_bundle` (write) — Import an OKF v0.1 bundle (memories + briefing-notes + tasks) into a target VantagePeers namespace.
|
|
273
290
|
|
|
274
|
-
### Other (
|
|
291
|
+
### Other (14)
|
|
275
292
|
|
|
276
293
|
- `add_repo_mapping` (write) — Register or update a GitHub repo to orchestrator mapping for webhook event routing.
|
|
277
294
|
- `claim_upload` (write) — Claim an uploaded blob for your organisation with the single-use ticket generate_upload_url returned.
|
|
@@ -280,6 +297,8 @@ _Applies to: Cloud and Self-host._
|
|
|
280
297
|
- `generate_upload_url` (write) — Mint a Convex storage upload URL for the Knowledge Base ingest flow.
|
|
281
298
|
- `get_bulk_complete_run` (read) — Read the status of one live bulk_complete_tasks run by the `bulkRunId` its first call returned.
|
|
282
299
|
- `get_github_owner_bindings` (read) — List the GitHub owners bound to your organisation (master: all), and for master the org-owned repo mappings that have no proof.
|
|
300
|
+
- `get_owner_tool_usage` (read) — List which MCP tools a person has used across all the agents it owns (one per AI client) and its own direct calls, summed per tool with the earliest first call and the latest last call.
|
|
301
|
+
- `get_tool_usage` (read) — List which MCP tools a caller has called, with the first call time, the last call time and the call count of each.
|
|
283
302
|
- `improvisation_digest` (read) — Scan a rolling time window of VP tasks, messages, and memories for durable artifacts that carry fleet/state tokens (commit SHA, PR#, VP id, or decisive verb such as merged/deployed/approved) but have NO VP-Sources footer.
|
|
284
303
|
- `list_blocked_on_me` (read) — List the tasks that other peers have BLOCKED on one of YOUR live tasks (blockedOnTaskId), oldest wait first, with the age of each wait.
|
|
285
304
|
- `list_repo_mappings` (read) — List all GitHub repo to orchestrator webhook mappings, newest first with cursor paging support.
|
|
@@ -307,6 +326,9 @@ _Applies to: Cloud and Self-host._
|
|
|
307
326
|
- **Tasks.** `create_task` and `update_task` take an optional `deliverable` (`{ pkg, export }`); `get_task` and `list_tasks` then show `deliverableState` and, when the export is published while the task is still open, `deliverableDivergence: "delivered-but-open"`. `bulk_complete_tasks` closes the first 500 matches in the call and the rest in the background; read the run with `get_bulk_complete_run` and the `bulkRunId` it returned. `list_blocked_on_me` lists the tasks other peers have blocked on your live tasks.
|
|
308
327
|
- **Recurring tasks.** A schedule whose previous task is still open creates nothing at its next run and records the skip (`skippedRuns`, `lastSkippedAt`, `lastSkipReason`, shown by `get_recurring_task` and `list_recurring_tasks`).
|
|
309
328
|
- **Debate rooms.** `debate_get_room` reads a room and its transcript; `debate_post_turn` posts your answer when it is your turn. Out-of-turn, non-participant, empty, stale or over-long posts are refused with their own codes (`not_your_turn`, `not_a_participant`, `empty`, `stale_turn`, `too_long`).
|
|
329
|
+
- **Dependencies append.** `add_task_dependency` and `block_task` (`blockedBy`) add to a task's existing dependencies, deduplicated, and answer the resulting list; they no longer replace it. `update_task` `dependsOn` stays the explicit replace. `link_commit_to_issue` skips a commit SHA already recorded.
|
|
330
|
+
- **Tool usage.** `get_tool_usage` lists which MCP tools a caller has called, with first call, last call and call count; `get_owner_tool_usage` sums that across the agents a person owns.
|
|
331
|
+
- **Refusal codes.** A refused `send_message` carries `RBAC_DENIED` or `INVALID_RECIPIENTS`, and a missing message `MESSAGE_NOT_FOUND`, instead of a bare server error.
|
|
310
332
|
- **Errors.** A protocol error thrown by a tool reads without the former `MCP error <code>:` prefix. `tools/list` stamps its JSON Schemas with the 2020-12 dialect and no longer carries `execution.taskSupport`.
|
|
311
333
|
|
|
312
334
|
## Security
|
|
@@ -318,7 +340,7 @@ _Applies to: Cloud._
|
|
|
318
340
|
- **Messages stay in your organisation.** A seat's direct messages and broadcasts reach its own organisation's roster, plus fleet coordinators your organisation is explicitly allowed to address.
|
|
319
341
|
- **Agent identity comes from a credential, not a typed name.** See [Agent identity](#agent-identity). A caller from another organisation cannot send a message, or act on a task, under one of your agents' names, even when both organisations have an agent with the same name.
|
|
320
342
|
- **A refusal never looks like an empty result.** A read you are not allowed to make returns an explicit error (for example, `list_peers`, `list_diaries` and `list_briefing_notes` return text opening with `REFUSED (RBAC_DENIED)`) rather than an empty list, so an agent cannot mistake "not allowed" for "nothing there". An agent credential that does not resolve is refused with its own code (`AGENT_CREDENTIAL_INVALID`, HTTP 401), distinct from a lookup failure. A signed-in user whose account has no organisation yet receives its own refusal, distinct from an invalid token.
|
|
321
|
-
- **Token checks.** Clerk session tokens are verified against the issuer's published keys, with issuer and audience both bound. OAuth client secrets are compared in constant time. `redirect_uri` must match a registered URI exactly, and dynamic registration rejects non-HTTPS redirect URIs (except `localhost
|
|
343
|
+
- **Token checks.** Clerk session tokens are verified against the issuer's published keys, with issuer and audience both bound. OAuth client secrets are compared in constant time. `redirect_uri` must match a registered URI exactly, and dynamic registration rejects non-HTTPS redirect URIs (except the loopback addresses `localhost`, `127.0.0.1` and `[::1]`, whose port may differ from the registered one, RFC 8252 section 7.3). The consent page's form post must come from the same origin.
|
|
322
344
|
- **Health document.** `/health` is public and publishes only aggregates (version, commit, serving runtime, transport, the agent-identity mode and where it comes from). It never echoes a secret or a customer identifier.
|
|
323
345
|
|
|
324
346
|
To report a vulnerability, open an issue at https://github.com/vantageos-agency/vantage-peers/issues without exploit details and ask for a private channel.
|
|
@@ -337,6 +359,8 @@ That is **VantagePeers Self-host**, a separate product with its own setup (backe
|
|
|
337
359
|
|
|
338
360
|
The stdio server answers MCP protocol `2026-07-28` and `2025-11-25` clients alike. It presents the service identity of your deployment to your backend (`CLERK_SECRET_KEY` and `CLERK_SERVICE_ACCOUNT_USER_ID`, see the Self-host guide); without it, it refuses to start.
|
|
339
361
|
|
|
362
|
+
The stdio server registers the same tools, so `list_tasks`, `list_messages`, `list_missions`, `list_memories`, `get_diary` and `get_briefing_note` carry the same `_meta.ui.resourceUri` links and serve the same static `ui://vp/apps/v1/<view>` documents for an MCP Apps-capable local client.
|
|
363
|
+
|
|
340
364
|
The package also exports typed function references for the VantagePeers backend at `vantage-peers-mcp/api`, for TypeScript services that call a deployment directly.
|
|
341
365
|
|
|
342
366
|
### Backend compatibility check
|
|
@@ -346,14 +370,33 @@ _Applies to: Self-host._
|
|
|
346
370
|
Before it serves anything, the server asks your backend for its contract manifest (`meta:backendContract`) and refuses to start, with a log line beginning `BACKEND INCOMPATIBLE (<reason>)`, when:
|
|
347
371
|
|
|
348
372
|
- the backend has no manifest (it predates this check);
|
|
349
|
-
- the backend's contract version is below **
|
|
350
|
-
- any of the **
|
|
373
|
+
- the backend's contract version is below **17**, the version this release requires;
|
|
374
|
+
- any of the **144** backend functions this release calls is missing (they are named in the log);
|
|
351
375
|
- the server cannot present its service identity, or the backend refuses it.
|
|
352
376
|
|
|
353
377
|
So upgrade in this order: deploy the backend of the same release first, then upgrade this package. The check sees a missing function, not a changed argument; the contract version covers that.
|
|
354
378
|
|
|
355
379
|
## Release notes
|
|
356
380
|
|
|
381
|
+
### 4.1.0
|
|
382
|
+
|
|
383
|
+
_Applies to: Cloud and Self-host._ Each item names the product it concerns.
|
|
384
|
+
|
|
385
|
+
**Action required (Self-host)**
|
|
386
|
+
|
|
387
|
+
- Self-host: the server now requires backend contract version 17 and 144 backend functions (was 10 and 141). Deploy the backend of this release first, then upgrade the package; an older backend is refused at start (see [Backend compatibility check](#backend-compatibility-check)).
|
|
388
|
+
|
|
389
|
+
**Added**
|
|
390
|
+
|
|
391
|
+
- Cloud and Self-host: `get_tool_usage` and `get_owner_tool_usage` (see [Tool inputs and outputs](#tool-inputs-and-outputs)).
|
|
392
|
+
- Cloud and Self-host: six tools name an interactive MCP Apps view (see [MCP Apps](#mcp-apps-interactive-views)).
|
|
393
|
+
- Cloud: a native client's loopback `redirect_uri` may vary its port (see [Security](#security)).
|
|
394
|
+
|
|
395
|
+
**Fixes**
|
|
396
|
+
|
|
397
|
+
- Cloud: every call runs inside the bearer's verified organisation, keyed by its permanent ID; a seat reaches its own `orchestrator/<agent ID>` and `project/<org>` on every path; diaries and mandate bindings stay inside the organisation; an agent can pause, resume and delete its own recurring tasks (see [Security](#security), [Agent identity](#agent-identity)).
|
|
398
|
+
- Cloud and Self-host: dependencies append instead of replacing; refusals carry their code (see [Tool inputs and outputs](#tool-inputs-and-outputs)).
|
|
399
|
+
|
|
357
400
|
### 4.0.0
|
|
358
401
|
|
|
359
402
|
_Applies to: Cloud and Self-host._ Each item names the product it concerns.
|
|
@@ -417,7 +460,7 @@ Full history: [CHANGELOG.md](https://github.com/vantageos-agency/vantage-peers/b
|
|
|
417
460
|
|
|
418
461
|
_Applies to: Self-host._
|
|
419
462
|
|
|
420
|
-
Node.js 26.12.1 (the October 2026 security release), for the Self-host stdio server and the `vantage-peers-mcp/api` exports: `engines.node` names that exact version. A backend of the same release (contract version
|
|
463
|
+
Node.js 26.12.1 (the October 2026 security release), for the Self-host stdio server and the `vantage-peers-mcp/api` exports: `engines.node` names that exact version. A backend of the same release (contract version 17, see [Backend compatibility check](#backend-compatibility-check)). VantagePeers Cloud clients need nothing installed.
|
|
421
464
|
|
|
422
465
|
## License
|
|
423
466
|
|
package/dist/server-http.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* NODE_ENV — set to "production" on Railway
|
|
34
34
|
*/
|
|
35
35
|
import { readFileSync } from "node:fs";
|
|
36
|
-
import { createMcpHandler, McpServer
|
|
36
|
+
import { createMcpHandler, McpServer } from "@modelcontextprotocol/server";
|
|
37
37
|
import { buildDiscoveryDocument, buildUserInfo, exchangeAuthorizationCode, oauthErrorFor, resumeAuthorize, startAuthorize, timingSafeEqual, } from "@vantageos/cloud-identity";
|
|
38
38
|
import { resolveClerkSessionForFormPost, resolveClerkSessionFromRequest, } from "@vantageos/cloud-identity/clerk-handshake";
|
|
39
39
|
import { Hono } from "hono";
|
|
@@ -44,7 +44,7 @@ import { buildAuthorizeRuntime, clerkHandshakeConfig, clientIdInState, convexCod
|
|
|
44
44
|
import { bootCheckOrExit } from "./src/backendContract.js";
|
|
45
45
|
import { BRAND_ICON_ROUTES, mcpImplementation } from "./src/brand.js";
|
|
46
46
|
import { registerTools } from "./src/tools.js";
|
|
47
|
-
import {
|
|
47
|
+
import { registerUiResources } from "./src/ui-resources/register.js";
|
|
48
48
|
let pkg;
|
|
49
49
|
try {
|
|
50
50
|
// Source mode: server-http.ts → ./package.json = mcp-server/package.json
|
|
@@ -168,9 +168,39 @@ async function loadScopeProfile(profileId) {
|
|
|
168
168
|
//
|
|
169
169
|
// URIs without a `*` keep the original exact-match semantics — this helper
|
|
170
170
|
// is a strict superset of the prior behavior.
|
|
171
|
+
//
|
|
172
|
+
// Loopback redirects (RFC 8252 section 7.3): a native client (VS Code, CLIs)
|
|
173
|
+
// listens on a port it picks per run, so the authorization server MUST allow
|
|
174
|
+
// any port for a registered `http` loopback URI. The match is still strict on
|
|
175
|
+
// everything else: scheme `http`, the SAME loopback literal (`127.0.0.1`,
|
|
176
|
+
// `localhost` or `[::1]`, RFC 8252 section 8.3), no userinfo, a valid port,
|
|
177
|
+
// and byte-equal path and query. A loopback URI is never matched against a
|
|
178
|
+
// non-loopback registration, nor the other way round.
|
|
179
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
180
|
+
function loopbackRedirectMatches(registeredUri, presentedUri) {
|
|
181
|
+
let registered;
|
|
182
|
+
let presented;
|
|
183
|
+
try {
|
|
184
|
+
registered = new URL(registeredUri);
|
|
185
|
+
presented = new URL(presentedUri);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return (registered.protocol === "http:" &&
|
|
191
|
+
presented.protocol === "http:" &&
|
|
192
|
+
LOOPBACK_HOSTS.has(registered.hostname) &&
|
|
193
|
+
registered.hostname === presented.hostname &&
|
|
194
|
+
presented.username === "" &&
|
|
195
|
+
presented.password === "" &&
|
|
196
|
+
presented.hash === "" &&
|
|
197
|
+
registered.pathname === presented.pathname &&
|
|
198
|
+
registered.search === presented.search);
|
|
199
|
+
}
|
|
171
200
|
export function redirectUriMatches(registeredUri, presentedUri) {
|
|
172
201
|
if (!registeredUri.includes("*")) {
|
|
173
|
-
return registeredUri === presentedUri
|
|
202
|
+
return (registeredUri === presentedUri ||
|
|
203
|
+
loopbackRedirectMatches(registeredUri, presentedUri));
|
|
174
204
|
}
|
|
175
205
|
// Escape regex metacharacters EXCEPT `*`, then expand `*`.
|
|
176
206
|
const escaped = registeredUri.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -390,8 +420,7 @@ app.post("/register", async (c) => {
|
|
|
390
420
|
}, 400);
|
|
391
421
|
}
|
|
392
422
|
const isHttpsScheme = parsed.protocol === "https:";
|
|
393
|
-
const isLocalhostHttp = parsed.protocol === "http:" &&
|
|
394
|
-
(parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
|
|
423
|
+
const isLocalhostHttp = parsed.protocol === "http:" && LOOPBACK_HOSTS.has(parsed.hostname);
|
|
395
424
|
if (!isHttpsScheme && !isLocalhostHttp) {
|
|
396
425
|
return c.json({
|
|
397
426
|
error: "invalid_redirect_uri",
|
|
@@ -1713,32 +1742,21 @@ app.all("/mcp", bearerAuthMiddleware(), async (c) => {
|
|
|
1713
1742
|
// client, so an instance never serves anyone else.
|
|
1714
1743
|
const buildServer = () => {
|
|
1715
1744
|
const server = new McpServer(mcpImplementation(pkg.version, iconOrigin));
|
|
1716
|
-
registerTools(server, convex, oauthCtx);
|
|
1717
|
-
// SEP-1865 ui:// resources for Generative UI primitives
|
|
1718
|
-
//
|
|
1719
|
-
//
|
|
1720
|
-
//
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
// Day-165-parity — thread the caller identity into the ui-resource
|
|
1732
|
-
// primitives the same way tools.ts does (mirrors the
|
|
1733
|
-
// master/callerIdentities computation at tools.ts:5712/5808/5934), so
|
|
1734
|
-
// briefingNotes:get/list resolve visibility inside Convex instead of
|
|
1735
|
-
// falling into the `callerIdentities === undefined` legacy-open branch.
|
|
1736
|
-
const master = oauthCtx === undefined || isMasterScope(oauthCtx);
|
|
1737
|
-
const callerIdentities = master ? undefined : oauthCtx.fromAllowList;
|
|
1738
|
-
return await readUiResource(uri.toString(), fetchConvex, {
|
|
1739
|
-
master,
|
|
1740
|
-
callerIdentities,
|
|
1741
|
-
});
|
|
1745
|
+
registerTools(server, convex, oauthCtx, { recordToolUsage: true });
|
|
1746
|
+
// SEP-1865 ui:// resources for Generative UI primitives — see
|
|
1747
|
+
// src/ui-resources/register.ts.
|
|
1748
|
+
// Day-165-parity — thread the caller identity into the ui-resource
|
|
1749
|
+
// primitives the same way tools.ts does (mirrors the
|
|
1750
|
+
// master/callerIdentities computation at tools.ts:5712/5808/5934), so
|
|
1751
|
+
// briefingNotes:get/list resolve visibility inside Convex instead of
|
|
1752
|
+
// falling into the `callerIdentities === undefined` legacy-open branch.
|
|
1753
|
+
// (An undefined oauthCtx never reaches a read: the registration's gate
|
|
1754
|
+
// refuses it before any Convex query.)
|
|
1755
|
+
const master = oauthCtx === undefined || isMasterScope(oauthCtx);
|
|
1756
|
+
const callerIdentities = master ? undefined : oauthCtx.fromAllowList;
|
|
1757
|
+
registerUiResources(server, convex, oauthCtx, {
|
|
1758
|
+
master,
|
|
1759
|
+
callerIdentities,
|
|
1742
1760
|
});
|
|
1743
1761
|
return server;
|
|
1744
1762
|
};
|
package/dist/src/auth.d.ts
CHANGED
|
@@ -155,6 +155,19 @@ export type OAuthContext = {
|
|
|
155
155
|
orgId: string;
|
|
156
156
|
agentName: string;
|
|
157
157
|
} | null;
|
|
158
|
+
/**
|
|
159
|
+
* `orchestrator/<verified agent ID>`: the seat's own agent namespace, set at the
|
|
160
|
+
* bearer boundary from the verified seat stamp only ((bearerAuthMiddleware)).
|
|
161
|
+
* The namespace ceiling admits it besides the mint-time prefix snapshot, which
|
|
162
|
+
* predates `orchestrator/<agentId>` for older seat tokens. Absent: no verified agent.
|
|
163
|
+
*/
|
|
164
|
+
ownAgentNamespace?: string;
|
|
165
|
+
/**
|
|
166
|
+
* `project/<the caller's own org slug>`: set together with
|
|
167
|
+
* {@link OAuthContext.ownAgentNamespace} at the same place, for a caller that has
|
|
168
|
+
* a verified agent. Absent: no verified agent.
|
|
169
|
+
*/
|
|
170
|
+
ownProjectNamespace?: string;
|
|
158
171
|
/**
|
|
159
172
|
* The agent a PERSON token designates (see {@link personalActorOf}); already
|
|
160
173
|
* folded into {@link OAuthContext.actor} at the bearer boundary. Kept for
|
|
@@ -332,7 +345,7 @@ export declare function actingClaimRefusal(ctx: OAuthContext | undefined, claime
|
|
|
332
345
|
* Believed only when the stamp's org is the token's OWN org: a stamp that names
|
|
333
346
|
* another org's agent is never an identity for this token.
|
|
334
347
|
*/
|
|
335
|
-
export declare function seatAgentOf(ctx: OAuthContext): {
|
|
348
|
+
export declare function seatAgentOf(ctx: Pick<OAuthContext, "seatAgent" | "clerkOrgSlug">): {
|
|
336
349
|
agentId: string;
|
|
337
350
|
orgId: string;
|
|
338
351
|
agentName: string;
|
|
@@ -537,6 +550,16 @@ field?: string): Promise<string | null>;
|
|
|
537
550
|
* Otherwise the target namespace must start with one of the prefixes.
|
|
538
551
|
*/
|
|
539
552
|
export declare function checkNamespacePrefix(prefixes: string[], namespace: string): boolean;
|
|
553
|
+
/**
|
|
554
|
+
* THE one derivation of a client agent's own namespaces, applied after EVERY
|
|
555
|
+
* bearer branch (attachContextAndProceed), so no path carries its own carve-out.
|
|
556
|
+
* The agent ID is the one the path VERIFIED: the credential Convex resolved
|
|
557
|
+
* (`actor`, which also covers a person's resolved personal agent), else the seat
|
|
558
|
+
* stamp. Never a name, never an argument. The acting agent's org is judged where the
|
|
559
|
+
* actor is resolved (resolveActorFromRequest, the personal-agent resolver), not here. A caller with no verified agent
|
|
560
|
+
* owns no agent namespace and no extra project namespace.
|
|
561
|
+
*/
|
|
562
|
+
export declare function ownNamespacesOf(agentId: string | undefined, principalOrgSlug: string | null): Pick<OAuthContext, "ownAgentNamespace" | "ownProjectNamespace">;
|
|
540
563
|
export declare function checkNamespaceRead(ctx: OAuthContext | undefined, namespace: string | undefined): string | null;
|
|
541
564
|
export declare function checkNamespaceWrite(ctx: OAuthContext | undefined, namespace: string): string | null;
|
|
542
565
|
type ClerkPayload = {
|
package/dist/src/auth.js
CHANGED
|
@@ -669,6 +669,36 @@ export function checkNamespacePrefix(prefixes, namespace) {
|
|
|
669
669
|
}
|
|
670
670
|
return false;
|
|
671
671
|
}
|
|
672
|
+
/**
|
|
673
|
+
* The caller's own namespaces, set by {@link ownNamespacesOf} at the bearer
|
|
674
|
+
* boundary from a verified identity: `orchestrator/<agent ID>` and
|
|
675
|
+
* `project/<org slug>`. Admitted in read and write besides the prefix list.
|
|
676
|
+
*/
|
|
677
|
+
function checkOwnNamespaces(ctx, namespace) {
|
|
678
|
+
const own = [ctx.ownAgentNamespace, ctx.ownProjectNamespace].filter((p) => p !== undefined);
|
|
679
|
+
return own.length > 0 && checkNamespacePrefix(own, namespace);
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* THE one derivation of a client agent's own namespaces, applied after EVERY
|
|
683
|
+
* bearer branch (attachContextAndProceed), so no path carries its own carve-out.
|
|
684
|
+
* The agent ID is the one the path VERIFIED: the credential Convex resolved
|
|
685
|
+
* (`actor`, which also covers a person's resolved personal agent), else the seat
|
|
686
|
+
* stamp. Never a name, never an argument. The acting agent's org is judged where the
|
|
687
|
+
* actor is resolved (resolveActorFromRequest, the personal-agent resolver), not here. A caller with no verified agent
|
|
688
|
+
* owns no agent namespace and no extra project namespace.
|
|
689
|
+
*/
|
|
690
|
+
export function ownNamespacesOf(agentId, principalOrgSlug) {
|
|
691
|
+
// The master bearer arrives with no principal org (null) and owns everything by
|
|
692
|
+
// its "*" prefixes: it derives nothing here.
|
|
693
|
+
if (principalOrgSlug === null || principalOrgSlug === "")
|
|
694
|
+
return {};
|
|
695
|
+
if (agentId === undefined || agentId === "")
|
|
696
|
+
return {};
|
|
697
|
+
return {
|
|
698
|
+
ownAgentNamespace: `orchestrator/${agentId}`,
|
|
699
|
+
ownProjectNamespace: `project/${principalOrgSlug}`,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
672
702
|
export function checkNamespaceRead(ctx, namespace) {
|
|
673
703
|
if (!ctx)
|
|
674
704
|
return NO_CONTEXT_REFUSAL;
|
|
@@ -701,6 +731,8 @@ export function checkNamespaceRead(ctx, namespace) {
|
|
|
701
731
|
checkNamespacePrefix([`team/${ctx.orgClerkId}`], namespace)) {
|
|
702
732
|
return null;
|
|
703
733
|
}
|
|
734
|
+
if (checkOwnNamespaces(ctx, namespace))
|
|
735
|
+
return null;
|
|
704
736
|
return `Forbidden: namespace='${namespace}' is not readable by scope_profile=${ctx.scopeProfile}.`;
|
|
705
737
|
}
|
|
706
738
|
export function checkNamespaceWrite(ctx, namespace) {
|
|
@@ -710,6 +742,9 @@ export function checkNamespaceWrite(ctx, namespace) {
|
|
|
710
742
|
return null;
|
|
711
743
|
if (checkNamespacePrefix(ctx.namespaceWritePrefixes, namespace))
|
|
712
744
|
return null;
|
|
745
|
+
// The seat's own agent namespace by its verified agent ID (see ownNamespacesOf).
|
|
746
|
+
if (checkOwnNamespaces(ctx, namespace))
|
|
747
|
+
return null;
|
|
713
748
|
return `Forbidden: namespace='${namespace}' is not writable by scope_profile=${ctx.scopeProfile}.`;
|
|
714
749
|
}
|
|
715
750
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -940,7 +975,17 @@ export function bearerAuthMiddleware() {
|
|
|
940
975
|
c.header("WWW-Authenticate", wwwAuthHeader);
|
|
941
976
|
return c.json({ error: resolution.error }, resolution.status);
|
|
942
977
|
}
|
|
943
|
-
|
|
978
|
+
const withActor = resolution.actor
|
|
979
|
+
? { ...base, actor: resolution.actor }
|
|
980
|
+
: base;
|
|
981
|
+
c.set("oauthContext", {
|
|
982
|
+
...withActor,
|
|
983
|
+
// The agent ID this path verified: the credential Convex resolved (also a
|
|
984
|
+
// person's resolved personal agent), else the seat stamp. The actor's org
|
|
985
|
+
// was judged where it was resolved (a credential of another org is a 403
|
|
986
|
+
// in resolveActorFromRequest); no local comparison here.
|
|
987
|
+
...ownNamespacesOf(withActor.actor?.agentId ?? seatAgentOf(withActor)?.agentId, principalOrgSlug),
|
|
988
|
+
});
|
|
944
989
|
await next();
|
|
945
990
|
return undefined;
|
|
946
991
|
};
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* throws loudly, the latter is simply not a code path this client has.
|
|
20
20
|
*/
|
|
21
21
|
import type { ConvexHttpClient } from "convex/browser";
|
|
22
|
+
import { type OAuthContext } from "./auth.js";
|
|
22
23
|
/**
|
|
23
24
|
* Selects the per-request Convex client identity to attach to a /mcp call.
|
|
24
25
|
*
|
|
@@ -55,12 +56,27 @@ import type { ConvexHttpClient } from "convex/browser";
|
|
|
55
56
|
* an oauthContext for either shape — that credential class is refused
|
|
56
57
|
* with 401 before it ever reaches this selector).
|
|
57
58
|
*/
|
|
58
|
-
export declare function selectConvexClientForRequest(convexUrl: string, oauthCtx: {
|
|
59
|
-
clerkJwt?: string;
|
|
60
|
-
} | undefined, deps?: {
|
|
59
|
+
export declare function selectConvexClientForRequest(convexUrl: string, oauthCtx: OAuthContext | undefined, deps?: {
|
|
61
60
|
createServiceAccountClient?: (url: string) => ConvexHttpClient;
|
|
62
61
|
createPlainClient?: (url: string) => ConvexHttpClient;
|
|
63
62
|
}): ConvexHttpClient;
|
|
63
|
+
/**
|
|
64
|
+
* The organisation a NON-master, non-Clerk bearer's calls act for: the
|
|
65
|
+
* permanent org ID on its verified oauthContext, or undefined (no client is
|
|
66
|
+
* then given). The ONE predicate the client selection and the ui:// read gate
|
|
67
|
+
* share.
|
|
68
|
+
*/
|
|
69
|
+
export declare function actingOrgOfBearer(oauthCtx: Pick<OAuthContext, "orgClerkId">): string | undefined;
|
|
70
|
+
/** The reserved argument Convex reads on the service-account branch only. */
|
|
71
|
+
export declare const ACTING_ORG_ARG = "__actingOrg";
|
|
72
|
+
/**
|
|
73
|
+
* Every query/mutation/action of `client` carries `__actingOrg = org`, set last
|
|
74
|
+
* so a caller-supplied value never survives. A new args object each call; the
|
|
75
|
+
* caller's is not mutated. Other members pass through.
|
|
76
|
+
*/
|
|
77
|
+
export declare function withActingOrg(client: ConvexHttpClient, org: string): ConvexHttpClient;
|
|
78
|
+
/** The refusal every call of a no-organisation client rejects with. */
|
|
79
|
+
export declare const NO_ORG_CLIENT_REFUSAL = "RBAC_DENIED: refusing to call Convex \u2014 this caller has no verified organisation and absence is never the fleet";
|
|
64
80
|
/**
|
|
65
81
|
* Wraps an already-authenticated (`.setAuth()` already called) ConvexHttpClient
|
|
66
82
|
* so that `.query()` alone gets the single dead-socket retry (see
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* throws loudly, the latter is simply not a code path this client has.
|
|
20
20
|
*/
|
|
21
21
|
import { ConvexHttpClient as ConvexHttpClientCtor } from "convex/browser";
|
|
22
|
+
import { isMasterScope } from "./auth.js";
|
|
22
23
|
import { getServiceAccountToken } from "./serviceAccountAuth.js";
|
|
23
24
|
import { withSingleRetryOnSocketClose } from "./socketRetry.js";
|
|
24
25
|
const INTERCEPTED_METHODS = new Set(["query", "mutation", "action"]);
|
|
@@ -73,7 +74,72 @@ export function selectConvexClientForRequest(convexUrl, oauthCtx, deps) {
|
|
|
73
74
|
client.setAuth(clerkJwt);
|
|
74
75
|
return withQueryRetry(client);
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
+
// Absence is never master: no verified context, no client.
|
|
78
|
+
if (oauthCtx === undefined) {
|
|
79
|
+
return refusingClient("no authorization context on this request");
|
|
80
|
+
}
|
|
81
|
+
// The fleet (master bearer, local stdio trust): the plain service account.
|
|
82
|
+
if (isMasterScope(oauthCtx)) {
|
|
83
|
+
return createServiceAccountClient(convexUrl);
|
|
84
|
+
}
|
|
85
|
+
// Every other bearer reaches Convex as the service account ACTING FOR its own
|
|
86
|
+
// organisation (task k179y0wpsd6fv7055f4p2w6b358hdrxe). The org is the
|
|
87
|
+
// permanent ID `oauth:getAccessTokenByHash` read LIVE from the token row's
|
|
88
|
+
// ACTIVE mapping: a verified claim of the principal, never a tool argument.
|
|
89
|
+
// A bearer whose org resolves to no ID gets no client at all.
|
|
90
|
+
const actingOrg = actingOrgOfBearer(oauthCtx);
|
|
91
|
+
if (actingOrg === undefined) {
|
|
92
|
+
return refusingClient("this bearer's organisation resolves to no active organisation ID");
|
|
93
|
+
}
|
|
94
|
+
return withActingOrg(createServiceAccountClient(convexUrl), actingOrg);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The organisation a NON-master, non-Clerk bearer's calls act for: the
|
|
98
|
+
* permanent org ID on its verified oauthContext, or undefined (no client is
|
|
99
|
+
* then given). The ONE predicate the client selection and the ui:// read gate
|
|
100
|
+
* share.
|
|
101
|
+
*/
|
|
102
|
+
export function actingOrgOfBearer(oauthCtx) {
|
|
103
|
+
const org = oauthCtx.orgClerkId;
|
|
104
|
+
return org === undefined || org === "" ? undefined : org;
|
|
105
|
+
}
|
|
106
|
+
/** The reserved argument Convex reads on the service-account branch only. */
|
|
107
|
+
export const ACTING_ORG_ARG = "__actingOrg";
|
|
108
|
+
/**
|
|
109
|
+
* Every query/mutation/action of `client` carries `__actingOrg = org`, set last
|
|
110
|
+
* so a caller-supplied value never survives. A new args object each call; the
|
|
111
|
+
* caller's is not mutated. Other members pass through.
|
|
112
|
+
*/
|
|
113
|
+
export function withActingOrg(client, org) {
|
|
114
|
+
return new Proxy(client, {
|
|
115
|
+
get(target, prop, receiver) {
|
|
116
|
+
const original = Reflect.get(target, prop, receiver);
|
|
117
|
+
if (typeof prop === "string" &&
|
|
118
|
+
INTERCEPTED_METHODS.has(prop) &&
|
|
119
|
+
typeof original === "function") {
|
|
120
|
+
return (fn, args, ...rest) => original.call(target, fn, { ...(args ?? {}), [ACTING_ORG_ARG]: org }, ...rest);
|
|
121
|
+
}
|
|
122
|
+
return original;
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** The refusal every call of a no-organisation client rejects with. */
|
|
127
|
+
export const NO_ORG_CLIENT_REFUSAL = "RBAC_DENIED: refusing to call Convex — this caller has no verified organisation and absence is never the fleet";
|
|
128
|
+
/**
|
|
129
|
+
* A client none of whose calls reach the wire: each rejects RBAC_DENIED. What a
|
|
130
|
+
* caller with no resolvable organisation gets instead of the fleet identity.
|
|
131
|
+
*/
|
|
132
|
+
function refusingClient(reason) {
|
|
133
|
+
const refuse = async () => {
|
|
134
|
+
throw new Error(`${NO_ORG_CLIENT_REFUSAL} — ${reason}`);
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
query: refuse,
|
|
138
|
+
mutation: refuse,
|
|
139
|
+
action: refuse,
|
|
140
|
+
setAuth: () => undefined,
|
|
141
|
+
clearAuth: () => undefined,
|
|
142
|
+
};
|
|
77
143
|
}
|
|
78
144
|
/**
|
|
79
145
|
* Wraps an already-authenticated (`.setAuth()` already called) ConvexHttpClient
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* to it -- write the literal.
|
|
40
40
|
*/
|
|
41
41
|
/** Contract version this MCP build requires from the backend. */
|
|
42
|
-
export declare const REQUIRED_CONTRACT_VERSION =
|
|
42
|
+
export declare const REQUIRED_CONTRACT_VERSION = 17;
|
|
43
43
|
/** Every public Convex function this MCP build calls (`module:function`). */
|
|
44
44
|
export declare const MCP_CALLED_FUNCTIONS: readonly string[];
|
|
45
45
|
export type BackendCompatFailure = "no-manifest" | "refused" | "cannot-authenticate" | "version-too-old" | "malformed" | "missing-functions" | "unreachable";
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* to it -- write the literal.
|
|
40
40
|
*/
|
|
41
41
|
/** Contract version this MCP build requires from the backend. */
|
|
42
|
-
export const REQUIRED_CONTRACT_VERSION =
|
|
42
|
+
export const REQUIRED_CONTRACT_VERSION = 17;
|
|
43
43
|
/** Every public Convex function this MCP build calls (`module:function`). */
|
|
44
44
|
export const MCP_CALLED_FUNCTIONS = [
|
|
45
45
|
"agentCredentials:resolveAgentCredential",
|
|
@@ -183,6 +183,9 @@ export const MCP_CALLED_FUNCTIONS = [
|
|
|
183
183
|
"tasks:searchTasksByKeyword",
|
|
184
184
|
"tasks:start",
|
|
185
185
|
"tasks:update",
|
|
186
|
+
"toolUsage:getToolUsage",
|
|
187
|
+
"toolUsage:record",
|
|
188
|
+
"toolUsage:usageByOwner",
|
|
186
189
|
];
|
|
187
190
|
const MANIFEST_DOOR = "meta:backendContract";
|
|
188
191
|
const RETRY_DELAYS_MS = [1000, 2000, 4000];
|
package/dist/src/doorScope.d.ts
CHANGED
|
@@ -22,12 +22,28 @@ export declare const DOOR_SCOPE: Readonly<Record<string, DoorScopeRule>>;
|
|
|
22
22
|
* caller (whose own org Convex already sees) have none here.
|
|
23
23
|
*/
|
|
24
24
|
export declare function verifiedOrgSlugOf(oauthCtx: OAuthContext | undefined): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The permanent Clerk org ID of the organisation {@link verifiedOrgSlugOf} names,
|
|
27
|
+
* when the verified token carries it (`orgClerkId`, read LIVE from the org's
|
|
28
|
+
* ACTIVE mapping by `oauth:getAccessTokenByHash`). Convex keys the `verifiedOrg`
|
|
29
|
+
* claim by this ID: a slug is a renamable label another organisation can take
|
|
30
|
+
* over. It is the ID of the TOKEN's organisation; an agent credential presented
|
|
31
|
+
* with a non-master bearer is already bound to that same organisation at the
|
|
32
|
+
* boundary (auth.ts resolveActorFromRequest refuses ORG_MISMATCH otherwise), so
|
|
33
|
+
* the ID names the verified org whichever of the two the slug was read from.
|
|
34
|
+
* Used only beside a verified slug, which the master and a Clerk session never
|
|
35
|
+
* have. Undefined when the Convex predates the field or the org has no ID yet;
|
|
36
|
+
* the claim then goes slug-only, which Convex still accepts.
|
|
37
|
+
*/
|
|
38
|
+
export declare function verifiedOrgIdOf(oauthCtx: OAuthContext | undefined): string | undefined;
|
|
25
39
|
/** What the verified oauthContext says about the caller. Never a tool argument. */
|
|
26
40
|
export type DoorScopeFacts = {
|
|
27
41
|
/** The bearer hash of a PERSON token, when the caller is a person acting as itself. */
|
|
28
42
|
readonly personAccessTokenHash?: string;
|
|
29
43
|
/** The bearer's verified org (agent credential's, or the token row's); none for master / Clerk. */
|
|
30
44
|
readonly verifiedOrgSlug?: string;
|
|
45
|
+
/** The permanent ID of that org (see {@link verifiedOrgIdOf}); absent forwards the slug alone. */
|
|
46
|
+
readonly verifiedOrgId?: string;
|
|
31
47
|
/** True when the bearer resolved ONE agent ID (withVerifiedActor forwards it). */
|
|
32
48
|
readonly hasVerifiedActor: boolean;
|
|
33
49
|
/** The seat's org for a recipient-scoped door (resolveSeatOrg). */
|
|
@@ -39,6 +55,7 @@ export type DoorScopeArgs = {
|
|
|
39
55
|
};
|
|
40
56
|
verifiedOrg?: {
|
|
41
57
|
orgSlug: string;
|
|
58
|
+
orgId?: string;
|
|
42
59
|
};
|
|
43
60
|
seatOrgSlug?: string;
|
|
44
61
|
seatOrgClerkId?: string;
|