Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(mcp-host): throw a typed broker error carrying status and code
Jose Ramirez27dfcedf3234
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 365674759..1b2cdbea5 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.232",+ "version": "0.1.233","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.232",+ "version": "0.1.233","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 92d6ef984..ec5770fb2 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.232",+ "version": "0.1.233","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/tools/__tests__/workflowBrokerClient.error.test.ts b/mcp-host/src/core/tools/__tests__/workflowBrokerClient.error.test.tsnew file mode 100644index 000000000..2825caad7--- /dev/null+++ b/mcp-host/src/core/tools/__tests__/workflowBrokerClient.error.test.ts@@ -0,0 +1,34 @@+import { describe, expect, it, vi } from 'vitest'+import { WorkflowBrokerClient, WorkflowBrokerRequestError } from '../workflowBrokerClient'++function clientWithResponse(status: number, body: string) {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => new Response(body, { status }))+ )+ return new WorkflowBrokerClient(+ (key: string) => (key === 'MCP_HOST_GATEWAY_URL' ? 'http://gateway.test' : undefined),+ { getWorkflowControlToken: async () => 'token' }+ )+}++describe('WorkflowBrokerClient.request error typing', () => {+ it('throws WorkflowBrokerRequestError with status and code for a 404', async () => {+ const client = clientWithResponse(404, JSON.stringify({ error: 'medium_account_not_found' }))+ await expect(client.request('/api/v1/x', { method: 'POST' })).rejects.toMatchObject({+ status: 404,+ code: 'medium_account_not_found',+ })+ await expect(client.request('/api/v1/x', { method: 'POST' })).rejects.toBeInstanceOf(+ WorkflowBrokerRequestError+ )+ })++ it('sets code to null when the body carries no recognizable error code', async () => {+ const client = clientWithResponse(500, 'upstream exploded')+ await expect(client.request('/api/v1/x', { method: 'POST' })).rejects.toMatchObject({+ status: 500,+ code: null,+ })+ })+})diff --git a/mcp-host/src/core/tools/workflowBrokerClient.ts b/mcp-host/src/core/tools/workflowBrokerClient.tsindex 238154d3f..dae058f93 100644--- a/mcp-host/src/core/tools/workflowBrokerClient.ts+++ b/mcp-host/src/core/tools/workflowBrokerClient.ts@@ -2,6 +2,18 @@ import type { EnvGetter } from './workflowShared'import { trimTrailingSlash } from './workflowShared'import type { WorkflowControlTokenProvider } from './workflowTokenProvider'+export class WorkflowBrokerRequestError extends Error {+ readonly status: number+ readonly code: string | null++ constructor(status: number, code: string | null, message: string) {+ super(message)+ this.name = 'WorkflowBrokerRequestError'+ this.status = status+ this.code = code+ }+}+export class WorkflowBrokerClient {private readonly tokenProvider: WorkflowControlTokenProvider@@ -47,7 +59,11 @@ export class WorkflowBrokerClient {if (!response.ok) {const body = await response.text().catch(() => '')- throw new Error(formatBrokerError(response.status, body))+ throw new WorkflowBrokerRequestError(+ response.status,+ safeErrorCodeFromBody(body),+ formatBrokerError(response.status, body)+ )}return response.json()@@ -65,7 +81,11 @@ export class WorkflowBrokerClient {if (!response.ok) {const body = await response.text().catch(() => '')- throw new Error(formatBrokerError(response.status, body))+ throw new WorkflowBrokerRequestError(+ response.status,+ safeErrorCodeFromBody(body),+ formatBrokerError(response.status, body)+ )}const contentLength = response.headers.get('content-length')?.trim() || ''