Skip to content

Commit 905b270

Browse files
committed
admin_add_server_exception_update_fix
Signed-off-by: Satya <[email protected]>
1 parent 0a10983 commit 905b270

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

mcpgateway/admin.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,9 @@ async def admin_add_gateway(request: Request, db: Session = Depends(get_db), use
22932293
# Convert KeyError to ValidationError-like response
22942294
return JSONResponse(content={"message": f"Missing required field: {e}", "success": False}, status_code=422)
22952295

2296-
except ValueError as ex:
2296+
except ValidationError as ex:
22972297
# --- Getting only the custom message from the ValueError ---
2298-
error_ctx = []
2299-
logger.info(f" ALL -> {ex.errors()}")
2300-
for err in ex.errors():
2301-
error_ctx.append(str(err["ctx"]["error"]))
2298+
error_ctx = [str(err["ctx"]["error"]) for err in ex.errors()]
23022299
return JSONResponse(content={"success": False, "message": "; ".join(error_ctx)}, status_code=422)
23032300

23042301
try:

mcpgateway/schemas.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,16 @@ class PromptInvocation(BaseModelWithConfigDict):
15721572

15731573
# --- Transport Type ---
15741574
class TransportType(str, Enum):
1575+
"""
1576+
Enumeration of supported transport mechanisms for communication between components.
1577+
1578+
Attributes:
1579+
SSE (str): Server-Sent Events transport.
1580+
HTTP (str): Standard HTTP-based transport.
1581+
STDIO (str): Standard input/output transport.
1582+
STREAMABLEHTTP (str): HTTP transport with streaming.
1583+
"""
1584+
15751585
SSE = "SSE"
15761586
HTTP = "HTTP"
15771587
STDIO = "STDIO"
@@ -1690,6 +1700,24 @@ def create_auth_value(cls, v, info):
16901700
@field_validator("transport")
16911701
@classmethod
16921702
def validate_transport(cls, v: str) -> str:
1703+
"""
1704+
Validates that the given transport value is one of the supported TransportType values.
1705+
1706+
Args:
1707+
v (str): The transport value to validate.
1708+
1709+
Returns:
1710+
str: The validated transport value if it is valid.
1711+
1712+
Raises:
1713+
ValueError: If the provided value is not a valid transport type.
1714+
1715+
Valid transport types are defined in the TransportType enum:
1716+
- SSE
1717+
- HTTP
1718+
- STDIO
1719+
- STREAMABLEHTTP
1720+
"""
16931721
if v not in [t.value for t in TransportType]:
16941722
raise ValueError(f"Invalid transport type: {v}. Must be one of: {', '.join([t.value for t in TransportType])}")
16951723
return v

0 commit comments

Comments
 (0)