Skip to main content
Glama
sirlordt
by sirlordt

vscode-terminal-mcp

npm version

MCP 服务器,可在可见的 VSCode 终端标签页中执行命令并完整捕获输出。与内联执行不同,每条命令都在真实终端中运行,您可以查看、滚动并与之交互。

主要特性

  • 可见终端:命令在真实的 VSCode 终端标签页中运行,而非隐藏进程。您可以实时看到一切。

  • 会话复用run 工具自动复用空闲会话,仅在需要时创建新终端。

  • 长时间运行支持:使用 waitForCompletion: false 进行即发即忘执行,然后通过 read 增量轮询输出。

  • 子代理隔离:使用 agentId 标记会话,以保持并行代理工作负载的分离。

Related MCP server: Terminal MCP

要求

  • VS Code 1.93+(用于 Shell Integration API)

  • Node.js 20+

快速开始

Claude Code

claude mcp add BashTerm -- npx vscode-terminal-mcp@latest

VS Code / Copilot

添加到您的 .vscode/mcp.json

{
  "servers": {
    "BashTerm": {
      "type": "stdio",
      "command": "npx",
      "args": ["vscode-terminal-mcp@latest"]
    }
  }
}

添加到您的 .cursor/mcp.json

{
  "mcpServers": {
    "BashTerm": {
      "command": "npx",
      "args": ["-y", "vscode-terminal-mcp@latest"]
    }
  }
}

添加到您的 claude_desktop_config.json

{
  "mcpServers": {
    "BashTerm": {
      "command": "npx",
      "args": ["-y", "vscode-terminal-mcp@latest"]
    }
  }
}

您的第一个提示

安装后,尝试询问:

在终端中运行 ls -la

您应该会看到 VSCode 中打开一个新的终端标签页,并显示命令输出。

截图

使用 run 运行命令

运行命令输出

exec 的权限对话框

Exec 权限对话框

Exec 结果,输出干净

Exec 完成

工具

快速执行

工具

描述

run

一步创建(或复用)终端并执行命令。返回干净的输出和退出码。

会话管理

工具

描述

create

创建新的可见终端会话。返回 sessionId

exec

在现有会话中执行命令并捕获输出。

read

从会话中读取输出,支持分页。支持增量读取和尾部模式(offset: -N)。

input

向交互式终端发送文本(提示、REPL、确认)。

list

列出活动会话。可选按 agentId 过滤。

close

关闭终端会话及其 VSCode 标签页。

使用模式

简单命令

run 工具处理一切——如果需要则创建终端,执行并返回干净的输出:

> Run npm test
$ npm test
PASS src/utils.test.ts (3 tests)
PASS src/index.test.ts (5 tests)

[exit: 0 | 1243ms | session-abc123]

长时间运行进程

对于构建、部署或任何需要较长时间的命令:

> Start `npm run build` without waiting, then check progress

代理将:

  1. 调用 run 并设置 waitForCompletion: false — 立即返回

  2. 调用 read 并设置 offset: -10 以检查最后 10 行

  3. 重复直到进程完成

交互式命令

对于需要用户输入的命令:

> Run npm init and answer the prompts

代理将:

  1. 调用 run 执行 npm init

  2. 调用 read 查看提示

  3. 调用 input 发送答案

并行代理

子代理可以使用 agentId 在隔离的终端中工作:

> Have one agent run tests while another runs the linter

每个子代理获得自己的终端,并用其 agentId 标记,防止输出混合。

配置

扩展从 VSCode 设置中读取 terminalMcp.* 下的配置:

设置

类型

默认值

描述

terminalMcp.maxSessions

number

10

最大并发终端会话数

terminalMcp.commandTimeout

number

30000

默认命令超时时间(毫秒)

terminalMcp.maxOutputLines

number

5000

每个会话输出缓冲区保留的最大行数

terminalMcp.idleTimeout

number

1800000

空闲会话在此毫秒数后关闭(0 = 禁用)

terminalMcp.blockedCommands

string[]

["rm -rf /"]

将被拒绝的命令

推荐:设置为首选工具

LLM 代理(如 Claude Code)内置了 Bash 工具,可在聊天中内联执行命令。输出嵌入在对话中,难以阅读,尤其是对于输出冗长的命令。我们建议告诉代理优先使用此 MCP 而不是其内置的 Bash 工具。

将以下内容添加到项目的 CLAUDE.md(或等效的指令文件)中:

## Terminal Execution

Prefer the BashTerm MCP tools (`run`, `exec`, `read`, etc.) over the built-in Bash tool for executing commands.
BashTerm runs commands in visible VSCode terminal tabs where the user can see output in real time.
Only fall back to the built-in Bash tool for simple, non-interactive operations like reading environment variables.

For commands that may take longer than 30 seconds or produce large amounts of output (builds, test suites,
deployments, installs), use the pull mode pattern:
1. Call `run` with `waitForCompletion: false` to launch the command without blocking.
2. Call `read` with `offset: -10` to check the last 10 lines of output.
3. Repeat step 2 until you see the command has finished (look for exit messages, prompts, or "Done").
4. Report the final result to the user.

This prevents conversation timeouts and lets the user watch progress in the terminal in real time.

为什么这很重要:

内置 Bash

BashTerm MCP

输出可见性

嵌入在聊天中,难以滚动

在 VSCode 终端标签页中可见

实时反馈

用户直到命令完成才看到任何内容

用户实时观看输出

长时间运行命令

阻塞对话直到超时

即发即忘 + 轮询

会话状态

每条命令都是隔离的

持久会话,带历史记录

交互式命令

不支持

向提示/REPL 发送输入

开发:更新扩展

VSCode 会积极缓存内存中的扩展。在本地开发时,code --install-extension 甚至“开发者:重新加载窗口”可能不会重新加载您的更改。请使用此工作流程:

快速更新(无需重启)

修改源文件后,构建并直接复制到已安装的扩展目录中:

cd /path/to/vscode-terminal-mcp
npm run build
cp dist/extension.js ~/.vscode/extensions/sirlordt.vscode-terminal-mcp-<version>/dist/extension.js

然后运行 “开发者:重新加载窗口”Ctrl+Shift+P)。

完全重新安装(当快速更新不起作用时)

如果 VSCode 仍使用旧代码:

# 1. Uninstall and remove all copies
code --uninstall-extension sirlordt.vscode-terminal-mcp
rm -rf ~/.vscode/extensions/sirlordt.vscode-terminal-mcp-*

# 2. Check for ghost entries with old publisher names
# Look in ~/.vscode/extensions/extensions.json for stale entries
# Remove any entries with old publisher IDs (e.g., "terminal-mcp.vscode-terminal-mcp")

# 3. Close VSCode completely (not just reload)

# 4. Rebuild and install
npm run build
npx vsce package --allow-missing-repository
code --install-extension vscode-terminal-mcp-<version>.vsix --force

# 5. Open VSCode

验证已加载正确的版本

# Check which extension directories exist
ls ~/.vscode/extensions/ | grep terminal

# Verify your changes are in the installed extension
grep "YOUR_UNIQUE_STRING" ~/.vscode/extensions/sirlordt.vscode-terminal-mcp-*/dist/extension.js

# Compare checksums
md5sum dist/extension.js ~/.vscode/extensions/sirlordt.vscode-terminal-mcp-*/dist/extension.js

大输出处理

read 返回的输出超过 MCP 客户端的令牌限制时,系统会自动将完整输出保存到临时 JSON 文件中,并在错误消息中返回文件路径。

要提取相关内容:

# Get the last 50 lines (most relevant for status)
tail -50 /path/to/saved/file.txt

# Or parse the JSON to extract the text content
python3 -c "import json; data=json.load(open('/path/to/file.txt')); print(data[0]['text'][-2000:])"

文件格式为 JSON:[{"type": "text", "text": "..."}]

这通常发生在产生大量 TUI 输出(进度条、ANSI 转义码)的命令中。使用较小的 offset 值(例如,offset: -20 而不是 offset: -100)以减少捕获的输出大小。

工作原理

  1. VSCode 扩展激活并在 Unix 套接字上启动 IPC 服务器

  2. MCP 入口点mcp-entry.js)由 MCP 客户端生成,并在 JSON-RPC stdio 和 IPC 套接字之间进行桥接

  3. 命令使用 Shell Integration API 在真实的 VSCode 终端中执行,以可靠地捕获输出和检测退出码

  4. 输出存储在循环缓冲区中,支持分页以高效读取

最新更改(0.1.6)

  • README 中的截图,用于市场

  • 所有工具的干净输出格式 — 不再有原始 JSON

  • 修复了 waitForCompletion: false 不起作用的问题

  • 禁用了空闲回收器 — 用户手动关闭会话

  • 每个工作区唯一的 IPC 套接字(多实例支持)

  • 自定义终端标签页名称,带日期格式

  • 大输出处理文档

完整历史记录请参阅 CHANGELOG.md

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Enables management of visible, interactive terminal sessions across platforms (macOS, Windows, Linux, WSL). Supports creating, executing commands, capturing output, and managing multiple terminal windows simultaneously.
    5
    1
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Enables AI assistants to execute shell commands and manage long-running processes within persistent tmux sessions across isolated workspaces. It features a dual-window architecture to separate raw command execution from interactive terminal output.
    8
    9
    1
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables interactive terminal sessions within Claude Code and Desktop, allowing users and AI to execute commands and manage multiple tabs.
    2

View all related MCP servers

Related MCP Connectors

  • Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.

  • Live browser debugging for AI assistants — DOM, console, network via MCP.

  • A paid remote MCP for AI agent browser DevTools MCP, built to return verdicts, receipts, usage logs,

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sirlordt/vscode-terminal-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server