MDA DB MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MDA DB MCPMICS 里有没有和教育年限相关的变量?画一下它的分布"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MDA 数据库问答
用中文或英文提问,LLM 自动搜索元数据、写 SQL、返回结果并画图。 覆盖 5 个调查项目、1149 张表的社会经济调查微观数据。
由两部分组成:
MCP Server —— 把「查这个数据库」包装成 14 个标准工具。 既给自家网页用,也能直接挂到 Claude Desktop / Claude Code。
问答网页 —— 中英双语界面,API Key 在网页上配置,聊天历史本地留存。
启动
./mda_db_mcp_start.sh打开 http://localhost:3344 就能用。
指定端口:
默认端口 3344。想换:
./mda_db_mcp_start.sh 8080 # 位置参数
PORT=8080 ./mda_db_mcp_start.sh # 或环境变量其他参数:
命令 | 作用 |
| 改代码自动重载(开发用) |
| 允许局域网内其他设备访问 |
| 看全部用法 |
mda_db_mcp_start.sh 启动前会跑一遍预检 —— 依赖、端口、数据库、元数据索引、API Key。
这几项是实际最容易卡住的地方,有问题时直接告诉你怎么修,
而不是等服务起来之后丢一段 traceback:
MDA 数据库问答 —— 启动预检
依赖就绪
端口 3344 可用
数据库已连接(mda_viewer 可见 1149 张表)
元数据索引:106,291 条,0.1 天前建立
API Key 已配置(deepseek / deepseek-flash,来自本地配置)
→ http://127.0.0.1:3344
Ctrl+C 停止首次运行会自动 uv sync 装依赖、自动建立元数据索引(约 10 秒)。
怎么停
脚本会占住终端。Ctrl+C 或直接关掉终端窗口都会停止服务并释放端口。
脚本不是用 exec 交棒,而是后台跑 uvicorn 再配一个信号 trap,
为的是保证「退出时端口一定被释放」:
退出方式 | 端口释放 | 优雅关闭 |
Ctrl+C | ✓ | ✓ |
关闭终端窗口 | ✓ | 直接终止(见下) |
| ✓ | ✓(trap 转发 SIGTERM) |
| ✓ | ✗(强杀无法优雅) |
trap 会等子进程自己关(最多 3 秒),没动静才转发 SIGTERM, 再等 7 秒仍不退就强杀 —— 所以不会出现「Ctrl+C 之后终端卡住」 或者「端口被僵尸进程占着」。
关于「优雅关闭」:指 uvicorn 执行 lifespan 关闭流程,
主动结束 MCP 子进程、关掉连接池。关闭终端时(SIGHUP)uvicorn 不处理这个信号
会直接终止,但实测不会留下任何东西 —— MCP 子进程的 stdin 管道断开后
会自行退出,数据库连接由操作系统关闭 socket 时释放。
我按 Ctrl+C、关终端、kill 脚本、kill -9、以及 --dev 重载模式
五种情况逐一验证过:端口连接数和 mda_viewer 的数据库连接数都归零。
想确认有没有残留:
lsof -nP -iTCP:3344 # 应该没有输出
psql -d mda -c "select count(*) from pg_stat_activity where usename='mda_viewer'"不用脚本直接起
uv run uvicorn backend.main:app --port 3344只是少了预检。想单独跑预检:uv run python -m backend.preflight。
Related MCP server: CNBS MCP Server
首次使用
启动后点「设置」,填入 DeepSeek 或 Gemini 的 API Key:
DeepSeek:https://platform.deepseek.com/api_keys (便宜,中文好)
Gemini:https://aistudio.google.com/apikey (有免费额度)
填完点「测试连接」再保存 —— 这样配错了能立刻看到原因, 而不是存下来之后提问时才报错。
模型名是自由输入的,下拉列表只是建议。两家的模型 ID 换得很快
(DeepSeek 已从 deepseek-chat 换成 deepseek-flash,Gemini 从 2.5 一路到 3.8),
所以别写死在代码里,去控制台看当前可用的名字直接填。
Key 加密后存在 ~/.mda_db_mcp/(项目目录之外,不会被 git 提交)。
能问什么
你问 | 它做什么 |
现在哪些调查入库了? |
|
MICS 包括哪些 sections? |
|
有没有和教育年限相关的变量? |
|
|
|
画一下做饭燃料的分布 |
|
每一步的工具调用和 SQL 都实时显示,可以展开核对它写得对不对。
结构
mda_db_mcp_start.sh 一条命令启动(含预检)
mcp_server/ MCP Server —— 把「查数据库」包装成 14 个标准工具
db.py 连接池 + 通用 SQL(元数据查询、安全检查)
catalog.py 调查目录层:四个调查族三种元数据形态,用适配器统一
index.py 本地 FTS5 变量索引(建索引 + 检索排序)
variables.py 单变量统计与可视化(缺失值、加权)
server.py 工具定义,也是给 LLM 的使用说明
backend/ 网页后端
main.py FastAPI 接口
config_store.py API Key 加密存储、供应商与推理参数定义
history.py 聊天历史(SQLite)
mcp_bridge.py 后端作为 MCP 客户端,翻译工具格式给 LLM
preflight.py 启动预检(数据库 / 索引 / Key)
agent.py agent 循环:LLM ↔ 工具的来回对话
web/index.html 前端(单文件,无需构建,中英双语)
test_mcp.py 手动测试 MCP Server
grants.sql 开通蒙古 HSES/LFS 只读权限(已执行;换机器时需重跑)
revoke_grants.sql 撤销上述授权MCP Server 提供的 14 个工具
按调查结构探索
工具 | 用途 |
| 有哪些调查入库了。区分已入库可读 / 在库但无权限 / 未入库三种状态 |
| 某调查包含哪些 section。返回物理分表和问卷章节两种,附 grain 和连接键 |
| 读库内自带的 |
找变量(核心)
工具 | 用途 |
| 主要工具。在本地 FTS5 索引里按语义搜变量,< 10ms,带词干还原和相关性排序 |
| 重建索引。新数据入库或新开通 schema 权限后需要跑一次 |
| 索引状态:建立时间、条目数、各调查覆盖情况 |
看变量和画图
工具 | 用途 |
| 有多少回答、取值分布(带码值含义)、描述统计、加权结果 |
| 画条形图或直方图,图直接显示在网页上 |
通用
工具 | 用途 |
| 物理结构 |
| 搜表名/列名/注释(精确子串匹配,找变量请用 |
| 抽几行看真实取值 |
| 执行只读 SQL |
数据库里有什么
全部 5 个调查族都已开通只读访问(mda_viewer 可见 1339 张表):
调查 | 规模 | 位置 |
MICS(UNICEF 多指标簇调查) | 255 数据集 / 97 国 / MICS2–MICS6(1999–2023) |
|
DHS(人口与健康调查) | 112 调查 / 82 国 / 1985–2024 |
|
CSES(柬埔寨社会经济调查) | 10 个波次 / 2004–2021 |
|
HSES(蒙古家庭社会经济调查) | 11 个波次 / 2002–2020 / 5.9 GB |
|
LFS(蒙古劳动力调查) | 14 个波次 |
|
另有气候数据(final_CLIMATE_DAILY_ADMIN2 等)和尼泊尔生活标准调查 2022,都在 public。
权限
蒙古的 6 个 schema 最初对 mda_readonly 没有 USAGE 权限,已通过 grants.sql
开通(只授予 SELECT,角色仍是只读)。撤销用 revoke_grants.sql。
开通新 schema 后必须重建索引,否则搜不到新数据。
四个调查族,三种元数据形态
catalog.py 用「每个调查一个适配器、输出统一 10 列」的方式抹平差异:
调查 | 协调层 | 变量层 | 值标签 | section 来源 |
MICS |
| 同左 | — |
|
CSES / DHS |
|
|
| 表名正则 |
HSES |
|
|
|
|
LFS |
|
|
| 无 |
加新调查(比如将来接别的国家)只需在 PROJECTS 里加一条并写好它的
extracts SQL,五个工具全部自动生效。
两个针对具体数据的处理
HSES 的协调层有 3 个发布版本(hses-alignment-v1 / v1.1 / v1.2),
每个概念在每个版本里各存一行。工具只取最新版本 —— 版本号用 int[] 比较
而不是字符串,否则 v1.10 会被判定小于 v1.9。
HSES 只索引 concept 层,不索引原始列层:1881 个原始列名里有 1877 个
已被 concept 覆盖(它的 aligned_name 常常就是原始列名),两层都索引会让
每次搜索结果出现两份重复。
LFS 的协调变量会标注状态:8 个变量里只有 2 个是 qualified_core,
其余 6 个是 candidate_only(尚未验证)。工具把状态拼进变量说明里,
避免 LLM 把候选变量当成已验证的推荐出去。
「语义搜索」是怎么做的
find_variables 不是向量检索。语义能力来自两层配合:
LLM 扩词:你说「教育年限」,LLM 展开成
["education","schooling","grade","attainment","years attended","diploma"]本地 FTS5 索引检索排序:10 万条变量元数据,porter 词干还原 + BM25 排序
所以搜「教育年限」能同时找到 years_attended_school(教育年限)和
highest_education_level(最终学历)—— 这正是你要的「语义相关」。
为什么不直接查数据库:
实时查库 | 本地 FTS5 索引 | |
耗时 | 1.4 秒 | < 10ms |
词干还原 | 无 | ✅ education / educational 互通 |
相关性排序 | 手写 | ✅ 内置 BM25 |
数据库负载 | 每次全表扫 130 万行 | 零 |
装不了 pg_trgm / pgvector(只读角色没权限),所以索引放在本地
~/.mda_db_mcp/metadata_index.db(约 28 MB,建一次 9 秒)。
代价:索引是快照。新数据入库后要重建,否则搜不到新变量。
find_variables 会返回索引年龄,超过 30 天会附带提醒。
排序的实用性调整
除了 BM25 相关性,排序还做了几项调整,依据来自库内文档和数据分布:
canonical(协调变量,有定义和语义分类)排在source(原始列裸标签)前CP_前缀的列往前排 ——_guide的cp_prefix章节明确说跨数据集分析要优先用它们survey_specific_response类往后压 —— DHS 里有 777 个这种单一调查专用变量 (JO_2023_woman_education_recode),关键词一命中就会挤掉真正可跨国比较的变量覆盖数据集多的变量往前排
库内自带的文档(重要)
数据库的 public schema 里有三张维护者手写的文档表,比任何从 pg_catalog
推断出来的信息都权威。read_guide 工具把它们读出来给 LLM:
表 | 内容 |
| 7 章使用指南:连接约定、编码约定、协调变量清单、 |
| 每张表的 grain、连接键、说明、caveats、行数、数据集数 |
| 已知数据问题(当前 1 个未解决、63 个已修) |
里面有几条推断不出来但极其关键的规则:
CP_前缀 = carefully processed,跨数据集分析优先用这些列原始变量的缺失哨兵是 7/9、97/98/99、9997-9999;
*_harmonized/*_years已置 NULL性别 1=男 2=女;是/否通常 1=是 2=否,但 MICS2 时代(1999–2001)常是 0=否 1=是
final_WM_MICS的户标识列是hh_number,不是household_number连接键在部分表是 TEXT、部分是 DOUBLE PRECISION,跨表连接要先转类型
键只在同一
dataset_name内唯一,连接必须带上dataset_name跨国分析用
CP_country/CP_country_code,不要解析dataset_name
MCP Server 的工具说明已经把这些写给 LLM,并要求它涉及 MICS 或跨数据集比较时先读指南。
缺失值与加权
这是调查数据分析最容易出错的两点,工具层面都做了处理:
缺失值编码:98="don't know"、99="missing" 这类编码在元数据里是机器可读的
(value_labels JSONB),所以不靠猜 96–99,而是读元数据判断。
读不到时会明确说「无法判断」而不是假装没有。
抽样权重:variable_stats 和 plot_variable 会自动发现权重列
(household_weight、person_weight 等)并在返回里列出;传 weight 参数即加权。
未加权时会提示「这是样本数不是总体估计」。
实测差异:CSES 教育年限未加权均值 6.33,加权后 6.20。
界面语言
右上角按钮切换中文 / English。切换的不只是界面文案——模型的回答语言也会跟着换, 所以给客户演示时切成 English,整个界面和答案都是英文的。
语言选择存在浏览器 localStorage 里,同时同步到后端配置。
进度提示(「正在思考…」「返回 120 行 × 8 列」)也是按当前语言渲染的:
后端只发 summary_key + 参数,文案由前端拼,所以加语种不用改后端。
Markdown 渲染
LLM 的回答按 Markdown 渲染:表格、标题、列表、代码块、粗体、链接。
给客户演示时表格能正常显示,不是一堆 |---|---|。
不引 marked / DOMPurify,自己写了一个约 150 行的渲染器,原因:
保持单文件零依赖、离线可用 —— CDN 挂了不会让页面变空白
安全模型简单到能一眼看完:先把整段文本转义,之后渲染器生成的标签 就是页面上唯一的 HTML,LLM 输出和数据库内容都无法注入
占位符用 <F0> 这种形式:转义之后文本里不可能再出现 <(都成了 <),
所以用户或 LLM 无论写什么都撞不上占位符。
故意不支持 _斜体_ 和 __粗体__
这个库的变量名全是下划线。支持下划线强调会把回答毁掉:
years_attended_school → years<em>attended</em>school
q0611__2020_000cb8d1 → q0611<strong>2020</strong>000cb8d1LLM 写强调基本都用 *,所以这个取舍没有实际损失。
链接白名单
只放行 http://、https://、mailto: 和站内相对路径。
javascript:、data:、vbscript: 以及 //evil.com(协议相对 URL,会跳外站)
都拒绝,原样显示成文本。
流式渲染节流
一次回答有上百个 token,每来一个就重排表格既抖又费。
所以流式期间 120ms 渲染一次,收到 done 时立即定稿。
原文存在元素的 dataset 上,定时器回调取最新值,不会渲染到过期内容。
错误信息不走 Markdown
报错文字是我们自己生成的,里面常带 SQL 报错原文(含 *、_、| 等字符),
按纯文本显示更不容易看错。
聊天历史
自动保存,存在 ~/.mda_db_mcp/history.db(SQLite)。
为什么不存在 mda 数据库里:mda 是只读的(角色 mda_viewer 属于 mda_readonly
组),写不进去;而且调查数据库不该混进应用自己的数据。
每条助手消息除了正文,还存下:
工具调用过程(包括完整 SQL)—— 打开历史会话时会原样重现,给客户演示时可以回放
思考过程 —— 模型的推理内容
token 用量 —— 用来核对推理档位的实际开销
侧边栏操作:单击打开、双击标题重命名(自动生成的标题多半不适合给客户看)、 悬停点 × 删除。设置页有「清空全部历史」。
历史库和 API Key 一样是 600 权限,包括 SQLite 的 -wal / -shm 旁支文件
(它们装着同样的内容,只锁主库等于没锁)。
推理与 Token 控制
设置页的「推理与 Token 控制」有三个旋钮,作用范围不同:
控件 | 作用 | 什么时候用 |
推理档位 | 两家通用的标准档位 | 日常调节的首选 |
输出 token 上限 | 输出总量上限 | 限制 thinking 开销最直接的手段 |
高级:原生参数 (JSON) | 直接透传给 API | 上面两个表达不了时 |
为什么用 reasoning_effort 而不是各家的原生参数:各家把它映射到自己的原生
参数(Gemini 3.x → thinking_level,Gemini 2.5 → thinking_budget,
DeepSeek → thinking 模式档位),原生参数名一直在变,标准参数不用跟着改。
各家可选档位:
DeepSeek:
none/low/high/max,默认high。 选none关闭思考,回答更快更便宜,简单查询够用。Gemini:
none/minimal/low/medium/high。none只有 2.5 Flash 系列支持,2.5 Pro 和 3.x 系列不能关闭思考,传了会报错。
关于输出上限:思考 token 算在输出里,所以这是限制 thinking 花费最有效的办法。 但设太小会让回答被截断在半句话——建议至少留 4096。
关于高级参数:只在标准档位不够用时使用,比如要指定确切的预算:
{"google": {"thinking_config": {"thinking_level": "low", "include_thoughts": true}}}注意 reasoning_effort 和 thinking_level / thinking_budget 互斥,
同时设置会报 400。
参数被拒时不会静默降级:如果你设的档位这个模型不支持,界面会明确报错并告诉你 是哪个设置的问题——不会偷偷丢掉参数重试,那样你会以为设置生效了。
看实际花了多少:每条回答下面会显示 token:输入 8900 · 思考 100 · 输出 190,
多轮工具调用是累加的。调完档位看这一行就知道有没有效果。
DeepSeek 的一个坑:思考模式下不支持指名工具调用(required 或指定某个工具),
会返回 400。本项目用的是自动模式(auto),不受影响,但你要是改代码去指定工具,
记得先关思考。
安全设计
三层防护,任一层单独失效都不会造成数据损坏:
数据库层:连接角色
mda_viewer只属于mda_readonly组, PostgreSQL 直接拒绝任何写操作,也访问不到mng_*那几个受限 schema。连接层:连接池设
default_transaction_read_only=on, 每条查询再包一层readonly=True事务 + 30 秒超时。SQL 层:只放行
SELECT/WITH/EXPLAIN等开头的语句, 拒绝多语句,拉黑pg_read_file、dblink、COPY等函数。
另外:
查询结果用游标分页,只从数据库取需要的行数 (库里有几百 MB 的表,全量拉回来会打满内存)
单次最多返回 500 行
数据库密码不存在配置里,走
~/.pgpassAPI Key 用 Fernet 加密存
~/.mda_db_mcp/config.json, 密钥文件secret.key权限 600,都在项目目录之外,不会被 git 提交
挂到 Claude Desktop / Claude Code
这个 MCP Server 是标准实现,不止能给自家网页用。
Claude Code
在项目目录下执行,路径自动解析,不用手填:
claude mcp add mda-db \
--env MDA_DATABASE_URL=postgresql://mda_viewer@localhost:5432/mda \
-- "$(pwd)/.venv/bin/python" -m mcp_server.serverClaude Desktop
配置文件不支持变量展开,所以要填绝对路径。先在项目目录下打印出该填的值:
echo "command: $(pwd)/.venv/bin/python"
echo "cwd: $(pwd)"然后编辑 ~/Library/Application Support/Claude/claude_desktop_config.json
(Windows 在 %APPDATA%\Claude\),把上面两个值填进去:
{
"mcpServers": {
"mda-db": {
"command": "<上面打印的 command>",
"args": ["-m", "mcp_server.server"],
"cwd": "<上面打印的 cwd>",
"env": { "MDA_DATABASE_URL": "postgresql://mda_viewer@localhost:5432/mda" }
}
}
}command 必须指向项目虚拟环境里的 python(.venv/bin/python),
不能用系统 python —— 否则找不到 mcp、asyncpg 这些依赖。
环境变量(可选,优先级高于网页配置)
变量 | 用途 |
| 数据库连接串 |
| LLM API Key(设了它网页里就改不动) |
| 配置和历史库目录,默认 |
排查问题
端口被占用
mda_db_mcp_start.sh 会告诉你是哪个进程占的,换个端口 ./mda_db_mcp_start.sh 3345 或 kill <PID>。
网页显示「数据库未连接」
psql -h localhost -U mda_viewer -d mda -c "select 1" # 先确认数据库本身能连
uv run python test_mcp.py # 再单测 MCP Server提问报 HTTP 400 / 401 Key 不对或没额度。设置页点「测试连接」,错误原文会显示出来。
LLM 说找不到变量 先确认索引存在:设置页看「元数据索引」,没有就点「重建索引」。 索引在的话,让它换一批英文同义词再搜——元数据是英文的,中文关键词搜不到。
新入库的数据搜不到
索引是快照,需要重建:设置页点「重建索引」,或让 LLM 调
rebuild_metadata_index。建一次约 9 秒。
开通了新 schema 权限但还是搜不到
grants.sql 只改数据库权限,索引不会自动更新。执行后必须重建索引。
某个调查搜出来的结果成对重复
说明它的协调层和原始列层指向同一批变量(HSES 就是这种情况,已在
catalog.py 里去掉了它的 source 层)。新接调查时要检查这一点:
比较协调层的变量名集合和原始列名集合的重叠度。
回答里的数字看着不对 调查数据的缺失值常用 96/97/98/99 编码,直接求平均会算错。 展开「查看 SQL」核对它有没有排除这些值、有没有用抽样权重加权。
回答说到一半就断了 输出 token 上限设太小了。思考 token 也算在里面,调大或设成 0。
报错提到 thinking / reasoning / effort
推理设置这个模型不接受。最常见两种:给 Gemini 2.5 Pro 或 3.x 传了
reasoning_effort: none(它们不能关思考);或者档位和高级参数里的
thinking_level 同时设了(两者互斥)。
切了英文但模型还是回中文 语言指令是在提问时发出去的,只影响新提问。已有的回答不会重新翻译。
Available Tools
14 toolsdescribe_tableA
查看一张表的完整结构:所有列的名字、类型、是否可空、以及列注释;外加主键、外键、索引和估算行数。写 SQL 之前必须先调这个确认列名。
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | 表名,大小写敏感,例如 final_HH_CSES | |
| schema | Yes | schema 名,例如 cses_data |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. The read verb '查看' implies a safe read, and the enumerated return contents (PK, FK, indexes, row counts) tell the agent what to expect. However, it says nothing about whether the data is live or from the metadata index (siblings rebuild_metadata_index / metadata_index_status hint at caching), nor about permissions or latency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single dense sentence whose output list is front-loaded, followed by the one imperative usage rule. Nothing is padded or redundant.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return values need no explanation, and the description still summarizes them. Both required parameters are covered by the schema, and the invocation precondition is stated, leaving nothing critical missing for a read-only introspection tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, and both parameters (schema, table) are already documented in the schema, including casing sensitivity and examples. The description adds no additional meaning beyond that, so the baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (查看/view) and resource (一张表/a table), then enumerates exactly what is returned: column names, types, nullability, comments, plus primary keys, foreign keys, indexes, and estimated row count. An agent can distinguish it from siblings like list_tables or sample_rows without opening the schema.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly mandates when to call it: '写 SQL 之前必须先调这个确认列名' (must call this before writing SQL to confirm column names). That is a clear precondition, but it names no alternative tools (e.g., find_variables, search_metadata) or conditions for choosing among them.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
find_variablesA
【找变量的主要工具】按语义搜索整个数据库的变量元数据(变量定义、问卷原文、变量标签、值标签)。 ★ 调用前必须把概念展开成多个英文同义词——元数据是英文的,中文关键词搜不到任何东西,而且同一概念在不同调查里叫法不同。 例:使用者问「有没有教育年限相关的变量」,应传 keywords=["education","schooling","grade","attainment","years attended","diploma","degree"],这样才能同时命中 years_attended_school 和 highest_education_level。 宁可多给同义词也不要少给。搜索自带词干还原,不必列单复数词形。第一次结果不理想就换一批同义词再搜,不要直接说没有。
| Name | Required | Description | Default |
|---|---|---|---|
| level | No | 限定层级:canonical(协调变量,最可靠)/ question(问卷原文)/ source(原始列) | |
| limit | No | 返回多少条 | |
| survey | No | 限定调查:cses / dhs / mng_hses / mng_lfs | |
| section | No | 限定 section,如 ED / WM / HO | |
| keywords | Yes | 英文同义词列表,3-10 个。必须是英文,可以是词组 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations present, the description carries the behavioral burden and does so reasonably well: it discloses that the metadata index is English-only, that Chinese keywords return nothing, that stemming is applied, and that iterative re-querying is expected. It does not discuss result ranking, pagination, or cost/latency, which are minor gaps for a search tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The content is front-loaded with a bracketed role marker and a ★ callout for the critical keyword rule, and each sentence adds something (language constraint, example, stemming, retry policy). It is somewhat long, and the worked example could be tightened, but it does not feel padded.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so the description needn't explain return values, and it covers purpose, keyword construction, and retry behavior adequately for a search tool. The main omission is disambiguation from the similarly named search_metadata sibling, which leaves the agent to guess which search surface to use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is already 100%, so the baseline is 3, but the description materially adds to the keywords parameter: the concept-expansion strategy, the 3-10 synonym count intent, and a worked example mapping a natural-language question to concrete terms. This goes beyond restating the schema by explaining what a good keyword set looks like.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description opens with a bracketed label identifying this as the primary tool for finding variables and specifies semantic search over variable metadata (definitions, questionnaire text, labels, value labels) across the whole database. The verb+resource+scope are all clear. However, it never names the very similar sibling search_metadata, so the boundary between the two tools is left for the agent to infer.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
It gives strong, actionable guidance on how to invoke the tool — expand concepts into multiple English synonyms, prefer over-supplying, rely on stemming, and re-query with new synonyms rather than reporting no results. What it lacks is explicit routing: it does not state when to prefer this over search_metadata, run_query, or variable_stats, so no alternative-selection criteria are given.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_schemasA
列出数据库里所有可访问的 schema(数据分区),带每个 schema 的表数量和总体积。探索一个陌生库时先调这个。
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the disclosure burden. It does describe the accessibility filter and the two returned aggregates, but says nothing about permission requirements or whether results are paginated or cached. Adequate for a zero-parameter read, but not rich.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two short sentences: the first defines output and scope, the second gives the usage trigger. Zero filler and front-loaded.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return values need not be re-explained, and the description covers scope plus the recommended call order. Only the absence of any permission/access caveat keeps it from fully complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes no parameters, so there is nothing to disambiguate; baseline 4 applies. The description correctly does not waste space on parameter semantics.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb and resource ('list all accessible schemas/data partitions') and adds the returned fields (table count, total size), which distinguishes it from siblings like list_tables and search_metadata. An agent can tell immediately what this tool returns.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly says to call it first when exploring an unfamiliar database, which is a clear contextual trigger. It stops short of naming alternatives (e.g. list_tables or describe_table) for enumerating objects, so routing advice is slightly incomplete.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_sectionsA
列出某个调查包含哪些 section(模块/章节)。返回两种:physical_sections 是数据的分表方式(CSES 的 EC/ED/HH/HO/VL,DHS 的 WM/CH/BR/PR 等,带含义说明);questionnaire_sections 是问卷文档的章节。两者不是一一对应的。
| Name | Required | Description | Default |
|---|---|---|---|
| survey | Yes | 调查代号,如 cses / dhs(先用 list_surveys 查看可用值) |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full behavioral burden. It does disclose meaningful output semantics — the two distinct section taxonomies, example code sets per survey family, and the caveat that they don't correspond — which is real value. It says nothing about read-only behavior, permissions, or cost, though for a listing tool that gap is modest.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The purpose is front-loaded in the first clause, followed by the two-category breakdown and the non-correspondence caveat. The enumerated examples (EC/ED/HH/HO/VL, WM/CH/BR/PR) tighten the sentences somewhat, but they are illustrative rather than filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return-value documentation is not the description's burden; even so, the description supplies the interpretive key (two taxonomies that don't map one-to-one) that a schema alone would not convey. Combined with the schema's parameter guidance, an agent has enough to call it correctly.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100% and the single 'survey' parameter is already documented in the schema, including the 'use list_surveys to see available values' hint and examples. The description adds no parameter-level syntax or format detail beyond what the schema provides, so the baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb+resource — listing the sections a survey contains — and even defines the resource into two concrete categories (physical_sections, questionnaire_sections) with example codes. It does not explicitly contrast itself with siblings like list_tables or list_schemas, which could plausibly be confused with 'physical_sections' as a table-splitting scheme.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Usage is implied rather than stated: it's evident you call this to discover a survey's section structure, and the note that the two lists are not one-to-one helps interpret results. However, there is no explicit when-to-use/when-not or routing to alternatives, even though list_tables and list_schemas overlap conceptually with physical sections.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_surveysA
列出数据库里有哪些调查项目(CSES / DHS / HSES / LFS 等),带调查数量、覆盖国家、年份范围、表数和体积。会明确区分三种状态:已入库可读 / 数据在库但当前角色无权限 / 根本没入库——被问到某个调查有没有时,按这个区分如实回答。
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full disclosure burden and does well: it reveals that results are permission-aware, distinguishing 'ingested and readable' from 'present but role lacks permission' from 'not ingested'. It does not mention cost, pagination, or latency, which keeps it short of a 5.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, front-loaded with what is listed and what metadata accompanies each entry, followed by the permission/status nuance. The closing instruction to 'answer truthfully' is slightly prescriptive but earns its place by tying the three states to a concrete answering behavior.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return-shape explanation is not strictly required, yet the description still summarizes the per-survey fields and adds the permission-state nuance an agent needs to answer existence questions without over-claiming. Nothing essential is missing for a zero-argument listing tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes zero parameters, so the baseline is 4. There is nothing for the description to disambiguate, and it correctly spends no words on arguments.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb and resource (list survey projects) and names concrete examples (CSES / DHS / HSES / LFS) that distinguish it from sibling listing tools like list_tables and list_schemas. It also enumerates the fields returned, so an agent knows exactly what this tool answers.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Gives a clear trigger condition: when asked whether a particular survey exists, use this tool and answer according to the three-state distinction. It stops short of explicitly naming alternative tools (e.g., search_metadata) for other survey-discovery needs, so routing is implied rather than fully specified.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_tablesA
列出某个 schema 下的表,带表注释、估算行数和体积。可用 name_contains 按表名过滤。注意有的 schema 有 600 多张表,建议配合过滤条件使用,或者直接用 search_metadata。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | 最多返回多少张表 | |
| schema | Yes | schema 名,例如 cses_data | |
| name_contains | No | 按表名模糊过滤,不区分大小写 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden and does disclose a real behavioral trait: result sets can be very large (600+ tables) and filtering is advised. It also previews returned fields (comments, row estimates, size). It stops short of covering permissions or rate/limit behavior beyond the schema's limit field.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Purpose is front-loaded, then the filter hint, then the large-schema warning, all in three compact sentences. The listing of returned fields is mildly redundant given an output schema exists, but nothing is bloated.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return values need no explanation, and the description still adds the crucial large-schema caveat plus the sibling alternative. Complete enough for correct invocation, missing only minor operational detail.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already documents schema, name_contains and limit. The description only restates the name_contains filter, adding no syntax or format detail beyond the schema, so the baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (list) and resource (tables under a schema), and further specifies the returned payload (table comments, estimated row counts, size). It also distinguishes itself from the sibling search_metadata, so an agent can route between them without opening either schema.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly tells the agent to pair it with a filter (name_contains) and, when that isn't appropriate, to use search_metadata instead. It also warns that some schemas exceed 600 tables, giving a concrete condition that selects the alternative.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
metadata_index_statusA
查看本地元数据索引的状态:建立时间、条目数、各调查的覆盖情况。
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must carry the behavioral burden. It discloses the informational payload (build time, entry count, coverage per survey), which implies a non-mutating read, but it never confirms that the tool does not trigger a rebuild nor describes cost, latency, or behavior on a missing/empty index.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
A single front-loaded sentence with no filler; the resource is named first and the returned fields follow immediately. Every clause earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With an output schema present, the description need not enumerate return values in detail, and it already names the main status fields. The only shortfall is the absence of guidance tying it to rebuild_metadata_index as the read/write pair.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes zero parameters, so there is nothing for the description to disambiguate beyond what the schema shows. The schema coverage is 100% and the empty property set is self-explanatory.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb and resource ('查看本地元数据索引的状态' - view the local metadata index status) and enumerates what the status comprises: creation time, entry count, and per-survey coverage. This clearly separates it from the sibling rebuild_metadata_index, though it does not name that sibling explicitly.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Usage is only implied: an agent can infer this is the read-side counterpart to rebuild_metadata_index, useful for checking index freshness. There is no explicit when-to-use statement, no condition that selects this over alternatives, and no stated prerequisites.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
plot_variableA
把一个变量画成图,图会直接显示在网页上。kind='auto' 时自动选择:类别型画条形图(用码值含义当标签),连续数值画直方图。缺失值编码默认排除。传 weight 参数可按抽样权重加权——调查数据展示总体分布时应该加权。
| Name | Required | Description | Default |
|---|---|---|---|
| top | No | 条形图最多显示几个类别 | |
| bins | No | 直方图分几组 | |
| kind | No | auto / bar(条形图)/ histogram(直方图) | auto |
| table | Yes | 表名,如 final_HO_CSES(大小写敏感) | |
| column | Yes | 列名 | |
| schema | No | schema 名。省略时自动按表名解析 | |
| weight | No | 抽样权重列名 | |
| include_missing | No | 是否把缺失值编码也画进去(默认排除) |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full behavioral burden, and it does disclose key defaults: missing-value codes are excluded by default, kind='auto' resolves to bar vs histogram by data type, and weight triggers weighted aggregation. It omits any permission/auth or size-limit behavior, keeping it short of a 5.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Front-loaded with the core action, then the auto-selection rule, then defaults and the weight caveat. Every sentence carries information with little waste, though the auto/weight sentences are somewhat dense.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists so return values need no explanation, and the description covers the decisions an agent must make: chart type resolution, missing-value handling, and weighting. Nothing required to call it correctly is missing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so baseline is 3, but the description adds genuine meaning beyond the schema for kind ('auto' resolution logic), weight (survey weighting semantics), and include_missing (default exclusion). This goes past merely restating the parameter list.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb+resource ('把一个变量画成图') and explains the rendering target ('图会直接显示在网页上'). It distinguishes itself from sibling stats tools like variable_stats by being a visualizer, but never names a sibling explicitly, so it stops short of a 5.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Provides real conditional guidance for one parameter ('调查数据展示总体分布时应该加权'), but gives no guidance on when to reach for this tool over describe_table, variable_stats, or sample_rows. Usage context is implied rather than framed against alternatives.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
read_guideA
读出数据库自带的使用指南(public._guide)、表目录(public._catalog)和未解决的数据问题(public.data_issues)。 ★ 这是数据库维护者手写的权威文档,包含跨数据集比较的关键陷阱:哪些列是清洗过的(CP 前缀)、缺失值哨兵编码、不同年代数据集的编码差异、表之间的连接键和坑。 涉及 MICS 数据、或者要做跨数据集/跨国比较、或者要连接多张表时,先调这个工具读一遍。它和其他工具的推断性说明冲突时,以它为准。
| Name | Required | Description | Default |
|---|---|---|---|
| section | No | 只读某一章节,如 join_conventions / coding_conventions / cp_prefix / harmonized_variables。省略则返回全部 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must carry the behavioral burden. It clearly implies a read-only operation ('读出') and discloses that it returns authoritative handwritten documentation containing pitfalls, and that it takes precedence over other tools. It does not explicitly state side-effect safety or permissions, leaving a minor gap.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Three tightly written sentences: first states what it reads, second explains its value and contents, third gives usage conditions and precedence. It is front-loaded and free of redundancy.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
With an output schema present, return values are covered. The description supplies purpose, content, usage triggers, and precedence, which is complete for a read-only guide tool with one optional parameter.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, and the schema itself documents the single optional 'section' parameter with examples. The description adds no additional syntax or format details for the parameter, so baseline 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (读出/read out) and three specific resources (public._guide, public._catalog, public._data_issues). It distinguishes itself from sibling metadata tools by declaring itself the authoritative handwritten source and specifying it should be consulted first for MICS, cross-dataset, and join work.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly states when to call it (MICS data, cross-dataset/cross-country comparisons, joining multiple tables) and instructs to call it first. It also establishes precedence over other tools' inferential descriptions. However, it does not specify when not to use it or name specific alternative tools, so it falls short of the top score.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
rebuild_metadata_indexA
重建本地元数据索引。数据库里新增了调查/变量之后,或者刚开通了新 schema 的权限之后,需要重建一次搜索才能找到新内容。耗时约 10 秒到 2 分钟,取决于数据量。
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full behavioral burden, and it does disclose a valuable trait: the operation costs roughly 10 seconds to 2 minutes depending on data volume, which tells the agent this is expensive and slow. However, it says nothing about whether the rebuild is idempotent, whether it blocks concurrent queries, or whether it can fail partway.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Three sentences, front-loaded: what it does, then the conditions that require it, then the cost. Every sentence earns its place and nothing is repeated from structured fields.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return values need not be explained, and the description covers purpose, trigger conditions, and latency. What remains thin is failure/concurrency behavior for a long-running mutation, but for a parameterless maintenance command this is close to complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes zero parameters, so there is no parameter semantics for the description to add; the baseline for a parameterless tool is 4. Schema coverage is also 100%, so nothing is left undocumented.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb+resource ('重建本地元数据索引' / rebuild the local metadata index) that is unambiguous and clearly distinct from the read-only lookup siblings like search_metadata and metadata_index_status. It stops short of explicitly naming the sibling that reports index state, so an agent must infer that distinction rather than being told.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Gives two concrete trigger conditions: after new surveys/variables are added to the database, and after being granted access to a new schema. That is clear 'when to use' context. It does not state when NOT to run it or point at metadata_index_status as the cheaper way to check whether a rebuild is actually needed.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
run_queryA
执行一条只读 SQL 查询并返回结果。只接受 SELECT / WITH / EXPLAIN 等只读语句,单次最多返回 500 行,超时 30 秒。表名列名含大写字母时记得加双引号。统计总体指标时请使用表里的抽样权重列加权。
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | 一条只读 SQL 语句,不要加结尾分号 | |
| limit | No | 最多返回多少行 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full behavioral burden and does so well: it discloses the read-only enforcement (SELECT/WITH/EXPLAIN), a hard 500-row cap, and a 30-second timeout — exactly the operational traits an agent needs. It omits what happens on rejection or how to page past 500 rows, so it is strong but not exhaustive.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Four sentences, front-loaded with what the tool does before the constraints, then syntax and domain tips. Every sentence carries information, though the weighting advice sits slightly apart from the query-execution mechanics.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists so return values need not be described, and the description still covers safety, limits, timeout, and identifier-quoting pitfalls. With no annotations to lean on, the remaining gap is error behavior and pagination semantics beyond the 500-row ceiling.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so the baseline is 3, but the description adds real semantics: the allowed statement classes for the sql parameter, the requirement to double-quote uppercase identifiers, and the weight-column convention for aggregate metrics. The limit parameter's 500-row ceiling is stated, though the description doesn't explain how it interacts with the server-side cap.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb+resource ('执行一条只读 SQL 查询并返回结果') with the scope qualifier '只读'. It is clearly distinguishable in practice from metadata-oriented siblings like describe_table and sample_rows, but it never names an alternative, so it stops short of explicit sibling differentiation.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
It defines the usage envelope (read-only statements only, 500-row cap, 30s timeout, weighting advice for aggregate metrics), which implicitly tells the agent when this tool applies. However, it never says when to prefer run_query over describe_table, sample_rows, variable_stats, or plot_variable, so routing guidance is left to inference.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
sample_rowsA
从一张表里抽几行真实数据看看。用来确认取值形态——特别是缺失值编码(96/97/98/99 之类)和字段的实际格式。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | 取几行 | |
| table | Yes | 表名,大小写敏感 | |
| schema | Yes | schema 名 | |
| columns | No | 只看这几列。表很宽(可能上百列)时强烈建议指定 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. Sampling implies a read-only, non-destructive operation, but the description never states that explicitly, nor does it mention the 50-row cap or any access requirements. It adds genuine context about why one samples (missing-value encodings, field formats), which lifts it above a bare minimum.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two tight sentences with zero waste; the action is front-loaded and the rationale follows immediately. Nothing is padded or repeated from the schema.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return values need no explanation, and all four parameters are documented in the schema. The description covers purpose and use context adequately; only the read-only/safety framing and routing against siblings are absent, which is a minor gap for a low-risk sampling tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already documents schema, table, columns and limit (including the 1-50 bounds and the advice to specify columns on wide tables). The description adds no parameter-level syntax or format detail beyond that, so the baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb+resource: sample a few real rows from a table, and goes further by naming the goal (confirming value shapes, missing-value codes like 96/97/98/99, field formats). This is far more concrete than a bare 'sample_rows' restatement, though it does not explicitly contrast itself with run_query or describe_table.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Gives a clear use context — use it to verify how values are actually encoded and formatted, especially sentinel missing-value codes. It does not name alternatives (e.g. run_query for filtered pulls, describe_table for schema-only inspection) or state when-not-to-use, so it stops short of the top band.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_metadataA
按关键词搜索数据库的物理结构:表名、表注释、列名、列注释。适用于「我知道大概的表名或列名,帮我定位」这类需求,或者想看某张表的注释说明。 ★ 找变量请优先用 find_variables——它搜的是变量协调层(变量定义、问卷原文、值标签),带词干还原和相关性排序,对「有没有 xx 相关的变量」这类语义问题效果好得多。本工具搜的是物理结构,只做精确子串匹配,没有同义词和词干处理。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | 最多返回多少条命中 | |
| schema | No | 限定只在某个 schema 内搜索 | |
| keyword | Yes | 搜索关键词,建议用英文单词,如 income / education / age |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden and does disclose the key behavioral trait: matching is exact substring only, with no synonyms or stemming, unlike find_variables. It doesn't cover auth/permission needs, but the output schema exists and return shape is not its job. Solid disclosure of the most decision-relevant behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Front-loaded with purpose before the guidance note, and the two sentences each carry information. The starred alternative note is longer but earns its place by preventing misuse against find_variables.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists so return values needn't be explained, and the description covers scope, matching limitations, and the alternative tool. For a 3-parameter search tool this is complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so limit and schema are fully documented in the schema already, establishing a baseline of 3. The description adds only a hint about keyword content (English words), which the schema also states, so little value beyond structured fields.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb and resource (keyword search over physical structure: table names, table comments, column names, column comments) and explicitly contrasts itself with find_variables. An agent can distinguish this from list_tables, describe_table, and find_variables without opening any schema.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Gives both when-to-use ('I roughly know the table/column name, help me locate', or view a table's comment) and when-not-to-use, naming the sibling find_variables and explaining what that tool searches instead. It even explains why find_variables is better for semantic queries (stemming, relevance ranking).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
variable_statsA
统计一个变量:有多少非空回答、排除缺失值编码后的有效回答、取值分布(带码值含义)、数值型的描述统计(均值/中位数/标准差)、以及可用的抽样权重列。缺失值编码(98=不知道、99=缺失这类)会根据元数据自动识别并单独报告,不是靠猜 96-99;元数据里查不到值标签时会明确说明无法判断。
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | 表名,如 final_ED_CSES(大小写敏感) | |
| column | Yes | 列名,如 years_attended_school | |
| schema | No | schema 名。省略时自动按表名解析 | |
| weight | No | 抽样权重列名。算总体量时应该传,返回值里会列出可用的权重列 |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full behavioral burden, and it does disclose non-obvious behavior: missing-value codes are auto-detected from metadata rather than heuristically guessing 96-99, codes are reported separately, and the tool explicitly signals when value labels cannot be resolved. This is meaningful transparency, with only auth/performance characteristics left unaddressed.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The content is front-loaded with the core purpose and then details the missing-value handling, which is the most valuable differentiator. It is dense but each clause (counts, distribution, descriptives, weights, missing-code logic) earns its place, with no filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
An output schema exists, so return values need not be explained, yet the description still clarifies the semantics of what is returned (valid vs non-null, code meanings). Combined with the absence of annotations, the description covers the behavioral surface an agent needs; only cross-tool routing guidance is missing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so all four parameters (table, column, schema, weight) are already documented in the schema. The description adds only a light framing note that sampling weight columns are surfaced, which does not go beyond the schema's own explanation. Baseline 3 applies.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description names a specific verb and resource: computing statistics for a single variable, enumerating exactly what is returned (non-null counts, valid counts after missing-code exclusion, value distribution with code meanings, numeric descriptives, available weight columns). This is clearly distinct from sibling tools like describe_table or plot_variable, though no sibling is named explicitly.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Usage is implied by the scope of the outputs — an agent can infer this is the tool to reach for when it needs per-variable summary statistics. However, there is no explicit when-to-use versus alternatives (e.g., describe_table vs run_query vs plot_variable) and no stated prerequisites or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
14 tool updates
v0.1.0- First observed
describe_table - First observed
find_variables - First observed
list_schemas - First observed
list_sections - First observed
list_surveys - First observed
list_tables - First observed
metadata_index_status - First observed
plot_variable - First observed
read_guide - First observed
rebuild_metadata_index - First observed
run_query - First observed
sample_rows - First observed
search_metadata - First observed
variable_stats
TDQS
Scored across 14 tools
Although several tools touch exploration (find_variables, search_metadata, list_tables, describe_table), the descriptions explicitly delineate boundaries—e.g. find_variables searches the semantic harmonization layer while search_metadata does exact substring matching on physical structure. Hierarchical listers (schemas/tables/surveys/sections) and the stats/plot pair are clearly distinct. No two tools appear interchangeable.
Almost all names follow a clean verb_noun snake_case pattern (describe_table, run_query, list_surveys, find_variables, plot_variable, search_metadata, rebuild_metadata_index). Only variable_stats and metadata_index_status deviate into noun_noun form, but they read consistently as 'X_stats'/'X_status' queries and cause no confusion.
14 tools sit comfortably in the well-scoped range for a rich survey-microdata domain. Each tool maps to a distinct workflow stage—discovery, inspection, query, analysis, documentation, index maintenance—so nothing feels padded or redundant.
The surface covers discovery (schemas, tables, surveys, sections, variables), inspection (describe_table, sample_rows), querying (run_query), analysis (variable_stats, plot_variable), authoritative docs (read_guide) and index management, which is strong lifecycle coverage. Minor gaps remain—no result export/download or crosstab/join helpers—but agents can work around these with run_query.
Maintenance
Related MCP Connectors
Connect your ads, shop, analytics, social, CRM and finance platforms once, then let Claude, ChatGPT, Cursor or any MCP client read, join and explain your numbers. Public statistics from the World Bank, IMF, Eurostat, OECD, WHO and SEC filings come as context, searchable and chartable from the same tools. Read-only by design, every number carries its source.
- OleanderOAuthdev.oleander
The all-in-one data stack for agents. Upload files, run SQL, evolve tables, and render charts.
Ask data questions in natural language. Get SQL, insights, and charts from your databases.
- LyssnaOAuthcom.lyssna
Query and summarize research data across tests and surveys
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides database access capabilities to Claude with support for both SQLite and SQL Server databases. It enables users to manage schemas, execute SQL queries, and export results through natural language interaction.997 npmMIT
- AlicenseAqualityDmaintenanceEnables querying China National Bureau of Statistics data including economic indicators, time series, and regional statistics. Supports natural language search, batch queries, comparisons, and analysis across monthly, quarterly, and yearly datasets.3156 npm8Apache 2.0
- AlicenseNot gradedqualityFmaintenanceEnables connecting to any SQL database, exploring schemas, running queries, and visualizing results with interactive charts from Claude Desktop.MIT
- AlicenseNot gradedqualityCmaintenanceEnables querying statistical data from China NBS, World Bank, IMF, OECD, BIS, census, and department statistics via MCP tools.Apache 2.0