winterm-mcp 0.1.2__tar.gz → 0.1.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winterm-mcp
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A Model Context Protocol (MCP) service for executing Windows terminal commands asynchronously
5
5
  Author-email: winterm-mcp contributors <maintainer@example.com>
6
6
  License: MIT
@@ -27,8 +27,8 @@ Dynamic: license-file
27
27
 
28
28
  # winterm-mcp
29
29
 
30
- **更新日期**: 2026-01-16
31
- **版本**: 0.1.1
30
+ **更新日期**: 2026-01-16
31
+ **版本**: 0.1.4
32
32
 
33
33
  Windows Terminal MCP Service - 专门支持 Windows 终端的异步命令执行工具。
34
34
 
@@ -58,8 +58,50 @@ pip install -e .
58
58
  ```json
59
59
  {
60
60
  "mcpServers": {
61
- "winterm-mcp": {
62
- "command": "winterm-mcp"
61
+ "winterm": {
62
+ "command": "uvx",
63
+ "args": [
64
+ "winterm-mcp"
65
+ ]
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ ### 环境配置
72
+
73
+ #### PowerShell 路径配置
74
+
75
+ 在某些受限环境(如沙箱环境)中,系统 PATH 可能不包含 PowerShell 路径。winterm-mcp 会自动探测以下位置:
76
+
77
+ 1. `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
78
+ 2. `C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe`
79
+ 3. `C:\Program Files\PowerShell\7\pwsh.exe`(PowerShell Core)
80
+ 4. `C:\Program Files (x86)\PowerShell\7\pwsh.exe`
81
+
82
+ 如果 PowerShell 安装在非标准位置,可通过环境变量指定:
83
+
84
+ **方式一:系统环境变量**
85
+
86
+ ```bash
87
+ # Windows CMD
88
+ set WINTERM_POWERSHELL_PATH=D:\CustomPath\powershell.exe
89
+
90
+ # Windows PowerShell
91
+ $env:WINTERM_POWERSHELL_PATH = "D:\CustomPath\powershell.exe"
92
+ ```
93
+
94
+ **方式二:MCP 配置**
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "winterm": {
100
+ "command": "uvx",
101
+ "args": ["winterm-mcp"],
102
+ "env": {
103
+ "WINTERM_POWERSHELL_PATH": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
104
+ }
63
105
  }
64
106
  }
65
107
  }
@@ -1,7 +1,7 @@
1
1
  # winterm-mcp
2
2
 
3
- **更新日期**: 2026-01-16
4
- **版本**: 0.1.1
3
+ **更新日期**: 2026-01-16
4
+ **版本**: 0.1.4
5
5
 
6
6
  Windows Terminal MCP Service - 专门支持 Windows 终端的异步命令执行工具。
7
7
 
@@ -31,8 +31,50 @@ pip install -e .
31
31
  ```json
32
32
  {
33
33
  "mcpServers": {
34
- "winterm-mcp": {
35
- "command": "winterm-mcp"
34
+ "winterm": {
35
+ "command": "uvx",
36
+ "args": [
37
+ "winterm-mcp"
38
+ ]
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ ### 环境配置
45
+
46
+ #### PowerShell 路径配置
47
+
48
+ 在某些受限环境(如沙箱环境)中,系统 PATH 可能不包含 PowerShell 路径。winterm-mcp 会自动探测以下位置:
49
+
50
+ 1. `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
51
+ 2. `C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe`
52
+ 3. `C:\Program Files\PowerShell\7\pwsh.exe`(PowerShell Core)
53
+ 4. `C:\Program Files (x86)\PowerShell\7\pwsh.exe`
54
+
55
+ 如果 PowerShell 安装在非标准位置,可通过环境变量指定:
56
+
57
+ **方式一:系统环境变量**
58
+
59
+ ```bash
60
+ # Windows CMD
61
+ set WINTERM_POWERSHELL_PATH=D:\CustomPath\powershell.exe
62
+
63
+ # Windows PowerShell
64
+ $env:WINTERM_POWERSHELL_PATH = "D:\CustomPath\powershell.exe"
65
+ ```
66
+
67
+ **方式二:MCP 配置**
68
+
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "winterm": {
73
+ "command": "uvx",
74
+ "args": ["winterm-mcp"],
75
+ "env": {
76
+ "WINTERM_POWERSHELL_PATH": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
77
+ }
36
78
  }
37
79
  }
38
80
  }
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "winterm-mcp"
7
- version = "0.1.2"
7
+ version = "0.1.4"
8
8
  description = "A Model Context Protocol (MCP) service for executing Windows terminal commands asynchronously"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -47,3 +47,9 @@ include = ["winterm_mcp*"]
47
47
 
48
48
  [project.entry-points."mcp.servers"]
49
49
  winterm-mcp = "winterm_mcp.__main__:main"
50
+
51
+ [tool.black]
52
+ line-length = 88
53
+
54
+ [tool.flake8]
55
+ max-line-length = 88
@@ -54,8 +54,7 @@ def init_service(service: RunCmdService) -> None:
54
54
  def _svc() -> RunCmdService:
55
55
  if _service is None:
56
56
  raise RuntimeError(
57
- "Service not initialized. "
58
- "Call init_service() before running the server."
57
+ "Service not initialized. " "Call init_service() before running the server."
59
58
  )
60
59
  return _service
61
60
 
@@ -93,9 +92,7 @@ def run_command(
93
92
  包含token和状态信息的字典
94
93
  """
95
94
  try:
96
- token = _svc().run_command(
97
- command, shell_type, timeout, working_directory
98
- )
95
+ token = _svc().run_command(command, shell_type, timeout, working_directory)
99
96
  return {"token": token, "status": "pending", "message": "submitted"}
100
97
  except Exception as e:
101
98
  return {"error": str(e)}
@@ -6,8 +6,78 @@ import subprocess
6
6
  import threading
7
7
  import uuid
8
8
  import time
9
+ import os
10
+ import shutil
9
11
  from datetime import datetime
10
- from typing import Dict, Optional, Any
12
+ from typing import Dict, Optional, Any, List
13
+
14
+
15
+ # PowerShell 可执行文件的标准路径(按优先级排序)
16
+ POWERSHELL_PATHS: List[str] = [
17
+ r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",
18
+ r"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe",
19
+ ]
20
+
21
+ # PowerShell Core (pwsh) 的常见路径
22
+ PWSH_PATHS: List[str] = [
23
+ r"C:\Program Files\PowerShell\7\pwsh.exe",
24
+ r"C:\Program Files (x86)\PowerShell\7\pwsh.exe",
25
+ ]
26
+
27
+ # 环境变量名称
28
+ ENV_POWERSHELL_PATH = "WINTERM_POWERSHELL_PATH"
29
+
30
+
31
+ def _find_powershell() -> str:
32
+ """
33
+ 查找可用的 PowerShell 可执行文件路径
34
+
35
+ 查找顺序:
36
+ 1. 环境变量 WINTERM_POWERSHELL_PATH(用户自定义)
37
+ 2. Windows PowerShell 标准路径
38
+ 3. PowerShell Core 标准路径
39
+ 4. PATH 环境变量中的 powershell/pwsh(兼容正常环境)
40
+
41
+ Returns:
42
+ PowerShell 可执行文件的绝对路径
43
+
44
+ Raises:
45
+ FileNotFoundError: 如果找不到 PowerShell
46
+ """
47
+ # 1. 检查用户配置的环境变量
48
+ custom_path = os.environ.get(ENV_POWERSHELL_PATH)
49
+ if custom_path:
50
+ if os.path.isfile(custom_path):
51
+ return custom_path
52
+ # 用户配置了但路径无效,记录警告但继续查找
53
+
54
+ # 2. 检查 Windows PowerShell 标准路径
55
+ for path in POWERSHELL_PATHS:
56
+ if os.path.isfile(path):
57
+ return path
58
+
59
+ # 3. 检查 PowerShell Core 标准路径
60
+ for path in PWSH_PATHS:
61
+ if os.path.isfile(path):
62
+ return path
63
+
64
+ # 4. 尝试 PATH 环境变量(兼容正常环境)
65
+ ps_path = shutil.which("powershell")
66
+ if ps_path:
67
+ return ps_path
68
+
69
+ pwsh_path = shutil.which("pwsh")
70
+ if pwsh_path:
71
+ return pwsh_path
72
+
73
+ # 所有方法都失败
74
+ checked_paths = POWERSHELL_PATHS + PWSH_PATHS
75
+ raise FileNotFoundError(
76
+ f"PowerShell not found. "
77
+ f"Set {ENV_POWERSHELL_PATH} environment variable or "
78
+ f"ensure PowerShell is installed. "
79
+ f"Checked paths: {', '.join(checked_paths)}"
80
+ )
11
81
 
12
82
 
13
83
  class RunCmdService:
@@ -18,6 +88,23 @@ class RunCmdService:
18
88
  def __init__(self):
19
89
  self.commands: Dict[str, Dict[str, Any]] = {}
20
90
  self.lock = threading.Lock()
91
+ self._powershell_path: Optional[str] = None
92
+
93
+ def _get_powershell_path(self) -> str:
94
+ """
95
+ 获取 PowerShell 可执行文件路径(带缓存)
96
+
97
+ 首次调用时查找并缓存路径,后续调用直接返回缓存值。
98
+
99
+ Returns:
100
+ PowerShell 可执行文件的绝对路径
101
+
102
+ Raises:
103
+ FileNotFoundError: 如果找不到 PowerShell
104
+ """
105
+ if self._powershell_path is None:
106
+ self._powershell_path = _find_powershell()
107
+ return self._powershell_path
21
108
 
22
109
  def run_command(
23
110
  self,
@@ -88,7 +175,18 @@ class RunCmdService:
88
175
  encoding = "gbk"
89
176
 
90
177
  if shell_type == "powershell":
91
- cmd_args = ["powershell", "-NoProfile", "-NonInteractive", "-Command", command]
178
+ # 使用绝对路径调用 PowerShell,避免 PATH 环境变量限制
179
+ ps_path = self._get_powershell_path()
180
+ cmd_args = [
181
+ ps_path,
182
+ "-NoProfile",
183
+ "-NoLogo",
184
+ "-NonInteractive",
185
+ "-ExecutionPolicy",
186
+ "Bypass",
187
+ "-Command",
188
+ command,
189
+ ]
92
190
  else:
93
191
  cmd_args = ["cmd", "/c", command]
94
192
 
@@ -99,6 +197,7 @@ class RunCmdService:
99
197
  timeout=timeout,
100
198
  cwd=working_directory,
101
199
  encoding=encoding,
200
+ stdin=subprocess.DEVNULL, # 防止等待输入导致挂起
102
201
  )
103
202
 
104
203
  execution_time = time.time() - start_time
@@ -115,6 +214,20 @@ class RunCmdService:
115
214
  }
116
215
  )
117
216
 
217
+ except FileNotFoundError as e:
218
+ execution_time = time.time() - start_time
219
+ with self.lock:
220
+ if token in self.commands:
221
+ self.commands[token].update(
222
+ {
223
+ "status": "completed",
224
+ "stdout": "",
225
+ "stderr": f"PowerShell not found: {e}",
226
+ "exit_code": -2,
227
+ "execution_time": execution_time,
228
+ "timeout_occurred": False,
229
+ }
230
+ )
118
231
  except subprocess.TimeoutExpired:
119
232
  execution_time = time.time() - start_time
120
233
  with self.lock:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winterm-mcp
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A Model Context Protocol (MCP) service for executing Windows terminal commands asynchronously
5
5
  Author-email: winterm-mcp contributors <maintainer@example.com>
6
6
  License: MIT
@@ -27,8 +27,8 @@ Dynamic: license-file
27
27
 
28
28
  # winterm-mcp
29
29
 
30
- **更新日期**: 2026-01-16
31
- **版本**: 0.1.1
30
+ **更新日期**: 2026-01-16
31
+ **版本**: 0.1.4
32
32
 
33
33
  Windows Terminal MCP Service - 专门支持 Windows 终端的异步命令执行工具。
34
34
 
@@ -58,8 +58,50 @@ pip install -e .
58
58
  ```json
59
59
  {
60
60
  "mcpServers": {
61
- "winterm-mcp": {
62
- "command": "winterm-mcp"
61
+ "winterm": {
62
+ "command": "uvx",
63
+ "args": [
64
+ "winterm-mcp"
65
+ ]
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ ### 环境配置
72
+
73
+ #### PowerShell 路径配置
74
+
75
+ 在某些受限环境(如沙箱环境)中,系统 PATH 可能不包含 PowerShell 路径。winterm-mcp 会自动探测以下位置:
76
+
77
+ 1. `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
78
+ 2. `C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe`
79
+ 3. `C:\Program Files\PowerShell\7\pwsh.exe`(PowerShell Core)
80
+ 4. `C:\Program Files (x86)\PowerShell\7\pwsh.exe`
81
+
82
+ 如果 PowerShell 安装在非标准位置,可通过环境变量指定:
83
+
84
+ **方式一:系统环境变量**
85
+
86
+ ```bash
87
+ # Windows CMD
88
+ set WINTERM_POWERSHELL_PATH=D:\CustomPath\powershell.exe
89
+
90
+ # Windows PowerShell
91
+ $env:WINTERM_POWERSHELL_PATH = "D:\CustomPath\powershell.exe"
92
+ ```
93
+
94
+ **方式二:MCP 配置**
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "winterm": {
100
+ "command": "uvx",
101
+ "args": ["winterm-mcp"],
102
+ "env": {
103
+ "WINTERM_POWERSHELL_PATH": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
104
+ }
63
105
  }
64
106
  }
65
107
  }
File without changes
File without changes