Skip to content

Commit 89d4b15

Browse files
committed
docker
1 parent 2378a5e commit 89d4b15

2 files changed

Lines changed: 59 additions & 12 deletions

File tree

rmcp/transport/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464

6565
# SSL/TLS configuration validation
6666
if self.ssl_keyfile or self.ssl_certfile:
67+
# First check if both are provided
6768
if not self.ssl_keyfile:
6869
raise ValueError(
6970
"SSL key file is required when SSL certificate is specified"
@@ -73,7 +74,7 @@ def __init__(
7374
"SSL certificate file is required when SSL key is specified"
7475
)
7576

76-
# Validate files exist
77+
# Only validate file existence if both are specified
7778
from pathlib import Path
7879

7980
if not Path(self.ssl_keyfile).is_file():

tests/integration/transport/test_https.py

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,49 @@ async def mock_handler(message):
219219
assert health_data["status"] == "healthy"
220220
assert health_data["transport"] == "HTTP"
221221

222-
# Test MCP endpoint with JSON-RPC
223-
mcp_response = await client.post(
222+
# First initialize the session
223+
init_response = await client.post(
224224
"https://127.0.0.1:8444/mcp",
225225
json={
226226
"jsonrpc": "2.0",
227227
"id": 1,
228+
"method": "initialize",
229+
"params": {
230+
"protocolVersion": "2025-06-18",
231+
"capabilities": {},
232+
"clientInfo": {"name": "test-client", "version": "1.0.0"},
233+
},
234+
},
235+
headers={
236+
"Content-Type": "application/json",
237+
"MCP-Protocol-Version": "2025-06-18",
238+
},
239+
)
240+
assert init_response.status_code == 200
241+
242+
# Get session ID from response headers
243+
session_id = init_response.headers.get("mcp-session-id")
244+
assert session_id is not None
245+
246+
# Then test MCP endpoint with tools/list using the same session
247+
mcp_response = await client.post(
248+
"https://127.0.0.1:8444/mcp",
249+
json={
250+
"jsonrpc": "2.0",
251+
"id": 2,
228252
"method": "tools/list",
229253
"params": {},
230254
},
231255
headers={
232256
"Content-Type": "application/json",
233-
"MCP-Protocol-Version": "2024-11-05",
257+
"MCP-Protocol-Version": "2025-06-18",
258+
"mcp-session-id": session_id,
234259
},
235260
)
236261
assert mcp_response.status_code == 200
237262
mcp_data = mcp_response.json()
238263
assert mcp_data["jsonrpc"] == "2.0"
239-
assert mcp_data["id"] == 1
264+
assert mcp_data["id"] == 2
240265
assert mcp_data["result"]["status"] == "ok"
241266
assert mcp_data["result"]["method"] == "tools/list"
242267

@@ -258,13 +283,24 @@ def test_cors_configuration_with_https(self, https_certificates):
258283
)
259284

260285
# Check that FastAPI app has CORS middleware configured
261-
middleware_classes = [
262-
type(m.cls) if hasattr(m, "cls") else type(m)
263-
for m in transport.app.user_middleware
264-
]
265286
from fastapi.middleware.cors import CORSMiddleware
266287

267-
assert CORSMiddleware in middleware_classes
288+
# Debug: Print actual middleware structure
289+
middleware_info = []
290+
for m in transport.app.user_middleware:
291+
if hasattr(m, "cls"):
292+
middleware_info.append(m.cls)
293+
else:
294+
middleware_info.append(type(m))
295+
296+
# Check if CORSMiddleware is configured (could be in middleware stack)
297+
has_cors = any(
298+
cls == CORSMiddleware
299+
or (hasattr(cls, "__name__") and "CORSMiddleware" in cls.__name__)
300+
for cls in middleware_info
301+
)
302+
303+
assert has_cors, f"CORS middleware not found. Found: {middleware_info}"
268304

269305
def test_security_warning_for_remote_http(self, caplog):
270306
"""Test that security warning is issued for remote HTTP binding."""
@@ -311,10 +347,10 @@ def test_environment_variable_ssl_configuration(
311347
monkeypatch.setenv("RMCP_HTTP_SSL_KEYFILE", https_certificates["key_file"])
312348
monkeypatch.setenv("RMCP_HTTP_SSL_CERTFILE", https_certificates["cert_file"])
313349

314-
# Import after setting environment variables
350+
# Import after setting environment variables and force reload
315351
from rmcp.config import get_config
316352

317-
config = get_config()
353+
config = get_config(reload=True)
318354

319355
# Verify configuration picked up environment variables
320356
assert config.http.ssl_keyfile == https_certificates["key_file"]
@@ -350,6 +386,11 @@ class TestHTTPSEdgeCases:
350386

351387
def test_partial_ssl_configuration_cli_keyfile_only(self, https_certificates):
352388
"""Test error when only keyfile is provided via CLI."""
389+
# Clear config cache to avoid fallback values from previous tests
390+
from rmcp.config import get_config
391+
392+
get_config(reload=True)
393+
353394
with pytest.raises(ValueError, match="SSL certificate file is required"):
354395
HTTPTransport(
355396
host="localhost",
@@ -360,6 +401,11 @@ def test_partial_ssl_configuration_cli_keyfile_only(self, https_certificates):
360401

361402
def test_partial_ssl_configuration_cli_certfile_only(self, https_certificates):
362403
"""Test error when only certfile is provided via CLI."""
404+
# Clear config cache to avoid fallback values from previous tests
405+
from rmcp.config import get_config
406+
407+
get_config(reload=True)
408+
363409
with pytest.raises(ValueError, match="SSL key file is required"):
364410
HTTPTransport(
365411
host="localhost",

0 commit comments

Comments
 (0)