使用 mcp-toolbox 的 looker-get-connection-tables 工具从 Looker 连接中枚举表结构【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolboxlooker-get-connection-tables是 MCP Toolbox for Databases本仓库为 Looker 集成提供的一款只读 MCP 工具用于返回指定 Looker 数据库连接下某个 schema 内的全部表。本文以该工具的官方文档为核心结合仓库源码与测试完整讲解其参数语义、YAML 配置方式、底层 Looker SDK 调用链与返回结构并说明它在连接发现工具链中的实际用法帮助你在 Agent 场景中直接落地使用。工具定位Looker 连接元数据发现链的关键一环在 mcp-toolbox 的 Looker 集成中数据库元数据发现被拆分为一系列职责单一的只读工具looker-get-connection-tables处于连接 → schema → 表 → 列逐层下钻的中间位置looker-get-connections列出 Looker 中配置的全部数据库连接无参数looker-get-connection-schemas列出某连接下的 schema接受conn与可选的dblooker-get-connection-tables本文主角列出某 schema 下的全部表looker-get-connection-table-columns进一步列出表内的列信息如列名、数据类型、是否可空。相关工具的完整预置配置可在 looker-dev.yaml 中查看各工具通过type字段区分例如本工具的类型固定为looker-get-connection-tables。按照官方文档的定义该工具返回一个连接中的所有表接受必填的conn、schema参数以及可选的db参数见 looker-get-connection-tables.md。参数说明conn、schema 与可选的 db工具的运行时参数由Initialize阶段声明见 lookergetconnectiontables.go具体如下参数类型必填说明connstring是包含目标表的数据库连接名称来源于get_connections的输出schemastring是要枚举表的 schema 名称来源于get_connection_schemas的输出dbstring否可选的目标数据库名仅对支持多数据库的连接生效可用get_connections的supports_multiple_databases字段判断源码中的参数注册与文档完全一致lookergetconnectiontables.goconnParameter : parameters.NewStringParameter(conn, The connection containing the tables.) dbParameter : parameters.NewStringParameter(db, The optional database to search, parameters.WithStringRequired(false)) schemaParameter : parameters.NewStringParameter(schema, The schema containing the tables.)在Invoke阶段conn与schema会被强制断言为字符串若类型不符则返回 Agent 级错误db通过类型断言安全读取db, _ : mapParams[db].(string)为空时不会传入请求lookergetconnectiontables.go。YAML 配置示例完整字段与参数描述该工具是 MCP Toolbox 的预置/自定义工具之一通过声明式 YAML 注册。官方文档给出的最小可用配置如下kind: tool name: get_connection_tables type: looker-get-connection-tables source: looker-source description: | This tool retrieves a list of tables available within a specified database schema through a Looker connection. Parameters: - connection_name (required): The name of the database connection, obtained from get_connections. - schema (required): The name of the schema to list tables from, obtained from get_connection_schemas. - database (optional): The name of the database to filter by. Only applicable for connections that support multiple databases (check with get_connections). Output: A JSON array of strings, where each string is the name of an available table.字段说明来自官方文档的 Reference 表格与源码Config结构对应见 lookergetconnectiontables.go字段类型必填说明typestring是必须为looker-get-connection-tablessourcestring是所用 Looker 实例的 source 名称descriptionstring是传给 LLM 的工具描述直接影响模型的调用判断几点实践提示description是必填的。Initialize中若cfg.Description 会直接报错description is required for tool ...lookergetconnectiontables.go因此请在描述中写清参数来源如连接名取自get_connections与输出格式帮助 Agent 正确组织调用链。source必须指向兼容的 Looker source。ValidateSource会检查 source 是否实现了compatibleSource接口UseClientAuthorization、GetAuthTokenHeaderName、LookerApiSettings、GetLookerSDK不匹配会返回source is not a compatible type错误lookergetconnectiontables.go。字段不可随意扩展。单元测试验证了 YAML 解析的严格性若在配置中多写method字段解析会失败并提示unknown field method见 lookergetconnectiontables_test.go。该工具在预置配置中的实际写法可参考 looker-dev.yaml其description与官方文档示例一致source统一指向looker-source。底层实现从 Invoke 到 Looker SDK 的完整调用链当 Agent 调用该工具时执行路径如下核心逻辑见 lookergetconnectiontables.go类型校验从parameters.ParamValues解析出conn、schema、可选db获取 SDK调用source.GetLookerSDK(ctx, accessToken)得到 Looker v4 SDK 实例。在客户端授权end-user token模式下SDK 的 HTTP 传输层会注入Authorization与x-looker-appid: go-sdk请求头并支持透传X-Forwarded-For/X-Real-IP若未提供 access token 则报错no access token supplied with request见 looker.go构造请求组装v4.RequestConnectionTables{ConnectionName: conn, SchemaName: schema}仅在db非空时设置Database字段lookergetconnectiontables.go调用 API执行sdk.ConnectionTables(req, source.LookerApiSettings())即 Looker API v4 的GET /connections/{connection_name}/tables语义错误处理若 SDK 返回包含status401的错误统一转换为401 unauthorized其余错误经util.ProcessGeneralError归一化处理lookergetconnectiontables.go。返回结构不只是表名数组值得注意官方文档description中写给 LLM 的是A JSON array of strings简化语义但源码实际返回的是带 schema 分组的对象数组lookergetconnectiontables.go。每条记录结构为{ schema_name: demo_db, is_default: true, tables: [ { table_name: Employees, sql_escaped_name: Employees } ] }字段含义schema_name本次查询的 schema 名is_default该 schema 是否为连接的默认 schematables表对象数组每个对象含table_name表名与sql_escaped_nameSQL 转义后的表名可直接拼接进 SQL 语句。理解这一真实结构有助于你在上层编排时正确解析结果或为 LLM 编写更精确的description。测试验证单元测试与端到端集成测试仓库为该工具提供了两级测试保障配置解析单元测试lookergetconnectiontables_test.go验证最小 YAML 配置能被正确解析为Config结构包括Name、Description、Type、Source与空AuthRequired同时验证非法字段会被拒绝。端到端集成测试looker_integration_test.go一方面断言 MCP 工具清单中get_connection_tables暴露的参数与源码注册一致conn必填、db可选、schema必填且描述文本逐字匹配另一方面实际发起调用tests.RunToolInvokeParametersTest(t, get_connection_tables, []byte({conn: thelook, schema: demo_db}), wantResult) // wantResult Employees即对连接thelook、schemademo_db的调用返回了表Employees与同文件中对get_connection_schemas返回demo_db、get_connection_table_columns返回EmpID等列信息的断言构成了完整的连接发现链路验证looker_integration_test.go。在 Agent 工作流中的典型用法在实际的数据库问答或分析场景中looker-get-connection-tables通常不是孤立调用而是作为元数据发现流水线的一环get_connections → get_connection_schemas → get_connection_tables → get_connection_table_columns → 生成 SQL / LookML先用get_connections拿到连接列表通过supports_multiple_databases判断是否需要传db用get_connection_schemas枚举 schema再用本工具枚举目标 schema 下的表最后用get_connection_table_columns获取列级信息为后续查询生成提供完整元数据。小结looker-get-connection-tables是 mcp-toolbox Looker 集成中稳定、只读的元数据枚举工具配置上仅需type、source、description三个字段即可注册运行时通过connschema可选db驱动底层 Looker v4 SDK 的ConnectionTables接口返回值携带 schema 分组与sql_escaped_name便于直接衔接 SQL 生成。配合官方文档与 looker-dev.yaml 预置配置你可以在数分钟内将其接入自己的 MCP Server 配置为 Agent 补齐连接内有哪些表这一关键元数据能力。【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考