feat: add CLI flags and tests for transport security#2
Conversation
- Add --disable-dns-rebinding-protection, --allowed-hosts, --allowed-origins CLI flags - Move transport security from module-level init to main() (after argparse) - Apply transport security only for SSE and streamable-http transports (not stdio) - Env vars (POSTGRES_MCP_*) override CLI flags when both are set - Add comprehensive test suite: 10 scenarios × 2 transports = 20 tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Align with the shorter MCP_* naming convention used in the original PR. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds CLI-level configuration for FastMCP transport security (DNS rebinding protection + allow-lists) and introduces unit tests validating the CLI/env-var interactions for network transports (sse, streamable-http).
Changes:
- Add CLI flags:
--disable-dns-rebinding-protection,--allowed-hosts,--allowed-origins. - Apply
TransportSecuritySettingsonly for network transports and set them at runtime inmain(). - Add a new parametrized unit test suite covering CLI/env behavior across the two network transports.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/postgres_mcp/server.py |
Adds CLI flags and runtime application of TransportSecuritySettings for sse/streamable-http. |
tests/unit/test_transport_security.py |
New integration-style unit tests asserting the transport-security settings derived from CLI flags and env vars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename MCP_DNS_REBINDING_PROTECTION to MCP_ENABLE_DNS_REBINDING_PROTECTION - Add monkeypatch fixture to clear MCP_* env vars in tests - Remove coupling to FastMCP upstream defaults in test_default_defers_to_fastmcp - Update README with CLI flags documentation table Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed all 4 Copilot review comments in the latest push:
|
Summary
Enhancements to your transport security PR (crystaldba#144 on crystaldba/postgres-mcp):
--disable-dns-rebinding-protection,--allowed-hosts,--allowed-origins) — consistent with the project's existing argparse pattern for--transport,--sse-host, etc.sseandstreamable-httpmain()— allows CLI flags to participate and keeps all initialization in one placeMCP_*env vars take precedence when both are setTest plan