coding-tools-mcp 0.1.3__py3-none-any.whl

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.
@@ -0,0 +1,3 @@
1
+ """Coding Tools MCP server package."""
2
+
3
+ __version__ = "0.1.3"
@@ -0,0 +1,7 @@
1
+ from __future__ import annotations
2
+
3
+ from .server import main
4
+
5
+
6
+ if __name__ == "__main__":
7
+ raise SystemExit(main())
@@ -0,0 +1,64 @@
1
+ from __future__ import annotations
2
+
3
+ import ctypes
4
+ import os
5
+ import shutil
6
+ import sys
7
+ from typing import Any
8
+
9
+
10
+ PR_SET_NO_NEW_PRIVS = 38
11
+ SYS_LANDLOCK_RESTRICT_SELF = 446
12
+
13
+ _LIBC: Any | None = None
14
+
15
+
16
+ def landlock_libc() -> Any:
17
+ global _LIBC
18
+ if _LIBC is None:
19
+ _LIBC = ctypes.CDLL(None, use_errno=True)
20
+ return _LIBC
21
+
22
+
23
+ def libc_syscall(number: int, *args: object) -> int:
24
+ ctypes.set_errno(0)
25
+ return int(landlock_libc().syscall(number, *args))
26
+
27
+
28
+ def fail(message: str) -> int:
29
+ print(message, file=sys.stderr)
30
+ return 126
31
+
32
+
33
+ def main(argv: list[str] | None = None) -> int:
34
+ if sys.platform != "linux":
35
+ return fail("landlock_exec is only supported on Linux")
36
+ args = list(sys.argv[1:] if argv is None else argv)
37
+ if len(args) != 2:
38
+ return fail("landlock_exec requires: <ruleset-fd> <command>")
39
+ try:
40
+ ruleset_fd = int(args[0])
41
+ except ValueError:
42
+ return fail("landlock_exec received an invalid ruleset fd")
43
+ cmd = args[1]
44
+
45
+ rc = int(landlock_libc().prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
46
+ if rc != 0:
47
+ err = ctypes.get_errno()
48
+ return fail(f"failed to set no_new_privs before Landlock restrict: {os.strerror(err)}")
49
+ rc = libc_syscall(SYS_LANDLOCK_RESTRICT_SELF, ruleset_fd, 0)
50
+ if rc != 0:
51
+ err = ctypes.get_errno()
52
+ return fail(f"failed to apply Landlock restrict_self: {os.strerror(err)}")
53
+ try:
54
+ os.close(ruleset_fd)
55
+ except OSError:
56
+ pass
57
+
58
+ shell = os.environ.get("SHELL") or shutil.which("sh") or "/bin/sh"
59
+ os.execvpe(shell, [shell, "-c", cmd], os.environ)
60
+ return 127
61
+
62
+
63
+ if __name__ == "__main__":
64
+ raise SystemExit(main())