mcpshield-agent 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/PKG-INFO +1 -1
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/__init__.py +1 -1
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/cli.py +20 -6
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/client.py +11 -3
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/tool_scanner.py +6 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/PKG-INFO +1 -1
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/SOURCES.txt +1 -0
- mcpshield_agent-0.2.1/tests/test_client.py +62 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/README.md +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/__main__.py +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/config.py +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent/scanner.py +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/dependency_links.txt +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/entry_points.txt +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/requires.txt +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/top_level.txt +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/pyproject.toml +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/setup.cfg +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/tests/test_cli.py +0 -0
- {mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/tests/test_scanner.py +0 -0
|
@@ -151,13 +151,17 @@ def scan(dry_run: bool, deep: bool):
|
|
|
151
151
|
|
|
152
152
|
# Report servers
|
|
153
153
|
result = client.report_servers(servers)
|
|
154
|
-
|
|
154
|
+
|
|
155
|
+
skipped = result.get('servers_skipped', 0)
|
|
155
156
|
click.echo("")
|
|
156
|
-
|
|
157
|
+
if skipped:
|
|
158
|
+
click.echo(f"Reported ({skipped} server(s) not recorded — plan limit reached)")
|
|
159
|
+
else:
|
|
160
|
+
click.echo("Success!")
|
|
157
161
|
click.echo(f" Created: {result.get('created', 0)}")
|
|
158
162
|
click.echo(f" Updated: {result.get('updated', 0)}")
|
|
159
163
|
click.echo(f" Alerts: {result.get('alerts', 0)}")
|
|
160
|
-
|
|
164
|
+
|
|
161
165
|
# Show risk info if available
|
|
162
166
|
if 'servers' in result:
|
|
163
167
|
click.echo("")
|
|
@@ -166,7 +170,12 @@ def scan(dry_run: bool, deep: bool):
|
|
|
166
170
|
risk = s.get('risk_level', 'unknown')
|
|
167
171
|
score = s.get('risk_score', 0)
|
|
168
172
|
click.echo(f" {s['server_name']}: {risk} (score: {score})")
|
|
169
|
-
|
|
173
|
+
|
|
174
|
+
# Surface the backend's upgrade message on a hit tier limit (HTTP 402).
|
|
175
|
+
if skipped and result.get('detail'):
|
|
176
|
+
click.echo("")
|
|
177
|
+
click.echo(result['detail'])
|
|
178
|
+
|
|
170
179
|
except Exception as e:
|
|
171
180
|
click.echo(f"Error: Failed to report - {e}")
|
|
172
181
|
|
|
@@ -324,8 +333,13 @@ def daemon(interval: int):
|
|
|
324
333
|
|
|
325
334
|
client.heartbeat(hostname, os_type, username, ip, __version__)
|
|
326
335
|
result = client.report_servers(servers)
|
|
327
|
-
|
|
328
|
-
if result:
|
|
336
|
+
|
|
337
|
+
if result and result.get('servers_skipped'):
|
|
338
|
+
click.echo(
|
|
339
|
+
f"[Cycle {cycle}] Reported — {result['servers_skipped']} "
|
|
340
|
+
"server(s) not recorded (plan limit reached)"
|
|
341
|
+
)
|
|
342
|
+
elif result:
|
|
329
343
|
click.echo(f"[Cycle {cycle}] Reported to backend successfully")
|
|
330
344
|
else:
|
|
331
345
|
click.echo(f"[Cycle {cycle}] Warning: Failed to report to backend")
|
|
@@ -48,14 +48,22 @@ class MCPShieldClient:
|
|
|
48
48
|
def report_servers(self, servers: List[Dict]) -> Dict:
|
|
49
49
|
"""
|
|
50
50
|
Report discovered MCP servers.
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
POST /api/v1/mcp/report
|
|
53
|
+
|
|
54
|
+
A 402 (free-tier MCP-server limit reached) still returns a useful JSON
|
|
55
|
+
body: the servers that WERE recorded, plus a ``detail`` message with the
|
|
56
|
+
upgrade URL. Return that body instead of raising a generic HTTPError,
|
|
57
|
+
so the CLI can surface the backend's message to the user rather than a
|
|
58
|
+
bare "402 Client Error".
|
|
53
59
|
"""
|
|
54
60
|
url = f"{self.api_url}/api/v1/mcp/report"
|
|
55
|
-
|
|
61
|
+
|
|
56
62
|
payload = {"servers": servers}
|
|
57
|
-
|
|
63
|
+
|
|
58
64
|
response = self.session.post(url, json=payload, timeout=30)
|
|
65
|
+
if response.status_code == 402:
|
|
66
|
+
return response.json()
|
|
59
67
|
response.raise_for_status()
|
|
60
68
|
return response.json()
|
|
61
69
|
|
|
@@ -7,6 +7,12 @@ malicious server hides side-instructions in tool descriptions that the
|
|
|
7
7
|
agent ingests as context).
|
|
8
8
|
|
|
9
9
|
Patterns ported from Cerberus tool-scan.ts / injection.ts (MIT).
|
|
10
|
+
|
|
11
|
+
SECURITY NOTE: a --deep scan *executes* the command found in the MCP config
|
|
12
|
+
(subprocess.Popen([command] + args, ...)) in order to speak JSON-RPC to it.
|
|
13
|
+
A malicious or tampered config is therefore run, not just parsed. Only run
|
|
14
|
+
--deep against configs you trust. --deep is never automatic; it is an
|
|
15
|
+
explicit flag the user opts into.
|
|
10
16
|
"""
|
|
11
17
|
|
|
12
18
|
import json
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MCPShield Agent - API client tests.
|
|
3
|
+
|
|
4
|
+
Focused on the 402 (free-tier limit) path: the backend returns a useful JSON
|
|
5
|
+
body with the recorded servers + an upgrade message, and the client must
|
|
6
|
+
surface it rather than raising a generic HTTPError.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from unittest.mock import MagicMock, patch
|
|
10
|
+
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from mcpshield_agent.client import MCPShieldClient
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _response(status_code: int, json_body: dict) -> MagicMock:
|
|
17
|
+
resp = MagicMock()
|
|
18
|
+
resp.status_code = status_code
|
|
19
|
+
resp.json.return_value = json_body
|
|
20
|
+
# Mirror requests' real behaviour: raise_for_status raises on >= 400.
|
|
21
|
+
if status_code >= 400:
|
|
22
|
+
resp.raise_for_status.side_effect = requests.exceptions.HTTPError(
|
|
23
|
+
f"{status_code} Client Error"
|
|
24
|
+
)
|
|
25
|
+
else:
|
|
26
|
+
resp.raise_for_status.return_value = None
|
|
27
|
+
return resp
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TestReportServers402:
|
|
31
|
+
def test_402_returns_body_without_raising(self):
|
|
32
|
+
body = {
|
|
33
|
+
"created": 2,
|
|
34
|
+
"updated": 0,
|
|
35
|
+
"alerts": 1,
|
|
36
|
+
"servers": [],
|
|
37
|
+
"servers_skipped": 3,
|
|
38
|
+
"detail": "Free tier is limited to 50 MCP servers. Upgrade to Pro.",
|
|
39
|
+
}
|
|
40
|
+
client = MCPShieldClient("http://localhost:8000", "mcp_sk_test")
|
|
41
|
+
with patch.object(client.session, "post", return_value=_response(402, body)):
|
|
42
|
+
result = client.report_servers([{"server_name": "x"}])
|
|
43
|
+
|
|
44
|
+
# No exception, and the useful fields (esp. the upgrade message) survive.
|
|
45
|
+
assert result["servers_skipped"] == 3
|
|
46
|
+
assert "Upgrade to Pro" in result["detail"]
|
|
47
|
+
|
|
48
|
+
def test_200_still_returns_body(self):
|
|
49
|
+
body = {"created": 1, "updated": 0, "alerts": 0, "servers": [], "servers_skipped": 0}
|
|
50
|
+
client = MCPShieldClient("http://localhost:8000", "mcp_sk_test")
|
|
51
|
+
with patch.object(client.session, "post", return_value=_response(200, body)):
|
|
52
|
+
result = client.report_servers([{"server_name": "x"}])
|
|
53
|
+
assert result["created"] == 1
|
|
54
|
+
|
|
55
|
+
def test_500_still_raises(self):
|
|
56
|
+
client = MCPShieldClient("http://localhost:8000", "mcp_sk_test")
|
|
57
|
+
with patch.object(client.session, "post", return_value=_response(500, {})):
|
|
58
|
+
try:
|
|
59
|
+
client.report_servers([{"server_name": "x"}])
|
|
60
|
+
assert False, "expected HTTPError to propagate on 500"
|
|
61
|
+
except requests.exceptions.HTTPError:
|
|
62
|
+
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mcpshield_agent-0.2.0 → mcpshield_agent-0.2.1}/mcpshield_agent.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|