Resolved

Python servers crash on startup due to OpenAI SDK dependency and improper shutdown operations

Python
API
Debugging
Migration
Backend
Dependency Management

FastMCP 2.0 servers failed to initialize due to missing OpenAI SDK dependencies and improper shutdown handling, resulting in connection and I/O errors.

A Python-based server system for video generation relied on a standardized HTTP client architecture for API calls. However, the introduction of the OpenAI SDK caused servers to crash during startup due to missing dependencies and improper shutdown operations.

Issue

Three critical servers crashed during initialization with errors including:

  • Connection failures: RuntimeError: Client failed to connect due to missing dependencies.
  • Missing module errors: ModuleNotFoundError: No module named 'openai' due to the absence of the OpenAI SDK.
  • Shutdown I/O errors: I/O operation on closed file during improper shutdown sequences.

The crashes occurred after junior developers introduced the OpenAI SDK instead of using the FastMCP 2.0’s native httpx pattern for API calls, violating architectural guidelines.

Culprit

The root causes included:

  • Unnecessary dependency introduction: Use of the OpenAI SDK (openai>=1.0.0) added significant bloat (50+ MB) and violated the standardized httpx-based HTTP client pattern.
  • Improper shutdown handling: The evaluator server contained print() statements after closing the HTTP client, causing I/O errors during shutdown.
  • Overcomplication of async patterns: The orchestrator used AsyncOpenAI() despite compatibility with standard HTTP POST requests, adding unnecessary complexity.

Solution

Migration to Standardized HTTP Client

All OpenAI SDK calls were replaced with FastMCP-compliant httpx.AsyncClient implementations:

  1. Standardized HTTP configuration: Used httpx.AsyncClient with proper headers and timeouts for all external API calls.
  2. Context management: Implemented proper async context management for HTTP clients, ensuring clean shutdowns.
  3. Dependency cleanup: Removed the OpenAI SDK entirely, reducing dependency bloat and ensuring consistency with the architecture.

Key Changes

  • Removed all OpenAI SDK references and replaced them with direct HTTP client usage.
  • Fixed shutdown I/O errors by ensuring no operations were performed after client closure.
  • Standardized async patterns to use httpx exclusively, eliminating unnecessary complexity.

Verification: All servers now initialize successfully without errors, and dependency checks confirm the removal of the OpenAI SDK.