Skip to content

Comments

Allow configuring FastMCP transport setting in the same way as other configuration#1796

Open
jvdmr wants to merge 2 commits intoPrefectHQ:mainfrom
jvdmr:feature/settings-transport
Open

Allow configuring FastMCP transport setting in the same way as other configuration#1796
jvdmr wants to merge 2 commits intoPrefectHQ:mainfrom
jvdmr:feature/settings-transport

Conversation

@jvdmr
Copy link

@jvdmr jvdmr commented Sep 9, 2025

`run_async()` hardcoded `"stdio"` as the fallback when no transport was specified, which meant users running third-party servers (like AWS MCP servers in ECS containers) had no way to change the default transport without modifying source code. The CLI and `fastmcp.json` provided workarounds, but a bare `mcp.run()` call was locked to stdio.

This adds a `transport` field to `Settings` so that `FASTMCP_TRANSPORT=http` (or any valid transport) controls the default. `run_async` reads from the setting instead of hardcoding `"stdio"`, while explicit `transport=` arguments and CLI `--transport` flags still override it. Fits naturally alongside the existing `FASTMCP_HOST` and `FASTMCP_PORT` settings.

```python

Third-party server code you can't modify:

mcp.run() # reads FASTMCP_TRANSPORT from env

Or in your own code:

import fastmcp
fastmcp.settings.transport = "http"
```

Closes #1795

@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. labels Sep 9, 2025
@jlowin jlowin force-pushed the feature/settings-transport branch from beedaf6 to c8b672e Compare February 16, 2026 15:34
Co-authored-by: Joris Vandermeersch <joris.vandermeersch@vrt.be>
@jlowin jlowin force-pushed the feature/settings-transport branch from c8b672e to b6d6777 Compare February 16, 2026 15:36
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

The transport configuration option has been made configurable through the Settings class. A new transport field was added to Settings with type Literal["stdio", "http", "sse", "streamable-http"] and a default value of "stdio". The transport selection logic in the transport mixin was updated to delegate to this configuration field when no transport is explicitly provided, rather than using a hardcoded default value.

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: making transport configurable via settings mechanism, which is the primary objective of the PR.
Description check ✅ Passed The PR description clearly explains the problem, solution, and provides code examples. It includes the closing issue reference but lacks coverage of testing and documentation updates.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #1795: adding a transport field to Settings that can be configured via FASTMCP_TRANSPORT environment variable, allowing users to override the hardcoded stdio default.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: adding transport field to Settings and updating run_async() to use it instead of hardcoding stdio. No extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jlowin
Copy link
Member

jlowin commented Feb 16, 2026

@jvdmr now that #3148 is in, we can get this merged - apologies for the significant delay. This will go out after 3.0 releases.

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

Labels

cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. enhancement Improvement to existing functionality. For issues and smaller PR improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Further allow configuring FastMCP through environment variables

2 participants