pyddock 0.3.7__tar.gz → 0.4.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.
- {pyddock-0.3.7 → pyddock-0.4.0}/PKG-INFO +6 -3
- {pyddock-0.3.7 → pyddock-0.4.0}/README.md +4 -1
- {pyddock-0.3.7 → pyddock-0.4.0}/pyproject.toml +2 -2
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_audit_enforcement.py +5 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_subprocess_patch.py +21 -14
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/server.py +16 -5
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/shell_executor.py +208 -78
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_shell_executor.py +148 -8
- pyddock-0.4.0/uv.lock +657 -0
- pyddock-0.3.7/uv.lock +0 -582
- {pyddock-0.3.7 → pyddock-0.4.0}/.gitignore +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/.gitignore +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/0527dc28646c9360 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/106d94c8123c0256 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/1685e03b3aa38c02 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/1deca112ec6f2f3c +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/2488a3a95c48acfb +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/2a94d83a13979745 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/30ee1be194c33a1d +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/453881856851f311 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/499f1d5a639a382a +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/4ee6f24fa151b65d +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/5b1b2189b70f5ef2 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/5d6f8b26b2137fe1 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/5f020be48d90847d +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/61f9b905d7da14e0 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/6627988645b1286c +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/671fefe2f5d9935c +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/67a7f4ab2d372f23 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/6c6f5083ece3f86b +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/805cbcbb07e3332d +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/827e18b40f235443 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/8401e4039d635fbc +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/8490e7baefc8c8c3 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/93108f7a5abfd484 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/a7c132b836381d0d +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/b395547bc71e5c52 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/ca50661510a40488 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/d115f833e13f93f9 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/df249c25d70870dc +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/e2c54b7949469c07 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/e78de40070f52f91 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/constants/e8cd7befaa4dd723 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/tmp/tmpl8oe65gb +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/tmp/tmpqwper0dp +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/unicode_data/15.1.0/charmap.json.gz +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/unicode_data/15.1.0/codec-utf-8.json.gz +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/unicode_data/16.0.0/charmap.json.gz +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/.hypothesis/unicode_data/16.0.0/codec-utf-8.json.gz +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/LICENSE +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/publish-to-pypi.ps1 +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/__init__.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_base.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_enforcement.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_fs_enforcement.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_import_hook.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_prewarm.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_process_utils.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_proxies.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/_runtime.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/ast_validator.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/cli.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/config.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/default_config.toml +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/executor.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/script_registry.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/__init__.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/fs_append.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/fs_delete.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/fs_find.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/fs_grep.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/read_file.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/stat_file.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/tools/str_replace.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/src/pyddock/venv_manager.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/__init__.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/_config_helpers.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_ast_properties.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_attr_reflection_hardening.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_audit_hook_backstop.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_chmod_integration.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_config.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_deny_always_wins.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_deny_messages.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_env_policy.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_executor.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_file_tools.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_filesystem_guards.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_jailbreak_regression.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_proxy_properties.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_realistic.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_runtime.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_sandbox_escape_hardening.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_security_guards.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_server.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_shell_arg_paths.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_shell_properties.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_subprocess_enforcement.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_subprocess_properties.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_subst_trusted_path.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_trusted_prefixes_uv_cache.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_venv_recreation.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_venv_stamp.py +0 -0
- {pyddock-0.3.7 → pyddock-0.4.0}/tests/test_workspace_imports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyddock
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: MCP server that gives AI agents pre-approved Python, shell, and file I/O tools with declarative policy controls
|
|
5
5
|
Project-URL: Homepage, https://github.com/portablestew/pyddock
|
|
6
6
|
Project-URL: Repository, https://github.com/portablestew/pyddock
|
|
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
17
17
|
Classifier: Topic :: Security
|
|
18
18
|
Classifier: Topic :: Software Development :: Libraries
|
|
19
19
|
Requires-Python: >=3.14
|
|
20
|
-
Requires-Dist: mcp
|
|
20
|
+
Requires-Dist: mcp<3,>=2
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
|
|
23
23
|
# pyddock
|
|
@@ -77,10 +77,13 @@ The last expression in your snippet is captured as RESULT (like a Jupyter cell)
|
|
|
77
77
|
| `command` | string | Executable name or script path (must match a shell policy) |
|
|
78
78
|
| `args` | string[] | Arguments passed directly to the command (no shell interpretation) |
|
|
79
79
|
| `timeout` | number | Seconds (default: 30) |
|
|
80
|
+
| `cwd` | string | Working directory, relative to the workspace root (default: the workspace root) |
|
|
80
81
|
|
|
81
82
|
Commands are executed directly — no shell interpretation, pipes, redirects, chaining, or variable expansion. Only commands matching a `[shell.*]` policy in your config are permitted. The tool is only registered when at least one `[shell.*]` section exists in the config.
|
|
82
83
|
|
|
83
|
-
Script files get automatic interpreter mapping: `.ps1` → powershell, `.py` → python, `.sh` → bash, `.bat` → cmd /c.
|
|
84
|
+
Script files get automatic interpreter mapping: `.ps1` → powershell, `.py` → python, `.sh` → bash, `.bat` → cmd /c. A script or path-like command is resolved relative to the workspace root, never to `cwd`, so `cwd` cannot change which file executes.
|
|
85
|
+
|
|
86
|
+
`cwd` is subject to the command's `arg_paths` policy — normally it must be an existing directory inside the workspace and outside protected directories. Relative path arguments are resolved by the command against `cwd`, and are path-checked against both `cwd` and the workspace root.
|
|
84
87
|
|
|
85
88
|
## Output format
|
|
86
89
|
|
|
@@ -55,10 +55,13 @@ The last expression in your snippet is captured as RESULT (like a Jupyter cell)
|
|
|
55
55
|
| `command` | string | Executable name or script path (must match a shell policy) |
|
|
56
56
|
| `args` | string[] | Arguments passed directly to the command (no shell interpretation) |
|
|
57
57
|
| `timeout` | number | Seconds (default: 30) |
|
|
58
|
+
| `cwd` | string | Working directory, relative to the workspace root (default: the workspace root) |
|
|
58
59
|
|
|
59
60
|
Commands are executed directly — no shell interpretation, pipes, redirects, chaining, or variable expansion. Only commands matching a `[shell.*]` policy in your config are permitted. The tool is only registered when at least one `[shell.*]` section exists in the config.
|
|
60
61
|
|
|
61
|
-
Script files get automatic interpreter mapping: `.ps1` → powershell, `.py` → python, `.sh` → bash, `.bat` → cmd /c.
|
|
62
|
+
Script files get automatic interpreter mapping: `.ps1` → powershell, `.py` → python, `.sh` → bash, `.bat` → cmd /c. A script or path-like command is resolved relative to the workspace root, never to `cwd`, so `cwd` cannot change which file executes.
|
|
63
|
+
|
|
64
|
+
`cwd` is subject to the command's `arg_paths` policy — normally it must be an existing directory inside the workspace and outside protected directories. Relative path arguments are resolved by the command against `cwd`, and are path-checked against both `cwd` and the workspace root.
|
|
62
65
|
|
|
63
66
|
## Output format
|
|
64
67
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyddock"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "MCP server that gives AI agents pre-approved Python, shell, and file I/O tools with declarative policy controls"
|
|
5
5
|
requires-python = ">=3.14"
|
|
6
6
|
license = "MIT"
|
|
@@ -19,7 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Topic :: Security",
|
|
20
20
|
]
|
|
21
21
|
dependencies = [
|
|
22
|
-
"mcp>=
|
|
22
|
+
"mcp>=2,<3",
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
[project.urls]
|
|
@@ -65,6 +65,7 @@ from typing import Any, Callable
|
|
|
65
65
|
from pyddock._base import SNIPPET_FILENAME
|
|
66
66
|
from pyddock.shell_executor import (
|
|
67
67
|
assert_env_locks,
|
|
68
|
+
coerce_cwd,
|
|
68
69
|
evaluate_arg_paths,
|
|
69
70
|
evaluate_arg_policy,
|
|
70
71
|
evaluate_cwd,
|
|
@@ -239,6 +240,10 @@ def evaluate_spawn_command(
|
|
|
239
240
|
workspace_root=ws_path,
|
|
240
241
|
workspace_module_dirs=ws_mods,
|
|
241
242
|
shell_command_patterns=patterns,
|
|
243
|
+
# A relative arg is resolved by the child against its own cwd, so a
|
|
244
|
+
# cwd-bearing spawn must be scanned against that base too — matching
|
|
245
|
+
# the subprocess proxy.
|
|
246
|
+
resolve_base=coerce_cwd(cwd),
|
|
242
247
|
)
|
|
243
248
|
if path_reason is not None:
|
|
244
249
|
raise PermissionError(
|
|
@@ -14,6 +14,7 @@ from typing import Any
|
|
|
14
14
|
from pyddock._base import _ORIGINALS, _find_deny_hint
|
|
15
15
|
from pyddock._process_utils import make_child_env
|
|
16
16
|
from pyddock.shell_executor import (
|
|
17
|
+
coerce_cwd,
|
|
17
18
|
evaluate_arg_paths,
|
|
18
19
|
evaluate_arg_policy,
|
|
19
20
|
evaluate_cwd,
|
|
@@ -121,11 +122,18 @@ def apply_subprocess_patch(
|
|
|
121
122
|
_looks_like_path_rt = looks_like_path
|
|
122
123
|
_extract_path_candidates_rt = extract_path_candidates
|
|
123
124
|
|
|
124
|
-
def _check_arg_paths(
|
|
125
|
+
def _check_arg_paths(
|
|
126
|
+
policy: dict, cmd_args: list[str], cwd: Any = None
|
|
127
|
+
) -> str | None:
|
|
125
128
|
"""Scan args for path-like values and validate against arg_paths policy.
|
|
126
129
|
|
|
127
130
|
Thin wrapper over the shared evaluate_arg_paths() so subprocess.run stays
|
|
128
131
|
in lockstep with run_shell (ShellExecutor) and the audit shell disposition.
|
|
132
|
+
|
|
133
|
+
`cwd` is forwarded as the resolution base: a relative arg is resolved by
|
|
134
|
+
the child against ITS cwd, so scanning only against the workspace root
|
|
135
|
+
would let a cwd-bearing spawn reach a protected directory through an arg
|
|
136
|
+
that looks harmless when anchored at the root.
|
|
129
137
|
"""
|
|
130
138
|
return evaluate_arg_paths(
|
|
131
139
|
cmd_args,
|
|
@@ -135,6 +143,7 @@ def apply_subprocess_patch(
|
|
|
135
143
|
shell_command_patterns=[
|
|
136
144
|
p.get("command", "") for p in shell_policies.values()
|
|
137
145
|
],
|
|
146
|
+
resolve_base=coerce_cwd(cwd),
|
|
138
147
|
)
|
|
139
148
|
|
|
140
149
|
def _check_cwd(policy: dict, cwd: Any) -> str | None:
|
|
@@ -169,13 +178,8 @@ def apply_subprocess_patch(
|
|
|
169
178
|
"""
|
|
170
179
|
deny_patterns, env_default = resolve_env_policy(_env_base, policy)
|
|
171
180
|
resolve_bases: list[pathlib.Path] = [_ws_root]
|
|
172
|
-
|
|
173
|
-
if
|
|
174
|
-
cwd_str = (
|
|
175
|
-
cwd.decode("utf-8", "surrogateescape")
|
|
176
|
-
if isinstance(cwd, (bytes, bytearray))
|
|
177
|
-
else str(cwd)
|
|
178
|
-
)
|
|
181
|
+
cwd_str = coerce_cwd(kwargs.get("cwd"))
|
|
182
|
+
if cwd_str is not None:
|
|
179
183
|
# `_ws_root / cwd_str` yields cwd_str unchanged when it is absolute,
|
|
180
184
|
# and resolves it against the workspace when relative — matching how
|
|
181
185
|
# the child process resolves its own cwd.
|
|
@@ -238,8 +242,9 @@ def apply_subprocess_patch(
|
|
|
238
242
|
if hint:
|
|
239
243
|
msg += f"\n[{hint}]"
|
|
240
244
|
raise PermissionError(msg)
|
|
241
|
-
# Check arg paths against protected directories
|
|
242
|
-
|
|
245
|
+
# Check arg paths against protected directories, resolving relative args
|
|
246
|
+
# against the spawn's cwd as well as the workspace root.
|
|
247
|
+
path_rejection = _check_arg_paths(policy, cmd_args, kwargs.get("cwd"))
|
|
243
248
|
if path_rejection is not None:
|
|
244
249
|
msg = f"PermissionError: {path_rejection}"
|
|
245
250
|
hint = _find_deny_hint(
|
|
@@ -258,8 +263,10 @@ def apply_subprocess_patch(
|
|
|
258
263
|
if hint:
|
|
259
264
|
msg += f"\n[{hint}]"
|
|
260
265
|
raise PermissionError(msg)
|
|
261
|
-
# Apply interpreter mapping (same as run_shell) and execute
|
|
262
|
-
|
|
266
|
+
# Apply interpreter mapping (same as run_shell) and execute. The
|
|
267
|
+
# workspace root anchors a path-like command so an agent-supplied cwd
|
|
268
|
+
# cannot re-target which script file actually runs.
|
|
269
|
+
resolved = _resolve_cmd(command, _ws_root)
|
|
263
270
|
full_cmd = resolved + cmd_args
|
|
264
271
|
_apply_env_policy(policy, kwargs)
|
|
265
272
|
kwargs["shell"] = False
|
|
@@ -311,7 +318,7 @@ def apply_subprocess_patch(
|
|
|
311
318
|
if hint:
|
|
312
319
|
msg += f"\n[{hint}]"
|
|
313
320
|
raise PermissionError(msg)
|
|
314
|
-
path_rejection = _check_arg_paths(policy, cmd_args)
|
|
321
|
+
path_rejection = _check_arg_paths(policy, cmd_args, cwd)
|
|
315
322
|
if path_rejection is not None:
|
|
316
323
|
msg = f"PermissionError: {path_rejection}"
|
|
317
324
|
hint = _find_deny_hint(
|
|
@@ -329,7 +336,7 @@ def apply_subprocess_patch(
|
|
|
329
336
|
if hint:
|
|
330
337
|
msg += f"\n[{hint}]"
|
|
331
338
|
raise PermissionError(msg)
|
|
332
|
-
resolved = _resolve_cmd(command)
|
|
339
|
+
resolved = _resolve_cmd(command, _ws_root)
|
|
333
340
|
return resolved + cmd_args, cmd_args, policy
|
|
334
341
|
|
|
335
342
|
class _SafePopen:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""MCP server entry point for pyddock.
|
|
2
2
|
|
|
3
|
-
Exposes the `run_python` tool via the MCP protocol using
|
|
3
|
+
Exposes the `run_python` tool via the MCP protocol using MCPServer.
|
|
4
4
|
Orchestrates the full pipeline: validate → install → execute → return.
|
|
5
5
|
"""
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ import asyncio
|
|
|
10
10
|
import logging
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
|
|
13
|
-
from mcp.server.
|
|
13
|
+
from mcp.server.mcpserver import MCPServer
|
|
14
14
|
|
|
15
15
|
from pyddock.ast_validator import ASTValidator
|
|
16
16
|
from pyddock.config import PyddockConfig, load_config
|
|
@@ -72,6 +72,8 @@ def _build_shell_tool_description(config: PyddockConfig) -> str:
|
|
|
72
72
|
"",
|
|
73
73
|
"Script files get automatic interpreter mapping: .ps1→powershell, .py→python, .sh→bash, .bat→cmd /c.",
|
|
74
74
|
"",
|
|
75
|
+
"Pass 'cwd' to set the working directory (relative to the workspace root; defaults to it).",
|
|
76
|
+
"",
|
|
75
77
|
"Shell policies only gate the initial command — child processes spawned by an allowed script are not restricted. "
|
|
76
78
|
"For example, a build script can internally invoke compilers, tools, or other executables freely.",
|
|
77
79
|
"",
|
|
@@ -101,7 +103,7 @@ def _build_shell_tool_description(config: PyddockConfig) -> str:
|
|
|
101
103
|
return "\n".join(parts)
|
|
102
104
|
|
|
103
105
|
|
|
104
|
-
def create_server(workspace: Path | None = None, debug: bool = False) ->
|
|
106
|
+
def create_server(workspace: Path | None = None, debug: bool = False) -> MCPServer:
|
|
105
107
|
"""Create and configure the pyddock MCP server.
|
|
106
108
|
|
|
107
109
|
Loads config, creates venv, installs allowed packages, and registers
|
|
@@ -112,7 +114,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
112
114
|
debug: Enable the audit-trail debug log (.pyddock/tmp/audit.jsonl).
|
|
113
115
|
|
|
114
116
|
Returns:
|
|
115
|
-
Configured
|
|
117
|
+
Configured MCPServer server instance.
|
|
116
118
|
"""
|
|
117
119
|
if workspace is None:
|
|
118
120
|
workspace = Path.cwd()
|
|
@@ -141,7 +143,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
141
143
|
executor = SubprocessExecutor(config, venv_manager, debug=debug)
|
|
142
144
|
|
|
143
145
|
# Create MCP server
|
|
144
|
-
mcp =
|
|
146
|
+
mcp = MCPServer("pyddock")
|
|
145
147
|
|
|
146
148
|
tool_description = _build_tool_description(config)
|
|
147
149
|
|
|
@@ -214,6 +216,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
214
216
|
command: str | None = None,
|
|
215
217
|
args: list[str] | None = None,
|
|
216
218
|
timeout: float | None = None,
|
|
219
|
+
cwd: str | None = None,
|
|
217
220
|
) -> str:
|
|
218
221
|
"""Execute a pre-approved shell command.
|
|
219
222
|
|
|
@@ -221,6 +224,8 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
221
224
|
command: Executable name or script path (must match a shell policy).
|
|
222
225
|
args: Arguments passed directly to the command.
|
|
223
226
|
timeout: Execution timeout in seconds.
|
|
227
|
+
cwd: Working directory, relative to the workspace root.
|
|
228
|
+
Defaults to the workspace root.
|
|
224
229
|
|
|
225
230
|
Returns:
|
|
226
231
|
Human-readable text with stdout, stderr, and exit code.
|
|
@@ -235,6 +240,11 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
235
240
|
if timeout is not None and timeout <= 0:
|
|
236
241
|
return _shell_error_output(f"Timeout must be positive, got: {timeout}")
|
|
237
242
|
|
|
243
|
+
# Normalize an explicitly-blank cwd to None (workspace root) rather
|
|
244
|
+
# than letting "" reach the path checks as a bogus candidate.
|
|
245
|
+
if cwd is not None and cwd.strip() == "":
|
|
246
|
+
cwd = None
|
|
247
|
+
|
|
238
248
|
# Enforce max_timeout
|
|
239
249
|
effective_timeout = timeout if timeout is not None else config.execution.timeout
|
|
240
250
|
if effective_timeout > config.execution.max_timeout:
|
|
@@ -250,6 +260,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
250
260
|
command,
|
|
251
261
|
args,
|
|
252
262
|
effective_timeout,
|
|
263
|
+
cwd,
|
|
253
264
|
)
|
|
254
265
|
|
|
255
266
|
return _shell_output_to_text(result)
|