使用说明
启动器mcp服务器
具有CLI支持的现代MCP(模型上下文协议)服务器启动器模板。
特性
- 🚀 双模式:既可作为MCP服务器又可作为CLI工具
- 🔧 内置工具:天气警报和预报(NWS API)
- ♻️ 代码重用:MCP和CLI之间共享业务逻辑
- 📦 类型安全:完全支持TypeScript
- ✅ 已测试:全面的测试覆盖率
- 🎯 简单:最小的架构,易于扩展
快速开始
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run as MCP server (default)
node dist/cli.mjs
# Or use CLI commands
node dist/cli.mjs get-alerts CA
node dist/cli.mjs get-forecast 39.7456 -97.0892
# Quick start with npm scripts
pnpm cli:help # Show help
pnpm cli:alerts # Example: Get CA alerts
pnpm cli:forecast # Example: Get forecast
pnpm demo # Run full demo
CLI使用情况
# Start MCP server (no arguments)
node dist/cli.mjs
# Get weather alerts for a state
node dist/cli.mjs get-alerts CA
# Get weather forecast for a location
node dist/cli.mjs get-forecast 39.7456 -97.0892
# Show help
node dist/cli.mjs --help
有关详细的CLI文档,请参阅 CLI_USAGE.md.
MCP服务器配置
添加到您的MCP客户端配置中(例如,Claude Desktop):
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/starter-mcp-server/dist/index.mjs"]
}
}
}
或者通过npx使用:
{
"mcpServers": {
"weather": {
"command": "npx",
"args": ["-y", "starter-mcp-server@latest"]
}
}
}
发展
# Run tests
pnpm test
# Type check
pnpm typecheck
# Lint
pnpm lint
# Debug with MCP Inspector
pnpx @modelcontextprotocol/inspector node dist/index.mjs
项目结构
src/
├── lib/
│ └── weather.ts # Core business logic
├── tools/
│ ├── get-alerts.ts # MCP tool registration
│ └── get-forecast.ts
├── cli.ts # CLI entry point
├── server.ts # MCP Server instance
└── index.ts # MCP Server entry point
添加新工具
看 CLI_USAGE.md 详细说明。
快速概述:
- 在中添加业务逻辑
src/lib/ - 在中注册MCP工具
src/tools/ - 在中添加CLI命令
src/cli.ts(可选) - 更新
src/index.ts注册该工具
体系结构分析
有关项目架构和设计决策的详细分析,请参阅 建筑师_分析.md.
发布
# First release
pnpm publish
# Future releases
pnpm run release
