Commit 1f18569
fix(mcp): make remote /api/v1/mcp data plane work for external agents
The remote MCP HTTP surface (ADR-0036) was non-functional for external
agents: every call 401'd with a valid key, standard MCP clients couldn't
connect, and writes threw "ql.insert is not a function". All three are the
same family — the MCP route resolves data services differently from REST.
- resolveExecutionContext getQl: resolve objectql from the per-request kernel
directly (kernel.getServiceAsync) instead of the scoped resolveService, which
in the multi-env runtime hands back an instance blind to the env's
sys_api_key rows so the api-key never resolved (→ 401). REST already resolves
identity this way (rest-server), so REST + MCP no longer drift.
- extractApiKey: accept `Authorization: Bearer osk_<key>` (prefix-gated). Remote
MCP clients (Claude Desktop / Cursor / Claude Code) send the key as a Bearer
per the MCP spec; a better-auth session Bearer never carries the osk_ prefix,
so the session path is unaffected.
- callData create/update/delete: route through protocol.createData/updateData/
deleteData (mirroring the read paths and REST) instead of calling ql.insert on
context.dataDriver, which in the multi-env runtime is a raw db driver with no
ORM methods.
Validated on a local isolated stack: tools/list 401->200 (X-API-Key AND Bearer),
create_record succeeds, sys_* and no-auth stay fail-closed, REST unaffected.
Unit: mcp 44/44, core api-key 10/10, runtime mcp/exec-ctx/keys 41/41.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7e223a8 commit 1f18569
4 files changed
Lines changed: 74 additions & 15 deletions
File tree
- packages
- core/src/security
- runtime/src
- security
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
46 | 58 | | |
47 | 59 | | |
48 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
291 | 300 | | |
292 | 301 | | |
293 | 302 | | |
| |||
310 | 319 | | |
311 | 320 | | |
312 | 321 | | |
313 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
314 | 326 | | |
315 | 327 | | |
316 | 328 | | |
| |||
323 | 335 | | |
324 | 336 | | |
325 | 337 | | |
326 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
327 | 342 | | |
328 | 343 | | |
329 | 344 | | |
| |||
3192 | 3207 | | |
3193 | 3208 | | |
3194 | 3209 | | |
3195 | | - | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
3196 | 3227 | | |
3197 | 3228 | | |
3198 | 3229 | | |
| |||
Lines changed: 11 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
138 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
142 | 149 | | |
143 | 150 | | |
144 | 151 | | |
| |||
0 commit comments