MCP Tools Guide
建立型別安全的 MCP 工具
手動建立 MCP 工具需要理解複雜的巨集系統與型別限制。本技能提供使用 rmcp crate 建立型別安全工具的專家指引,涵蓋自動綱要生成、驗證與 async 模式。
تنزيل ZIP المهارة
رفع في Claude
اذهب إلى Settings → Capabilities → Skills → Upload skill
فعّل وابدأ الاستخدام
اختبرها
استخدام "MCP Tools Guide". How do I create an MCP tool with optional parameters?
النتيجة المتوقعة:
- Use Option<T> for optional parameters in your tool methods:
- ```rust
- #[tool(tool_box)]
- impl SearchService {
- #[tool(description = "Search with optional filters")]
- async fn search(
- &self,
- query: String,
- limit: Option<u32>,
- offset: Option<u32>,
- ) -> Vec<String> {
- let limit = limit.unwrap_or(10);
- // Search logic
- vec![]
- }
- }
- ```
استخدام "MCP Tools Guide". What return types can MCP tools use?
النتيجة المتوقعة:
- MCP tools support various return types:
- 1. **Simple types**: i32, String, bool, etc.
- 2. **Complex objects**: Structs deriving Serialize, Deserialize, JsonSchema
- 3. **Collections**: Vec<T> for arrays
- 4. **Result types**: Result<T, Error> for error handling
- Example Result return:
- ```rust
- async fn fetch(&self, id: String) -> Result<String, ServiceError> {
- // Return Ok or Err(ServiceError::NotFound)
- }
- ```
التدقيق الأمني
آمنDocumentation-only skill. Static scanner flagged Rust code examples in markdown documentation as security patterns. All findings are false positives. The SKILL.md file contains educational code examples, not executable code with security implications. No actual external commands, network calls, or credential access patterns exist in this skill.
درجة الجودة
ماذا يمكنك بناءه
學習 MCP 工具基礎
新手開發者可透過引導範例理解 MCP 工具的核心概念,包括 #[tool] 巨集系統、參數型別與工具呼叫模式。
建置生產環境工具
有經驗的開發者可參考 CRUD 操作、驗證、錯誤處理與效能最佳化模式,用於建置實際的 MCP 伺服器。
設計 API 整合
建立外部 API 整合的開發者可學習服務結構化、憑證安全處理與 async 作業管理的最佳實務。
جرّب هذه الموجهات
Show me how to create a simple MCP tool that adds two numbers together using the rmcp crate. Include the tool_box declaration and async method.
How do I define a tool that accepts a complex object with multiple fields? Show me how to use #[tool(aggr)] and derive the required traits.
What is the best way to handle errors in MCP tools? Show me how to use thiserror to create custom error types that integrate with the tool result system.
Show me a complete CRUD implementation pattern for MCP tools. Include state management, validation, and proper async patterns.
أفضل الممارسات
- 使用強型別作為參數而非泛用字串,以啟用編譯期驗證並提升 AI 的理解能力
- 提供清楚且具描述性的工具說明,解釋 AI 何時以及如何使用該工具
- 以可採取行動的錯誤訊息實作正確的錯誤處理,協助 AI 從失敗中復原
تجنب
- 避免在 async 工具中使用阻塞操作;請使用 tokio::fs 與其他 async 變體取代 std::fs
- 不要在未嚴格驗證與清理的情況下接受原始 SQL 或命令字串作為參數
- 避免將工具緊密耦合到特定資料庫實作;請抽象化資料存取模式