refactor: extract transport-agnostic core and shared tool registry
Introduce aegis_gitea_mcp.registry as the single name->handler source of truth consumed by every transport adapter, moving TOOL_HANDLERS out of the FastAPI server module. Add aegis_gitea_mcp.errors.ToolError so core handlers no longer import fastapi.HTTPException; raw_tools now raises ToolError and the HTTP adapter maps it back to HTTPException, preserving status codes and audit behavior. Add a subprocess boundary test asserting the core imports without pulling in fastapi/uvicorn/starlette. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""Transport-agnostic error types raised by the core.
|
||||
|
||||
Core tool handlers and the authorization layer must not depend on the web stack
|
||||
(FastAPI). They raise :class:`ToolError` carrying an advisory HTTP status code;
|
||||
each transport adapter maps it to its own wire format (the HTTP adapter to
|
||||
``fastapi.HTTPException``, the stdio adapter to an MCP error). This keeps the
|
||||
core importable without FastAPI installed.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class ToolError(Exception):
|
||||
"""Error raised by a core tool handler or the authorization layer.
|
||||
|
||||
Args:
|
||||
message: Human-readable, non-sensitive error detail.
|
||||
status_code: Advisory HTTP status (e.g. 403 for denied). Adapters map
|
||||
this to their transport; the stdio adapter only uses the message.
|
||||
"""
|
||||
|
||||
def __init__(self, message: str, *, status_code: int = 400) -> None:
|
||||
super().__init__(message)
|
||||
self.status_code = status_code
|
||||
self.detail = message
|
||||
Reference in New Issue
Block a user