Applications
Mountable ASGI application types.
AsgiApplication
Base class for all genro-asgi applications.
AsgiApplication package.
- 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"
- __init__(**kwargs)[source]
Initialize app with default main router.
- Parameters:
**kwargs (
Any) – Passed toon_init()after extractingbase_diranddb_name.
- 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 package.
- class genro_asgi.applications.mcp_application.McpApplication(**kwargs)[source]
Bases:
AsgiApplicationMCP Streamable HTTP transport as a genro-asgi application.
Accepts an external genro-routes Router and exposes its @route entries as MCP tools via JSON-RPC 2.0 over HTTP POST.
Mounts inside the server like any other app and participates in the full middleware chain (auth, CORS, errors). The
indexroute handles all JSON-RPC messages via the default_entry mechanism.Usage:
class SourcererMcpApp(McpApplication): mcp_name = "sourcerer" mcp_version = "1.0.0" def on_init(self, **kwargs): api = SourcererAPI(...) self.set_router(api.api)