Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/getting-started/FAQ.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ icon: question

## Usage
### How do I configure HTTP request timeouts?
By default, HTTP requests timeout after 5 seconds. If you have API endpoints that take longer to respond, you can configure a custom timeout by injecting your own httpx client.
By default, HTTP requests timeout after 10 seconds. If you have API endpoints that take longer to respond, you can configure a custom timeout by injecting your own `httpx.AsyncClient`.

If you replace the default client, keep the in-process `ASGITransport` and `base_url` so the MCP server still routes tool calls back into your FastAPI app.

For a working example, see [Configure HTTP Timeout Example](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/07_configure_http_timeout_example.py).

Expand Down
13 changes: 11 additions & 2 deletions examples/07_configure_http_timeout_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
This example shows how to configure the HTTP client timeout for the MCP server.
In case you have API endpoints that take longer than 5 seconds to respond, you can increase the timeout.
By default, FastApiMCP uses a 10 second timeout.
If you provide your own client, preserve the in-process ASGI transport and base URL so tool execution
continues to target the local FastAPI app.
"""

from examples.shared.apps.items import app # The FastAPI app
Expand All @@ -13,7 +15,14 @@
setup_logging()


mcp = FastApiMCP(app, http_client=httpx.AsyncClient(timeout=20))
mcp = FastApiMCP(
app,
http_client=httpx.AsyncClient(
transport=httpx.ASGITransport(app=app, raise_app_exceptions=False),
base_url="http://apiserver",
timeout=20.0,
),
)
mcp.mount_http()


Expand Down
1 change: 1 addition & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_default_configuration(simple_fastapi_app: FastAPI):
# Check default options
assert mcp_server._describe_all_responses is False
assert mcp_server._describe_full_response_schema is False
assert mcp_server._http_client.timeout.connect == 10.0


def test_custom_configuration(simple_fastapi_app: FastAPI):
Expand Down