Skip to content

Conversation

@crivetimihai
Copy link
Member

Summary

  • Ensure server exists before deletion by calling get_server() first
  • Return HTTP 404 (not 400) when attempting to delete a non-existent server

Related

Changes

  1. mcpgateway/main.py: Add get_server() call before delete_server() to validate server existence
  2. tests/unit/mcpgateway/test_main.py: Update existing test and add new test for 404 response

Root Cause

The delete_server service method has a broad except Exception handler that catches ServerNotFoundError and converts it to a generic ServerError, resulting in HTTP 400 instead of 404.

Solution

This fix follows the same pattern used by delete_gateway (line 3874 in main.py) - call the getter first to trigger the proper 404 response.

A more comprehensive refactor of the service exception handling is tracked in #1591.

DuarteMartinho and others added 2 commits December 13, 2025 01:01
…nction

Signed-off-by: Duarte Martinho <dmartinho@ibm.com>
Update test_delete_server_endpoint to mock get_server which is now
called before delete_server to verify server existence.

Add test_delete_server_not_found to verify that attempting to delete
a non-existent server returns HTTP 404 instead of 400.

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai merged commit f256e98 into main Dec 13, 2025
52 checks passed
@crivetimihai crivetimihai deleted the fix/server-delete-404 branch December 13, 2025 01:08
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]: When attempting to delete a virtual server that is not found - it returns wrong status code

3 participants