mcpField
S
schema-exploration

schema-exploration

github.com/langchain-ai数据与数据库30.7k1.3k 次安装今天更新
代码仓库

关于 schema-exploration

schema-exploration 是一项使用 SQL 数据库工具检查表、列、样例行、键和关联的技能,帮助 Agent 说明可用数据,并在查询前厘清表之间的关系。

主要功能

  1. 01列出数据库中的可用表
  2. 02检查列、类型和样例行
  3. 03识别主键与外键
  4. 04梳理表之间的关联
  5. 05为查询规划说明数据结构

适用场景

  1. 01查找包含相关数据的表
  2. 02说明表的列和键
  3. 03梳理分析所需的联接关系

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/langchain-ai/deepagents --skill schema-exploration

安装后在 Claude Code 中输入/schema-exploration确认已加载。

详细介绍

架构探索技能

工作流

1. 列出所有表

使用 sql_db_list_tables 工具查看数据库中所有可用的表。

这会返回你可以查询的完整表列表。

2. 获取指定表的架构

使用 sql_db_schema 工具并传入表名,查看以下内容:

  • 列名 - 有哪些可用字段
  • 数据类型 - INTEGER、TEXT、DATETIME 等
  • 示例数据 - 3 行示例,帮助理解内容
  • 主键 - 行的唯一标识符
  • 外键 - 与其他表的关联关系
3. 梳理关系

识别表之间的连接方式:

  • 查找以 "Id" 结尾的列(例如 CustomerId、ArtistId)
  • 外键指向其他表中的主键
  • 记录父子关系
4. 回答问题

提供以下方面的清晰信息:

  • 可用的表及其用途
  • 列名及其包含的内容
  • 表之间的关联方式
  • 用于说明内容的示例数据

示例:"有哪些表可用?"

第 1 步: 使用 sql_db_list_tables

响应:

The Chinook database has 11 tables:
1. Artist - Music artists
2. Album - Music albums
3. Track - Individual songs
4. Genre - Music genres
5. MediaType - File formats (MP3, AAC, etc.)
6. Playlist - User-created playlists
7. PlaylistTrack - Tracks in playlists
8. Customer - Store customers
9. Employee - Store employees
10. Invoice - Customer purchases
11. InvoiceLine - Individual items in invoices

示例:"Customer 表有哪些列?"

第 1 步: 使用 sql_db_schema 并传入表名 "Customer"

响应:

The Customer table has these columns:

- CustomerId (INTEGER) - Primary key, unique customer ID
- FirstName (NVARCHAR) - Customer's first name
- LastName (NVARCHAR) - Customer's last name
- Company (NVARCHAR) - Company name (optional)
- Address, City, State, Country, PostalCode - Location fields
- Phone (NVARCHAR) - Phone number
- Fax (NVARCHAR) - Fax number
- Email (NVARCHAR) - Email address
- SupportRepId (INTEGER) - Foreign key to Employee table

Sample data shows customers like:
- Luís Gonçalves from Brazil
- Leonie Köhler from Germany
- François Tremblay from Canada

示例:"如何查询每位艺术家的收入?"

第 1 步: 确定所需的表

  • Artist(包含艺术家名称)
  • Album(将艺术家与曲目关联)
  • Track(将专辑与销售记录关联)
  • InvoiceLine(包含销售数据)
  • Invoice(包含收入总额)

第 2 步: 梳理关系

Artist (ArtistId)
  ↓ 1:many
Album (ArtistId, AlbumId)
  ↓ 1:many
Track (AlbumId, TrackId)
  ↓ 1:many
InvoiceLine (TrackId, UnitPrice, Quantity)

响应:

To find revenue by artist, you'll need to:
1. Start with the Artist table
2. JOIN to Album on ArtistId
3. JOIN to Track on AlbumId
4. JOIN to InvoiceLine on TrackId
5. SUM the revenue (UnitPrice * Quantity)
6. GROUP BY artist name

This requires the query-writing skill to execute.

质量指南

对于"列出表"类问题:

  • 显示所有表名
  • 为每个表添加简要说明其内容
  • 对相关表进行分组(例如音乐目录、交易、人员)

对于"描述表"类问题:

  • 列出所有列及其数据类型
  • 说明每列包含的内容
  • 展示示例数据以提供上下文
  • 注明主键和外键
  • 说明与其他表的关联关系

对于"如何查询 X"类问题:

  • 确定所需的表
  • 梳理 JOIN 路径
  • 解释关系链
  • 建议后续步骤(使用 query-writing 技能)

评论

支持 Markdown