使用说明
MCP工具包服务器
MCP(模型上下文协议)服务器实现工具、资源和提示,带有依赖注入的提供者和用于演示的模拟模式。
概述
MCP服务器的顶层实现,使用 @modelcontextprotocol/sdk展示了2025 MCP规范的所有特性:
- 工具:文本分析(摘要、情感、实体)、Brave网络搜索、天气、smart_summarize(采样)、configure_analysis(启发)
- 采样:
smart_summarize发送sampling/createMessage连接到已连接的客户端(双向MCP) - 引出:
configure_analysis用途elicitation/create用于结构化用户跟进问题 - 工具注释:所有工具包括
readOnlyHint,idempotentHint,destructiveHint,openWorldHint根据2025年MCP规范 - 输出方案:文本分析工具声明结构化输出模式
- 资源:服务器配置、工具目录、运行状况
- 提示:研究主题、文本分析、天气简报模板
- 生产供应商:真正勇敢的搜索API和OpenWeatherMap当
MCP_MODE=production
默认情况下,所有操作都以模拟模式运行-不需要API键。
特性
| 特性 | 描述 |
|---|---|
| 7 MCP工具 | 总结、情感、实体、勇敢搜索、天气、智能总结、配置分析 |
| MCP采样 | smart_summarize 向客户端发送采样/创建消息 |
| MCP激发 | configure_analysis 使用JSON模式进行启发/创建 |
| 工具注释 | 2025规范readOnly提示、幂等提示、解构提示、openWorldHint |
| outputSchema | 文本分析工具的结构化输出模式 |
| 3资源 | 配置、工具目录、健康检查 |
| 3个提示模板 | 研究、分析、天气简报 |
| 模拟模式 | 确定性响应,无API键 |
| 制作模式 | 真勇敢搜索API+OpenWeatherMap |
| 提供者DI | 通过以下方式在运行时交换模拟/生产 MCP_MODE |
| Zod验证 | 类型安全输入模式 |
| 结果类型 | 显式错误处理 |
安装
npm install -g @jstilb/mcp-toolkit-server
或者直接运行而不安装:
npx @jstilb/mcp-toolkit-server
或克隆开发:
git clone https://github.com/jstilb/mcp-toolkit-server.git
cd mcp-toolkit-server
npm install
快速开始
示范模式
make demo
# or
npm run demo
Claude桌面集成
添加到您的Claude桌面配置(claude_desktop_config.json):
模拟模式(不需要API键):
{
"mcpServers": {
"mcp-toolkit": {
"command": "npx",
"args": ["@jstilb/mcp-toolkit-server"],
"env": {
"MCP_MODE": "mock"
}
}
}
}
生产模式(使用真实API):
{
"mcpServers": {
"mcp-toolkit": {
"command": "npx",
"args": ["@jstilb/mcp-toolkit-server"],
"env": {
"MCP_MODE": "production",
"BRAVE_API_KEY": "your-brave-api-key",
"OPENWEATHERMAP_API_KEY": "your-openweathermap-api-key"
}
}
}
}
Claude Desktop配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 窗户:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Claude代码集成
与克劳德代码(Claude.ai/Code)一起使用:
# Add to your project's MCP config
claude mcp add @jstilb/mcp-toolkit-server
# Or run directly in a project session
claude --mcp-server "npx @jstilb/mcp-toolkit-server"
您也可以将其添加到您的 .claude/settings.json:
{
"mcpServers": {
"mcp-toolkit": {
"command": "npx",
"args": ["@jstilb/mcp-toolkit-server"],
"env": {
"MCP_MODE": "mock"
}
}
}
}
在Claude代码中使用MCP特性
连接后,Claude Code可以使用所有服务器工具:
# Summarize text with client-side LLM (sampling)
> Use smart_summarize to summarize: "Your long text here..."
# Configure analysis with follow-up questions (elicitation)
> Use configure_analysis on this text
# Search the web (mock mode returns structured mock results)
> Use brave_web_search to find "MCP protocol examples"
# Get weather
> Use get_weather for "San Francisco"
发展
bun run dev # Watch mode
bun run build # Compile TypeScript
bun run test # Run tests with coverage
建筑
src/
server.ts # MCP server setup (tools, resources, prompts)
config.ts # Environment-based configuration
result.ts # Result<T, E> type for error handling
tools/
text-analysis.ts # Summarize, sentiment, entity extraction
web-search.ts # Web search tool
weather.ts # Weather tool
resources/
index.ts # MCP resources (config, tools, health)
prompts/
index.ts # MCP prompt templates
providers/
provider.ts # Provider interfaces
mock.ts # Mock implementations
index.ts # Provider factory
看 docs/architecture.md 查看详细图表。
API 参考
工具
| 工具 | 描述 | 输入 |
|---|---|---|
summarize |
总结文本 | {text, maxLength?} |
analyze_sentiment |
情绪分析 | {text} |
extract_entities |
命名实体提取 | {text, types?} |
web_search |
网络搜索 | {query, maxResults?} |
get_weather |
当前天气 | {location, unit?} |
资源
| URI | 描述 |
|---|---|
toolkit://config |
服务器配置 |
toolkit://tools |
可用工具目录 |
toolkit://health |
健康和状态 |
提示
| 名称 | 描述 | 参数 |
|---|---|---|
research_topic |
研究工作流程 | topic, depth? |
analyze_text |
文本分析工作流程 | text |
weather_briefing |
天气预报 | location |
配置
| 变量 | 默认值 | 描述 |
|---|---|---|
MCP_MODE |
mock |
mock, production,或 hybrid |
BRAVE_API_KEY |
- | 勇敢搜索API密钥(生产模式) |
OPENWEATHERMAP_API_KEY |
- | OpenWeatherMap API密钥(生产模式) |
MCP_MAX_CONCURRENT |
5 |
最大并发工具调用数 |
MCP_TOOL_TIMEOUT_MS |
30000 |
工具调用超时 |
测试
make test # All tests with coverage
make test-unit # Unit tests only
make lint # ESLint + Prettier
make type-check # TypeScript strict check
贡献
- 分叉存储库
- 创建要素分支
- 先写测试(TDD)
- 实现您的功能
- 跑
make check - 提交拉取请求
许可证
MIT许可证-请参阅 许可证 了解详情。