MCP研讨会
学习使用模型上下文协议(MCP)构建AI连接工具。
先决条件
- Node.js v20 LTS(下载)
- 代码编辑器(建议使用Cursor)
车间前设置
在研讨会之前,请确认您的环境已准备就绪:
cd pre-workshop-setup
node setup.js这将检查Node.js v20是否已安装,以及所有依赖项是否正常工作。
练习
| 练习 | 主题 | 命令 |
|---|---|---|
| 1 | 基本服务器 | npm run ex1 |
| 2 | 工具 | npm run ex2 |
| 2.1 | 错误处理 | npm run ex2.1 |
| 3 | 提示 | npm run ex3 |
| 4 | 第三方API | npm run ex4 |
| 5 | 班级结构 | npm run ex5 |
每个命令都会在以下位置打开MCP检查器http://localhost:5173服务器已预先配置。
如何使用
- 做一个练习:
npm run ex1 - 点击 连接 在检查员
- 打开
exercises/01-basic-server/src/index.ts在你的编辑器中 - 按照练习README中的说明进行操作
- 在检查器中测试您的更改
解决方案
如果遇到问题,运行解决方案以查看一个工作示例:
npm run sol1 # Solution for Exercise 1
npm run sol2 # Solution for Exercise 2
npm run sol2.1 # Solution for Exercise 2.1
npm run sol3 # Solution for Exercise 3
npm run sol4 # Solution for Exercise 4
npm run sol5 # Solution for Exercise 5故障排除
| 问题 | 解决方案 |
|---|---|
| 找不到模块 | 运行 node setup.js 再一次 |
| 端口已在使用中 | 按 Ctrl+C 停止运行服务器 |
| 检查器无法连接 | 检查终端是否有错误,验证Node.js v20 |
