المهارات MCP Tools Guide
📦

MCP Tools Guide

آمن

建立型別安全的 MCP 工具

手動建立 MCP 工具需要理解複雜的巨集系統與型別限制。本技能提供使用 rmcp crate 建立型別安全工具的專家指引,涵蓋自動綱要生成、驗證與 async 模式。

يدعم: Claude Codex Code(CC)
⚠️ 66 ضعيف
1

تنزيل ZIP المهارة

2

رفع في Claude

اذهب إلى Settings → Capabilities → Skills → Upload skill

3

فعّل وابدأ الاستخدام

اختبرها

استخدام "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)
  • }
  • ```

التدقيق الأمني

آمن
v1 • 1/23/2026

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.

1
الملفات التي تم فحصها
698
الأسطر التي تم تحليلها
0
النتائج
1
إجمالي عمليات التدقيق
لا توجد مشكلات أمنية
تم تدقيقه بواسطة: claude

درجة الجودة

38
الهندسة المعمارية
100
قابلية الصيانة
87
المحتوى
20
المجتمع
100
الأمان
61
الامتثال للمواصفات

ماذا يمكنك بناءه

學習 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 或命令字串作為參數
  • 避免將工具緊密耦合到特定資料庫實作;請抽象化資料存取模式

الأسئلة المتكررة

什麼是 rmcp crate?
rmcp crate 是用於建置 MCP(Model Context Protocol)伺服器的 Rust 函式庫。它提供用於定義工具的 #[tool] 巨集系統、自動綱要生成,以及與 MCP 用戶端溝通的基礎架構。
我需要手動衍生 traits 嗎?
是的,對於複雜參數,你需要衍生 Deserialize、Serialize 與 JsonSchema。rmcp crate 會用這些來解析參數並自動產生綱要,讓 AI 助手理解你的工具。
工具可以存取環境變數嗎?
MCP 工具可以透過 std::env 存取環境變數,但應謹慎處理。像 API keys 這類敏感值應在初始化時存入服務結構中,而非每次呼叫都讀取。
如何測試 MCP 工具?
像測試任何 async Rust 程式碼一樣,使用 tokio::test 測試 MCP 工具。你可以直接實例化服務並呼叫方法。針對整合測試,可考慮透過 list_tools 與 call_tool 方法測試工具呼叫流程。
什麼是好的工具描述?
好的描述會說明工具的用途、可接受的參數,以及 AI 何時該使用它。請具體說明限制與回傳值,避免含糊的語言讓 AI 不清楚何時要呼叫該工具。
我可以在工具參數中使用 enums 嗎?
是的,enum 很適合用於受限制的選項。請定義一個帶有 #[derive(Deserialize, Serialize, JsonSchema)] 的 enum,並使用像 #[serde(rename_all = "lowercase")] 的 serde 屬性,以生成整潔的綱要。

تفاصيل المطور

بنية الملفات

📄 SKILL.md