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: RoutingClass

Base 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.

index()[source]

Return HTML splash page. Override for custom index.

Return type:

str

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.

Return type:

tuple[bytes, str] | None

Returns:

Tuple of (content_bytes, mime_type) or None if not found.

on_init(**kwargs)[source]

Called after base initialization. Override for custom setup.

Parameters:

**kwargs (Any) – Parameters from config.yaml app definition.

Return type:

None

on_shutdown()[source]

Called when server stops. Override for custom cleanup.

Can be sync or async. Called in reverse order of startup.

Return type:

None

on_startup()[source]

Called when server starts. Override for custom initialization.

Can be sync or async. Called after all apps are mounted.

Return type:

None

openapi_info: ClassVar[dict[str, Any]] = {}
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: AsgiApplication

ASGI 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)
__init__(**kwargs)[source]

Initialize with optional mcp_name/mcp_version overrides.

mcp_name: str = 'genro-mcp'
mcp_version: str = '1.0.0'
set_router(router)[source]

Set the external genro-routes Router to expose as MCP tools.

Return type:

None