Resolved

FastMCP client fails with connection closed and unknown tool errors

Python
FastMCP
Debugging
Backend
Microservices
Transport Layer
Virtual Environment
Async

FastMCP orchestrator crashes with 'Connection closed' when using STDIO transport and 'Unknown tool' errors for undecorated functions | Root cause involves subprocess environment inheritance and missing MCP tool decorators

Migration from STDIO to In-Memory Transport

Issue

The video generation orchestrator failed during initialization due to two critical issues:

  1. Connection errors when using STDIO transport, caused by subprocesses not inheriting the required virtual environment and dependencies.
  2. Tool registration errors where specific tools, such as split_code_into_segments, were not recognized by the MCP (Microservice Communication Protocol), preventing workflow execution.

Culprit

The STDIO transport environment was mismatched, as subprocesses failed to inherit the correct Python virtual environment and dependencies. Additionally, the split_code_into_segments function was not decorated with the @mcp.tool() decorator, rendering it invisible to the MCP tool registry.

Solution

The system was updated to use in-memory transport instead of STDIO transport, allowing server instances to be imported directly and executed within the same Python process. This eliminated subprocess overhead and ensured consistent access to dependencies and the virtual environment. Additionally, the missing @mcp.tool() decorator was added to expose the split_code_into_segments function to the MCP registry, enabling it to be called and used in workflows.