Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Fix formatting per pre-commit hooks

Jeremiah Lowin60c6441d7bbd
diff --git a/src/fastmcp/server/context.py b/src/fastmcp/server/context.py
index d920a0914..994052724 100644
--- a/src/fastmcp/server/context.py
+++ b/src/fastmcp/server/context.py
@@ -181,15 +181,15 @@ class Context:
@property
def session_id(self) -> str | None:
"""Get the MCP session ID for HTTP transports.
-
+
Returns the session ID that can be used as a key for session-based
data storage (e.g., Redis) to share data between tool calls within
the same client session.
-
+
Returns:
The session ID for HTTP transports (SSE, StreamableHTTP), or None
for stdio and in-memory transports which don't use session IDs.
-
+
Example:
```python
@server.tool
@@ -202,6 +202,7 @@ class Context:
"""
try:
from fastmcp.server.dependencies import get_http_headers
+
headers = get_http_headers(include_all=True)
return headers.get("mcp-session-id")
except RuntimeError:
diff --git a/tests/server/test_context.py b/tests/server/test_context.py
index 2c45ddb60..c80d75af6 100644
--- a/tests/server/test_context.py
+++ b/tests/server/test_context.py
@@ -92,7 +92,7 @@ class TestSessionId:
def test_session_id_with_http_headers(self, context):
"""Test that session_id returns the value from mcp-session-id header."""
mock_headers = {"mcp-session-id": "test-session-123"}
-
+
with patch(
"fastmcp.server.dependencies.get_http_headers", return_value=mock_headers
):
@@ -101,15 +101,15 @@ class TestSessionId:
def test_session_id_without_http_headers(self, context):
"""Test that session_id returns None when no HTTP headers are available."""
with patch(
- "fastmcp.server.dependencies.get_http_headers",
- side_effect=RuntimeError("No active HTTP request found.")
+ "fastmcp.server.dependencies.get_http_headers",
+ side_effect=RuntimeError("No active HTTP request found."),
):
assert context.session_id is None
def test_session_id_with_missing_header(self, context):
"""Test that session_id returns None when mcp-session-id header is missing."""
mock_headers = {"other-header": "value"}
-
+
with patch(
"fastmcp.server.dependencies.get_http_headers", return_value=mock_headers
):
@@ -118,7 +118,7 @@ class TestSessionId:
def test_session_id_with_empty_header(self, context):
"""Test that session_id returns None when mcp-session-id header is empty."""
mock_headers = {"mcp-session-id": ""}
-
+
with patch(
"fastmcp.server.dependencies.get_http_headers", return_value=mock_headers
):