mcp-vm-shell 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.
- mcp_vm_shell-1.0.0/LICENSE.md +21 -0
- mcp_vm_shell-1.0.0/PKG-INFO +25 -0
- mcp_vm_shell-1.0.0/README.md +12 -0
- mcp_vm_shell-1.0.0/pyproject.toml +23 -0
- mcp_vm_shell-1.0.0/pyproject.toml.orig +20 -0
- mcp_vm_shell-1.0.0/src/mcp_vm_shell/__init__.py +0 -0
- mcp_vm_shell-1.0.0/src/mcp_vm_shell/server.py +87 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 agowa
|
|
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,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-vm-shell
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An MCP server that provides shell access to a VM.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE.md
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Dist: fastmcp
|
|
10
|
+
Requires-Dist: tzlocal
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# mcp-vm-shell
|
|
15
|
+
|
|
16
|
+
MCP plugin to grant access to a KVM VM with its TTY accessible through a unix socket.
|
|
17
|
+
|
|
18
|
+
## Enter dev environment
|
|
19
|
+
|
|
20
|
+
1. Install [nix](https://nixos.org/download/)
|
|
21
|
+
2. Run `nix develop --impure --extra-experimental-features nix-command --extra-experimental-features flakes`
|
|
22
|
+
|
|
23
|
+
Bulding the pip package using `uv sync; uv build`.
|
|
24
|
+
Upload to pypi after configuring the API Token using `twine upload --verbose dist/*`
|
|
25
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# mcp-vm-shell
|
|
2
|
+
|
|
3
|
+
MCP plugin to grant access to a KVM VM with its TTY accessible through a unix socket.
|
|
4
|
+
|
|
5
|
+
## Enter dev environment
|
|
6
|
+
|
|
7
|
+
1. Install [nix](https://nixos.org/download/)
|
|
8
|
+
2. Run `nix develop --impure --extra-experimental-features nix-command --extra-experimental-features flakes`
|
|
9
|
+
|
|
10
|
+
Bulding the pip package using `uv sync; uv build`.
|
|
11
|
+
Upload to pypi after configuring the API Token using `twine upload --verbose dist/*`
|
|
12
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-vm-shell"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "An MCP server that provides shell access to a VM."
|
|
5
|
+
requires-python = ">=3.14"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE.md"]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"fastmcp",
|
|
11
|
+
"tzlocal",
|
|
12
|
+
]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
mcp-vm-shell = "mcp_vm_shell.server:main"
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["uv_build >= 0.12.5, <0.13.0"]
|
|
23
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-vm-shell"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "An MCP server that provides shell access to a VM."
|
|
5
|
+
requires-python = ">=3.14"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE.md"]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
dependencies = ["fastmcp", "tzlocal"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
mcp-vm-shell = "mcp_vm_shell.server:main"
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["uv_build >= 0.12.5, <0.13.0"]
|
|
20
|
+
build-backend = "uv_build"
|
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import socket
|
|
3
|
+
import threading
|
|
4
|
+
import uuid
|
|
5
|
+
|
|
6
|
+
from mcp.server.fastmcp import FastMCP
|
|
7
|
+
|
|
8
|
+
parser = argparse.ArgumentParser()
|
|
9
|
+
parser.add_argument("socket_path", help="Path to the VM Unix socket")
|
|
10
|
+
parser.add_argument("--timeout", type=float, default=30.0)
|
|
11
|
+
args = parser.parse_args()
|
|
12
|
+
|
|
13
|
+
mcp = FastMCP("vm-shell")
|
|
14
|
+
|
|
15
|
+
def sock_connect():
|
|
16
|
+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
17
|
+
sock.settimeout(30)
|
|
18
|
+
sock.connect(args.socket_path)
|
|
19
|
+
return sock
|
|
20
|
+
|
|
21
|
+
# One command at a time; a terminal is a shared stateful session.
|
|
22
|
+
lock = threading.Lock()
|
|
23
|
+
MAX_OUTPUT = 1024 * 1024
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def read_until(marker: bytes, deadline: float, sock) -> bytes:
|
|
27
|
+
import time
|
|
28
|
+
|
|
29
|
+
output = bytearray()
|
|
30
|
+
while time.monotonic() < deadline:
|
|
31
|
+
try:
|
|
32
|
+
chunk = sock.recv(4096)
|
|
33
|
+
except socket.timeout:
|
|
34
|
+
continue
|
|
35
|
+
|
|
36
|
+
if not chunk:
|
|
37
|
+
raise RuntimeError("VM socket disconnected")
|
|
38
|
+
|
|
39
|
+
output.extend(chunk)
|
|
40
|
+
|
|
41
|
+
if marker in output:
|
|
42
|
+
return bytes(output[:output.index(marker)])
|
|
43
|
+
|
|
44
|
+
if len(output) > MAX_OUTPUT:
|
|
45
|
+
raise RuntimeError("Output limit exceeded; session may need reset")
|
|
46
|
+
|
|
47
|
+
raise TimeoutError("Command timed out; terminal state may be uncertain")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@mcp.tool()
|
|
51
|
+
def shell(command: str) -> str:
|
|
52
|
+
"""Execute a command in the connected VM shell.
|
|
53
|
+
|
|
54
|
+
Requires an already authenticated interactive shell on the socket,
|
|
55
|
+
with terminal echo disabled (stty -echo).
|
|
56
|
+
Commands run in a persistent shell session.
|
|
57
|
+
"""
|
|
58
|
+
if not command.strip():
|
|
59
|
+
return "Error: empty command"
|
|
60
|
+
|
|
61
|
+
marker = f"__MCP_DONE_{uuid.uuid4().hex}__".encode()
|
|
62
|
+
|
|
63
|
+
# The socket must already represent an authenticated shell.
|
|
64
|
+
# Capture the exit code and emit a unique completion marker.
|
|
65
|
+
payload = (
|
|
66
|
+
command
|
|
67
|
+
+ f"\n__mcp_rc=$?; printf '\\n%s:%s\\n' "
|
|
68
|
+
f"'{marker.decode()}' \"$__mcp_rc\"\n"
|
|
69
|
+
).encode()
|
|
70
|
+
|
|
71
|
+
with lock:
|
|
72
|
+
import time
|
|
73
|
+
|
|
74
|
+
sock = sock_connect()
|
|
75
|
+
with sock:
|
|
76
|
+
deadline = time.monotonic() + args.timeout
|
|
77
|
+
sock.sendall(payload)
|
|
78
|
+
result = read_until(marker, deadline, sock)
|
|
79
|
+
return result.decode(errors="replace").strip()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
#mcp.run(transport="stdio")
|
|
84
|
+
mcp.settings.host="127.0.0.1"
|
|
85
|
+
mcp.settings.port=1427
|
|
86
|
+
mcp.run(transport="streamable-http")
|
|
87
|
+
|