Applications
Mountable ASGI application types.
AsgiApplication
Base class for all genro-asgi applications.
AsgiApplication - Base class for ASGI applications.
- class genro_asgi.applications.asgi_application.AsgiApplication(**kwargs)[source]
Bases:
RoutingClassBase class for apps mounted on AsgiServer.
Provides default main router and index() method. Subclasses define openapi_info for metadata and add routes with @route() decorator.
Example:
class MyApp(AsgiApplication): openapi_info = {"title": "My API", "version": "1.0.0"} @route() # Uses the only router (self.main) automatically def hello(self): return "Hello!" def __init__(self, **kwargs): super().__init__(**kwargs) # Required: creates self.main self.backoffice = Router(self, name="backoffice") @route("backoffice") # Must specify when multiple routers def admin(self): return "Admin panel"
- load_resource(*args, name)[source]
Load resource file content with mime type.
When mounted on server: uses server’s ResourceLoader with fallback to local. Standalone: reads directly from resources_dir.
- on_shutdown()[source]
Called when server stops. Override for custom cleanup.
Can be sync or async. Called in reverse order of startup.
- Return type:
- on_startup()[source]
Called when server starts. Override for custom initialization.
Can be sync or async. Called after all apps are mounted.
- Return type:
- property resources_dir: Path | None
Return path to app’s resources directory.
Works both when mounted on server and standalone.
- property server: AsgiServer | None
Return the server that mounted this app (semantic alias for _routing_parent).
McpApplication
MCP Streamable HTTP transport application.
McpApplication - MCP Streamable HTTP transport for genro-asgi.
Implements the MCP (Model Context Protocol) Streamable HTTP transport using JSON-RPC 2.0 envelopes over HTTP POST.
Spec references: - JSON-RPC 2.0: https://www.jsonrpc.org/specification - MCP Streamable HTTP: stateless mode (json_response=True, stateless_http=True)
Protocol summary: - All requests: POST / with JSON-RPC 2.0 body - Request (has “id”): process and return JSON-RPC result - Notification (no “id”): return HTTP 202, no body - tools/list: enumerate tools from the router - tools/call: dispatch to router node by path - initialize: return server capabilities
- Tool name to route path convention:
“code_search_symbols” → “code/search_symbols”
- class genro_asgi.applications.mcp_application.McpApplication(**kwargs)[source]
Bases:
AsgiApplicationASGI application implementing MCP Streamable HTTP transport.
Accepts an external genro-routes Router and exposes its @route entries as MCP tools via JSON-RPC 2.0 over HTTP POST.
Usage:
class SourcererMcpApp(McpApplication): mcp_name = "sourcerer" mcp_version = "1.0.0" def on_init(self, **kwargs): api = SourcererAPI(...) self.set_router(api.api)