my-mcp-server
My MCP Server(面向初学者)
自制 MCP(Model Context Protocol)服务器,包含:
通过
.env文件配置自己的 API key 和 URL示例工具:
echo和call_my_api可直接用 MCP Inspector 测试
可直接在 VS Code(GitHub Copilot Chat)中使用
1. 安装依赖
npm installRelated MCP server: mcp-server-demo
2. 创建 .env 文件
将 .env.example 复制为 .env,然后填入你自己的 API key 和 URL:
Copy-Item .env.example .env.env 文件内容:
MY_API_KEY=api-key-asli-kamu
MY_API_BASE_URL=https://api.contohkamu.com
MCP_SERVER_NAME=my-mcp-server⚠️ 切勿将
.env文件提交到 git。该文件已通过.gitignore自动忽略。
3. 构建项目
npm run build此命令会将 src/ 中的 TypeScript 编译为 build/ 中的 JavaScript。
4. 使用 MCP Inspector 测试
MCP Inspector 是一款基于浏览器的可视化工具,无需其他客户端即可测试你的 MCP 工具。
npm run inspector这将运行 npx @modelcontextprotocol/inspector node build/index.js 并在浏览器中打开 Inspector。在那里你可以:
点击 工具 标签页
选择工具
echo或call_my_api填写参数,点击 运行工具,查看结果
5. 直接在 VS Code 中使用
已准备好 .vscode/mcp.json 文件。打开命令面板 → MCP: List Servers → 选择 my-mcp-server → Start Server。该服务器会自动通过 envFile 读取 .env。
项目结构
├── .env # rahasia kamu (tidak di-commit)
├── .env.example # contoh isi .env
├── .vscode/mcp.json # konfigurasi MCP untuk VS Code
├── src/
│ ├── config.ts # loader environment variable
│ ├── apiClient.ts # modul pemanggilan API eksternal (pakai API key & URL)
│ └── index.ts # server MCP utama + daftar tool
├── package.json
└── tsconfig.json添加新工具
在 src/index.ts 中添加新的 server.registerTool("nama_tool", { ... }, async (input) => { ... }) 代码块,然后重新运行 npm run build。
故障排查
错误:“环境变量 ... 未填写” → 请确保
.env文件已存在并已填写。工具
call_my_api失败 → 检查MY_API_BASE_URL和MY_API_KEY是否正确,以及 API 端点是否支持Authorization: Bearer <key>请求头。Inspector 无法打开 → 请确保已先运行
npm run build。
This server cannot be deployed
Maintenance
Related MCP Connectors
Remote MCP for 1,500+ APIs. Vault-managed credentials; OAuth or API key. Search, load, and execute.
Give any MCP-compatible AI assistant a builder for live, hosted web tools and workflows.
MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables users to expose arbitrary HTTP APIs as configurable MCP tools by defining tool specifications in a JSON configuration file.2,323 npm3-
- FlicenseNot gradedqualityDmaintenanceEnables AI clients to connect to example tools, resources, and prompts over MCP, demonstrating integration with IDEs, chatbots, and agent frameworks.-
- FlicenseNot gradedqualityCmaintenanceEnables MCP clients to search GitHub repositories and users, retrieve weather data and forecasts, and access NASA astronomy and image data through modular MCP tools.-
- AlicenseNot gradedqualityCmaintenanceEnables interaction with Infor systems by exposing verified HTTP/SOAP requests as MCP tools, supporting multiple services, configurable authentication, and extensible request definitions.Apache 2.0