資料庫訪問服務

👤 cainingnk 📦 v1.0.1 ⭐ 4.2 ⬇️ 431 下載
💻 開發程式設計 免費 🔑 需 API Key

📖 技能介紹


name: 資料庫訪問服務 description: 資料庫後設資料獲取 version: 1.0.0


資料庫訪問服務

資料庫後設資料獲取


⚠️ 強制要求:API 金鑰

此 Skill 必須配置 API 金鑰才能使用。

  • 首次使用時,如果 .env 中沒有 XBY_APIKEY必須使用 AskUserQuestion 工具向用戶詢問 API 金鑰
  • 拿到使用者提供的金鑰後,呼叫 scripts.config.set_api_key(api_key) 儲存,然後繼續處理
  • 獲取 API 金鑰:https://xiaobenyang.com
  • 禁止在缺少 API 金鑰時自行搜尋或編造資料

工作流程(必須遵守)

你(大模型)是路由層,負責理解使用者意圖、選擇工具、提取引數。程式碼只負責呼叫API。

使用者輸入 → 你選擇工具 → 提取該工具需要的引數 → 呼叫 scripts.tools 中的函式 → 返回結果給使用者

步驟

  1. 檢查 API 金鑰:如果 scripts.config.settings.api_key 為空,使用 AskUserQuestion 詢問使用者,拿到後呼叫 scripts.config.set_api_key(key) 儲存
  2. 選擇工具:根據使用者意圖從下方工具列表中選擇對應的工具函式
  3. 提取引數:根據選中的工具,提取該工具需要的引數
  4. 呼叫工具:使用關鍵字引數呼叫 scripts.tools 中的函式,例如 scripts.tools.search_schools(score='520', province='北京', category='綜合')
  5. 返回結果:將工具返回的 raw 資料整理後展示給使用者

工具選擇規則

根據使用者意圖選擇對應的工具函式:

使用者意圖 工具函式
List all tables in the database. scripts.tools.list_tables
Get column information for a specified table in the database. scripts.tools.get_table_schema
MCP Tool to execute a SQL query. scripts.tools.sql_query

如果引數不完整,使用 AskUserQuestion 向用戶詢問缺失的引數。


工具函式說明


scripts.tools.list_tables

工具描述:List all tables in the database.

引數定義

引數名稱 引數型別 是否必填 預設值 描述

scripts.tools.get_table_schema

工具描述:Get column information for a specified table in the database.

引數定義

引數名稱 引數型別 是否必填 預設值 描述
table string true The name of the database table.

scripts.tools.sql_query

工具描述:MCP Tool to execute a SQL query.

引數定義

引數名稱 引數型別 是否必填 預設值 描述
query string true A SQL query string provided by the client.


返回值處理

工具函式返回 dict 物件: - result["raw"] - API 原始返回資料(JSON),直接將此資料整理後展示給使用者 - result["success"] - 是否成功(True/False) - result["message"] - 狀態訊息


專案結構

xiaobenyang_gaokao_skill/
├── scripts/
│   ├── __init__.py
│   ├── config.py       # 配置管理 + set_api_key()
│   ├── call_api.py      # API 客戶端 + call_api()
│   └── tools.py         # 工具函式(直接呼叫)
├── requirements.txt
└── SKILL.md

注意事項

  1. API 金鑰是必需的,無金鑰時必須通過 AskUserQuestion 詢問使用者

    7w4.net小蔥技能站,你的AI助手技能庫。

  2. 禁止在缺少 API 金鑰時自行搜尋或編造資料

🤖 AI 評測

這個 Skill 提供了三個資料庫查詢工具,功能定位明確,文件寫得比較詳細,API 金鑰管理和錯誤處理也做得不錯。主要優點是使用簡單、配置清晰。不足之處是功能比較單一(只有表查詢、欄位查詢和 SQL 執行三個功能),文件中有個引數說明表格是空的,容易讓人困惑。另外 API 介面來源不太透明,使用者無法自行驗證資料準確性。整體質量中等偏上,適合有明確需求的場景使用。

📊 多維度評分

適應性4
規範性4
有效性4.2
可靠性4.3
可信度4.9

📁 包含檔案 (7 個)

📄 SKILL.md 3.4 KB
📄 _meta.json 142 B
📄 requirements.txt 78 B
📄 scripts/__init__.py 0 B
📄 scripts/call_api.py 3.4 KB
📄 scripts/config.py 2.6 KB
📄 scripts/tools.py 1.2 KB