项目:MCP服务器与Books API集成
作者:纳文·库马尔
先决条件-安装
- NodeJS最新版本
- Git
- 带有“Github Copilot”和“Github Copilot Chat”扩展的Visual Studio代码
- Nodemon全局包(
npm install -g nodemon 在cmd中) - Mongo数据库(仅当使用本地Mongo服务器时-首选)
运行MongoDB并添加DB种子
"C:\Users\user-1\Downloads\mongodb-win32-x86_64-windows-8.0.10\bin\mongod.exe" --dbpath="C:\Users\user-1\Downloads\mongodb-1\db" --logpath="C:\Users\user-1\Downloads\mongodb-1\logs\mongod.log"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"1\",\"title\":\"The Pragmatic Programmer\",\"author\":\"Andrew Hunt\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"2\",\"title\":\"Clean Code\",\"author\":\"Robert C. Martin\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"3\",\"title\":\"Design Patterns\",\"author\":\"Erich Gamma\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"4\",\"title\":\"Refactoring\",\"author\":\"Martin Fowler\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"5\",\"title\":\"You Don’t Know JS\",\"author\":\"Kyle Simpson\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"6\",\"title\":\"JavaScript: The Good Parts\",\"author\":\"Douglas Crockford\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"7\",\"title\":\"The Mythical Man-Month\",\"author\":\"Frederick P. Brooks Jr.\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"8\",\"title\":\"Working Effectively with Legacy Code\",\"author\":\"Michael Feathers\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"9\",\"title\":\"Structure and Interpretation of Computer Programs\",\"author\":\"Harold Abelson\"}"
curl -X POST http://localhost:12345/books/create -H "Content-Type: application/json" -d "{\"id\":\"10\",\"title\":\"Domain-Driven Design\",\"author\":\"Eric Evans\"}"
- 使用连接字符串更新MONGO_URI的config.ts。以下使用本地MONGO-db服务器的示例配置。
const MONGO_URI = "mongodb://localhost:27017";
通过命令提示符运行应用程序
npm run build
nodemon
VS代码中的MCP服务器配置
- 打开VS Code用户设置(Ctrl+Shift+P>键入“settings.json”>选择带有“用户设置”的选项)并添加,
"mcp": {
"inputs": [],
"servers": {
"books-mcp-server-api": {
"command": "node",
"args": [
"C:\\naveenkumar\\mcp-server-books\\build\\src\\index.js"
]
}
}
}
- 点击
Start 或 Restart 选项显示在顶部 books-mcp-server-api.
鸣谢
- https://github.com/karthikeyanVK/感谢他的团队为让我理解这个话题所做的努力。