Repository navigation
feat(broker): service tokens for apps (TZ-5, part 1) - #312
Conversation
An app may declare `service: "<id>"`; its tools get the caller's token to that service from the /mcp request header `X-Service-Token-<id>` through `call.serviceToken()` - its own service only, only while the call runs. No header, no token (fail closed). The token is masked in answers and errors and kept nowhere: a guard test looks for a fake token in every file of the data folder and every log line. - AppTool.run may return a Promise; callTool is async, the core's tools and apps without a token still answer synchronously - tools_call passes the request's headers on - callToolNow: the synchronous form for tests - service ids: ^[a-z0-9-]+$, one app per service; token: printable ASCII, no spaces, up to 1024, trimmed - the same rules as adapters/core Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Перевірив гілку локально (не лише diff): переключив клон на Логіка мені подобається: синхронний шлях справді лишається синхронним ( Блокерів немає. Три дрібниці, всі — «варто, але не зараз»:
Питання одне, не блокер: З мого боку (ТЗ-5, кроки 3–5) усе готове до інтеграції: |
…338) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TZ-5 v2 (project note #244), section 2, part 1: the core of the broker.
What changes
App.service?: string: the outside service an app works with on its callers' behalf (githubnext). Checked at start:^[a-z0-9-]+$, no two apps with the same service.AppTool.run(me, args, call): may return a Promise.call.serviceToken()takes no parameter: the token of the app's own service from the headerX-Service-Token-<service>of the current /mcp request, or null. Acallthe app keeps answers null once the call has ended.[service token].callToolis async and takesCallContext { headers };mcp.tspassesextra.requestInfo?.headers, andtools_callpasses them on. Everything else (preflight, tests) has no headers, so no token.settle/dispatch). Tests usecallToolNow, which throws on a tool that answers later.src/broker/service-tokens.ts: header parsing with the same rules assrc/adapters/core/serviceTokens.mjs(feat(adapters): shared service-token core #308): trimmed, printable ASCII without spaces, ≤1024. An empty value counts as no header ({file:}in OpenCode gives exactly that when the file is missing).Tests (
service-tokens.test.ts, through a real /mcp)callgives null after the callnpm testlocally: 672 tests, 666 pass. The 5 failures areupdater.testunder Git Bash (tartakesC:for a host), the environment and unrelated to this change; CI will run them properly.Next (part 2):
src/apps/github,GET /api/services,POST /api/services/<id>/check.🤖 Generated with Claude Code