#6397·genkit

feat(py/plugins/mcp): expose Genkit tools and prompts as an MCP server

Author: cabljacCreated Sep 22, 2026Updated Sep 22, 2026
Labelspython

Server half of the MCP plugin, the follow-up named in #6194. JS and Go both ship one; Python can call an MCP server but cannot be one.

Four stacked slices, each green on its own:

  • S1 stdio. create_mcp_server(ai, name) built on the lowlevel SDK Server rather than FastMCP, whose tool list is fixed at decoration time. The lowlevel list handler runs per request, so a tool defined after the server was built is still served. Result mapping is the inverse of the client's reader, so a tool re-exported through both keeps its output, content and metadata.
  • S2 sample. py/samples/mcp-server-hello, with a client that exercises it without an API key.
  • S3 streamable HTTP. session_manager() and asgi_app() for mounting into an existing Starlette or FastAPI app.
  • S4 prompts. Genkit prompts as MCP prompts. The prompts capability is advertised only once this lands, rather than always as JS does.

Deliberate deviations, each worth a yes or no:

  • Listing and calling read the same pairs, so a tool whose input schema is not an object is skipped from the listing and is not reachable by name either. MCP arguments are always an object; skipping it from the listing alone would leave it callable with a shape its handler cannot accept.
  • outputSchema is advertised for object schemas only. The SDK rejects any unstructured result from a tool that declares one, so advertising a scalar schema would break every call to that tool.
  • The call handler never raises. A Genkit error names a trace id the client cannot see, so a failure becomes an isError result carrying the cause's message alone.
  • start() captures the real stdout for the transport, then points the process's stdout at stderr, because stdout is the wire and structlog's default writes there. redirect_stdout=False opts out. Same hazard as #2954 on the JS side.
  • Tools from a dynamic action provider are re-exported only through an explicit providers= walk, off by default, since the registry listing does not include them. A server that transitively hosts a client of itself spawns a child per listing; documented rather than guarded.
  • create_mcp_server registers nothing, so it is a create_ and not a define_, matching the split the client already uses.

Known gaps: scalar outputs and strings that look like JSON do not round-trip exactly, matching JS; TextPart content folds into output on the way back; no notifications/tools/list_changed, and neither JS nor Go sends it; no progress, cancellation, sampling or elicitation; Windows stdio untested, since py CI is ubuntu-only.

Excluded: MCP resources, which are being removed from py core.