异步MCP
该服务器实现了模型上下文协议(MCP),用于处理带有实时状态跟踪、强大错误处理和自动资源管理的异步任务。
可用工具 (2 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
process_task 3 个参数 需填 1 项
Start processing a task asynchronously.
必填参数:input
check_task_status 1 个参数 需填 1 项
Check the status of an async task
必填参数:taskId
服务介绍
MCP 异步服务器
🚀 一个高性能的模型上下文协议 (MCP) 服务器实现,展示了具有强大状态跟踪和错误处理功能的异步任务处理。
✨ 特性
- 🔄 异步任务处理 - 高效处理长时间运行的操作
- 📊 实时状态跟踪 - 支持轮询监控任务进度
- 🧹 自动资源管理 - 智能任务清理和内存管理
- ⏱️ 超时处理 - 可配置的任务超时
- 🛡️ 强大的错误处理 - 自定义错误类型和全面的错误报告
- 📝 TypeScript 支持 - 完全类型安全和现代 JavaScript 功能
- 🔍 内置检查器 - 轻松调试和测试您的 MCP 服务器
🚀 快速开始
前提条件
- Node.js 20.x 或更高版本
- npm 9.x 或更高版本
通过 Smithery 安装
要通过 Smithery 自动安装适用于 Claude Desktop 的 Async MCP 服务器:
npx -y @smithery/cli install @ViezeVingertjes/example-async-mcp --client claude
安装
# Clone the repository
git clone https://github.com/ViezeVingertjes/example-async-mcp.git
# Navigate to the project directory
cd example-async-mcp
# Install dependencies
npm install
# Build the project
npm run build
运行服务器
npm start
使用检查器
npm run inspector
📖 API 参考
可用工具
process_task
创建一个新的异步任务。
{
"name": "process_task",
"arguments": {
"input": "Hello, World!",
"delayMs": 5000,
"timeoutMs": 30000
}
}
| 参数 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
| input | string | ✅ | - | 要处理的输入字符串 |
| delayMs | number | ❌ | 5000 | 处理延迟(毫秒) |
| timeoutMs | number | ❌ | 30000 | 任务超时(毫秒) |
check_task_status
检查现有任务的状态。
{
"name": "check_task_status",
"arguments": {
"taskId": "550e8400-e29b-41d4-a716-446655440000"
}
}
| 参数 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| taskId | string | ✅ | 要检查的任务 ID |
任务状态
| 状态 | 描述 |
|---|---|
🕒 pending |
任务已创建但尚未开始 |
⚡ processing |
任务正在处理中 |
✅ complete |
任务成功完成 |
❌ error |
任务失败 |
⚙️ 配置
在 src/constants.ts 中的关键配置选项:
export const DEFAULT_TASK_TIMEOUT_MS = 30000; // 30 seconds
export const DEFAULT_TASK_DELAY_MS = 5000; // 5 seconds
export const DEFAULT_POLL_DELAY_MS = 10000; // 10 seconds
export const POLL_INTERVAL_MS = 100; // 100ms
export const MAX_TASKS = 1000; // Maximum concurrent tasks
🛠️ 开发
项目结构
src/
├── index.ts # Main server implementation
├── types.ts # TypeScript types and interfaces
├── constants.ts # Configuration constants
└── utils.ts # Utility functions
开发命令
# Build the project
npm run build
# Watch for changes
npm run watch
# Run tests
npm test
# Run inspector
npm run inspector
📝 许可证
此项目根据 MIT 许可证发布 - 详情请参阅 LICENSE 文件。
请注意,这里将“Made with ❤️ by the MCP community”翻译成了“由MCP社区用心制作❤️”,保持了原始的爱心符号和markdown格式。如果有特定的风格或术语要求,请告知我以便调整。