Add MCP safety limits and guardrails #25
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces comprehensive security hardening measures to reduce the attack surface when connecting to untrusted or misconfigured MCP servers. It addresses five key vulnerability categories identified during a security review.
Vulnerabilities Addressed
1. Untrusted Tool Schema Exploitation
Problem: Remote MCP servers supply JSON Schema that is trusted and converted to Pydantic models. A malicious server could craft huge/complex schemas to cause CPU/memory exhaustion or validation slowdowns.
Solution: Added defensive schema validation in
src/deepmcpagent/tools.py:2. Unbounded Network/Tool Calls (DoS Risk)
Problem:
_FastMCPTool._arunsets no timeouts or retries, so a hanging MCP server can stall the agent indefinitely and consume concurrent worker slots.Solution: Added network resilience in
src/deepmcpagent/tools.py:anyio.fail_after3. Prompt Injection Surface
Problem: Default system prompt gives broad autonomy; malicious tool descriptions or user content can steer the model to exfiltrate secrets or skip safeguards.
Solution: Hardened default prompt in
src/deepmcpagent/prompt.py:4. Stdio Transport Ambiguity
Problem:
StdioServerSpecis exposed but documented as needing an adapter; using it without a safe adapter could lead to command execution risks or unstable behavior.Solution: Added runtime warning in
src/deepmcpagent/config.py:5. Credential Leakage Risk
Problem: CLI allows arbitrary headers to be forwarded to any URL; without guardrails/TLS validation guidance, users might leak tokens to untrusted endpoints.
Solution: Added HTTPS safety checks in
src/deepmcpagent/cli.py:--https-onlyflag: When enabled, the CLI rejects any non-HTTPS MCP server URLAuthorizationheader is provided over plain HTTP, a warning is printed:Files Changed
src/deepmcpagent/tools.pysrc/deepmcpagent/prompt.pysrc/deepmcpagent/config.pysrc/deepmcpagent/cli.py--https-onlyflag, HTTP auth warning, URL parsingREADME.mdImpact Summary
MCPClientError--https-onlyflag + console warningRuntimeWarningwhen stdio spec is used; documented riskUsage Examples
Enforce HTTPS-only connections
Warning when using HTTP with auth
Testing
tests/test_tools_schema.py,tests/test_cli_parse.py,tests/test_agent.py,tests/test_config.pypip install -e ".[dev]" && pytest -qBreaking Changes
None. All changes are backward-compatible:
--https-only) is opt-inSecurity Best Practices (Added to README)
--https-onlyin the CLI rejects non-HTTPS URLs