mcp-guard-lint 0.3.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.
- mcp_guard_lint-0.3.1/LICENSE +21 -0
- mcp_guard_lint-0.3.1/PKG-INFO +165 -0
- mcp_guard_lint-0.3.1/README.md +134 -0
- mcp_guard_lint-0.3.1/pyproject.toml +44 -0
- mcp_guard_lint-0.3.1/setup.cfg +4 -0
- mcp_guard_lint-0.3.1/src/mcp_guard_lint.egg-info/PKG-INFO +165 -0
- mcp_guard_lint-0.3.1/src/mcp_guard_lint.egg-info/SOURCES.txt +15 -0
- mcp_guard_lint-0.3.1/src/mcp_guard_lint.egg-info/dependency_links.txt +1 -0
- mcp_guard_lint-0.3.1/src/mcp_guard_lint.egg-info/entry_points.txt +2 -0
- mcp_guard_lint-0.3.1/src/mcp_guard_lint.egg-info/requires.txt +3 -0
- mcp_guard_lint-0.3.1/src/mcp_guard_lint.egg-info/top_level.txt +1 -0
- mcp_guard_lint-0.3.1/src/mcp_lint/__init__.py +0 -0
- mcp_guard_lint-0.3.1/src/mcp_lint/cli.py +67 -0
- mcp_guard_lint-0.3.1/src/mcp_lint/rules.py +41 -0
- mcp_guard_lint-0.3.1/src/mcp_lint/sarif.py +71 -0
- mcp_guard_lint-0.3.1/src/mcp_lint/scanner.py +141 -0
- mcp_guard_lint-0.3.1/tests/test_scanner.py +38 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 [Staggerlee60]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-guard-lint
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Zero-dependency static security and hygiene linter for MCP server configurations.
|
|
5
|
+
Author: staggerlee60
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/staggerlee60/mcp-lint
|
|
8
|
+
Project-URL: Repository, https://github.com/staggerlee60/mcp-lint
|
|
9
|
+
Project-URL: Issues, https://github.com/staggerlee60/mcp-lint/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,security,linter,sarif,claude,ai-agents
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# mcp-lint
|
|
33
|
+
|
|
34
|
+
[](https://github.com/staggerlee60/mcp-lint/actions/workflows/ci.yml)
|
|
35
|
+
[](https://python.org)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](https://azurewebsites.net)
|
|
38
|
+
[](#cross-platform-support)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
A lightweight, zero-dependency static security and hygiene linter for Model Context Protocol (`.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, and `claude_desktop_config.json`) configurations.
|
|
42
|
+
|
|
43
|
+
## Quick Demo
|
|
44
|
+
|
|
45
|
+
<img width="1219" height="298" alt="image" src="https://github.com/user-attachments/assets/6af77ca4-f509-4874-89a8-c2e65685f745" />
|
|
46
|
+
|
|
47
|
+
Run `mcp-lint` against any MCP config (or run with no arguments to auto-discover local configs):
|
|
48
|
+
|
|
49
|
+
```console
|
|
50
|
+
$ mcp-lint tests/fixtures/unsafe_mcp.json
|
|
51
|
+
tests/fixtures/unsafe_mcp.json: [MEDIUM] MCP002 (unsafe-fs): Unpinned package '@modelcontextprotocol/server-filesystem' via npx; pin a specific version.
|
|
52
|
+
tests/fixtures/unsafe_mcp.json: [CRITICAL] MCP003 (unsafe-fs): Possible hardcoded API token or secret detected in server config.
|
|
53
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP004 (unsafe-fs): Overly broad filesystem path '/' exposed to MCP server.
|
|
54
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP005 (unsafe-remote): Unencrypted remote endpoint 'http://example.com'; use https:// instead.
|
|
55
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP006 (injected-server): Suspicious prompt-injection or instruction-override phrase detected in config.
|
|
56
|
+
tests/fixtures/unsafe_mcp.json: [CRITICAL] MCP007 (injected-server): Privileged execution detected via 'sudo'; run MCP servers with least privilege.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
- **MCP001:** Flags direct raw shell invocations (`bash`, `sh`, `zsh`, `pwsh`, `powershell`, `cmd`).
|
|
61
|
+
- **MCP002:** Warns on unpinned `npx` and `uvx` package executions (including scoped packages without version pins).
|
|
62
|
+
- **MCP003:** Detects hardcoded API keys and bearer tokens in `env` or `args`.
|
|
63
|
+
- **MCP004:** Flags overly broad filesystem mounts (`/`, `C:\`, `~`, `/Users`, `/home`, `C:\Users`).
|
|
64
|
+
- **MCP005:** Flags unencrypted remote `http://` MCP URLs (excluding `localhost` / `127.0.0.1`) and disabled TLS verification flags.
|
|
65
|
+
- **MCP006:** Detects suspicious prompt-injection or instruction-override phrases in server descriptions, arguments, or environment variables.
|
|
66
|
+
- **MCP007:** Flags privileged or root-level command execution (`sudo`, `runas`, `docker run --privileged`).
|
|
67
|
+
- **Auto-Discovery:** Automatically finds and scans local project and user MCP configuration files when run with no arguments.
|
|
68
|
+
- **SARIF 2.1.0 Output:** Exports findings in SARIF format (`--format sarif`) for native GitHub Code Scanning and PR annotations.
|
|
69
|
+
- **Pre-commit Support:** Ships with `.pre-commit-hooks.yaml` to catch insecure MCP configs before they are committed.
|
|
70
|
+
|
|
71
|
+
## Cross-Platform Support
|
|
72
|
+
|
|
73
|
+
`mcp-lint` runs natively on **Windows, macOS, and Linux** with zero external dependencies:
|
|
74
|
+
- **Windows-Aware Paths & Shells:** Flags Windows root mounts (`C:\`, `C:\Users`), privileged `runas` usage, and raw `pwsh` / `powershell` / `cmd` invocations.
|
|
75
|
+
- **Auto-Discovery Across OSes:** Automatically locates `%APPDATA%\Claude\claude_desktop_config.json` on Windows, `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, and `~/.config/Claude/claude_desktop_config.json` on Linux.
|
|
76
|
+
- **UTF-8 BOM Resilient:** Cleanly parses JSON files saved with a UTF-8 Byte Order Mark by PowerShell or Windows editors.
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Run directly without installing
|
|
82
|
+
uvx --from mcp-guard-lint mcp-lint
|
|
83
|
+
|
|
84
|
+
# Or install via pip
|
|
85
|
+
pip install mcp-guard-lint
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Auto-discover project and user MCP configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, Claude Desktop)
|
|
92
|
+
mcp-lint
|
|
93
|
+
|
|
94
|
+
# Auto-discover only configs inside the current project directory
|
|
95
|
+
mcp-lint --no-user-configs
|
|
96
|
+
|
|
97
|
+
# Scan one or more specific configuration files
|
|
98
|
+
mcp-lint path/to/.mcp.json .cursor/mcp.json
|
|
99
|
+
|
|
100
|
+
# Export SARIF 2.1.0 output for GitHub Code Scanning
|
|
101
|
+
mcp-lint --format sarif --output mcp-lint.sarif
|
|
102
|
+
|
|
103
|
+
# Scan Claude Desktop's config on Windows PowerShell
|
|
104
|
+
mcp-lint "$env:APPDATA\Claude\claude_desktop_config.json"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Example Output
|
|
108
|
+
```text
|
|
109
|
+
.mcp.json: [CRITICAL] MCP003 (unsafe-fs): Possible hardcoded API token or secret detected in server config.
|
|
110
|
+
.mcp.json: [MEDIUM] MCP002 (unsafe-fs): Unpinned package '@modelcontextprotocol/server-filesystem' via npx; pin a specific version.
|
|
111
|
+
.mcp.json: [HIGH] MCP004 (unsafe-fs): Overly broad filesystem path '/' exposed to MCP server.
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## GitHub Actions Code Scanning (SARIF)
|
|
115
|
+
|
|
116
|
+
Add a workflow (e.g., `.github/workflows/mcp-security.yml`) to surface MCP security findings directly in your repository's **Security Code scanning** tab:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
name: MCP Config Security Scan
|
|
120
|
+
on: [push, pull_request]
|
|
121
|
+
|
|
122
|
+
jobs:
|
|
123
|
+
mcp-lint:
|
|
124
|
+
runs-on: ubuntu-latest
|
|
125
|
+
permissions:
|
|
126
|
+
security-events: write
|
|
127
|
+
contents: read
|
|
128
|
+
steps:
|
|
129
|
+
- uses: actions/checkout@v4
|
|
130
|
+
- uses: actions/setup-python@v5
|
|
131
|
+
with:
|
|
132
|
+
python-version: "3.12"
|
|
133
|
+
- run: pip install mcp-guard-lint
|
|
134
|
+
id: lint
|
|
135
|
+
- run: mcp-lint --no-user-configs --format sarif --output mcp-lint.sarif
|
|
136
|
+
continue-on-error: true
|
|
137
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
138
|
+
with:
|
|
139
|
+
sarif_file: mcp-lint.sarif
|
|
140
|
+
- name: Fail if findings detected
|
|
141
|
+
if: steps.lint.outcome == 'failure'
|
|
142
|
+
run: exit 1
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Pre-commit Hook
|
|
146
|
+
|
|
147
|
+
Add `mcp-lint` to your `.pre-commit-config.yaml` to block unpinned packages, broad mounts, or hardcoded secrets before they are committed:
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
repos:
|
|
151
|
+
- repo: https://github.com/Staggerlee60/mcp-lint
|
|
152
|
+
rev: v0.3.1
|
|
153
|
+
hooks:
|
|
154
|
+
- id: mcp-lint
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Running Tests
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pytest -v
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# mcp-lint
|
|
2
|
+
|
|
3
|
+
[](https://github.com/staggerlee60/mcp-lint/actions/workflows/ci.yml)
|
|
4
|
+
[](https://python.org)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://azurewebsites.net)
|
|
7
|
+
[](#cross-platform-support)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
A lightweight, zero-dependency static security and hygiene linter for Model Context Protocol (`.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, and `claude_desktop_config.json`) configurations.
|
|
11
|
+
|
|
12
|
+
## Quick Demo
|
|
13
|
+
|
|
14
|
+
<img width="1219" height="298" alt="image" src="https://github.com/user-attachments/assets/6af77ca4-f509-4874-89a8-c2e65685f745" />
|
|
15
|
+
|
|
16
|
+
Run `mcp-lint` against any MCP config (or run with no arguments to auto-discover local configs):
|
|
17
|
+
|
|
18
|
+
```console
|
|
19
|
+
$ mcp-lint tests/fixtures/unsafe_mcp.json
|
|
20
|
+
tests/fixtures/unsafe_mcp.json: [MEDIUM] MCP002 (unsafe-fs): Unpinned package '@modelcontextprotocol/server-filesystem' via npx; pin a specific version.
|
|
21
|
+
tests/fixtures/unsafe_mcp.json: [CRITICAL] MCP003 (unsafe-fs): Possible hardcoded API token or secret detected in server config.
|
|
22
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP004 (unsafe-fs): Overly broad filesystem path '/' exposed to MCP server.
|
|
23
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP005 (unsafe-remote): Unencrypted remote endpoint 'http://example.com'; use https:// instead.
|
|
24
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP006 (injected-server): Suspicious prompt-injection or instruction-override phrase detected in config.
|
|
25
|
+
tests/fixtures/unsafe_mcp.json: [CRITICAL] MCP007 (injected-server): Privileged execution detected via 'sudo'; run MCP servers with least privilege.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
- **MCP001:** Flags direct raw shell invocations (`bash`, `sh`, `zsh`, `pwsh`, `powershell`, `cmd`).
|
|
30
|
+
- **MCP002:** Warns on unpinned `npx` and `uvx` package executions (including scoped packages without version pins).
|
|
31
|
+
- **MCP003:** Detects hardcoded API keys and bearer tokens in `env` or `args`.
|
|
32
|
+
- **MCP004:** Flags overly broad filesystem mounts (`/`, `C:\`, `~`, `/Users`, `/home`, `C:\Users`).
|
|
33
|
+
- **MCP005:** Flags unencrypted remote `http://` MCP URLs (excluding `localhost` / `127.0.0.1`) and disabled TLS verification flags.
|
|
34
|
+
- **MCP006:** Detects suspicious prompt-injection or instruction-override phrases in server descriptions, arguments, or environment variables.
|
|
35
|
+
- **MCP007:** Flags privileged or root-level command execution (`sudo`, `runas`, `docker run --privileged`).
|
|
36
|
+
- **Auto-Discovery:** Automatically finds and scans local project and user MCP configuration files when run with no arguments.
|
|
37
|
+
- **SARIF 2.1.0 Output:** Exports findings in SARIF format (`--format sarif`) for native GitHub Code Scanning and PR annotations.
|
|
38
|
+
- **Pre-commit Support:** Ships with `.pre-commit-hooks.yaml` to catch insecure MCP configs before they are committed.
|
|
39
|
+
|
|
40
|
+
## Cross-Platform Support
|
|
41
|
+
|
|
42
|
+
`mcp-lint` runs natively on **Windows, macOS, and Linux** with zero external dependencies:
|
|
43
|
+
- **Windows-Aware Paths & Shells:** Flags Windows root mounts (`C:\`, `C:\Users`), privileged `runas` usage, and raw `pwsh` / `powershell` / `cmd` invocations.
|
|
44
|
+
- **Auto-Discovery Across OSes:** Automatically locates `%APPDATA%\Claude\claude_desktop_config.json` on Windows, `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, and `~/.config/Claude/claude_desktop_config.json` on Linux.
|
|
45
|
+
- **UTF-8 BOM Resilient:** Cleanly parses JSON files saved with a UTF-8 Byte Order Mark by PowerShell or Windows editors.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Run directly without installing
|
|
51
|
+
uvx --from mcp-guard-lint mcp-lint
|
|
52
|
+
|
|
53
|
+
# Or install via pip
|
|
54
|
+
pip install mcp-guard-lint
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Auto-discover project and user MCP configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, Claude Desktop)
|
|
61
|
+
mcp-lint
|
|
62
|
+
|
|
63
|
+
# Auto-discover only configs inside the current project directory
|
|
64
|
+
mcp-lint --no-user-configs
|
|
65
|
+
|
|
66
|
+
# Scan one or more specific configuration files
|
|
67
|
+
mcp-lint path/to/.mcp.json .cursor/mcp.json
|
|
68
|
+
|
|
69
|
+
# Export SARIF 2.1.0 output for GitHub Code Scanning
|
|
70
|
+
mcp-lint --format sarif --output mcp-lint.sarif
|
|
71
|
+
|
|
72
|
+
# Scan Claude Desktop's config on Windows PowerShell
|
|
73
|
+
mcp-lint "$env:APPDATA\Claude\claude_desktop_config.json"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Example Output
|
|
77
|
+
```text
|
|
78
|
+
.mcp.json: [CRITICAL] MCP003 (unsafe-fs): Possible hardcoded API token or secret detected in server config.
|
|
79
|
+
.mcp.json: [MEDIUM] MCP002 (unsafe-fs): Unpinned package '@modelcontextprotocol/server-filesystem' via npx; pin a specific version.
|
|
80
|
+
.mcp.json: [HIGH] MCP004 (unsafe-fs): Overly broad filesystem path '/' exposed to MCP server.
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## GitHub Actions Code Scanning (SARIF)
|
|
84
|
+
|
|
85
|
+
Add a workflow (e.g., `.github/workflows/mcp-security.yml`) to surface MCP security findings directly in your repository's **Security Code scanning** tab:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
name: MCP Config Security Scan
|
|
89
|
+
on: [push, pull_request]
|
|
90
|
+
|
|
91
|
+
jobs:
|
|
92
|
+
mcp-lint:
|
|
93
|
+
runs-on: ubuntu-latest
|
|
94
|
+
permissions:
|
|
95
|
+
security-events: write
|
|
96
|
+
contents: read
|
|
97
|
+
steps:
|
|
98
|
+
- uses: actions/checkout@v4
|
|
99
|
+
- uses: actions/setup-python@v5
|
|
100
|
+
with:
|
|
101
|
+
python-version: "3.12"
|
|
102
|
+
- run: pip install mcp-guard-lint
|
|
103
|
+
id: lint
|
|
104
|
+
- run: mcp-lint --no-user-configs --format sarif --output mcp-lint.sarif
|
|
105
|
+
continue-on-error: true
|
|
106
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
107
|
+
with:
|
|
108
|
+
sarif_file: mcp-lint.sarif
|
|
109
|
+
- name: Fail if findings detected
|
|
110
|
+
if: steps.lint.outcome == 'failure'
|
|
111
|
+
run: exit 1
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Pre-commit Hook
|
|
115
|
+
|
|
116
|
+
Add `mcp-lint` to your `.pre-commit-config.yaml` to block unpinned packages, broad mounts, or hardcoded secrets before they are committed:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
repos:
|
|
120
|
+
- repo: https://github.com/Staggerlee60/mcp-lint
|
|
121
|
+
rev: v0.3.1
|
|
122
|
+
hooks:
|
|
123
|
+
- id: mcp-lint
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Running Tests
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pytest -v
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mcp-guard-lint"
|
|
7
|
+
version = "0.3.1"
|
|
8
|
+
description = "Zero-dependency static security and hygiene linter for MCP server configurations."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "staggerlee60" }]
|
|
13
|
+
keywords = ["mcp", "model-context-protocol", "security", "linter", "sarif", "claude", "ai-agents"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Programming Language :: Python :: 3.15",
|
|
27
|
+
"Topic :: Security",
|
|
28
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
29
|
+
]
|
|
30
|
+
dependencies = []
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = ["pytest>=8.0"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/staggerlee60/mcp-lint"
|
|
37
|
+
Repository = "https://github.com/staggerlee60/mcp-lint"
|
|
38
|
+
Issues = "https://github.com/staggerlee60/mcp-lint/issues"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
mcp-lint = "mcp_lint.cli:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-guard-lint
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Zero-dependency static security and hygiene linter for MCP server configurations.
|
|
5
|
+
Author: staggerlee60
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/staggerlee60/mcp-lint
|
|
8
|
+
Project-URL: Repository, https://github.com/staggerlee60/mcp-lint
|
|
9
|
+
Project-URL: Issues, https://github.com/staggerlee60/mcp-lint/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,security,linter,sarif,claude,ai-agents
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# mcp-lint
|
|
33
|
+
|
|
34
|
+
[](https://github.com/staggerlee60/mcp-lint/actions/workflows/ci.yml)
|
|
35
|
+
[](https://python.org)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](https://azurewebsites.net)
|
|
38
|
+
[](#cross-platform-support)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
A lightweight, zero-dependency static security and hygiene linter for Model Context Protocol (`.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, and `claude_desktop_config.json`) configurations.
|
|
42
|
+
|
|
43
|
+
## Quick Demo
|
|
44
|
+
|
|
45
|
+
<img width="1219" height="298" alt="image" src="https://github.com/user-attachments/assets/6af77ca4-f509-4874-89a8-c2e65685f745" />
|
|
46
|
+
|
|
47
|
+
Run `mcp-lint` against any MCP config (or run with no arguments to auto-discover local configs):
|
|
48
|
+
|
|
49
|
+
```console
|
|
50
|
+
$ mcp-lint tests/fixtures/unsafe_mcp.json
|
|
51
|
+
tests/fixtures/unsafe_mcp.json: [MEDIUM] MCP002 (unsafe-fs): Unpinned package '@modelcontextprotocol/server-filesystem' via npx; pin a specific version.
|
|
52
|
+
tests/fixtures/unsafe_mcp.json: [CRITICAL] MCP003 (unsafe-fs): Possible hardcoded API token or secret detected in server config.
|
|
53
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP004 (unsafe-fs): Overly broad filesystem path '/' exposed to MCP server.
|
|
54
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP005 (unsafe-remote): Unencrypted remote endpoint 'http://example.com'; use https:// instead.
|
|
55
|
+
tests/fixtures/unsafe_mcp.json: [HIGH] MCP006 (injected-server): Suspicious prompt-injection or instruction-override phrase detected in config.
|
|
56
|
+
tests/fixtures/unsafe_mcp.json: [CRITICAL] MCP007 (injected-server): Privileged execution detected via 'sudo'; run MCP servers with least privilege.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
- **MCP001:** Flags direct raw shell invocations (`bash`, `sh`, `zsh`, `pwsh`, `powershell`, `cmd`).
|
|
61
|
+
- **MCP002:** Warns on unpinned `npx` and `uvx` package executions (including scoped packages without version pins).
|
|
62
|
+
- **MCP003:** Detects hardcoded API keys and bearer tokens in `env` or `args`.
|
|
63
|
+
- **MCP004:** Flags overly broad filesystem mounts (`/`, `C:\`, `~`, `/Users`, `/home`, `C:\Users`).
|
|
64
|
+
- **MCP005:** Flags unencrypted remote `http://` MCP URLs (excluding `localhost` / `127.0.0.1`) and disabled TLS verification flags.
|
|
65
|
+
- **MCP006:** Detects suspicious prompt-injection or instruction-override phrases in server descriptions, arguments, or environment variables.
|
|
66
|
+
- **MCP007:** Flags privileged or root-level command execution (`sudo`, `runas`, `docker run --privileged`).
|
|
67
|
+
- **Auto-Discovery:** Automatically finds and scans local project and user MCP configuration files when run with no arguments.
|
|
68
|
+
- **SARIF 2.1.0 Output:** Exports findings in SARIF format (`--format sarif`) for native GitHub Code Scanning and PR annotations.
|
|
69
|
+
- **Pre-commit Support:** Ships with `.pre-commit-hooks.yaml` to catch insecure MCP configs before they are committed.
|
|
70
|
+
|
|
71
|
+
## Cross-Platform Support
|
|
72
|
+
|
|
73
|
+
`mcp-lint` runs natively on **Windows, macOS, and Linux** with zero external dependencies:
|
|
74
|
+
- **Windows-Aware Paths & Shells:** Flags Windows root mounts (`C:\`, `C:\Users`), privileged `runas` usage, and raw `pwsh` / `powershell` / `cmd` invocations.
|
|
75
|
+
- **Auto-Discovery Across OSes:** Automatically locates `%APPDATA%\Claude\claude_desktop_config.json` on Windows, `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, and `~/.config/Claude/claude_desktop_config.json` on Linux.
|
|
76
|
+
- **UTF-8 BOM Resilient:** Cleanly parses JSON files saved with a UTF-8 Byte Order Mark by PowerShell or Windows editors.
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Run directly without installing
|
|
82
|
+
uvx --from mcp-guard-lint mcp-lint
|
|
83
|
+
|
|
84
|
+
# Or install via pip
|
|
85
|
+
pip install mcp-guard-lint
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Auto-discover project and user MCP configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, Claude Desktop)
|
|
92
|
+
mcp-lint
|
|
93
|
+
|
|
94
|
+
# Auto-discover only configs inside the current project directory
|
|
95
|
+
mcp-lint --no-user-configs
|
|
96
|
+
|
|
97
|
+
# Scan one or more specific configuration files
|
|
98
|
+
mcp-lint path/to/.mcp.json .cursor/mcp.json
|
|
99
|
+
|
|
100
|
+
# Export SARIF 2.1.0 output for GitHub Code Scanning
|
|
101
|
+
mcp-lint --format sarif --output mcp-lint.sarif
|
|
102
|
+
|
|
103
|
+
# Scan Claude Desktop's config on Windows PowerShell
|
|
104
|
+
mcp-lint "$env:APPDATA\Claude\claude_desktop_config.json"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Example Output
|
|
108
|
+
```text
|
|
109
|
+
.mcp.json: [CRITICAL] MCP003 (unsafe-fs): Possible hardcoded API token or secret detected in server config.
|
|
110
|
+
.mcp.json: [MEDIUM] MCP002 (unsafe-fs): Unpinned package '@modelcontextprotocol/server-filesystem' via npx; pin a specific version.
|
|
111
|
+
.mcp.json: [HIGH] MCP004 (unsafe-fs): Overly broad filesystem path '/' exposed to MCP server.
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## GitHub Actions Code Scanning (SARIF)
|
|
115
|
+
|
|
116
|
+
Add a workflow (e.g., `.github/workflows/mcp-security.yml`) to surface MCP security findings directly in your repository's **Security Code scanning** tab:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
name: MCP Config Security Scan
|
|
120
|
+
on: [push, pull_request]
|
|
121
|
+
|
|
122
|
+
jobs:
|
|
123
|
+
mcp-lint:
|
|
124
|
+
runs-on: ubuntu-latest
|
|
125
|
+
permissions:
|
|
126
|
+
security-events: write
|
|
127
|
+
contents: read
|
|
128
|
+
steps:
|
|
129
|
+
- uses: actions/checkout@v4
|
|
130
|
+
- uses: actions/setup-python@v5
|
|
131
|
+
with:
|
|
132
|
+
python-version: "3.12"
|
|
133
|
+
- run: pip install mcp-guard-lint
|
|
134
|
+
id: lint
|
|
135
|
+
- run: mcp-lint --no-user-configs --format sarif --output mcp-lint.sarif
|
|
136
|
+
continue-on-error: true
|
|
137
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
138
|
+
with:
|
|
139
|
+
sarif_file: mcp-lint.sarif
|
|
140
|
+
- name: Fail if findings detected
|
|
141
|
+
if: steps.lint.outcome == 'failure'
|
|
142
|
+
run: exit 1
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Pre-commit Hook
|
|
146
|
+
|
|
147
|
+
Add `mcp-lint` to your `.pre-commit-config.yaml` to block unpinned packages, broad mounts, or hardcoded secrets before they are committed:
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
repos:
|
|
151
|
+
- repo: https://github.com/Staggerlee60/mcp-lint
|
|
152
|
+
rev: v0.3.1
|
|
153
|
+
hooks:
|
|
154
|
+
- id: mcp-lint
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Running Tests
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pytest -v
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/mcp_guard_lint.egg-info/PKG-INFO
|
|
5
|
+
src/mcp_guard_lint.egg-info/SOURCES.txt
|
|
6
|
+
src/mcp_guard_lint.egg-info/dependency_links.txt
|
|
7
|
+
src/mcp_guard_lint.egg-info/entry_points.txt
|
|
8
|
+
src/mcp_guard_lint.egg-info/requires.txt
|
|
9
|
+
src/mcp_guard_lint.egg-info/top_level.txt
|
|
10
|
+
src/mcp_lint/__init__.py
|
|
11
|
+
src/mcp_lint/cli.py
|
|
12
|
+
src/mcp_lint/rules.py
|
|
13
|
+
src/mcp_lint/sarif.py
|
|
14
|
+
src/mcp_lint/scanner.py
|
|
15
|
+
tests/test_scanner.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcp_lint
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from .sarif import format_sarif
|
|
5
|
+
from .scanner import discover_mcp_configs, scan_mcp_config
|
|
6
|
+
|
|
7
|
+
def main() -> int:
|
|
8
|
+
parser = argparse.ArgumentParser(
|
|
9
|
+
description="Lint MCP server JSON configs for security and hygiene issues."
|
|
10
|
+
)
|
|
11
|
+
parser.add_argument(
|
|
12
|
+
"paths",
|
|
13
|
+
nargs="*",
|
|
14
|
+
type=Path,
|
|
15
|
+
help="Path(s) to MCP config files. If omitted, auto-discovers standard local configs.",
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"--no-user-configs",
|
|
19
|
+
action="store_true",
|
|
20
|
+
help="During auto-discovery, only scan the current project directory.",
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--format",
|
|
24
|
+
choices=["text", "sarif"],
|
|
25
|
+
default="text",
|
|
26
|
+
help="Output format (default: text).",
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"--output",
|
|
30
|
+
type=Path,
|
|
31
|
+
help="Optional output file path (useful with --format sarif).",
|
|
32
|
+
)
|
|
33
|
+
args = parser.parse_args()
|
|
34
|
+
|
|
35
|
+
if args.paths:
|
|
36
|
+
targets = args.paths
|
|
37
|
+
for path in targets:
|
|
38
|
+
if not path.exists():
|
|
39
|
+
print(f"Error: File not found: {path}", file=sys.stderr)
|
|
40
|
+
return 2
|
|
41
|
+
else:
|
|
42
|
+
targets = discover_mcp_configs(include_user_configs=not args.no_user_configs)
|
|
43
|
+
|
|
44
|
+
findings_by_file = [(target, scan_mcp_config(target)) for target in targets]
|
|
45
|
+
total_findings = sum(len(f) for _, f in findings_by_file)
|
|
46
|
+
|
|
47
|
+
if args.format == "sarif":
|
|
48
|
+
rendered = format_sarif(findings_by_file)
|
|
49
|
+
if args.output:
|
|
50
|
+
args.output.write_text(rendered, encoding="utf-8")
|
|
51
|
+
else:
|
|
52
|
+
print(rendered)
|
|
53
|
+
else:
|
|
54
|
+
if not targets:
|
|
55
|
+
print("OK: No MCP configuration files discovered.")
|
|
56
|
+
return 0
|
|
57
|
+
for target, findings in findings_by_file:
|
|
58
|
+
if not findings:
|
|
59
|
+
print(f"OK: No issues found in {target}")
|
|
60
|
+
else:
|
|
61
|
+
for f in findings:
|
|
62
|
+
print(f"{target}: [{f.severity}] {f.rule_id} ({f.server}): {f.message}")
|
|
63
|
+
|
|
64
|
+
return 1 if total_findings > 0 else 0
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
SECRET_PATTERNS = [
|
|
5
|
+
re.compile(r"sk-[a-zA-Z0-9_-]{20,}"),
|
|
6
|
+
re.compile(r"ghp_[a-zA-Z0-9]{30,}"),
|
|
7
|
+
re.compile(r"AKIA[0-9A-Z]{16}"),
|
|
8
|
+
re.compile(r"Bearer\s+[a-zA-Z0-9._-]{20,}"),
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
RISKY_SHELL_COMMANDS = {"bash", "sh", "zsh", "pwsh", "powershell", "cmd", "cmd.exe"}
|
|
12
|
+
BROAD_PATHS = {"/", "C:\\", "C:/", "~", "/Users", "/home", "C:\\Users"}
|
|
13
|
+
LOCAL_HTTP_PREFIXES = ("http://localhost", "http://127.0.0.1", "http://[::1]")
|
|
14
|
+
TLS_BYPASS_TOKENS = {"--insecure", "--no-check-certificate", "NODE_TLS_REJECT_UNAUTHORIZED=0"}
|
|
15
|
+
|
|
16
|
+
PROMPT_INJECTION_PATTERNS = [
|
|
17
|
+
re.compile(r"ignore\s+(all\s+)?(previous|prior)\s+instructions", re.IGNORECASE),
|
|
18
|
+
re.compile(r"disregard\s+(all\s+)?(previous|prior)\s+instructions", re.IGNORECASE),
|
|
19
|
+
re.compile(r"override\s+(system|safety)\s+(prompt|instructions)", re.IGNORECASE),
|
|
20
|
+
re.compile(r"exfiltrate\s+(secrets|tokens|env|credentials)", re.IGNORECASE),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
PRIVILEGED_COMMANDS = {"sudo", "su", "doas", "runas", "pkexec"}
|
|
24
|
+
|
|
25
|
+
RULE_METADATA = {
|
|
26
|
+
"MCP001": ("DirectShellInvocation", "Direct raw shell invocation increases command-injection risk."),
|
|
27
|
+
"MCP002": ("UnpinnedPackageExecution", "Unpinned package execution via npx or uvx."),
|
|
28
|
+
"MCP003": ("HardcodedSecret", "Possible hardcoded API token or credential in MCP server config."),
|
|
29
|
+
"MCP004": ("OverlyBroadFilesystemMount", "Overly broad filesystem path exposed to MCP server."),
|
|
30
|
+
"MCP005": ("InsecureTransportOrTLS", "Unencrypted remote HTTP URL or disabled TLS certificate verification."),
|
|
31
|
+
"MCP006": ("SuspiciousPromptOverride", "Suspicious prompt-injection or instruction-override phrase in server config."),
|
|
32
|
+
"MCP007": ("PrivilegedExecution", "Privileged or root-level command execution in MCP server config."),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class Finding:
|
|
38
|
+
rule_id: str
|
|
39
|
+
severity: str
|
|
40
|
+
server: str
|
|
41
|
+
message: str
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from .rules import RULE_METADATA, Finding
|
|
5
|
+
|
|
6
|
+
SEVERITY_TO_SARIF = {
|
|
7
|
+
"CRITICAL": "error",
|
|
8
|
+
"HIGH": "error",
|
|
9
|
+
"MEDIUM": "warning",
|
|
10
|
+
"LOW": "note",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_version() -> str:
|
|
15
|
+
try:
|
|
16
|
+
return version("mcp-guard-lint")
|
|
17
|
+
except PackageNotFoundError:
|
|
18
|
+
return "0.3.1"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def format_sarif(
|
|
22
|
+
findings_by_file: list[tuple[Path, list[Finding]]],
|
|
23
|
+
tool_version: str | None = None,
|
|
24
|
+
) -> str:
|
|
25
|
+
resolved_version = tool_version or _get_version()
|
|
26
|
+
|
|
27
|
+
rules_list = [
|
|
28
|
+
{
|
|
29
|
+
"id": rule_id,
|
|
30
|
+
"name": name,
|
|
31
|
+
"shortDescription": {"text": desc},
|
|
32
|
+
}
|
|
33
|
+
for rule_id, (name, desc) in RULE_METADATA.items()
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
results = []
|
|
37
|
+
for file_path, findings in findings_by_file:
|
|
38
|
+
uri = file_path.as_posix()
|
|
39
|
+
for f in findings:
|
|
40
|
+
results.append({
|
|
41
|
+
"ruleId": f.rule_id,
|
|
42
|
+
"level": SEVERITY_TO_SARIF.get(f.severity, "warning"),
|
|
43
|
+
"message": {"text": f"[{f.server}] {f.message}"},
|
|
44
|
+
"locations": [
|
|
45
|
+
{
|
|
46
|
+
"physicalLocation": {
|
|
47
|
+
"artifactLocation": {"uri": uri},
|
|
48
|
+
"region": {"startLine": 1},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
sarif_log = {
|
|
55
|
+
"$schema": "https://schemastore.org",
|
|
56
|
+
"version": "2.1.0",
|
|
57
|
+
"runs": [
|
|
58
|
+
{
|
|
59
|
+
"tool": {
|
|
60
|
+
"driver": {
|
|
61
|
+
"name": "mcp-lint",
|
|
62
|
+
"version": resolved_version,
|
|
63
|
+
"informationUri": "https://github.com/staggerlee60/mcp-lint",
|
|
64
|
+
"rules": rules_list,
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"results": results,
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
}
|
|
71
|
+
return json.dumps(sarif_log, indent=2)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import platform
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from .rules import (
|
|
6
|
+
BROAD_PATHS,
|
|
7
|
+
LOCAL_HTTP_PREFIXES,
|
|
8
|
+
PRIVILEGED_COMMANDS,
|
|
9
|
+
PROMPT_INJECTION_PATTERNS,
|
|
10
|
+
RISKY_SHELL_COMMANDS,
|
|
11
|
+
SECRET_PATTERNS,
|
|
12
|
+
TLS_BYPASS_TOKENS,
|
|
13
|
+
Finding,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def discover_mcp_configs(base_dir: Path | None = None, include_user_configs: bool = True) -> list[Path]:
|
|
18
|
+
cwd = base_dir or Path.cwd()
|
|
19
|
+
candidates = [
|
|
20
|
+
cwd / ".mcp.json",
|
|
21
|
+
cwd / ".cursor" / "mcp.json",
|
|
22
|
+
cwd / ".vscode" / "mcp.json",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
if include_user_configs:
|
|
26
|
+
home = Path.home()
|
|
27
|
+
candidates.extend([
|
|
28
|
+
home / ".mcp.json",
|
|
29
|
+
home / ".cursor" / "mcp.json",
|
|
30
|
+
])
|
|
31
|
+
system = platform.system()
|
|
32
|
+
if system == "Windows" and os.environ.get("APPDATA"):
|
|
33
|
+
candidates.append(Path(os.environ["APPDATA"]) / "Claude" / "claude_desktop_config.json")
|
|
34
|
+
elif system == "Darwin":
|
|
35
|
+
candidates.append(home / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json")
|
|
36
|
+
else:
|
|
37
|
+
candidates.append(home / ".config" / "Claude" / "claude_desktop_config.json")
|
|
38
|
+
|
|
39
|
+
found: list[Path] = []
|
|
40
|
+
seen: set[Path] = set()
|
|
41
|
+
for path in candidates:
|
|
42
|
+
if path.is_file():
|
|
43
|
+
resolved = path.resolve()
|
|
44
|
+
if resolved not in seen:
|
|
45
|
+
seen.add(resolved)
|
|
46
|
+
found.append(path)
|
|
47
|
+
return found
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def scan_mcp_config(config_path: Path) -> list[Finding]:
|
|
51
|
+
data = json.loads(config_path.read_text(encoding="utf-8-sig"))
|
|
52
|
+
servers = data.get("mcpServers") or data.get("servers") or {}
|
|
53
|
+
findings: list[Finding] = []
|
|
54
|
+
|
|
55
|
+
for name, cfg in servers.items():
|
|
56
|
+
if not isinstance(cfg, dict):
|
|
57
|
+
continue
|
|
58
|
+
cmd = str(cfg.get("command", "")).strip()
|
|
59
|
+
cmd_base = Path(cmd).name.lower()
|
|
60
|
+
args = [str(a) for a in cfg.get("args", [])]
|
|
61
|
+
env = cfg.get("env", {})
|
|
62
|
+
url = str(cfg.get("url", "")).strip()
|
|
63
|
+
|
|
64
|
+
# MCP001: Raw shell execution
|
|
65
|
+
if cmd_base in RISKY_SHELL_COMMANDS:
|
|
66
|
+
findings.append(Finding(
|
|
67
|
+
"MCP001", "HIGH", name,
|
|
68
|
+
f"Direct shell invocation '{cmd}' increases command-injection risk."
|
|
69
|
+
))
|
|
70
|
+
|
|
71
|
+
# MCP002: Unpinned npx / uvx package execution
|
|
72
|
+
if cmd_base in {"npx", "uvx"}:
|
|
73
|
+
pkg_args = [a for a in args if not a.startswith("-")]
|
|
74
|
+
if pkg_args:
|
|
75
|
+
pkg = pkg_args[0]
|
|
76
|
+
has_version = ("@" in pkg[1:]) or ("==" in pkg)
|
|
77
|
+
if not has_version:
|
|
78
|
+
findings.append(Finding(
|
|
79
|
+
"MCP002", "MEDIUM", name,
|
|
80
|
+
f"Unpinned package '{pkg}' via {cmd}; pin a specific version."
|
|
81
|
+
))
|
|
82
|
+
|
|
83
|
+
# MCP003: Hardcoded credentials in env or args
|
|
84
|
+
combined_values = list(env.values()) + args
|
|
85
|
+
for val in combined_values:
|
|
86
|
+
if any(pat.search(str(val)) for pat in SECRET_PATTERNS):
|
|
87
|
+
findings.append(Finding(
|
|
88
|
+
"MCP003", "CRITICAL", name,
|
|
89
|
+
"Possible hardcoded API token or secret detected in server config."
|
|
90
|
+
))
|
|
91
|
+
break
|
|
92
|
+
|
|
93
|
+
# MCP004: Overly broad filesystem mounts
|
|
94
|
+
for arg in args:
|
|
95
|
+
if arg.rstrip("/\\") in {p.rstrip("/\\") for p in BROAD_PATHS}:
|
|
96
|
+
findings.append(Finding(
|
|
97
|
+
"MCP004", "HIGH", name,
|
|
98
|
+
f"Overly broad filesystem path '{arg}' exposed to MCP server."
|
|
99
|
+
))
|
|
100
|
+
|
|
101
|
+
# MCP005: Unencrypted remote HTTP URL or disabled TLS verification
|
|
102
|
+
urls_to_check = [url] if url else []
|
|
103
|
+
urls_to_check.extend(a for a in args if a.lower().startswith(("http://", "https://")))
|
|
104
|
+
for endpoint in urls_to_check:
|
|
105
|
+
lower_ep = endpoint.lower()
|
|
106
|
+
if lower_ep.startswith("http://") and not lower_ep.startswith(LOCAL_HTTP_PREFIXES):
|
|
107
|
+
findings.append(Finding(
|
|
108
|
+
"MCP005", "HIGH", name,
|
|
109
|
+
f"Unencrypted remote endpoint '{endpoint}'; use https:// instead."
|
|
110
|
+
))
|
|
111
|
+
break
|
|
112
|
+
|
|
113
|
+
env_pairs = {f"{k}={v}" for k, v in env.items()}
|
|
114
|
+
if any(tok in args or tok in env_pairs for tok in TLS_BYPASS_TOKENS):
|
|
115
|
+
findings.append(Finding(
|
|
116
|
+
"MCP005", "HIGH", name,
|
|
117
|
+
"TLS certificate verification is disabled in server args or environment."
|
|
118
|
+
))
|
|
119
|
+
|
|
120
|
+
# MCP006: Suspicious prompt-injection or override instructions in metadata/env/args
|
|
121
|
+
text_fields = [str(cfg.get("description", ""))] + [str(v) for v in env.values()] + args
|
|
122
|
+
for field in text_fields:
|
|
123
|
+
if any(pat.search(field) for pat in PROMPT_INJECTION_PATTERNS):
|
|
124
|
+
findings.append(Finding(
|
|
125
|
+
"MCP006", "HIGH", name,
|
|
126
|
+
"Suspicious prompt-injection or instruction-override phrase detected in config."
|
|
127
|
+
))
|
|
128
|
+
break
|
|
129
|
+
|
|
130
|
+
# MCP007: Privileged / root execution
|
|
131
|
+
is_priv_cmd = cmd_base in PRIVILEGED_COMMANDS
|
|
132
|
+
is_priv_docker = cmd_base in {"docker", "podman"} and (
|
|
133
|
+
"--privileged" in args or any(a in {"root", "0", "0:0"} for a in args)
|
|
134
|
+
)
|
|
135
|
+
if is_priv_cmd or is_priv_docker:
|
|
136
|
+
findings.append(Finding(
|
|
137
|
+
"MCP007", "CRITICAL", name,
|
|
138
|
+
f"Privileged execution detected via '{cmd}'; run MCP servers with least privilege."
|
|
139
|
+
))
|
|
140
|
+
|
|
141
|
+
return findings
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from mcp_lint.sarif import format_sarif
|
|
4
|
+
from mcp_lint.scanner import discover_mcp_configs, scan_mcp_config
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_detects_unsafe_config():
|
|
8
|
+
fixture = Path(__file__).parent / "fixtures" / "unsafe_mcp.json"
|
|
9
|
+
findings = scan_mcp_config(fixture)
|
|
10
|
+
rule_ids = {f.rule_id for f in findings}
|
|
11
|
+
assert {"MCP002", "MCP003", "MCP004", "MCP005", "MCP006", "MCP007"}.issubset(rule_ids)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_clean_pinned_config():
|
|
15
|
+
fixture = Path(__file__).parent / "fixtures" / "safe_mcp.json"
|
|
16
|
+
findings = scan_mcp_config(fixture)
|
|
17
|
+
assert findings == []
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_auto_discovery_finds_project_configs(tmp_path: Path):
|
|
21
|
+
root_cfg = tmp_path / ".mcp.json"
|
|
22
|
+
cursor_cfg = tmp_path / ".cursor" / "mcp.json"
|
|
23
|
+
cursor_cfg.parent.mkdir(parents=True)
|
|
24
|
+
|
|
25
|
+
sample = json.dumps({"mcpServers": {}})
|
|
26
|
+
root_cfg.write_text(sample, encoding="utf-8")
|
|
27
|
+
cursor_cfg.write_text(sample, encoding="utf-8")
|
|
28
|
+
|
|
29
|
+
discovered = discover_mcp_configs(base_dir=tmp_path, include_user_configs=False)
|
|
30
|
+
assert discovered == [root_cfg, cursor_cfg]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_sarif_output_structure():
|
|
34
|
+
fixture = Path(__file__).parent / "fixtures" / "unsafe_mcp.json"
|
|
35
|
+
findings = scan_mcp_config(fixture)
|
|
36
|
+
payload = json.loads(format_sarif([(fixture, findings)]))
|
|
37
|
+
assert payload["version"] == "2.1.0"
|
|
38
|
+
assert len(payload["runs"][0]["results"]) >= 6
|