Repository navigation
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
Description
Summary
When running mcp.types inside a constrained container (2 vCPU / 4 GB RAM), importing the top-level package already costs ~2.5 seconds before any server code runs. Profiling shows the time is spent entirely in import mcp.types because the module eagerly imports/open-initializes several heavy dependencies.
Environment
- fastmcp 2.12.5 (PyPI)
- Python 3.12
- Alpine-based container, 2 vCPU / 4 GB RAM
- No custom
.envor optional features enabled
What happens
Importing fastmcp alone blocks startup for ~2s. A py-spy flamegraph highlights:
fastmcp.server.server(~2.2s)mcp.types/jsonschema/rfc3987(combined ~1.8s)
All of this occurs beforeFastMCP('...')is even instantiated.
Why this hurts
In serverless-style deployments every cold start pays this tax, delaying HTTP readiness and tool registration. The delays come from JSON schema / OpenAPI generation and optional format checkers that the server might never need.
Requested fix
Please consider deferring or making optional the heavy module-level work. A few ideas:
- Move
jsonschemaformat checker registration,openapi-coreimports, and.envloading behind opt-in flags. - Generate OpenAPI/JSON schema lazily (only when
FastMCP.build_schema()is called) or allow caching. - Provide environment variables to disable optional features so small deployments can skip them entirely.
Thanks for looking into this—shaving even 1s off import time would significantly improve startup latency for containerized deployments.
Example Code
import mcp.typesVersion Information
FastMCP version: 2.12.5
MCP version: 1.16.0
Python version: 3.12.11
Platform: Linux-5.4.250.bsk.9-sign-amd64-x86_64-with-glibc2.35
FastMCP root path: /opt/python3.12/lib/python3.12/site-packages
Example Code
import mcp.typesPython & MCP Python SDK
1.18.0
Activity
ycjcl868 commentedon Nov 2, 2025
Ref: python-jsonschema/jsonschema#1428
wuliang229 commentedon Nov 11, 2025
@ycjcl868 do you know if this is resolved?
ycjcl868 commentedon Nov 11, 2025
We have indeed resolved this performance issue during loading on single/dual-core CPUs by implementing lazy loading for MCP. A detailed record of the refactoring process will be released later.