fix: normalize MCP tool error formatting

This commit is contained in:
2026-06-12 13:03:47 +01:00
parent b65ee3a598
commit d94f5b97c1
4 changed files with 92 additions and 20 deletions
+40 -1
View File
@@ -526,4 +526,43 @@ Register `review_plan`, `review_code`, `debug_issue`, and `architecture_review`
Status: ✅ Complete
### Task 5.4 - Normalize MCP tool error formatting (NEXT)
### Task 5.4 - Normalize MCP tool error formatting
Ensure all MCP tool error messages have a single, consistent "Error:" prefix.
Before this change, handlers returned errors prefixed with `"Error: "` and server.js prepended another `"Error: "`, producing duplicates like:
```
Error: Error: Configuration error: OPENAI_API_KEY is missing.
```
**Changes made (`src/server.js`):**
Each of the 5 tool registration callbacks now normalizes error text:
```js
const text = result.ok
? result.answer
: String(result.error || "Unknown error").startsWith("Error:")
? result.error
: `Error: ${result.error}`;
```
After fix:
- `"Error: Configuration error: OPENAI_API_KEY is missing."` — single prefix ✅
- Non-"Error:"-prefixed errors receive one prefix added by the server ✅
- Success responses unchanged ✅
Smoke tests:
| Test | Result |
|------|--------|
| npm test | ✅ 523 passed, no regressions |
| tools/list | ✅ 5 tools, unchanged |
| ask_chatgpt (no API key) | ✅ Single "Error:" prefix |
| review_plan (no API key) | ✅ Single "Error:" prefix |
Status: ✅ Complete
### Task 5.5 - Claude Code MCP configuration and local end-to-end setup (NEXT)