Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): derive Claude providerCode from the inner modeled type on fallthrough (R1-L1)
Diego Zacarias199af5b17f07
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 8519e148d..15f46834e 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.239",+ "version": "0.1.240","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.239",+ "version": "0.1.240","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 2dcb39dec..0fd114fe5 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.239",+ "version": "0.1.240","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/llm/__tests__/claude.classifyError.test.ts b/mcp-host/src/llm/__tests__/claude.classifyError.test.tsindex 962e47e47..6b56a9ea7 100644--- a/mcp-host/src/llm/__tests__/claude.classifyError.test.ts+++ b/mcp-host/src/llm/__tests__/claude.classifyError.test.ts@@ -100,6 +100,18 @@ describe('ClaudeProvider.classifyError', () => {expect(provider.classifyError(err).code).toBe(LlmErrorCode.ApiCallFailed)})+ it('surfaces the inner modeled type as providerCode for an unmapped enveloped error (R1-L1)', () => {+ // Derived from the real SDK constructor: `.error` is the FULL envelope, so a+ // fallthrough that reads the outer level gets the constant 'error' instead of+ // the real modeled type. invalid_request_error is not in the byType switch, so+ // it falls through to the shared HTTP classifier.+ const err = anthropicApiError(400, 'invalid_request_error', 'messages.0.role: Field required')+ const c = provider.classifyError(err)+ expect(c.code).toBe(LlmErrorCode.ApiCallFailed)+ expect(c.providerCode).toBe('invalid_request_error')+ expect(c.providerCode).not.toBe('error')+ })+it('falls back to unknown for plain Error', () => {const result = provider.classifyError(new Error('socket closed'))expect(result).toEqual({diff --git a/mcp-host/src/llm/claude.ts b/mcp-host/src/llm/claude.tsindex c53726137..5d08ba24a 100644--- a/mcp-host/src/llm/claude.ts+++ b/mcp-host/src/llm/claude.ts@@ -102,14 +102,24 @@ export class ClaudeProvider implements SingleTurnProvider {const httpClassification = classifyByHttpStatus(err)if (httpClassification) {+ // The shared classifier recovers providerCode from the OUTER envelope,+ // where Anthropic's modeled type is the constant 'error'. When the SDK gave+ // us the inner modeled type, prefer it so an unmapped Anthropic error (e.g.+ // invalid_request_error / authentication_error) surfaces its real code+ // instead of 'error' (R1-L1). No-op on non-enveloped shapes, where bodyType+ // already equals the shared classifier's providerCode.+ const classified =+ bodyType && httpClassification.providerCode !== bodyType+ ? { ...httpClassification, providerCode: bodyType }+ : httpClassification// Anthropic quirk: insufficient credit is reported as HTTP 400// (not 402), detectable only by message substring.if (- httpClassification.code === LlmErrorCode.ApiCallFailed &&- /credit balance is too low/i.test(httpClassification.message)+ classified.code === LlmErrorCode.ApiCallFailed &&+ /credit balance is too low/i.test(classified.message)) {return {- ...httpClassification,+ ...classified,code: LlmErrorCode.InsufficientQuota,retryable: false,// Prefer the inner-level message: on a real Anthropic envelope the@@ -117,7 +127,7 @@ export class ClaudeProvider implements SingleTurnProvider {message: rawMsg,}}- return httpClassification+ return classified}return classifyUnknown(err)}