Skip to content

Lazy import in src/mcp/__init__.py #1617

@wuliang229

Description

@wuliang229

Description

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.

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions