Skip to content

Support Python dependencies in Server #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged

Support Python dependencies in Server #34

merged 1 commit into from
Dec 2, 2024

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented Dec 2, 2024

When developing and deploying a server, we want to be able to specify Python dependencies without having to do --with dep every time.

In earlier versions of FastMCP, it was possible to use uv's [script dependencies] (https://docs.astral.sh/uv/guides/scripts/#declaring-script-dependencies) to declare dependenceis as frontmatter, but since we now use fastmcp run server.py instead of uv run server.py by default, they don't get parsed.

This PR makes the following code possible (which requires pandas) while keeping the install command fastmcp install demo.py

# demo.py

from fastmcp import FastMCP

mcp = FastMCP("demo", dependencies=['pandas']

@mcp.tool()
def demo():
    import pandas
    ...

The README is also updated to clarify that:

  • fastmcp install will respect server dependencies when creating an environment for Claude desktop
  • fastmcp dev will respect server dependencies when creating an environment for the MCP Inspector
  • fastmcp run will NOT respect dependencies; it assumes they are already set up. However it does not require a if name == 'main' block
  • python run and uv run are perfectly valid as long as the user calls mcp.run() themselves and takes responsibility for all dependencies.

@jlowin jlowin merged commit 03cc8b1 into main Dec 2, 2024
3 checks passed
@jlowin jlowin deleted the dependencies branch December 2, 2024 02:00
@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant