Skip to content

fix(mcp): preserve not found errors - #204

Open
epowell40 wants to merge 1 commit into
BetterDB-inc:masterfrom
epowell40:codex/mcp-not-found-errors
Open

epowell40 wants to merge 1 commit into
BetterDB-inc:masterfrom
epowell40:codex/mcp-not-found-errors

Conversation

@epowell40

Copy link
Copy Markdown

Summary

  • preserve existing Nest HttpExceptions thrown inside MCP controller handlers instead of wrapping them as generic 500s
  • keep non-HTTP failures mapped to the existing generic 500 responses
  • add focused controller tests covering connection lookup 404s, service-level 404s, and non-HTTP fallback behavior

Fixes #155.

Verification

  • git diff --check passes with only Windows LF-to-CRLF warnings
  • SKIP_DOCKER_SETUP=true corepack pnpm --filter api test -- src/mcp/__tests__/mcp.controller.spec.ts is blocked in this local checkout before this test runs because Jest/ts-jest resolves ../../proprietary/licenses/license.module.ts and cannot resolve @nestjs/common / @nestjs/config
  • corepack pnpm --filter api build is blocked by the same proprietary workspace dependency resolution problem before reaching this change

Shikha-code36 added a commit to Shikha-code36/monitor that referenced this pull request Aug 21, 2026
Address review: mapMcpError collapsed the per-call log message and the
client-facing fallback into one string, so restoring the real status
code for BetterDB-inc#155 lost the connection id from every log line. Give
mapMcpError an optional logMessage param (defaults to fallback, so the
other 8 existing callers are unaffected) and pass id-bearing log
messages from all 19 mcp.controller.ts call sites.

Also ports BetterDB-inc#204's tests, which exercise the actual registry.get()
NotFoundException path instead of a mocked service method, plus a new
test asserting the id survives in the log line.
KIvanow pushed a commit that referenced this pull request Aug 30, 2026
)

* fix(mcp): propagate real HTTP status instead of generic 500 (#155)

mcp.controller.ts caught every error and rethrew a hardcoded 500,
discarding the NotFoundException that ConnectionRegistry.get() already
throws for a non-existent instanceId override. Switch to mapMcpError,
the helper already used by the sibling mcp-analytics/mcp-ai/vector-search
controllers, so a bad instanceId now surfaces as 404 as expected.

* fix(mcp): preserve error id in logs, keep client message generic

Address review: mapMcpError collapsed the per-call log message and the
client-facing fallback into one string, so restoring the real status
code for #155 lost the connection id from every log line. Give
mapMcpError an optional logMessage param (defaults to fallback, so the
other 8 existing callers are unaffected) and pass id-bearing log
messages from all 19 mcp.controller.ts call sites.

Also ports #204's tests, which exercise the actual registry.get()
NotFoundException path instead of a mocked service method, plus a new
test asserting the id survives in the log line.

* fix(mcp): stop leaking internal error text to MCP clients

mapMcpError appended ': \' to the client-facing
HttpException for any non-HTTP error, so an arbitrary internal
failure (connection string, query detail, etc.) could reach an
authenticated MCP caller verbatim. Return only the generic fallback
to the client; the real error still goes to logger.error via
logMessage/stack.

Shared by mcp.controller, mcp-analytics, mcp-ai, and vector-search —
verified no other test asserted on the old suffix text.

* fix(client-analytics): include connectionId in snapshot fetch failure log

getActivityTimeline already receives connectionId but the catch block
around getClientSnapshots logged without it, so a snapshot-fetch
failure on this one path was unattributable on a multi-connection
deployment. Same gap flagged by jamby77 in #405 review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tools return generic 500 for non-existent instanceId override

1 participant