Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): warn on broker 403 so a platform defect is observable (R4-M6)
Diego Zacariascc5f755453a5
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex cf13a33a3..9c8f272d3 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.293",+ "version": "0.1.294","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.293",+ "version": "0.1.294","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 8c4839332..a45cd59f5 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.293",+ "version": "0.1.294","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/mcp/__tests__/brokerTokenProvider.test.ts b/mcp-host/src/mcp/__tests__/brokerTokenProvider.test.tsindex cc0052f82..5927c9214 100644--- a/mcp-host/src/mcp/__tests__/brokerTokenProvider.test.ts+++ b/mcp-host/src/mcp/__tests__/brokerTokenProvider.test.ts@@ -111,16 +111,38 @@ describe('createBrokerTokenProvider — fail-closed contract', () => {expect(f).toHaveBeenCalledTimes(2)})- it('404 no_grant → resolves undefined (fail-closed, call not forwarded)', async () => {- const f = stubFetch(() => jsonResponse(404, { error: 'no_grant' }))- const p = createBrokerTokenProvider({ name: 'gh' }, { userId: 'alice' }, deps(f))- expect(await p.resolve()).toBeUndefined()+ it('404 no_grant → resolves undefined (fail-closed, call not forwarded, no warn)', async () => {+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ try {+ const f = stubFetch(() => jsonResponse(404, { error: 'no_grant' }))+ const p = createBrokerTokenProvider({ name: 'gh' }, { userId: 'alice' }, deps(f))+ expect(await p.resolve()).toBeUndefined()+ // Normal revocation is silent — no observability noise.+ expect(warn).not.toHaveBeenCalled()+ } finally {+ warn.mockRestore()+ }})- it('403 insufficient_scope → resolves undefined (fail-closed)', async () => {- const f = stubFetch(() => jsonResponse(403, { error: 'insufficient_scope' }))- const p = createBrokerTokenProvider({ name: 'gh' }, { userId: 'alice' }, deps(f))- expect(await p.resolve()).toBeUndefined()+ it('403 → resolves undefined (fail-closed) AND warns with status + serverName (R4-M6)', async () => {+ // 403 is a platform/permission defect (control-api rejected the principal),+ // NOT a normal revocation like 404. It must fail closed like 404 but emit a+ // warn so it is distinguishable in logs — the user sees "Connect" and+ // reconnecting never fixes it, so a silent 403 leaves no trace.+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ try {+ const f = stubFetch(() => jsonResponse(403, { error: 'insufficient_scope' }))+ const p = createBrokerTokenProvider({ name: 'gh' }, { userId: 'alice' }, deps(f))+ expect(await p.resolve()).toBeUndefined()+ expect(warn).toHaveBeenCalledTimes(1)+ const msg = warn.mock.calls[0][0] as string+ expect(msg).toContain('403')+ expect(msg).toContain('gh')+ // Never leak the subject or any token material into the log.+ expect(msg).not.toContain('alice')+ } finally {+ warn.mockRestore()+ }})it('500 → throws (never forwards a stale/empty token)', async () => {diff --git a/mcp-host/src/mcp/brokerTokenProvider.ts b/mcp-host/src/mcp/brokerTokenProvider.tsindex e3d38720f..5339a5655 100644--- a/mcp-host/src/mcp/brokerTokenProvider.ts+++ b/mcp-host/src/mcp/brokerTokenProvider.ts@@ -160,8 +160,19 @@ export function createBrokerTokenProvider(}return data.token}- // no_grant / insufficient_scope → fail closed as "no token".- if (res.status === 404 || res.status === 403) {+ // 404 no_grant → normal, expected revocation; fail closed silently.+ if (res.status === 404) {+ cached = undefined+ return undefined+ }+ // 403 → control-api rejected the principal (a platform/permission defect,+ // NOT a normal revocation). Fail closed like 404, but WARN so it is+ // distinguishable in logs: reconnecting will never fix it. server.name is+ // non-PII; never log the token, userId, or the control token.+ if (res.status === 403) {+ console.warn(+ `[BrokerTokenProvider] broker returned 403 for ${server.name}; failing closed (platform/permission defect, reconnect will not fix)`+ )cached = undefinedreturn undefined}