Integrations
Creates and manages terminal sessions within Electron windows, enabling command execution and output retrieval through a programmatic API
Uses an Express HTTP server to facilitate communication between the MCP server and the Electron backend for terminal operations
Provides a bridge between the MCP protocol and Node.js to manage terminal sessions, execute commands, and retrieve terminal output
电子终端 MCP 服务器
1.描述
理想情况下,供应商会为终端提供自己的 MCP 集成,但与此同时,该项目提供了一个模型上下文协议 (MCP) 服务器,允许客户端与在 Electron 应用程序中运行的系统终端进行交互。它支持以编程方式执行命令、管理终端会话和检索输出。
该系统由两个主要部分组成:
- **MCP 服务器 (
index.js
):**一个 Node.js 脚本,用于通过标准输入/输出 (stdio) 监听 MCP 请求。它使用@modelcontextprotocol/sdk
并充当 Electron 后端的桥梁。如果 Electron 后端尚未运行,它会自动启动。它需要在mcp-package.json
中指定"type": "module"
。 - Electron 后端 (
main.js
): Electron 应用的主进程。它运行一个 Express HTTP 服务器(默认端口 3000),MCP 服务器 (index.js
) 会与该服务器通信,以进行健康检查和 API 调用。该后端使用node-pty
在隐藏的BrowserWindow
实例中管理实际的终端进程,用于加载terminal.html
。
2. 截图
以下是 Claude Desktop 等客户端中的终端交互方式:
带有终端输出的 Claude 桌面窗口:
单个电子终端窗口:
3.安装
- **先决条件:**确保您已安装 Node.js 和 npm。
- **克隆:**如果尚未克隆存储库,请先克隆。Copy
- **安装依赖项:**为 MCP 服务器和 Electron 应用程序安装 Node 模块。Copy
- **重建本机模块:**为 Electron 重建本机模块(如
node-pty
)。(详情请参阅Copyrebuild.js
)
3. 使用
- **启动 MCP 服务器:**使用 Node.js 运行
index.js
脚本。这将在 stdio 上监听 MCP 命令,如果 Electron 后端进程 (main.js
) 尚未运行且未监听预期的 HTTP 端口,则会自动尝试启动它。注意:Electron 进程在后台隐藏运行,并在需要时自动(重新)启动,并且尽可能重复使用。Copy - **通过 MCP 交互:**客户端通过 stdio 连接到
node index.js
进程,并使用use_mcp_tool
命令。服务器名称在index.js
中定义为“Electron Terminal”。可用工具:terminal_start
:创建一个新的终端会话并执行初始命令。- 输入:
{ "command": "string" }
- 输出:
{ "content": [...], "sessionId": "string" }
GXP5
- 输入:
terminal_execute
:在现有会话中执行命令。- 输入:
{ "command": "string", "sessionId": "string" }
- 输出:
{ "content": [...] }
(会话ID包含在文本内容中)GXP6
- 输入:
terminal_get_output
:检索会话的累积输出。- 输入:
{ "sessionId": "string" }
- 输出:
{ "content": [...] }
GXP7
- 输入:
terminal_stop
:终止特定的终端会话进程。- 输入:
{ "sessionId": "string" }
- 输出:
{ "content": [...] }
GXP8
- 输入:
terminal_get_sessions
:列出 Electron 后端管理的所有当前活动会话。- 输入:
{}
- 输出:
{ "content": [...] }
(内容包含活动会话的 JSON 字符串)GXP9
- 输入:
5. 与文件系统 MCP 服务器协同
此 Electron 终端 MCP 服务器与文件系统 MCP 服务器配合使用,效果显著。您可以使用文件系统服务器浏览目录、读写文件,然后使用此终端服务器执行目录内或文件相关的命令,从而提供全面的远程开发和交互体验,并与 Claude Desktop 内置的互联网搜索功能无缝协作。
6. 要求
- Node.js(建议使用 v20 或更高版本,我使用 node 22)
- npm
- 与 Electron 兼容的操作系统(Windows、macOS、Linux)
7.配置
Claude Desktop MCP 服务器配置
地点
claude_desktop_config.json
文件应放置在用户的 AppData 目录中:
- Windows:
C:\Users\<username>\AppData\Roaming\Claude\claude_desktop_config.json
Claude Desktop 使用该文件来发现和配置外部 MCP 服务器。
目的和结构
配置文件定义了 Claude Desktop 可以启动和连接的 MCP 服务器。每个服务器条目指定如何启动服务器进程。
mcpServers
:一个对象,其中每个键都是一个服务器名称,值是其启动配置。- 服务器配置示例(
command-terminal
) :command
:要运行的可执行文件(例如,Node.js 服务器的node
)。args
:传递给命令的参数数组(例如,MCP 服务器脚本的路径)。
例子
字段说明
mcpServers
:将服务器名称映射到其配置的顶级对象。command-terminal
:示例服务器名称。您可以在此对象中定义多个服务器。command
:用于启动 MCP 服务器的可执行文件。args
:传递给命令的参数,例如服务器脚本的路径。
8. 许可证
本项目遵循 MIT 许可证。详情请参阅 LICENSE 文件。
You must be authenticated.
local-only server
The server can only run on the client's local machine because it depends on local resources.
模型上下文协议服务器使客户端能够与在 Electron 应用程序中运行的系统终端进行交互,从而允许执行命令、管理终端会话和以编程方式检索输出。
Related Resources
Related MCP Servers
- -securityFlicense-qualityThis server enables running a Model Context Protocol in a web browser with functionalities including arithmetic operations and session-based key-value storage.Last updated -2TypeScript
- -securityFlicense-qualityA Model Context Protocol server that allows LLMs to execute shell commands and receive their output in a controlled manner.Last updated -Python
- AsecurityAlicenseAqualityA secure terminal execution server that enables controlled command execution with security features and resource limits via the Model Context Protocol (MCP).Last updated -1121JavaScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables seamless execution of commands, Python code, web content fetching, and reusable task management with secure credentials handling.Last updated -2PythonMIT License