You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Has the MCP team considered lazy importing in the mcp package?
Right now, if you import anything from mcp, it will run the mcp/init.py file, and it will import from all the submodules at the beginning. However, most people probably only need to develop for the server or client, but not both. Importing all the sub-modules will create a huge upfront cold start latency as more people are integrating MCP with their services in a auto-scaling format. Whenever a new server instance is cold-started, importing from MCP will take a non-trivial amount of time (~1s in my own laptop, it's usually slower on Cloud).
Would love to draft a PR if this is worth the value.
We do need to refactor the module names, and define what is private and public properly, but I don't think we need anything smart regarding imports. The imports being slow was mainly because of jsonschema.
Closing in favor of #1701 (define and document public API surface). Per discussion with @Kludex, the slow imports were mainly due to jsonschema - the fix is to properly refactor module names and define public/private API, not lazy imports.
Activity
maxisbey commentedon Nov 17, 2025
This is something that's been mentioned before in http://github.com/modelcontextprotocol/python-sdk/issues/1508
Currently it won't be prioritised, but potentially looked at for something in v2 of the SDK.
Kludex commentedon Dec 4, 2025
We do need to refactor the module names, and define what is private and public properly, but I don't think we need anything smart regarding imports. The imports being slow was mainly because of
jsonschema.felixweinberger commentedon Jan 16, 2026
Closing in favor of #1701 (define and document public API surface). Per discussion with @Kludex, the slow imports were mainly due to
jsonschema- the fix is to properly refactor module names and define public/private API, not lazy imports.