BashTerm
vscode-terminal-mcp
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@latestVS 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 结果,输出干净

工具
快速执行
工具 | 描述 |
| 一步创建(或复用)终端并执行命令。返回干净的输出和退出码。 |
会话管理
工具 | 描述 |
| 创建新的可见终端会话。返回 |
| 在现有会话中执行命令并捕获输出。 |
| 从会话中读取输出,支持分页。支持增量读取和尾部模式( |
| 向交互式终端发送文本(提示、REPL、确认)。 |
| 列出活动会话。可选按 |
| 关闭终端会话及其 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代理将:
调用
run并设置waitForCompletion: false— 立即返回调用
read并设置offset: -10以检查最后 10 行重复直到进程完成
交互式命令
对于需要用户输入的命令:
> Run npm init and answer the prompts代理将:
调用
run执行npm init调用
read查看提示调用
input发送答案
并行代理
子代理可以使用 agentId 在隔离的终端中工作:
> Have one agent run tests while another runs the linter每个子代理获得自己的终端,并用其 agentId 标记,防止输出混合。
配置
扩展从 VSCode 设置中读取 terminalMcp.* 下的配置:
设置 | 类型 | 默认值 | 描述 |
| number | 10 | 最大并发终端会话数 |
| number | 30000 | 默认命令超时时间(毫秒) |
| number | 5000 | 每个会话输出缓冲区保留的最大行数 |
| number | 1800000 | 空闲会话在此毫秒数后关闭(0 = 禁用) |
| string[] |
| 将被拒绝的命令 |
推荐:设置为首选工具
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)以减少捕获的输出大小。
工作原理
VSCode 扩展激活并在 Unix 套接字上启动 IPC 服务器
MCP 入口点(
mcp-entry.js)由 MCP 客户端生成,并在 JSON-RPC stdio 和 IPC 套接字之间进行桥接命令使用 Shell Integration API 在真实的 VSCode 终端中执行,以可靠地捕获输出和检测退出码
输出存储在循环缓冲区中,支持分页以高效读取
最新更改(0.1.6)
README 中的截图,用于市场
所有工具的干净输出格式 — 不再有原始 JSON
修复了
waitForCompletion: false不起作用的问题禁用了空闲回收器 — 用户手动关闭会话
每个工作区唯一的 IPC 套接字(多实例支持)
自定义终端标签页名称,带日期格式
大输出处理文档
完整历史记录请参阅 CHANGELOG.md。
许可证
MIT
This server cannot be installed
Maintenance
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
- FlicenseNot gradedqualityDmaintenanceProvides stateful, interactive terminal access for LLMs to spawn and maintain persistent processes like SSH sessions, debuggers, and REPLs with continuous input/output interaction across commands.7
- AlicenseAqualityDmaintenanceEnables management of visible, interactive terminal sessions across platforms (macOS, Windows, Linux, WSL). Supports creating, executing commands, capturing output, and managing multiple terminal windows simultaneously.51MIT
- AlicenseAqualityDmaintenanceEnables 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.891MIT
- FlicenseNot gradedqualityDmaintenanceEnables interactive terminal sessions within Claude Code and Desktop, allowing users and AI to execute commands and manage multiple tabs.2
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,
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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