sql-template-mcp
This server is an MCP tool for managing a reusable SQL template library, letting you save, search, retrieve, update, delete, and track usage of SQL templates backed by Supabase.
Save SQL templates: Persist generated SQL as reusable templates with metadata (title, category, scenario, SQL text, keywords, core tables, placeholders, execution flow, example case, verification status, source), including automatic embedding generation and similar-template duplicate checks.
Search templates: Use hybrid retrieval (semantic vector recall + keyword matching) to find reusable templates, sortable by similarity and usage count, with optional filters for document type, category, and verified-only results.
Semantic search: Perform natural-language / paraphrased queries using pgvector cosine similarity (NVIDIA embeddings) to find templates by business intent.
Get template details: Fetch the full content of a single template by its ID.
List templates: Overview the template library with optional filtering by category, document type, and verification status.
Update templates: Modify existing templates (e.g., correct SQL, mark as verified, add execution flow or example case) and refresh embeddings accordingly.
Delete templates: Remove wrong or outdated templates.
Record usage: Increment a template's usage count and refresh its last-used timestamp to improve retrieval ranking and assess template value.
Graceful degradation: If no NVIDIA API key is configured, semantic search services fall back to keyword-only retrieval without breaking core functionality.
Leverages NVIDIA's free embedding API (nv-embed-v1) to generate 2048-dimensional semantic vectors for SQL templates, enabling semantic search and similarity matching.
Provides a database backend for storing SQL templates, including schema management, vector storage for embeddings, and querying capabilities via Supabase API.
Click on "Install 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., "@sql-template-mcpsearch for a SQL template to get customer orders"
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.
sql-template-mcp
将 ssrc-sql-generator 技能生成的 SQL 步骤沉淀为可检索复用的模板库,解决本地 .md 模板手动维护繁琐的问题。与 zhenyun-pangu-mcp(数据库实时能力)互补解耦:后者负责查询公司内部生产库(实时事实,依赖 Archery 登录态),本工具负责读写自有模板库(历史经验,Supabase / Postgres)。
本目录是 uvx 打包版:通过
uvx --from <本目录>直接运行,无需pip install或手动建虚拟环境。含[project.scripts]入口sql-template-mcp(由sql_template_mcp.server:main提供)。.env通过MCP_ENV_DIR指定位置(uvx 运行在缓存目录,__file__不指向本项目,见config.py)。
一、能力一览
工具 | 作用 |
| 将生成的 SQL 沉淀为模板(含相似去重检查,自动生成 embedding;支持 |
| 混合检索:语义向量召回 + 关键词匹配,按相似度/使用次数排序 |
| 纯语义召回,适合自然语言/口语化、同义改写查询 |
| 按 id 获取单个模板完整内容 |
| 总览模板库(可按分类/单据类型/验证状态过滤) |
| 更新已有模板(如补充 ✅ 已验证标记、修正 SQL,同步刷新 embedding) |
| 删除错误/过期模板 |
| 记录模板被使用一次(统计使用次数,优化检索排序) |
Related MCP server: mcp-codesearch
二、零基础傻瓜式安装(Mac)
本工具用 uv 管理 Python 环境。uv 会自动下载对应版本的 Python 并拉取依赖,本机可以没有预装 Python。下面每一步照抄执行即可。
2.1 安装 uv(同时自带 uvx)
打开「终端」(Finder → 应用程序 → 实用工具 → 终端),粘贴下面命令回车:
curl -LsSf https://astral.sh/uv/install.sh | sh(如果你装了 Homebrew,也可以用 brew install uv,二选一即可。)
脚本装完后,把 uv 加进 PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc2.2 验证 uv 是否装好
uv --version
uvx --version两条命令都能输出版本号(建议 uv >= 0.5)即成功。若提示 command not found,说明 PATH 没生效:重开一个终端窗口再试;或用绝对路径 ~/.local/bin/uv --version 确认。
2.3 安装 Python(可选但推荐)
uv 会自动下载所需 Python,这步可跳过。想提前手动装一份独立的 Python(不污染系统)就执行:
uv python install 3.112.4 拉取依赖(预热,首次必做)
uvx 首次运行要先解析并缓存依赖,耗时较久,可能让 MCP 客户端超时。先手动预热一次:
cd /你的路径/zhenyun-tools/sql-template-mcp
uv sync看到 Installed <数量> packages 字样即完成。
国内网络受限时可先设置镜像再执行上面的
uv sync:export UV_DEFAULT_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple
2.5 配置 .env
在项目目录下,把模板复制成 .env:
cd /你的路径/zhenyun-tools/sql-template-mcp
cp .env.example .env用文本编辑器(VSCode / 文本编辑)打开 .env,填写:
SUPABASE_URL=https://your-project-ref.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
# 可选:语义检索。不填则自动降级为纯关键词检索
NVIDIA_API_KEY=SUPABASE_URL/SUPABASE_SERVICE_ROLE_KEY:Supabase 控制台 → Project Settings → API 中获取。NVIDIA_API_KEY:https://build.nvidia.com/nvidia/nv-embed-v1 免费申请,默认模型nvidia/nv-embed-v1(2048 维)。
Service Role Key 拥有绕过 RLS 的完整权限,仅限服务端/本地 MCP 使用,切勿暴露给前端或提交到仓库。
2.6 建表
在 Supabase 控制台 SQL Editor 中执行 schema.sql(幂等,可重复执行)。
2.7 写入种子模板 / 回填 embedding(可选)
# 种子模板(幂等,可重复执行)
uv run --directory "$DIR" python scripts/seed_data.py
# 仅在配置 NVIDIA_API_KEY、需要语义检索时回填 embedding
uv run --directory "$DIR" python scripts/backfill_embeddings.py2.8 注册为 MCP Server
在 MCP 客户端配置中加入(把 $DIR 替换成本目录绝对路径,例如 /你的路径/zhenyun-tools/sql-template-mcp):
{
"mcpServers": {
"sql-template": {
"command": "uvx",
"args": ["--from", "$DIR", "sql-template-mcp"],
"cwd": "$DIR",
"env": { "MCP_ENV_DIR": "$DIR" }
}
}
}要点:
必须使用绝对路径,不要用
~或相对路径。MCP_ENV_DIR指向包含.env的目录:uvx 运行在缓存目录,__file__不指向本项目,故.env需通过MCP_ENV_DIR显式指定(见config.py);不设置则回退到cwd目录的.env。凭据不写入客户端配置。
2.9 验证
# 连通 Supabase 并预览模板库前 5 条
uvx --from "$DIR" sqltpl该 MCP 提供 8 个工具,客户端显示 8 tools / 0 prompts 属正常。
三、零基础傻瓜式安装(Windows)
3.1 安装 uv(同时自带 uvx)
按 Win 键搜索「PowerShell」,右键 → 以管理员身份运行,粘贴下面命令回车:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"(如果你装了 winget,也可以用 winget install --id=astral-sh.uv -e,二选一即可。)
3.2 验证 uv 是否装好
安装后重开一个 PowerShell 窗口(让 PATH 生效),再执行:
uv --version
uvx --version两条命令都能输出版本号(建议 uv >= 0.5)即成功。若提示无法识别,说明 PATH 没生效:重开窗口再试。
3.3 安装 Python(可选但推荐)
uv 会自动下载所需 Python,这步可跳过。想提前装就执行:
uv python install 3.113.4 拉取依赖(预热,首次必做)
在 PowerShell 中进入项目目录并预热:
cd C:\你的路径\zhenyun-tools\sql-template-mcp
uv sync看到 Installed <数量> packages 字样即完成。
国内网络受限时可先设置镜像再执行上面的
uv sync:$env:UV_DEFAULT_INDEX = "https://pypi.tuna.tsinghua.edu.cn/simple"
3.5 复制并填写配置文件
在 PowerShell 中复制模板:
Copy-Item .env.example .env用编辑器(VSCode / 记事本)打开 .env,按「2.5」一节的变量说明填写。
3.6 建表
在 Supabase 控制台 SQL Editor 中执行 schema.sql(幂等,可重复执行)。
3.7 写入种子模板 / 回填 embedding(可选)
uv run --directory "$DIR" python scripts/seed_data.py
uv run --directory "$DIR" python scripts/backfill_embeddings.py3.8 注册为 MCP Server
在 MCP 客户端配置中加入(把 $DIR 替换成本目录绝对路径,Windows 路径统一用正斜杠,例如 C:/你的路径/zhenyun-tools/sql-template-mcp):
{
"mcpServers": {
"sql-template": {
"command": "uvx",
"args": ["--from", "$DIR", "sql-template-mcp"],
"cwd": "$DIR",
"env": { "MCP_ENV_DIR": "$DIR" }
}
}
}若客户端找不到 uvx,用 where uvx 查出绝对路径,把 command 改成该路径。
3.9 验证
uvx --from "$DIR" sqltpl四、语义检索(向量)说明
采用混合检索:保留原有表存储(SQL 原文、元数据、统计、去重指纹),新增 embedding 向量列做语义召回。无需替换表,只是能力升级。
Embedding 模型:NVIDIA 免费 API
nvidia/nv-embed-v1(2048 维),免费 key 在 build.nvidia.com 申请。 因 2048 维超过 pgvector 的 HNSW/IVFFlat 索引维度上限 2000,当前 schema 不创建向量索引,语义检索走顺序扫描(模板库规模小,性能足够)。未配置
NVIDIA_API_KEY时:search_sql_template自动降级为纯关键词检索,不破坏原有能力。存量模板:表升级后
embedding列为空,需跑一次回填脚本(见上文 2.7)。
五、与 ssrc-sql-generator 的协作
生成 SQL 前:技能调用
search_sql_template(混合检索,含语义召回)或semantic_search_sql_template(自然语言查询)检索可复用模板(优先 ✅ 已验证);命中含execution_flow的模板时强制分步执行(逐 STEP QUERY + ASSERT),禁止直接输出最终 SQL。生成 SQL 后:技能询问用户是否
save_sql_template沉淀本次结果(自动写入 embedding;数据修复类同时沉淀execution_flow与example_case)。MCP / NVIDIA 不可用时:技能降级为「纯关键词检索 / 不检索直接生成、提示无法沉淀」,不阻塞主流程。
Available Tools
8 toolsdelete_sql_templateB
删除指定模板(清理错误/过期模板)。
| Name | Required | Description | Default |
|---|---|---|---|
| template_id | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden of behavioral disclosure, but it does not mention side effects, idempotency, return values, or error behavior. The only added context is the cleanup purpose, which is more about usage than behavior. This is insufficient for a mutating operation.
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 description is a single, concise sentence that front-loads the action and includes a useful contextual note. It is appropriately sized for the tool's simplicity, though it might have earned a 5 with a bit more behavioral detail.
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?
While the tool is simple with one parameter and an output schema exists, the lack of annotations and minimal description makes it incomplete for a mutation operation. There is no mention of idempotency, error handling, or what happens to related data, which is expected for a delete operation with no other context.
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 0%, and the description provides no information about the template_id parameter or any additional arguments. The description fails to compensate for the low schema coverage, leaving the agent with no semantic guidance beyond the parameter name itself.
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 'Delete specified template' provides a clear verb+resource, and the parenthetical 'clean up incorrect/expired templates' adds a specific use case that distinguishes it from sibling tools like update or search. This meets the 5-point criterion of specific verb+resource with 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?
The parenthetical 'cleaning up incorrect/expired templates' gives a contextual hint about when to use this tool, but it is not explicit about when not to use it or how it differs from alternatives like update_sql_template. It provides light context without explicit exclusions or named alternatives.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_sql_templateA
按 id 获取单个模板的完整内容。
| Name | Required | Description | Default |
|---|---|---|---|
| template_id | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the transparency burden. It states the tool returns 'complete content,' which gives some behavioral detail but does not disclose error handling, authentication needs, or pagination. Adequate for a simple retrieval 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?
A single concise sentence that is front-loaded with the key action and scope. No wasted words or redundant details.
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?
For a simple get-by-id tool with one parameter and an output schema, the description covers the essential purpose and parameter role. It does not mention alternative usage scenarios, but the tool's simplicity makes the description reasonably 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 coverage is 0%, but the description explicitly references 'by id,' which maps the template_id parameter to its role as the identifier. Since there is only one self-explanatory parameter, this minimal compensation is sufficient.
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 clearly states the action (get), resource (single template), and scope (by id and complete content). This distinguishes it from sibling tools like search_sql_template and list_sql_templates which serve different retrieval purposes.
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 'by id'—the agent can infer this tool is for when a specific template_id is known. However, it does not explicitly mention when to use alternatives like search_sql_template or list_sql_templates, so guidance is minimal.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_sql_templatesA
列出模板库中的模板(可按分类/单据类型/验证状态过滤),用于总览。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| category | No | ||
| doc_type | No | ||
| verified_only | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the burden. It mentions filters and the overview purpose but does not disclose pagination behavior, result size, or any read-only guarantee. For a simple list tool, this is adequate but minimal.
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 description is a single, front-loaded sentence with zero filler. It conveys the core purpose and filters efficiently.
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?
Given that an output schema exists, return format details are unnecessary. The description covers filtering and usage context. It could mention the limit parameter or pagination, but the tool is simple enough that the description is largely 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?
With 0% schema description coverage, the description compensates by explaining the filter capabilities for category, doc_type, and verified_only. It does not mention limit, but that is a standard pagination parameter; overall it adds meaningful context beyond the schema titles.
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 clearly states the tool lists templates from the library with optional filters by category, document type, and verification status. It distinguishes itself from sibling tools like get_sql_template (single retrieval) and search_sql_template (search), making the purpose unambiguous.
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?
The description includes '用于总览' (for overview), which gives a mild usage hint, but it does not explicitly state when to choose this over search or semantic_search, nor does it provide exclusions. This is implied rather than explicit.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
record_template_usageA
记录某模板被实际使用一次(使用次数 +1,刷新最近使用时间)。
在技能复用模板生成最终 SQL 后调用,用于评估模板价值、优化检索排序。
| Name | Required | Description | Default |
|---|---|---|---|
| template_id | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the burden of disclosing side effects. It clearly states that calling this tool increments the usage count and refreshes the last-used timestamp, which is essential behavioral information for a mutating 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 description is two short sentences. The first sentence front-loads the core behavior and side effect; the second provides the invocation context and business rationale. Every word 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?
For a simple one-parameter tool, the description covers what it does, when to call it, and why it matters. An output schema exists, so not explaining return values is acceptable. It could mention error cases or idempotency, but these are not critical for basic invocation.
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 schema has only one required parameter, template_id, with no description, and schema coverage is 0%. The description does mention '某模板' (a template), which indirectly ties to the parameter, but it does not explain the parameter's source or constraints. Given the self-explanatory parameter name, this is adequate but not exceptional.
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 clearly states the tool's action: recording a template usage by incrementing the usage count and refreshing the last-used timestamp. This specific behavior distinguishes it from sibling CRUD/search tools like get_sql_template or update_sql_template.
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?
The description explicitly says to call this tool after a skill-reuse template generates final SQL, giving a clear invocation context. It does not explicitly list exclusions or alternative tools, but the context is strong enough for correct selection.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
save_sql_templateA
将一次生成的 SQL 步骤沉淀为模板,存入模板库(Supabase)。
参数:
title: 模板标题(如「询价单回退至报价中」)
category: 业务分类,建议取值:通用基础查询 / 询价单RFX / 征询单RF / 数据修复
scenario: 业务场景描述(检索主要依据,请写清楚用途)
sql_text: 完整 SQL 文本(保留
{...}或<...>占位符原样)execution_flow: 执行过程伪代码(数据修复类模板强烈建议填写)。标准语法: [INPUT] <入参1>, <入参2> [STEP n: 步骤名] QUERY: 前置查询 SQL(用 {变量} 引用上一步提取的真实值) ASSERT: 断言(如「必须返回 1 行,提取 {tenant_id};0 行则终止报错」) CONDITION: 条件短路(如「IF {status} == 'X' THEN RETURN 无需修复」) ACTION: 修复语句(UPDATE/DELETE/INSERT,带乐观锁 object_version_number+1) 指导大模型分步调用 execute_sql,禁止跳过前置校验直接生成修复 SQL。
example_case: 脱敏示例(Few-Shot)。含:输入参数 → 各 STEP 中间结果 (如「Step 1 结果: tenant_id=155357」)→ 最终生成的可执行 SQL,消除大模型猜测。
doc_type: 单据类型(通用/询价单/招标单/征询单/数据修复)
keywords: 关键词/标签,逗号分隔(如「回退,报价中,延时消息」),用于检索
core_tables: 涉及核心表,逗号分隔(如「ssrc_rfx_header,spfm_pending_message」)
placeholders: 占位符清单,逗号分隔(如「tenant_id,rfx_header_id」)
verified: 是否「✅ 已验证」(验证过的模板可被技能免 MCP 校验复用)
verified_at: 验证日期(verified=True 时建议填写,如 2026-07-23)
template_no: 模板编号(如 2.6.6),便于与历史模板对应
created_by: 作者(为团队共享预留)
source: 来源标记(auto=技能自动沉淀 / migrated=手工迁移 / manual=手工新增)
skip_dup_check: 跳过相似去重检查直接写入
返回:保存结果(含模板 id)或相似模板提示。
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| source | No | auto | |
| category | Yes | ||
| doc_type | No | 通用 | |
| keywords | No | ||
| scenario | Yes | ||
| sql_text | Yes | ||
| verified | No | ||
| created_by | No | ||
| core_tables | No | ||
| template_no | No | ||
| verified_at | No | ||
| example_case | No | ||
| placeholders | No | ||
| execution_flow | No | ||
| skip_dup_check | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive 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?
虽然描述较长,但每个参数都配有清晰说明和示例,结构化良好,关键信息靠前。有些内容可更精简,但整体信息密度高,未过度冗余。
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?
描述覆盖了所有 16 个参数的逐一解释,包括默认值、示例和关系(如 execution_flow 的语法),并说明了返回值概要和用途。对于创建型工具,上下文足够完整。
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 没有提供任何描述(schema coverage 0%),描述承担了全部参数解释职责。每个参数都有详细含义、示例值和推荐填写场合,远超 schema 提供的信息,完全补偿了 schema 的不足。
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?
描述明确说明工具用途:将生成的 SQL 步骤沉淀为模板并存入模板库(Supabase)。动词“沉淀”+宾语“模板”+存储位置,清晰区分于兄弟工具(get/search/list/update/delete 等)。
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?
描述包含详细的使用指导,如数据修复类模板强烈建议填写 execution_flow,并指导大模型分步调用 execute_sql。但未明确说明何时使用此工具 vs 兄弟工具(如 update_sql_template 或 list_sql_templates),也未说明替代方案。使用指南隐含在参数说明中,但缺少显式对比。
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_sql_templateA
在模板库中检索可复用的 SQL 模板(生成 SQL 前先调用,形成闭环)。
采用混合检索:语义向量召回(NVIDIA Embedding) + 关键词模糊匹配,按相似度/使用次数综合排序。 若未配置 NVIDIA_API_KEY,自动降级为纯关键词检索,不影响原有能力。
参数:
keyword: 关键词或自然语言描述(如「把询价单退回到报价中」「ssrc_rfx_header」)
doc_type: 按单据类型过滤(通用/询价单/招标单/征询单/数据修复)
category: 按业务分类过滤(通用基础查询/询价单RFX/征询单RF/数据修复)
verified_only: 仅返回「✅ 已验证」模板
limit: 返回条数上限
use_semantic: 是否启用语义召回(默认 true;无 NVIDIA key 时自动忽略)
返回:匹配模板的 Markdown 列表(含 SQL 与验证状态,语义命中会标注相似度)。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| keyword | No | ||
| category | No | ||
| doc_type | No | ||
| use_semantic | No | ||
| verified_only | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden and does so well. It discloses the hybrid retrieval mechanism, fallback behavior without NVIDIA_API_KEY, sorting criteria (similarity/usage count), and return format (Markdown list with SQL, verification status, and similarity scores). This is rich behavioral context beyond what structured fields provide.
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 description is well-structured with a clear purpose statement, retrieval behavior summary, and a bulleted parameter list. It is appropriately sized for a tool with six parameters and zero schema coverage; every sentence adds value without 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?
Given the tool's complexity (6 parameters, hybrid retrieval, fallback logic) and the lack of annotations, the description is complete. It covers when to use it, how retrieval works, all parameter semantics, and the return format. The presence of sibling tools does not create gaps because the description clearly positions this as the hybrid search entry point.
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 0%, so the description must compensate, and it does. It explains all six parameters with concrete examples (e.g., keyword examples like 「把询价单退回到报价中」), enumerates doc_type and category options, and clarifies use_semantic's default and fallback behavior. This adds substantial meaning beyond the bare input schema.
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 clearly states the tool retrieves reusable SQL templates from a template library and should be called before generating SQL. It distinguishes itself by specifying a hybrid retrieval approach (semantic vector + keyword fuzzy matching), which differentiates it from siblings like semantic_search_sql_template and list_sql_templates.
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?
The description provides a clear usage context: call before generating SQL to form a closed loop. It also explains the automatic fallback when NVIDIA_API_KEY is not configured. However, it does not explicitly name alternative tools or state when not to use this tool versus its siblings.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
semantic_search_sql_templateA
用语义向量召回模板,适合自然语言/口语化描述(如同义改写、业务意图)。
底层调用 schema.sql 的 match_sql_templates RPC(pgvector 余弦距离)。 需配置 NVIDIA_API_KEY;未配置或调用失败时返回降级提示。
参数:
query: 自然语言查询(如「把询价单退回到报价中状态」「查某供应商名下所有在执行的招标单」)
doc_type: 按单据类型过滤(通用/询价单/招标单/征询单/数据修复)
category: 按业务分类过滤(通用基础查询/询价单RFX/征询单RF/数据修复)
verified_only: 仅返回「✅ 已验证」模板
threshold: 相似度阈值(0~1,越高越严格,默认 0.5)
limit: 返回条数上限
返回:按语义相似度排序的模板 Markdown 列表(含相似度分值)。
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| query | Yes | ||
| category | No | ||
| doc_type | No | ||
| threshold | No | ||
| verified_only | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden and does a thorough job: it discloses the underlying match_sql_templates RPC, pgvector cosine distance, the NVIDIA_API_KEY requirement, the degradation behavior when the key is missing or the call fails, and the sorted Markdown return format. This goes well beyond a generic search description.
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 description is compact and well-structured: a one-sentence purpose, a short implementation/prerequisite note, a clean parameter list with human explanations, and a one-line return summary. Every element earns its place; no filler or 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?
Given six parameters, no annotations, and only an empty schema description, this tool's description is complete: it covers purpose, computational model, configuration prerequisite, failure behavior, parameter semantics, and return format. The presence of an output schema further reduces the need to explain return structure, but the description adds the useful Markdown/similarity-score 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 0%, and the description compensates fully by explaining all six parameters: query with concrete business examples, permitted doc_type/category values, verified_only filtering, threshold range with default, and limit. This adds substantial meaning beyond the raw input schema.
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?
Description opens with a specific verb+resource: '用语义向量召回模板' and states it suits natural-language/paraphrased queries such as '把询价单退回到报价中状态'. This semantic-search scope clearly distinguishes it from sibling tools like search_sql_template.
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 clear usage context: use for natural language/口语化 descriptions and semantic similarity, and it lists the prerequisite NVIDIA_API_KEY plus fallback behavior. It does not explicitly name alternatives or say 'do not use for exact keyword matching', but the suitability framing is enough.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
update_sql_templateB
更新已有模板的字段(如补充验证标记、修正 SQL、补充执行过程伪代码)。
execution_flow: 执行过程伪代码([INPUT]/[STEP]/QUERY/ASSERT/CONDITION/ACTION), 为存量高频数据修复模板渐进式补充,指导大模型分步执行。
example_case: 脱敏示例(输入参数 → 中间结果 → 最终 SQL 的完整轨迹)。
| Name | Required | Description | Default |
|---|---|---|---|
| title | No | ||
| category | No | ||
| doc_type | No | ||
| keywords | No | ||
| scenario | No | ||
| sql_text | No | ||
| verified | No | ||
| core_tables | No | ||
| template_id | Yes | ||
| template_no | No | ||
| verified_at | No | ||
| example_case | No | ||
| placeholders | No | ||
| execution_flow | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must carry the full behavioral burden. It explains the intended content of execution_flow and example_case, but does not disclose whether omitted fields are preserved or reset, what happens if the template does not exist, required permissions, or response/error 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?
The description is short and front-loaded: the first sentence states the core action, and the bullet points add only the field-specific guidance that is most likely to need explanation. No redundant or filler content is present.
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?
For a mutation tool with 14 parameters, no annotations, and zero schema descriptions, this description is severely incomplete. It covers only two fields in detail and leaves critical update semantics—partial vs. full replacement, validation, error cases, and permissions—entirely unaddressed.
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 0%, so the description must compensate for 14 parameters. It adds meaningful detail for only execution_flow and example_case, while the remaining 12 parameters (e.g., title, category, verified, placeholders) receive no semantic explanation beyond their schema names and defaults.
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 uses a specific verb ('更新' / update) and a concrete resource ('已有模板的字段' / fields of existing templates), with examples of what can be updated. This clearly differentiates it from sibling tools like get, search, list, delete, and save.
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?
The text implies the tool is for existing templates via '已有模板', but it does not explicitly state when to use this tool versus save_sql_template or when not to use it. There are no named alternatives or exclusion conditions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
TDQS
The tools are mostly distinct: save/get/search/list/update/delete/record cover different CRUD and search operations. However, search_sql_template and semantic_search_sql_template overlap in purpose (both retrieve templates), though the descriptions clarify the semantic variant is for natural language queries. This slight overlap prevents a perfect score.
All tool names follow a consistent verb_noun pattern: save_sql_template, get_sql_template, search_sql_template, semantic_search_sql_template, list_sql_templates, update_sql_template, delete_sql_template, record_template_usage. The pattern is uniform and predictable, with clear verbs and the domain noun 'sql_template' (or plural in list).
With 8 tools, the server is well-scoped for a template management system. Each tool serves a distinct function: CRUD operations, two search modes, and usage tracking. This is within the ideal 3-15 range and feels complete without being bloated.
The tool surface covers the full lifecycle of SQL templates: create (save), read (get, search, list), update, delete, and usage tracking. The two search modes (keyword and semantic) address different retrieval needs. No obvious gaps exist for the stated purpose of managing a template library.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
- mcpOAuthcom.gibsonai
GibsonAI MCP server: manage your databases with natural language
MCP server for VC pitch-deck scoring, thesis-fit matching, and deal-flow management.
Token-free MCP server for structured RevoGrid Core, Pro, and Enterprise knowledge retrieval.
Related MCP Servers
- AlicenseAqualityFmaintenanceMCP server for semantic code search that indexes your codebase and allows AI editors to search using natural language queries.911253MIT
- AlicenseAqualityAmaintenanceMCP server for semantic code search with AST-aware chunking, hybrid vectors, and query syntax.111Apache 2.0
- AlicenseNot gradedqualityBmaintenanceAn MCP server that provides SQL generation, validation, transpilation, and schema introspection across 10 SQL dialects, using a property graph schema and phase-locked reasoning to convert natural language to accurate SQL.2MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server for semantic code search using Qdrant vector database, enabling natural language queries to find relevant code snippets across indexed codebases.MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/nichuan/sql-template-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server