Skip to content

Unpack settings in FastMCP #1198

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 2 commits into from
Jul 26, 2025
Merged

Unpack settings in FastMCP #1198

merged 2 commits into from
Jul 26, 2025

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Jul 25, 2025

No description provided.

@Kludex Kludex requested a review from a team as a code owner July 25, 2025 09:59
@Kludex Kludex requested a review from ochafik July 25, 2025 09:59
Comment on lines +132 to +148
debug: bool = False,
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO",
host: str = "127.0.0.1",
port: int = 8000,
mount_path: str = "/",
sse_path: str = "/sse",
message_path: str = "/messages/",
streamable_http_path: str = "/mcp",
json_response: bool = False,
stateless_http: bool = False,
warn_on_duplicate_resources: bool = True,
warn_on_duplicate_tools: bool = True,
warn_on_duplicate_prompts: bool = True,
dependencies: Collection[str] = (),
lifespan: Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
auth: AuthSettings | None = None,
transport_security: TransportSecuritySettings | None = None,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change. The rest is just to comply with those types.

port: int = 8000,
mount_path: str = "/",
sse_path: str = "/sse",
message_path: str = "/messages/",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message_path: str = "/messages/",
message_path: str = "/messages",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to trust AI nowadays. 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, the AI didn't make a mistake.

The default on Settings.message_path was added with the /.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea i know :(, is that correct tho?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it doesn't follow the pattern, no. But also there's some redirect issues that people may be facing.

But should I really change it in this PR? It may affect people.

Comment on lines +133 to +148
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO",
host: str = "127.0.0.1",
port: int = 8000,
mount_path: str = "/",
sse_path: str = "/sse",
message_path: str = "/messages/",
streamable_http_path: str = "/mcp",
json_response: bool = False,
stateless_http: bool = False,
warn_on_duplicate_resources: bool = True,
warn_on_duplicate_tools: bool = True,
warn_on_duplicate_prompts: bool = True,
dependencies: Collection[str] = (),
lifespan: Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
auth: AuthSettings | None = None,
transport_security: TransportSecuritySettings | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main worry is that we now keep the defaults in sync between Settings and this. I think ideally, but sadly a BC break would be to just accept settings: Settings = Settings() here. Since I think that would be backwards incompatible. For now, since Settings is only used internally to FastMCP should we remove the defaults from the Settings class, such that we only provide it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we should remove the defaults from Settings.

Copy link
Member

@dsp-ant dsp-ant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Kludex Kludex merged commit 959d4e3 into main Jul 26, 2025
13 checks passed
@Kludex Kludex deleted the unpack-settings-fastmcp branch July 26, 2025 08:37
gspencergoog pushed a commit to gspencergoog/mcp-python-sdk that referenced this pull request Jul 29, 2025
@GZGavinZhao
Copy link

This PR likely broke a lot of uvx my-mcp-server workflows by removing **settings as an argument to FastMCP.__init__:

Traceback (most recent call last):
  File "/home/gavinzhao/.cache/uv/archive-v0/Sd9MpTigriP_4YpcGN7U3/bin/lean-lsp-mcp", line 6, in <module>
    from lean_lsp_mcp import main
  File "/home/gavinzhao/.cache/uv/archive-v0/Sd9MpTigriP_4YpcGN7U3/lib64/python3.13/site-packages/lean_lsp_mcp/__init__.py", line 3, in <module>
    from lean_lsp_mcp.server import mcp
  File "/home/gavinzhao/.cache/uv/archive-v0/Sd9MpTigriP_4YpcGN7U3/lib64/python3.13/site-packages/lean_lsp_mcp/server.py", line 98, in <module>
    mcp = FastMCP(**mcp_kwargs)
TypeError: FastMCP.__init__() got an unexpected keyword argument 'env_vars'

I understand that it's kind of awkward to have a backwards compatibility guarantee for a fast-moving package like mcp, but perhaps it'd be a good idea to at least document this change? Especially since this change is made in a patch release?

@MischaPanch
Copy link

MischaPanch commented Jul 31, 2025

This is a breaking change and you only updated the patch version of the package. It broke our code:
oraios/serena#381

You could fix this by rolling this back, urgently releasing 1.12.4, and then doing it in a backwards compatible way or make a new major version.

For reference of what breaks: this code now causes a pydantic validation error

mcp_settings: Settings = Settings(lifespan=self.server_lifespan, host=host, port=port)
mcp = FastMCP(**mcp_settings.model_dump(), instructions="...")

@MischaPanch
Copy link

Fun coincidence: I had raised the problem with the constructor a while ago and in the issue had proposed a backwards compatible way to handle this
#305

@GZGavinZhao
Copy link

GZGavinZhao commented Jul 31, 2025

For uvx users, a temporary fix for this is to have mcp==1.12.2 in a requirements.txt file and add --with-requirements=requirements.txt as the first arugment to uvx.

Actually, you can also add the environment variable UV_CONSTRAINT=<path-to-requirements.txt-above> to whatever MCP configuration you're using, e.g.:

{
  "mcpServers": {
    "lean-lsp": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "lean-lsp-mcp"
      ],
      "env": {
        "UV_CONSTRAINT": "requirements.txt"
      }
    }
  }
}

@mzyil
Copy link

mzyil commented Aug 2, 2025

please add a bot to your repo that verifies backwards compat. a lot of people depend on your code and you are past alpha.

@Kludex
Copy link
Member Author

Kludex commented Aug 3, 2025

It seems there were two different issues here:

  • Use of env_vars (i.e. passing unused parameter to the constructor)
  • Instantiating Settings by oneself, which I guess would be to have a false sense of type safety?

I didn't expect people to be instantiating the Settings themselves.


I guess the way to go here now is to:

  1. Ignore the messages above - this change seems reasonable.
  2. Add a kwargs back with a deprecation warning in it saying that those parameters are not used, and add the default values for settings back - which I think we should deprecate the Settings class itself.

@MischaPanch
Copy link

Settings is a public class and it was the only way to have the kwargs names and types analyzed by the IDE - how was the sense of type safety false?

But it seems like indeed few people were using it, otherwise this would have gotten more attention

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.

5 participants