Skip to content

Conversation

@wuliang229
Copy link

Changing the import of jsonschema to lazy import within the function that uses it, therefore decreasing the cold start import time of mcp.

Motivation and Context

When running import mcp.types at cold start in a Colab Notebook, the command takes around 2.5s, with the jsonschema library taking up 70% of the latency. As MCP is integrated into more production services, especially those that rely on cold start containerized environment like GCP Cloud Run, the cold start time means life-and-death to the application. Therefore, decreasing this import latency is critical to users.

How Has This Been Tested?

This is trivial change.

Breaking Changes

No.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Here's some profiling I do for running import mcp.types in Colab:
mcp_profiling

The import of `jsonschema` takes up almost 2s at cold start, which dramatically slow down the cold start in a containerized environment. Changing it to lazy import within the function that uses it will save those 2s at startup. As MCP is getting used more in production, this time-saving is critical.
@wuliang229 wuliang229 changed the title Lazy import jsonschema library chore: Lazy import jsonschema library Nov 8, 2025
@Kludex
Copy link
Member

Kludex commented Nov 8, 2025

Do we even need this package? @ihrpr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants