novelai_image_mcp.server

The MCP server composition root. Owns the shared httpx.AsyncClient and NovelAIClient via an MCP lifespan, registers all 11 tools, and selects the transport at startup.

See also

Architecture → MCPServer composition root for a narrative walkthrough of how the lifespan + tools wire together.

MCP server: lifespan owns the shared httpx session + NovelAIClient.

The server is a thin composition root over nai.NovelAIClient. The lifespan creates one long-lived httpx.AsyncClient (connection pooling) and one NovelAIClient; every tool reads them from ctx.request_context.lifespan_context (the MCP v2 Context API). Transport is selected at runtime from MCP_TRANSPORT (stdio by default, streamable-http for remote deployments).

class novelai_image_mcp.server.AppContext(client, settings)[source]

Bases: object

Shared state yielded by the lifespan to every tool invocation.

Parameters:
client: NovelAIClient
settings: NovelAISettings
novelai_image_mcp.server.lifespan(_server)[source]

Build the NovelAI client from settings; tear down on shutdown.

Parameters:

_server (MCPServer)

Return type:

AsyncIterator[AppContext]

novelai_image_mcp.server.main()[source]

Run the server with the transport selected from MCP_* settings.

Return type:

None