pdq-deploy-mcp 1.0.0__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.
- pdq_deploy_mcp-1.0.0/LICENSE +21 -0
- pdq_deploy_mcp-1.0.0/PKG-INFO +75 -0
- pdq_deploy_mcp-1.0.0/README.md +63 -0
- pdq_deploy_mcp-1.0.0/pyproject.toml +24 -0
- pdq_deploy_mcp-1.0.0/setup.cfg +4 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp/__init__.py +0 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp/server.py +382 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp.egg-info/PKG-INFO +75 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp.egg-info/SOURCES.txt +12 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp.egg-info/dependency_links.txt +1 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp.egg-info/entry_points.txt +2 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp.egg-info/requires.txt +1 -0
- pdq_deploy_mcp-1.0.0/src/pdq_deploy_mcp.egg-info/top_level.txt +1 -0
- pdq_deploy_mcp-1.0.0/test/test_server.py +40 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Evan Redden
|
|
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,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pdq-deploy-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An MCP server for read-only access to the PDQ Deploy database.
|
|
5
|
+
Author-email: Evan Redden <redden.evan@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: mcp>=2.0.0
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
<!-- mcp-name: io.github.eredden/pdq-deploy-mcp -->
|
|
14
|
+
|
|
15
|
+
# PDQ Deploy MCP Server
|
|
16
|
+
|
|
17
|
+
This project is an MCP (Model Context Protocol) server that provides **read-only** access to PDQ Deploy through a clone of its SQLite database. You can simply ask a question in plain English and have an AI agent query PDQ Deploy *for you!* This works well for open-ended, complex problems and questions that you can wait on while eating lunch.
|
|
18
|
+
|
|
19
|
+
This project was created by [Evan Redden](https://www.linkedin.com/in/eredden).
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Python 3.10+ and version 2.0.0+ of the `mcp` module.
|
|
24
|
+
- Access to a PDQ Deploy SQLite database.
|
|
25
|
+
- An MCP-compatible client like GitHub Copilot in VS Code.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
You can easily install this repository as a PIP package:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install pdq-deploy-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If you want to modify this repository, you can clone it and install the required modules instead:
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
git clone "https://github.com/eredden/PDQ-Deploy-MCP"
|
|
39
|
+
|
|
40
|
+
cd "PDQ-Deploy-MCP"
|
|
41
|
+
|
|
42
|
+
pip install -e .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Setup
|
|
46
|
+
|
|
47
|
+
You must create a clone of your PDQ Deploy SQLite database to read from. Do not use `Copy-Item` or `robocopy` to copy the database, as copying mid-write will corrupt your clone. Use the native [BackupDatabase command](https://docs.pdq.com/current-version/Deploy/index.html?cli-deploy-backupdatabase.htm) provided with PDQ Deploy to avoid corruption:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
PDQDeploy BackupDatabase -Path "C:\Backups\PDQ\" -Force
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If you are using the `.mcp.json` config provided for GitHub Copilot in this repository, then save the database in the default `.\db\Database.db` path of this repository.
|
|
54
|
+
|
|
55
|
+
**Do not point this MCP server at a live PDQ Deploy database.** Using the live database will create SHARED locks that prevent PDQ Deploy from writing to the SQLite database.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
### GitHub Copilot in Visual Studio Code
|
|
60
|
+
|
|
61
|
+
1. Open this repository in Visual Studio Code.
|
|
62
|
+
2. Open the .mcp.json file and select Start above the `pdq-deploy-mcp` string.
|
|
63
|
+
3. Open the Interactive Chat in Visual Studio Code using `CTRL + Alt + I`.
|
|
64
|
+
4. If you have not already authenticated with GitHub Coplot, then do that!
|
|
65
|
+
5. Ask GitHub Copilot about anything related to PDQ Deploy!
|
|
66
|
+
|
|
67
|
+
### Other Coding Assistants
|
|
68
|
+
|
|
69
|
+
You can run this MCP server manually using the following command:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pdq-deploy-mcp --db-path ".\path\to\your\Database.db"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
As for how to integrate it with other AI coding assistants, figure it out! Feel free to contribute information here if you find a way to do this.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<!-- mcp-name: io.github.eredden/pdq-deploy-mcp -->
|
|
2
|
+
|
|
3
|
+
# PDQ Deploy MCP Server
|
|
4
|
+
|
|
5
|
+
This project is an MCP (Model Context Protocol) server that provides **read-only** access to PDQ Deploy through a clone of its SQLite database. You can simply ask a question in plain English and have an AI agent query PDQ Deploy *for you!* This works well for open-ended, complex problems and questions that you can wait on while eating lunch.
|
|
6
|
+
|
|
7
|
+
This project was created by [Evan Redden](https://www.linkedin.com/in/eredden).
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Python 3.10+ and version 2.0.0+ of the `mcp` module.
|
|
12
|
+
- Access to a PDQ Deploy SQLite database.
|
|
13
|
+
- An MCP-compatible client like GitHub Copilot in VS Code.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
You can easily install this repository as a PIP package:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install pdq-deploy-mcp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
If you want to modify this repository, you can clone it and install the required modules instead:
|
|
24
|
+
|
|
25
|
+
```powershell
|
|
26
|
+
git clone "https://github.com/eredden/PDQ-Deploy-MCP"
|
|
27
|
+
|
|
28
|
+
cd "PDQ-Deploy-MCP"
|
|
29
|
+
|
|
30
|
+
pip install -e .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Setup
|
|
34
|
+
|
|
35
|
+
You must create a clone of your PDQ Deploy SQLite database to read from. Do not use `Copy-Item` or `robocopy` to copy the database, as copying mid-write will corrupt your clone. Use the native [BackupDatabase command](https://docs.pdq.com/current-version/Deploy/index.html?cli-deploy-backupdatabase.htm) provided with PDQ Deploy to avoid corruption:
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
PDQDeploy BackupDatabase -Path "C:\Backups\PDQ\" -Force
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If you are using the `.mcp.json` config provided for GitHub Copilot in this repository, then save the database in the default `.\db\Database.db` path of this repository.
|
|
42
|
+
|
|
43
|
+
**Do not point this MCP server at a live PDQ Deploy database.** Using the live database will create SHARED locks that prevent PDQ Deploy from writing to the SQLite database.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### GitHub Copilot in Visual Studio Code
|
|
48
|
+
|
|
49
|
+
1. Open this repository in Visual Studio Code.
|
|
50
|
+
2. Open the .mcp.json file and select Start above the `pdq-deploy-mcp` string.
|
|
51
|
+
3. Open the Interactive Chat in Visual Studio Code using `CTRL + Alt + I`.
|
|
52
|
+
4. If you have not already authenticated with GitHub Coplot, then do that!
|
|
53
|
+
5. Ask GitHub Copilot about anything related to PDQ Deploy!
|
|
54
|
+
|
|
55
|
+
### Other Coding Assistants
|
|
56
|
+
|
|
57
|
+
You can run this MCP server manually using the following command:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pdq-deploy-mcp --db-path ".\path\to\your\Database.db"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
As for how to integrate it with other AI coding assistants, figure it out! Feel free to contribute information here if you find a way to do this.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools >= 70.0"
|
|
4
|
+
]
|
|
5
|
+
build-backend = "setuptools.build_meta"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "pdq-deploy-mcp"
|
|
9
|
+
version = "1.0.0"
|
|
10
|
+
authors = [ {name = "Evan Redden", email = "redden.evan@gmail.com"} ]
|
|
11
|
+
description = "An MCP server for read-only access to the PDQ Deploy database."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.10"
|
|
16
|
+
dependencies = [
|
|
17
|
+
"mcp>=2.0.0"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.scripts]
|
|
21
|
+
pdq-deploy-mcp = "pdq_deploy_mcp.server:main"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["src"]
|
|
File without changes
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
# server.py - The PDQ Deploy MCP server.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from argparse import ArgumentParser
|
|
6
|
+
from contextlib import contextmanager
|
|
7
|
+
from mcp.server import MCPServer
|
|
8
|
+
from mcp.types import ToolAnnotations
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import sqlite3
|
|
12
|
+
|
|
13
|
+
MCP_SERVER = MCPServer("PDQ Deploy")
|
|
14
|
+
DB_PATH: Path = None
|
|
15
|
+
|
|
16
|
+
READ_ONLY_DB_ANNOTATIONS = ToolAnnotations(
|
|
17
|
+
read_only_hint=True,
|
|
18
|
+
destructive_hint=False,
|
|
19
|
+
idempotent_hint=True,
|
|
20
|
+
open_world_hint=False,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
@contextmanager
|
|
24
|
+
def get_db_cursor():
|
|
25
|
+
"""Open a short-lived, read-only connection and yields a cursor."""
|
|
26
|
+
|
|
27
|
+
if DB_PATH is None or not DB_PATH.is_file():
|
|
28
|
+
raise FileNotFoundError(f"{DB_PATH} not found.")
|
|
29
|
+
|
|
30
|
+
# The mode=ro flag forces the file to open in Read Only (RO) mode.
|
|
31
|
+
db_uri = f"{Path(DB_PATH).resolve().as_uri()}?mode=ro"
|
|
32
|
+
|
|
33
|
+
conn = sqlite3.connect(db_uri, uri=True, timeout=5.0)
|
|
34
|
+
conn.row_factory = sqlite3.Row # Replaces tuple rows with dict rows.
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
# Switching query_only to ON defends against writes on the SQLite level.
|
|
38
|
+
# This is technically redundant since the RO flag for the file URI should
|
|
39
|
+
# block writes anyways, but I am paranoid. Aaaaaaaaaaaaah!
|
|
40
|
+
cursor = conn.cursor()
|
|
41
|
+
cursor.execute("PRAGMA query_only = ON;")
|
|
42
|
+
|
|
43
|
+
yield cursor
|
|
44
|
+
|
|
45
|
+
finally:
|
|
46
|
+
# Ensures the connection and any read locks are closed immediately.
|
|
47
|
+
conn.close()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
51
|
+
def get_deployments(
|
|
52
|
+
package_id: int | None = None,
|
|
53
|
+
start_date: str | None = None,
|
|
54
|
+
end_date: str | None = None,
|
|
55
|
+
max_rows: int = 100,
|
|
56
|
+
) -> list[dict]:
|
|
57
|
+
"""Get deployment history filtered by optional package_id and inclusive ISO date range (YYYY-MM-DD)."""
|
|
58
|
+
|
|
59
|
+
if max_rows < 1:
|
|
60
|
+
raise ValueError("max_rows must be greater than or equal to 1.")
|
|
61
|
+
|
|
62
|
+
conditions = []
|
|
63
|
+
params = []
|
|
64
|
+
|
|
65
|
+
if package_id is not None:
|
|
66
|
+
conditions.append("d.PackageId = ?")
|
|
67
|
+
params.append(package_id)
|
|
68
|
+
|
|
69
|
+
if start_date:
|
|
70
|
+
conditions.append("d.Started >= ?")
|
|
71
|
+
params.append(start_date)
|
|
72
|
+
|
|
73
|
+
if end_date:
|
|
74
|
+
conditions.append("d.Started < date(?, '+1 day')")
|
|
75
|
+
params.append(end_date)
|
|
76
|
+
|
|
77
|
+
where_clause = f"WHERE {' AND '.join(conditions)}" if conditions else ""
|
|
78
|
+
params.append(max_rows)
|
|
79
|
+
|
|
80
|
+
# UserName is the user performing the PDQ job on the hosts,
|
|
81
|
+
# while DeployConsoleUser is the person who started the job.
|
|
82
|
+
query = f"""
|
|
83
|
+
SELECT
|
|
84
|
+
d.DeploymentId,
|
|
85
|
+
d.PackageId,
|
|
86
|
+
p.Name AS PackageName,
|
|
87
|
+
d.Started,
|
|
88
|
+
d.Finished,
|
|
89
|
+
d.Status,
|
|
90
|
+
d.UserName,
|
|
91
|
+
d.DeployConsoleUser,
|
|
92
|
+
COUNT(dc.DeploymentComputerId) AS TotalTargets
|
|
93
|
+
FROM Deployments d
|
|
94
|
+
LEFT JOIN Packages p ON d.PackageId = p.PackageId
|
|
95
|
+
LEFT JOIN DeploymentComputers dc ON d.DeploymentId = dc.DeploymentId
|
|
96
|
+
{where_clause}
|
|
97
|
+
GROUP BY d.DeploymentId
|
|
98
|
+
ORDER BY d.Started DESC
|
|
99
|
+
LIMIT ?;
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
with get_db_cursor() as cursor:
|
|
103
|
+
cursor.execute(query, tuple(params))
|
|
104
|
+
|
|
105
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
109
|
+
def get_deployment_failures(
|
|
110
|
+
start_date: str | None = None,
|
|
111
|
+
end_date: str | None = None,
|
|
112
|
+
package_id: int | None = None,
|
|
113
|
+
max_rows: int = 100
|
|
114
|
+
) -> list[dict]:
|
|
115
|
+
"""Get failed deployment targets filtered by inclusive date range and optional package_id."""
|
|
116
|
+
|
|
117
|
+
if max_rows < 1:
|
|
118
|
+
raise ValueError("max_rows must be greater than or equal to 1.")
|
|
119
|
+
|
|
120
|
+
conditions = [
|
|
121
|
+
"""(
|
|
122
|
+
COALESCE(dc.Error, '') <> ''
|
|
123
|
+
OR LOWER(COALESCE(dc.Status, '')) LIKE '%fail%'
|
|
124
|
+
OR LOWER(COALESCE(dc.Stage, '')) LIKE '%fail%'
|
|
125
|
+
)"""
|
|
126
|
+
]
|
|
127
|
+
params = []
|
|
128
|
+
|
|
129
|
+
if start_date:
|
|
130
|
+
conditions.append("d.Started >= ?")
|
|
131
|
+
params.append(start_date)
|
|
132
|
+
|
|
133
|
+
if end_date:
|
|
134
|
+
conditions.append("d.Started < date(?, '+1 day')")
|
|
135
|
+
params.append(end_date)
|
|
136
|
+
|
|
137
|
+
if package_id is not None:
|
|
138
|
+
conditions.append("d.PackageId = ?")
|
|
139
|
+
params.append(package_id)
|
|
140
|
+
|
|
141
|
+
params.append(max_rows)
|
|
142
|
+
query = f"""
|
|
143
|
+
SELECT
|
|
144
|
+
dc.DeploymentId,
|
|
145
|
+
d.PackageId,
|
|
146
|
+
d.PackageName,
|
|
147
|
+
d.Started,
|
|
148
|
+
dc.Name,
|
|
149
|
+
dc.Status,
|
|
150
|
+
dc.Error,
|
|
151
|
+
dc.Stage,
|
|
152
|
+
dc.Ended
|
|
153
|
+
FROM DeploymentComputers dc
|
|
154
|
+
JOIN Deployments d ON d.DeploymentId = dc.DeploymentId
|
|
155
|
+
WHERE {' AND '.join(conditions)}
|
|
156
|
+
ORDER BY d.Started DESC, dc.DeploymentComputerId DESC
|
|
157
|
+
LIMIT ?;
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
with get_db_cursor() as cursor:
|
|
161
|
+
cursor.execute(query, tuple(params))
|
|
162
|
+
|
|
163
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
167
|
+
def get_packages(search: str | None = None) -> list[dict]:
|
|
168
|
+
"""Get PDQ packages optionally filtered by a case-insensitive name substring."""
|
|
169
|
+
|
|
170
|
+
with get_db_cursor() as cursor:
|
|
171
|
+
if search:
|
|
172
|
+
cursor.execute(
|
|
173
|
+
"""
|
|
174
|
+
SELECT PackageId, Name, Version, Description, Path, Created, Modified
|
|
175
|
+
FROM Packages
|
|
176
|
+
WHERE Name LIKE ?
|
|
177
|
+
ORDER BY Name;
|
|
178
|
+
""",
|
|
179
|
+
(f"%{search}%",) # Wildcard for name filtering.
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
else:
|
|
183
|
+
cursor.execute(
|
|
184
|
+
"""
|
|
185
|
+
SELECT PackageId, Name, Version, Description, Path, Created, Modified
|
|
186
|
+
FROM Packages
|
|
187
|
+
ORDER BY Name;
|
|
188
|
+
"""
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
195
|
+
def get_package_schedules(package_id: int | None = None) -> list[dict]:
|
|
196
|
+
"""Get all schedules along with their assigned packages. Optionally filter by package_id."""
|
|
197
|
+
|
|
198
|
+
query = """
|
|
199
|
+
SELECT
|
|
200
|
+
s.ScheduleId,
|
|
201
|
+
s.Name AS ScheduleName,
|
|
202
|
+
s.IsEnabled,
|
|
203
|
+
s.LastError,
|
|
204
|
+
s.LastRun,
|
|
205
|
+
p.PackageId,
|
|
206
|
+
p.Name AS PackageName
|
|
207
|
+
FROM Schedules s
|
|
208
|
+
LEFT JOIN SchedulePackages sp ON s.ScheduleId = sp.ScheduleId
|
|
209
|
+
LEFT JOIN Packages p ON sp.LocalPackageId = p.PackageId
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
params = ()
|
|
213
|
+
|
|
214
|
+
if package_id is not None:
|
|
215
|
+
query += " WHERE p.PackageId = ?"
|
|
216
|
+
params = (package_id,)
|
|
217
|
+
|
|
218
|
+
# This isn't immediately in the query because we don't want to order
|
|
219
|
+
# all of the rows if we aren't going to use them all in the first place.
|
|
220
|
+
# That's why we add the WHERE p.PackageId = ? filter first.
|
|
221
|
+
query += " ORDER BY s.Name, p.Name;"
|
|
222
|
+
|
|
223
|
+
with get_db_cursor() as cursor:
|
|
224
|
+
cursor.execute(query, params)
|
|
225
|
+
|
|
226
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
230
|
+
def get_package_steps(package_id: int) -> list[dict]:
|
|
231
|
+
"""Get the sequence of steps for a specific package."""
|
|
232
|
+
|
|
233
|
+
query = """
|
|
234
|
+
SELECT
|
|
235
|
+
ps.PackageStepId,
|
|
236
|
+
ps.Sequence,
|
|
237
|
+
ps.Title,
|
|
238
|
+
ps.IsEnabled,
|
|
239
|
+
ps.ErrorMode
|
|
240
|
+
FROM Packages p
|
|
241
|
+
JOIN PackageSteps ps ON p.PackageDefinitionId = ps.PackageDefinitionId
|
|
242
|
+
WHERE p.PackageId = ?
|
|
243
|
+
ORDER BY ps.Sequence;
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
with get_db_cursor() as cursor:
|
|
247
|
+
cursor.execute(query, (package_id,))
|
|
248
|
+
|
|
249
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
253
|
+
def get_tables() -> list[str]:
|
|
254
|
+
"""Get a list of all the database tables excluding SQLite system tables."""
|
|
255
|
+
|
|
256
|
+
# We use sqlite_master as the master table since PDQ Deploy and Inventory use an older version
|
|
257
|
+
# of SQLite. Newer versions of SQLite use the sqlite_schema table instead.
|
|
258
|
+
with get_db_cursor() as cursor:
|
|
259
|
+
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';")
|
|
260
|
+
results = [item[0] for item in cursor.fetchall()]
|
|
261
|
+
|
|
262
|
+
return results
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
266
|
+
def get_table_schema(table_name: str) -> list[dict]:
|
|
267
|
+
"""Get column names and types for a specific table."""
|
|
268
|
+
|
|
269
|
+
valid_tables = get_tables()
|
|
270
|
+
|
|
271
|
+
if table_name not in valid_tables:
|
|
272
|
+
raise ValueError(f"Unknown table: {table_name}")
|
|
273
|
+
|
|
274
|
+
with get_db_cursor() as cursor:
|
|
275
|
+
cursor.execute(f"PRAGMA table_info(\"{table_name}\");")
|
|
276
|
+
|
|
277
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
281
|
+
def get_target_lists(target_list_id: int | None = None) -> list[dict]:
|
|
282
|
+
"""Get all target lists or the specific computer targets inside a given target_list_id."""
|
|
283
|
+
|
|
284
|
+
with get_db_cursor() as cursor:
|
|
285
|
+
if target_list_id is None:
|
|
286
|
+
cursor.execute(
|
|
287
|
+
"""
|
|
288
|
+
SELECT tl.TargetListId, tl.Name, tl.Description, COUNT(t.TargetId) AS TargetCount
|
|
289
|
+
FROM TargetLists tl
|
|
290
|
+
LEFT JOIN Targets t ON tl.TargetListId = t.TargetListId
|
|
291
|
+
GROUP BY tl.TargetListId
|
|
292
|
+
ORDER BY tl.Name;
|
|
293
|
+
"""
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
else:
|
|
297
|
+
cursor.execute(
|
|
298
|
+
"""
|
|
299
|
+
SELECT t.TargetId, t.TargetListId, tl.Name AS ListName, t.Name AS TargetName
|
|
300
|
+
FROM Targets t
|
|
301
|
+
JOIN TargetLists tl ON t.TargetListId = tl.TargetListId
|
|
302
|
+
WHERE t.TargetListId = ?
|
|
303
|
+
ORDER BY t.Name;
|
|
304
|
+
""",
|
|
305
|
+
(target_list_id,),
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
return [_sanitize_row(row) for row in cursor.fetchall()]
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@MCP_SERVER.tool(annotations=READ_ONLY_DB_ANNOTATIONS)
|
|
312
|
+
def run_read_only_query(sql: str, max_rows: int = 100) -> list[dict]:
|
|
313
|
+
"""
|
|
314
|
+
Execute a custom read-only SELECT or WITH query for questions not covered by standard tools.
|
|
315
|
+
Results are capped to 100 rows by default. Change the value of max_rows to bypass this.
|
|
316
|
+
Note that leading comments will cause this function to reject the query, so please avoid them.
|
|
317
|
+
"""
|
|
318
|
+
|
|
319
|
+
if max_rows < 1:
|
|
320
|
+
raise ValueError("max_rows must be greater than or equal to 1.")
|
|
321
|
+
|
|
322
|
+
cleaned = sql.strip()
|
|
323
|
+
|
|
324
|
+
# Even more defense-in-depth paranoia. This is the third layer of
|
|
325
|
+
# code intended to prevent writes to the SQLite database.
|
|
326
|
+
if not cleaned.upper().startswith(("SELECT", "WITH")):
|
|
327
|
+
raise ValueError("Only SELECT or WITH queries are permitted.")
|
|
328
|
+
|
|
329
|
+
with get_db_cursor() as cursor:
|
|
330
|
+
cursor.execute(cleaned)
|
|
331
|
+
|
|
332
|
+
return [_sanitize_row(row) for row in cursor.fetchmany(max_rows)]
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _sanitize_row(row: sqlite3.Row) -> dict:
|
|
336
|
+
"""Convert a sqlite3.Row object into a sanitized dictionary."""
|
|
337
|
+
|
|
338
|
+
serialized = {}
|
|
339
|
+
|
|
340
|
+
for key in row.keys():
|
|
341
|
+
value = row[key]
|
|
342
|
+
|
|
343
|
+
# Omit blobs entirely to prevent excessive token usage and to
|
|
344
|
+
# avoid sending binary data as JSON over the MCP protocol.
|
|
345
|
+
if isinstance(value, bytes):
|
|
346
|
+
serialized[key] = f"<BLOB: {len(value)} BYTES OMITTED>"
|
|
347
|
+
|
|
348
|
+
else:
|
|
349
|
+
serialized[key] = value
|
|
350
|
+
|
|
351
|
+
return serialized
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def main() -> None:
|
|
355
|
+
global DB_PATH
|
|
356
|
+
|
|
357
|
+
parser = ArgumentParser(
|
|
358
|
+
prog="PDQ Deploy MCP Server",
|
|
359
|
+
description="An MCP server for read-only access to the PDQ Deploy database."
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
parser.add_argument(
|
|
363
|
+
"--db-path",
|
|
364
|
+
"--db",
|
|
365
|
+
dest="db_path",
|
|
366
|
+
required=True,
|
|
367
|
+
type=str,
|
|
368
|
+
help="Path to the SQLite database used by the server."
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
args = parser.parse_args()
|
|
372
|
+
|
|
373
|
+
DB_PATH = Path(args.db_path).expanduser() if args.db_path else None
|
|
374
|
+
|
|
375
|
+
if DB_PATH is None or not DB_PATH.is_file():
|
|
376
|
+
raise ValueError("You must supply the PDQ Deploy SQLite database path with the --db-path argument.")
|
|
377
|
+
|
|
378
|
+
MCP_SERVER.run(transport="stdio")
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
if __name__ == "__main__":
|
|
382
|
+
main()
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pdq-deploy-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An MCP server for read-only access to the PDQ Deploy database.
|
|
5
|
+
Author-email: Evan Redden <redden.evan@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: mcp>=2.0.0
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
<!-- mcp-name: io.github.eredden/pdq-deploy-mcp -->
|
|
14
|
+
|
|
15
|
+
# PDQ Deploy MCP Server
|
|
16
|
+
|
|
17
|
+
This project is an MCP (Model Context Protocol) server that provides **read-only** access to PDQ Deploy through a clone of its SQLite database. You can simply ask a question in plain English and have an AI agent query PDQ Deploy *for you!* This works well for open-ended, complex problems and questions that you can wait on while eating lunch.
|
|
18
|
+
|
|
19
|
+
This project was created by [Evan Redden](https://www.linkedin.com/in/eredden).
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Python 3.10+ and version 2.0.0+ of the `mcp` module.
|
|
24
|
+
- Access to a PDQ Deploy SQLite database.
|
|
25
|
+
- An MCP-compatible client like GitHub Copilot in VS Code.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
You can easily install this repository as a PIP package:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install pdq-deploy-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If you want to modify this repository, you can clone it and install the required modules instead:
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
git clone "https://github.com/eredden/PDQ-Deploy-MCP"
|
|
39
|
+
|
|
40
|
+
cd "PDQ-Deploy-MCP"
|
|
41
|
+
|
|
42
|
+
pip install -e .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Setup
|
|
46
|
+
|
|
47
|
+
You must create a clone of your PDQ Deploy SQLite database to read from. Do not use `Copy-Item` or `robocopy` to copy the database, as copying mid-write will corrupt your clone. Use the native [BackupDatabase command](https://docs.pdq.com/current-version/Deploy/index.html?cli-deploy-backupdatabase.htm) provided with PDQ Deploy to avoid corruption:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
PDQDeploy BackupDatabase -Path "C:\Backups\PDQ\" -Force
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If you are using the `.mcp.json` config provided for GitHub Copilot in this repository, then save the database in the default `.\db\Database.db` path of this repository.
|
|
54
|
+
|
|
55
|
+
**Do not point this MCP server at a live PDQ Deploy database.** Using the live database will create SHARED locks that prevent PDQ Deploy from writing to the SQLite database.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
### GitHub Copilot in Visual Studio Code
|
|
60
|
+
|
|
61
|
+
1. Open this repository in Visual Studio Code.
|
|
62
|
+
2. Open the .mcp.json file and select Start above the `pdq-deploy-mcp` string.
|
|
63
|
+
3. Open the Interactive Chat in Visual Studio Code using `CTRL + Alt + I`.
|
|
64
|
+
4. If you have not already authenticated with GitHub Coplot, then do that!
|
|
65
|
+
5. Ask GitHub Copilot about anything related to PDQ Deploy!
|
|
66
|
+
|
|
67
|
+
### Other Coding Assistants
|
|
68
|
+
|
|
69
|
+
You can run this MCP server manually using the following command:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pdq-deploy-mcp --db-path ".\path\to\your\Database.db"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
As for how to integrate it with other AI coding assistants, figure it out! Feel free to contribute information here if you find a way to do this.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/pdq_deploy_mcp/__init__.py
|
|
5
|
+
src/pdq_deploy_mcp/server.py
|
|
6
|
+
src/pdq_deploy_mcp.egg-info/PKG-INFO
|
|
7
|
+
src/pdq_deploy_mcp.egg-info/SOURCES.txt
|
|
8
|
+
src/pdq_deploy_mcp.egg-info/dependency_links.txt
|
|
9
|
+
src/pdq_deploy_mcp.egg-info/entry_points.txt
|
|
10
|
+
src/pdq_deploy_mcp.egg-info/requires.txt
|
|
11
|
+
src/pdq_deploy_mcp.egg-info/top_level.txt
|
|
12
|
+
test/test_server.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcp>=2.0.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pdq_deploy_mcp
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# test_server.py - A simple test client for the PDQ Deploy MCP server.
|
|
2
|
+
|
|
3
|
+
from argparse import ArgumentParser
|
|
4
|
+
import asyncio
|
|
5
|
+
|
|
6
|
+
from mcp import ClientSession, StdioServerParameters
|
|
7
|
+
from mcp.client.stdio import stdio_client
|
|
8
|
+
|
|
9
|
+
async def main():
|
|
10
|
+
parser = ArgumentParser(description="Test the PDQ Deploy MCP server.")
|
|
11
|
+
|
|
12
|
+
parser.add_argument(
|
|
13
|
+
"--db-path",
|
|
14
|
+
required=True,
|
|
15
|
+
help="Path to the SQLite database used by the server.",
|
|
16
|
+
)
|
|
17
|
+
args = parser.parse_args()
|
|
18
|
+
|
|
19
|
+
server_params = StdioServerParameters(
|
|
20
|
+
command="pdq-deploy-mcp",
|
|
21
|
+
args=[
|
|
22
|
+
"--db-path",
|
|
23
|
+
args.db_path,
|
|
24
|
+
],
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
async with stdio_client(server_params) as (read, write):
|
|
28
|
+
async with ClientSession(read, write) as session:
|
|
29
|
+
await session.initialize()
|
|
30
|
+
|
|
31
|
+
# List the registered MCP tools.
|
|
32
|
+
tools = await session.list_tools()
|
|
33
|
+
print("Registered tools:", [t.name for t in tools.tools])
|
|
34
|
+
|
|
35
|
+
# Try calling the get_tables tool to see if the output shows all tables.
|
|
36
|
+
result = await session.call_tool("get_tables", arguments={})
|
|
37
|
+
print("Database tables:", result.content)
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
asyncio.run(main())
|