Skip to content

fix(mcp): return 404 when the MCP service is missing - #6208

Open
Yuaneen wants to merge 1 commit into
Tencent:mainfrom
Yuaneen:fix/mcp-service-not-found-404
Open

Yuaneen wants to merge 1 commit into
Tencent:mainfrom
Yuaneen:fix/mcp-service-not-found-404

Conversation

@Yuaneen

@Yuaneen Yuaneen commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

DELETE /mcp-services/{id}, GET /mcp-services/{id}/tools and GET /mcp-services/{id}/resources returned 500 Internal server error when the registration did not exist, while GET /mcp-services/{id} already returned 404 for the same missing resource.

The three service methods returned fmt.Errorf("MCP service not found") instead of the existing types.ErrMCPServiceNotFound sentinel (already returned by GetMCPServiceByID since #5921), so the handlers could not classify the miss and wrapped every error as an internal error. That also echoed the wrapped error text into the response body.

Return the sentinel from DeleteMCPService, GetMCPServiceTools and GetMCPServiceResources, and map it to 404 in the handlers. Any other error (for example a storage failure) stays a 500 and no longer appends internals to the message.

Type of Change

  • 🐛 Bug fix
  • 🧪 Test

Related Issue

Fixes #6207

Testing

  • New handler regressions exercise the real SQLite repository, service and error middleware:
    • TestMCPServiceMissingRegistrationReturnsNotFound: all three endpoints return 404 and the body does not contain Internal server error.
    • TestMCPServiceLookupFailureStaysInternalError: after closing the DB, all three still return 500 and the body does not contain database is closed.
  • Before the fix the first test failed with expected: 404, actual: 500, and the second failed because the storage error was echoed; both pass after the fix.
  • go test ./internal/handler -run 'TestMCPService' -count=1 -> ok
  • go test ./internal/handler -run 'MCP' -count=1 -> ok
  • go build ./internal/handler ./internal/application/service -> ok
  • gofmt -l on the changed files -> no output
  • git diff --check origin/main...HEAD -> passes

The full root-module go test ./... was not run locally because the environment cannot link the prebuilt DuckDB archives; CI covers it. golangci-lint is not installed in this environment.

Codex assisted with the implementation and test preparation; I reviewed the diff and ran the focused checks above.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages pass
  • golangci-lint (passes in CI in 1m22s)
  • Full go test ./... (covered by the CI "Format, vet, test, and build" job, 22m22s, pass)

DeleteMCPService, GetMCPServiceTools and GetMCPServiceResources returned an
untyped error for a missing registration, so their handlers answered 500
Internal server error while GET /mcp-services/{id} already answered 404.

Return the existing types.ErrMCPServiceNotFound sentinel from those three
service methods and map it to 404 in the handlers; any other error stays a
500 and no longer echoes internals into the response.
@Yuaneen
Yuaneen force-pushed the fix/mcp-service-not-found-404 branch from 0ee54d6 to 011829e Compare November 30, 2026 06:40
@Yuaneen
Yuaneen marked this pull request as ready for review November 30, 2026 07:04

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.

[Bug]: MCP service delete/tools/resources return 500 when the service is missing

1 participant