VSCode 内部命令 MCP 服务器 logo

VSCode 内部命令 MCP 服务器

Community
bestK

🚀 一个基于 FastMCP 框架的 VSCode 扩展,将 VSCode 转换为 MCP (Model Context Protocol) 服务器,支持外部客户端通过 HTTP Streaming 和 Server-Sent Events (SSE) 执行 VSCode 内部命令。

PublisherbestK
Repositoryvscode-internal-command-mcp-server
LanguageTypeScript
Forks
20
Stars
63
Available tools
0
Transport typestdio, streamable-http
Categories
Links
  • Connect tools to AI workflows

    VSCode 内部命令 MCP 服务器 exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    63 stars and 20 forks from the linked repository.

VSCode Internal Command MCP Server

🚀 一个基于 FastMCP 框架的 VSCode 扩展,将 VSCode 转换为 MCP (Model Context Protocol) 服务器,支持外部客户端通过 HTTP Streaming 和 Server-Sent Events (SSE) 执行 VSCode 内部命令。

English Documentation

✨ 功能特性

  • 🌐 HTTP Streaming 支持: 使用 text/event-stream 协议,支持实时通信
  • 🔧 VSCode 命令执行: 远程执行任意 VSCode 内部命令
  • 📊 工作区信息查询: 获取当前工作区状态和文件信息
  • ⚡ 异步后台执行: 支持异步命令执行,不阻塞用户界面
  • ⏰ 可配置延时: 支持设置命令执行延时
  • 🛡️ 安全控制: 可配置的命令白名单机制
  • 📡 实时状态监控: 状态栏显示服务器运行状态
  • 🔗 标准 MCP 协议: 完全兼容 Model Context Protocol 规范
  • ⚡ 高性能: 基于 FastMCP 框架,支持并发请求和会话管理
  • 🩺 健康检查: 内置健康检查端点

📦 安装

1. 克隆项目

bash
git clone https://github.com/bestk/vscode-internal-command-mcp-server
cd vscode-internal-command-mcp-server

2. 安装依赖

bash
npm install

3. 编译项目

bash
npm run compile

4. 在 VSCode 中安装

  • 按 F5 启动扩展开发主机
  • 或者打包为 .vsix 文件进行安装

⚙️ 配置

在 VSCode 设置中配置服务器参数:

json
{
    "vscode-internal-command-mcp-server.port": 8080,
    "vscode-internal-command-mcp-server.host": "localhost",
    "vscode-internal-command-mcp-server.autoStart": true,
    "vscode-internal-command-mcp-server.asyncExecution": true,
    "vscode-internal-command-mcp-server.executionDelay": 1000,
    "vscode-internal-command-mcp-server.showAsyncNotifications": false,
    "vscode-internal-command-mcp-server.allowedCommands": [
        "editor.action.formatDocument",
        "workbench.action.files.save",
        "editor.action.clipboardCopyAction"
    ]
}

配置说明

配置项类型默认值说明
portnumber8080MCP 服务器端口
hoststring"localhost"MCP 服务器主机地址
autoStartbooleantrue扩展激活时自动启动服务器
asyncExecutionbooleantrue启用异步命令执行(立即返回,后台执行)
executionDelaynumber0命令执行延时(毫秒)
showAsyncNotificationsbooleanfalse显示异步命令执行完成通知
allowedCommandsstring[][]允许执行的命令列表(空数组表示允许所有命令)

🚀 使用方法

启动服务器

  1. 自动启动: 扩展激活时自动启动(如果 autoStart 为 true)
  2. 手动启动:
    • 命令面板: VSCode Internal Command MCP Server: Start Server
    • 或点击状态栏中的 🚀 VSCode internal command MCP 按钮

服务器地址

  • MCP 端点: http://localhost:8080/mcp
  • 健康检查: http://localhost:8080/health

状态监控

  • 状态栏显示: 🚀 VSCode internal command MCP 🟢 (运行中) / 🚀 VSCode internal command MCP 🔴 (已停止)
  • 命令面板: VSCode Internal Command MCP Server: Show Status 查看详细状态

🛠️ 可用工具 (MCP Tools)

1. execute_vscode_command

执行 VSCode 内部命令

参数:

typescript
{
  command: string;      // VSCode 命令 ID
  arguments?: string[]; // 命令参数(可选)
}

异步执行响应示例:

json
{
    "success": true,
    "async": true,
    "taskId": "bg_task_1_1756952250790",
    "message": "命令 'composer.cancelComposerStep' 已提交到后台执行,将在 1000ms 后执行",
    "command": "composer.cancelComposerStep",
    "arguments": [],
    "executionDelay": 1000,
    "queueLength": 1,
    "taskStats": {
        "total": 1,
        "pending": 1,
        "running": 0,
        "completed": 0,
        "failed": 0,
        "cancelled": 0
    }
}

2. list_vscode_commands

列出所有可用的 VSCode 命令

参数: 无

返回: 命令列表(前20个,如果超过会显示省略提示)

3. get_workspace_info

获取当前工作区信息

参数: 无

返回:

typescript
{
    name: string; // 工作区名称
    folders: Array<{
        // 工作区文件夹
        name: string;
        uri: string;
    }>;
    activeEditor: string; // 当前活动编辑器文件路径
}

🔌 客户端连接

使用官方 MCP SDK

typescript
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';

const transport = new StreamableHTTPClientTransport(new URL('http://localhost:8080/mcp'), {
    requestInit: {
        headers: {
            'Content-Type': 'application/json',
            Accept: 'application/json, text/event-stream',
        },
    },
});

const client = new Client({
    name: 'vscode-mcp-client',
    version: '1.0.0',
});

// 连接并使用
await client.connect(transport);

// 调用工具
const result = await client.callTool({
    name: 'execute_vscode_command',
    arguments: {
        command: 'editor.action.formatDocument',
    },
});

console.log('Command result:', result);

使用 Cursor

在 Cursor 中配置 MCP 服务器:

json
{
    "mcpServers": {
        "vscode-internal-commands": {
            "url": "http://localhost:8080/mcp",
            "transport": "http"
        }
    }
}

使用 curl 测试

bash
# 健康检查
curl http://localhost:8080/health

# 列出工具
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

# 执行命令
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "execute_vscode_command",
      "arguments": {
        "command": "workbench.action.files.save"
      }
    }
  }'

🏗️ 技术架构

核心组件

┌─────────────────────────┐
│   VSCode Extension      │
├─────────────────────────┤
│   FastMcpServer         │ ← 基于 FastMCP 框架
├─────────────────────────┤
│   ServerManager         │ ← 服务器管理和状态
├─────────────────────────┤
│   CommandExecutor       │ ← VSCode 命令执行器
├─────────────────────────┤
│ BackgroundTaskExecutor  │ ← 后台任务执行器
├─────────────────────────┤
│   TaskProvider          │ ← VS Code 任务提供者
└─────────────────────────┘

技术栈

  • 框架: FastMCP - TypeScript MCP 服务器框架
  • 协议: Model Context Protocol (MCP)
  • 传输: HTTP Streaming with Server-Sent Events (SSE)
  • 验证: Zod Schema 验证
  • 平台: VSCode Extension API
  • 异步执行: 基于 setInterval 的后台任务队列

网络协议

  • 传输类型: httpStream
  • 内容类型: text/event-stream
  • 支持协议: HTTP/1.1
  • CORS: 默认启用

异步执行机制

  • 任务队列: 基于 Map 数据结构的内存队列
  • 执行器: 使用 setInterval 定期检查待执行任务
  • 状态管理: 支持 pending、running、completed、failed、cancelled 状态
  • 延时执行: 支持配置延时,任务在指定时间后执行
  • 通知系统: 可选的执行完成通知

🔧 开发

项目结构

vscode-internal-command-mcp-server/
├── src/
│   ├── extension.ts              # 扩展入口点
│   ├── fastMcpServer.ts         # FastMCP 服务器实现
│   ├── serverManager.ts         # 服务器管理器
│   ├── commandExecutor.ts       # VSCode 命令执行器
│   ├── backgroundTaskExecutor.ts # 后台任务执行器
│   └── taskProvider.ts          # VS Code 任务提供者
├── out/                         # 编译输出
├── package.json                 # 扩展配置和依赖
├── tsconfig.json               # TypeScript 配置
└── README.md                   # 项目文档

开发命令

bash
# 开发模式编译
npm run compile

# 监视模式编译
npm run watch

# 启动开发
code . # 打开 VSCode,按 F5 启动调试

调试

  1. 在 VSCode 中打开项目
  2. 按 F5 启动扩展开发主机
  3. 在新窗口中测试扩展功能
  4. 查看调试控制台输出

🧪 测试

使用内置测试工具

  1. 启动服务器后,使用命令: VSCode Internal Command MCP Server: Test MCP Tools
  2. 选择要测试的工具
  3. 输入必要的参数
  4. 查看执行结果

使用 FastMCP CLI

bash
# 使用 FastMCP 开发工具测试
npx fastmcp dev src/fastMcpServer.ts

# 使用 MCP Inspector 检查
npx fastmcp inspect src/fastMcpServer.ts

🛡️ 安全考虑

命令白名单

为了安全起见,建议配置 allowedCommands 白名单:

json
{
    "vscode-internal-command-mcp-server.allowedCommands": [
        "editor.action.formatDocument",
        "workbench.action.files.save",
        "workbench.action.files.saveAll",
        "editor.action.clipboardCopyAction",
        "editor.action.clipboardPasteAction"
    ]
}

网络安全

  • 默认只监听 localhost,避免外部访问
  • 支持 CORS,但建议在生产环境中配置适当的源限制
  • 所有命令执行都在 VSCode 安全上下文中进行

异步执行安全

  • 任务队列在内存中管理,扩展关闭时自动清理
  • 支持任务取消和状态监控
  • 执行失败时提供详细错误信息

📝 更新日志

v0.0.2 (当前版本)

  • ✅ 重构异步执行机制,使用后台任务队列
  • ✅ 修复配置刷新问题,确保配置变更立即生效
  • ✅ 优化任务状态管理和监控
  • ✅ 改进错误处理和日志记录
  • ✅ 简化代码结构,移除冗余组件

v0.0.1

  • ✅ 基于 FastMCP 框架实现 MCP 服务器
  • ✅ 支持 HTTP Streaming 和 SSE
  • ✅ 实现三个核心工具:命令执行、命令列表、工作区信息
  • ✅ 状态栏集成和实时监控
  • ✅ 健康检查端点
  • ✅ Zod Schema 参数验证
  • ✅ TypeScript 5.9+ 支持

🤝 贡献

欢迎提交 Issue 和 Pull Request!

开发指南

  1. Fork 项目
  2. 创建功能分支: git checkout -b feature/amazing-feature
  3. 提交更改: git commit -m 'Add amazing feature'
  4. 推送分支: git push origin feature/amazing-feature
  5. 创建 Pull Request

📄 许可证

MIT License - 详见 LICENSE 文件

🙏 致谢

📞 支持

如果您遇到问题或有疑问:

  1. 查看 Issues
  2. 创建新的 Issue
  3. 查看 FastMCP 文档: https://github.com/punkpeye/fastmcp

🚀 让 VSCode 成为您的 MCP 服务器,释放无限可能!

Installation

TypingMind
{
  "mcpServers": {
    "vscode-internal-command-mcp-server": {
      "command": "node",
      "args": [
        "./out/stdio-server.js"
      ]
    }
  }
}

Use VSCode 内部命令 MCP 服务器 MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once VSCode 内部命令 MCP 服务器 is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. You can run MCP locally on your device or connect to a remote MCP server URL.

Option 1: Use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add VSCode 内部命令 MCP 服务器 as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the VSCode 内部命令 MCP 服务器 MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "vscode-internal-command-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "vscode-internal-command-mcp-server"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the VSCode 内部命令 MCP 服务器 MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the VSCode 内部命令 MCP 服务器 MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use VSCode 内部命令 MCP 服务器 to help me with this task?
VSCode 内部命令 MCP 服务器
Sure. I read it.
Here is what I found using VSCode 内部命令 MCP 服务器.

Option 2: Add an MCP server URL

Use this when VSCode 内部命令 MCP 服务器 is already hosted remotely or your team wants one shared connector that multiple users can access.

1

Open MCP connectors

In TypingMind, go to Plugins, open MCP connectors, then choose Add URL.

  1. Open TypingMind in your browser.
  2. Go to Plugins.
  3. Open MCP connectors.
  4. Click Add URL.
TypingMind Add Custom MCP Server URL form
2

Paste the server URL

Enter the MCP server URL from the provider in the Server URL field. Add a connection name, description, icon, custom HTTP headers, or OAuth client settings if the server requires them.

  1. Paste the MCP server URL from the provider into the Server URL field.
  2. Enter a connection name for VSCode 内部命令 MCP 服务器.
  3. Add a description and icon if you want it to be easier to identify.
  4. Add custom HTTP headers or OAuth client details if the server requires authentication.
3

Create the connection

Click Create connection, then return to the Plugins list and confirm the new MCP connection is active.

  1. Click Create connection.
  2. Return to the MCP connectors list.
  3. Confirm the VSCode 内部命令 MCP 服务器 connection appears as active.
  4. Refresh the plugin list if the connection does not appear immediately.
4

Switch models without reconnecting

Start a chat with your preferred model, enable the VSCode 内部命令 MCP 服务器 tools from Plugins, and switch to another model whenever needed. The MCP connection stays available to the TypingMind workspace.

  1. Start a new chat in TypingMind.
  2. Select the AI model you want to use.
  3. Enable the VSCode 内部命令 MCP 服务器 tools from Plugins.
  4. Ask the model to use the tool when needed.
  5. Switch to another AI model and reuse the same MCP connection.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use VSCode 内部命令 MCP 服务器 to help me with this task?
VSCode 内部命令 MCP 服务器
Sure. I read it.
Here is what I found using VSCode 内部命令 MCP 服务器.

Frequently asked questions

What is the VSCode 内部命令 MCP 服务器 MCP server used for?

VSCode 内部命令 MCP 服务器 is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use VSCode 内部命令 MCP 服务器 MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use VSCode 内部命令 MCP 服务器 with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use VSCode 内部命令 MCP 服务器 MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With VSCode 内部命令 MCP 服务器 connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect VSCode 内部命令 MCP 服务器 MCP to TypingMind?

VSCode 内部命令 MCP 服务器 can be connected in TypingMind with the local MCP connector or by adding a remote MCP server URL. Use the local connector when the server needs access to files, apps, or private resources on your device, and use a server URL when the MCP server is hosted remotely.

What tools does VSCode 内部命令 MCP 服务器 MCP provide in TypingMind?

VSCode 内部命令 MCP 服务器 exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use VSCode 内部命令 MCP 服务器 MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If VSCode 内部命令 MCP 服务器 requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇