novelai_image_mcp.server

MCP サーバーのコンポジションルート。MCP の lifespan を通じて共有の httpx.AsyncClient と NovelAIClient を所有し、11 個すべてのツールを登録し、起動時にトランスポートを選択します。

関連項目

アーキテクチャ → FastMCP コンポジションルート — ライフスパンとツールがどう配線されるかの解説

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

The server is a thin composition root over nai.NovelAIClient, built on the FastMCP 4 framework (which itself runs on the MCP SDK v2). The lifespan creates one long-lived httpx.AsyncClient (connection pooling, with Chrome TLS + header fingerprint impersonation via create_http_client) and one NovelAIClient; every MCP component receives them through dependency injection (see deps) instead of reaching into the request context.

Tools, resources and prompts are attached to the shared mcp instance by importing their modules at the bottom of this file: each one decorates mcp at import time and imports mcp back from this module, which is safe because mcp is already bound by then.

novelai_image_mcp.server.INSTRUCTIONS

The server-level instructions an agent receives, describing the tools, the intended workflow and where generated images land.

novelai_image_mcp.server.lifespan(_server)[ソース]

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

パラメータ:

_server (FastMCP)

戻り値の型:

AsyncIterator[AppContext]

novelai_image_mcp.server.main()[ソース]

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

戻り値の型:

None