From 60c6441d7bbd73048779a131d58ad3ab0524aeed Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 19 Jun 2025 18:21:45 -0400 Subject: [PATCH] Fix formatting per pre-commit hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/fastmcp/server/context.py | 7 ++++--- tests/server/test_context.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) 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 ):