跳至主要內容
hs-sql-agent
2.0.2
文件 2.0.2
文件 MCP

MCP Tools Reference

hs-sql-agent 2.0.1 正式 built-in MCP tools 的參數、回傳、authorization 與風險邊界。

low risk
Schema discovery get_schemas、get_tables、get_columns 先探索 key 綁定的 database,再產生 SQL。
read
Query SQL execute_query_sql 接受單一 governed SELECT,回傳 serialized result rows。
approval
Safe DML execute_dml_sql 只能透過 preview、Elicitation 與 commit-time revalidation 執行支援的 mutation。

2.0.1 由 MCP key 正式管理的 built-in tool surface 只有五個 tool names:

ToolPublic inputResult shapeRisk
get_schemascomma-separated schema namesmetadata read
get_tablesschemaName: stringcomma-separated table descriptionsmetadata read
get_columnsschemaName: string, tableName: stringJSON array of column objectsmetadata read
execute_query_sqlsql: stringJSON result rows,或 execution error textdata read
execute_dml_sqlsql: stringapproval/execution result textdata mutation

Published Custom Tools 可以依 database 擴充 tool collection,但不算額外 built-in tools。

建議 discovery flow

01 get_schemas
02 get_tables
03 get_columns
04 execute_query_sql
先探索 physical structure,再要求 model 產生 SQL。DML 刻意不放進預設 read flow。

Client 不知道可靠 schema 時,先用 metadata tools。這些 tool 都在 authenticated key 的 database context 中執行,不接受 model 自行傳入 connection string。

get_schemas

回傳 MCP key 綁定 database 的 provider metadata runtime 所提供的 schemas。

Parameters: 無。

Success result: 以逗號串接的 schema names。

Authorization / limits:

  • explicit tool allowlist 存在時,key 必須允許 get_schemas
  • database provider/connection 由 authenticated key context 解析;
  • operation 會取得 shared SQL-concurrency limiter lease;
  • success/failure 會寫 audit action mcp.get_schemas

Tool 不接受 database ID 或 connection string 作為 model input。

get_tables

get_tables(schemaName: string)

回傳指定 schema 的 provider-reported tables;如果 MCP key 有 table whitelist,結果會先被過濾。

如果綁定的 Database Management entry 有 semantic metadata,可見 table 還可能附加:

  • display name;
  • description;
  • synonyms;
  • 該 table scope 下的 metric descriptions。

Success result: comma-separated string,因此 entry 可能比 raw physical table name 更豐富。

Audit action: mcp.get_tables

get_columns

get_columns(schemaName: string, tableName: string)

Server 先檢查 requested qualified table 是否在 MCP key 允許範圍,再讀 provider column metadata,最後 serialize 成 JSON array。

2.0.1 每個 ColumnInfo object 會暴露:

Property意義
Namephysical column name
Column同一 column-name value 的 alias
Typeprovider-reported column type
Description有 semantic enrichment 時的描述
IsPrimaryKeyprovider metadata 是否標示為 primary key 一部分
PrimaryKeyOrdinalcomposite primary key 中的 nullable ordinal

Semantic enrichment 可以把 display name、description、synonyms 與 relationship descriptions 加進 Description。Relationship context 只有在 key table whitelist 同時允許兩端 table 時才會出現。

Audit action: mcp.get_columns

execute_query_sql

execute_query_sql(sql: string)

接受單一 SELECT SQL statement。2.0.1 public tool description 明確列出常見 query forms:JOIN、WHERE、GROUP BY、HAVING、ORDER BY、LIMIT/OFFSET、DISTINCT、CTE、subquery,以及 UNION/INTERSECT/EXCEPT。

01 Parse
02 Bind
03 Authorize tables
04 Validate policy
05 Compile immutable command
06 Execute
Raw SQL 不會直接送給 provider。

Request 進入 F# typed-query runtime。Runtime 會在 governed path 中取得 referenced tables、CTE/subquery 等 facts,並用於 audit evidence。

Success result: returned row collection 的 JSON serialization。

Failure result: 一般失敗回傳以 Execution failed: 開頭的文字;caller cancellation 則直接 propagate,不會包成普通 result string。

Runtime boundaries:

  • MCP tool allowlist;
  • MCP-key database binding;
  • table whitelist;
  • current security/query policy;
  • SQL concurrency limiter;
  • source/target SQL capability checks;
  • audit event mcp.query.executed,記錄 operation、duration、returned rows 與 compiler-derived definition facts。

可搭配 SQL 支援參考

execute_dml_sql

execute_dml_sql(sql: string)

MCP-visible input 是 SQL。.NET method 裡的 McpServer 與 cancellation token 是 runtime 注入的 infrastructure,不是 agent 要傳的欄位。

2.0.1 MCP DML path 支援:

Statement狀態
UPDATEparse、capability、policy、approval 全部通過時支援
DELETEparse、capability、policy、approval 全部通過時支援
INSERT ... VALUES支援 immutable-payload approval semantics
INSERT ... SELECT2.0.1 fail-closed 拒絕
01 Parse + verify profile
02 Compile mutation
03 Preview exact impact
04 Human Elicitation
05 Transaction revalidation
06 Commit
Approval 綁定 validated mutation context,不只是原始 SQL 文字。

UPDATE/DELETE approval 會綁定精確 primary-key row set,commit-time code 在 transaction 內再次驗證 row identities。INSERT VALUES 則把 approval 綁定 immutable literal payload 與 exact compiled command,commit 時再驗證 approved payload row count。

若真人拒絕或 validation 無法完成,mutation 不 commit。Audit 使用 mcp.dml.executed,並記錄 operation、processing duration、affected rows、approval status 與必要的 error category。

完整 protocol 請見 Safe DML

Built-in tools 的共通 errors

常見失敗包括:

  • MCP authorization context 缺失;
  • explicit tool allowlist 不含該 tool;
  • database provider/connection configuration 無效;
  • SQL-concurrency limiter 無法取得 lease(Server busy);
  • requested table 不在 key whitelist;
  • SQL 為空、語法不支援、policy rejection 或 capability rejection;
  • provider execution failure。

Tool 會回傳 bounded error information,而不是 fallback 到 unrestricted provider execution。

Custom Tools

Published Custom Tools 會依 MCP key 綁定的 Database Management entry 載入,也可以依名稱放進同一個 AllowedTools。執行仍會經過 runtime database binding、table whitelist、security policy、concurrency controls、audit path;DML custom tool 同樣要走 approval pipeline。

請見 Custom Tools

Semantic metadata 不列為第六個正式 built-in

2.0.1 repository 裡確實存在 semantic-management implementation detail,但正式 MCP key built-in registry 與 Admin key-management surface 所管理的仍是本頁五個 tools。因此官方 2.0.1 docs 把 semantic metadata 視為由 Admin/control plane 管理、由 schema discovery 消費的能力,不把它宣稱成額外正式 built-in MCP contract。

請見 Semantic Metadata