教程:在Visual Studio代码中运行两个MCP服务器
一个教程,用于构建Go和部署以及MCP服务器,部署Node 1并使用Visual Studio Code作为MCP客户端。
概述
截至2025年4月,大多数MCP教程和演示目前都针对Claude Desktop应用程序。但是,如果您有带有代理模式的GitHub Copilot,并使用Visual Studio Code作为MCP客户端,您也可以执行开发和测试。
MCP服务器正在用多种语言编写。本指南实现了两个MCP服务器。一个在Go中,另一个在Node(bun.sh)中。Go MCP服务器基于MCP-Go包,Go服务器基于包仓库中的一个示例。Node包是我正在开发的用于获取表模式的东西。
什么是MCP服务器
MCP(模型上下文协议)服务器是一个轻量级程序,旨在通过标准化的模型上下文协议公开特定功能。该协议允许应用程序安全有效地向大型语言模型(LLM)提供上下文。
将MCP服务器视为将LLM连接到本地和远程各种数据源和工具的桥梁。它们使LLM能够以受控的方式访问文件、数据库、API和其他服务并与之交互。这使得构建复杂的工作流程和将AI模型与不同系统集成变得更加容易。
参考文献
需求
- Visual Studio Code
- 具有代理模式的Github Copilot
- 一些Go知识和Go安装
- 一些Node知识(或bun.sh)和已安装的Node或bun
在Windows中构建和部署服务器
构建Go服务器
MCP Go软件包
在我的测试中,我使用了以下示例代码:
- Go包:
mcp-go - 服务器代码: mcp go/示例/一切
构建Go服务器
- 克隆此仓库
- 将目录更改为:
server - 获取所需的软件包:
go mod tidy - 构建了mcp服务器:
go build . - 复制完整的可执行路径:
C:\Users\user\git\msalemor\mcp-vscode-tutorial\go-server\mcpgo.exe
部署Go服务器
- 打开Github Copilot聊天
- 将副驾驶更改为代理模式
- 
- 在“代理”窗格中,单击“工具”
- 在顶部栏弹出窗口中,单击
+ Add More Tools
- 
- 在顶部栏弹出窗口中,单击
+ Add MCP Server
- 
- 在顶部栏弹出窗口中,选择
Command (stdio)
- 
- 在要运行的命令上,将完整路径粘贴到Go可执行文件
- 根据需要命名服务器
- 将MCP配置保存为用户(全局)或工作区(仅适用于项目)设置
- 如果选择工作区,Visual Studio将在以下位置生成以下设置
.vscode/mcp.json
{
"servers": {
"mcpgo1": {
"type": "stdio",
"command": "C:\\Users\\user\\git\\msalemor\\mcp-vscode-tutorial\\go-server\\mcpgo.exe",
"args": []
}
}
}- 启动服务器
- 
- VSCode应显示5个工具(如果您没有添加其他工具)
部署节点服务器
- 打开
.vscode/mcp.json文件 - 添加节点
bun-serverMCP配置如下: - > 注意:我使用bun.sh而不是node
{
"servers": {
"mcpgo-server": {
"type": "stdio",
"command": "C:\\Users\\user\\git\\msalemor\\mcp-vscode-tutorial\\go-server\\mcpgo.exe",
"args": []
},
"bun-server": {
"type": "stdio",
"command": "bun", // change to Node if using node and do not add this comment
"args": [
"run",
"C:\\Users\\user\\git\\msalemor\\mcp-vscode-tutorial\\node-server\\index.ts"
]
}
}
}运行服务器
- 确保两台服务器都在运行
- Status srvers running in the MCP configuration
- 如果它们没有运行,请单击开始
测试服务器
- 创建一个名为的文件:
types.go - 确保该文件是代理上下文
- 在代理类型中:
Get the table schema for users. Create a structure for the schema. Notify the user when done.
预期结果
服务器正在运行
在屏幕截图中,我们可以看到MCP服务器正在运行,并且在VSCode中注册了6个工具。我们还可以看到,Agent使用了两个工具来创建Go types.go 基于的文件 users 模式。
示例查询和结果
- 在“代理”窗口中键入:
Get the table schema for users. Create a structure based on the schema. Notify the user when done. - 按 Enter
