
MCP Toolbox 实战使用 looker-get-parameters 工具检索 Looker Explore 参数【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox导读looker-get-parameters是 MCP Toolbox for Databases 中 Looker 集成工具集toolset的一员用于返回指定 Looker 模型中某个 explore 内定义的全部 LookML 参数parameters元数据。本文以 looker-get-parameters.md 为核心结合仓库源码 lookergetparameters.go 与预构建配置 looker.yaml完整讲解该工具的配置方法、调用参数、返回结构、底层实现原理与常见使用场景读完即可在 MCP Toolbox 中配置并使用该工具为 LLM 提供动态 LookML 参数能力。工具概述什么是 looker-get-parameters在 Looker 中parameter是 LookML 中一类特殊的字段类型parameter:它不直接参与GROUP BY而是作为用户可见的动态输入控件配合liquid模板如{% parameter %}影响查询行为从而在不修改底层 LookML 的前提下实现灵活的数据探查、动态仪表盘与报表。looker-get-parameters工具正是为这类场景设计它读取某个 explore 的元数据返回其中定义的全部参数及其属性让 LLM 或用户了解该 explore 提供哪些可动态注入的输入项。文档对该工具的定位是Alooker-get-parameterstool returns all the parameters from a given explore in a given model in the source.该工具只接收两个输入参数model模型名与exploreexplore 名对应 Looker API 中的GET /4.0/lookml_models/{model_name}/explores/{explore_name}接口。配置示例在 MCP Toolbox 中注册该工具MCP Toolbox 通过 YAML 配置文件声明工具。looker-get-parameters的典型配置如下完整示例同样出现在预构建配置 looker.yaml 中工具名为get_parameterskind: tool name: get_parameters type: looker-get-parameters source: looker-source description: | This tool retrieves a list of parameters defined within a specific Looker explore. LookML parameters are dynamic input fields that allow users to influence query behavior without directly modifying the underlying LookML. They are often used with liquid templating to create flexible dashboards and reports, enabling users to choose dimensions, measures, or other query components at runtime. Parameters: - model_name (required): The name of the LookML model, obtained from get_models. - explore_name (required): The name of the explore within the model, obtained from get_explores.各字段含义如下表fieldtyperequireddescriptiontypestringtrue必须为looker-get-parameters。sourcestringtrue该工具执行所依赖的 source 名称须为 Looker source如looker-source。descriptionstringtrue传递给 LLM 的工具描述帮助模型理解何时调用该工具。配置解析的源码印证工具类型通过包级init()注册到全局工具注册表tools.Register(resourceType, newConfig)其中resourceType looker-get-parameters见 lookergetparameters.go。若类型重复注册会直接panic保证类型名的唯一性。Config结构体将type、source标为validate:requireddescription在Initialize阶段被强校验——若为空会返回错误description is required for tool ...见 lookergetparameters.go。测试用例 lookergetparameters_test.go 验证了合法配置可被正确解析为Config{Type: looker-get-parameters, Source: my-instance}同时TestFailParseFromYamlLookerGetParameters证明未知字段如method会导致解析失败并报错unknown field method说明该工具配置不接受任何额外字段。运行时参数model 与 explore该工具暴露给 LLM 的运行时参数由公共函数GetFieldParameters()定义见 lookercommon.gomodelstring必填包含目标 explore 的 LookML 模型名通常来自looker-get-models工具的返回结果explorestring必填模型内的 explore 名通常来自looker-get-explores工具的返回结果。调用时Invoke通过ProcessFieldArgs见 lookercommon.go从参数映射中取出model与explore两个字符串若类型不符会返回model must be a string, got %T之类的 Agent 级错误。这两个参数在预构建配置的描述中同样被标注为 required形成先用get_models/get_explores枚举再用get_parameters深入的工具链协作模式。返回结构参数元数据 JSON 数组调用成功后工具返回一个 JSON 数组数组中的每个元素对应 explore 中的一个参数结构如下文档原文{ name: field name, description: field description, type: field type, label: field label, label_short: field short label, tags: [tags, ...], synonyms: [synonyms, ...], suggestions: [suggestion, ...], suggest_explore: explore, suggest_dimension: dimension }各字段语义字段说明name参数的 LookML 全限定名如view.parameter_namedescription参数的描述信息type参数类型如unquoted、string等label参数的完整显示标签label_short参数的短标签tags参数上配置的标签数组synonyms同义词数组suggestions建议取值数组仅当参数suggestable为 true 时返回suggest_explore提供建议值的 exploresuggest_dimension提供建议值的 dimension响应生成的源码细节返回结构由ExtractLookerFieldProperties见 lookercommon.go从 Looker SDK 的LookmlModelExploreField对象转换而来关键处理逻辑包括跳过_raw字段以_raw结尾的字段名会被直接跳过strings.HasSuffix(*v.Name, _raw)避免把底层原始字段混入结果隐藏字段过滤当 source 的show_hidden_fields为 false 时hiddentrue的参数被过滤为 true 时全部返回见 looker.go 的LookerShowHiddenFields()可建议性suggestable控制只有suggestable为 true 时才输出suggestions且仅当suggest_explore与suggest_dimension同时存在时才输出这两个字段nil 安全所有指针字段均判空后才写入 map字段缺失时直接省略对应 key。底层实现原理一次 Looker API 调用链looker-get-parameters的核心调用链位于 lookergetparameters.go 的Invoke方法source 类型断言运行时将sources.Source断言为compatibleSource接口见 lookergetparameters.go该接口要求实现GetLookerSDK、LookerApiSettings、LookerShowHiddenFields等能力——由 Looker source 提供见 looker.go。不兼容的 source 会返回 500 错误获取 SDK通过source.GetLookerSDK(ctx, accessToken)取得 Looker v4 SDK 实例构造请求使用v4.RequestLookmlModelExplore{LookmlModelName, ExploreName, Fields}其中Fields由公共常量ParametersFields指定fields(parameters(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))该字段子集见 lookercommon.go与DimensionsFields/MeasuresFields/FiltersFields结构一致仅将集合替换为parameters属于同一套字段元数据提取机制发起请求sdk.LookmlModelExplore(req, source.LookerApiSettings())调用 Looker API 的 explore 元数据端点。若返回 401包装为unauthorized error其他错误交由ProcessGeneralError统一处理校验与提取CheckLookerExploreFields检查响应中Fields是否为 nil随后ExtractLookerFieldProperties完成字段转换最终以[]anyJSON 数组形式返回给调用方。该工具被标记为只读工具tools.NewReadOnlyAnnotations并支持客户端授权RequiresClientAuthorization委托给 source 的UseClientAuthorization()认证令牌通过GetAuthTokenHeaderName指定的 header 传递。典型使用场景与工具链协作looker-get-parameters在 MCP Toolbox 的 Looker 工具集中与以下工具配合形成完整的元数据发现 → 查询构建工作流发现阶段用looker-get-models枚举模型用looker-get-explores枚举 explore深入阶段调用looker-get-parameters获取目标 explore 的可用参数同时可用looker-get-dimensions、looker-get-measures、looker-get-filters获取其余字段类型looker.yaml 明确提示Use get_dimensions, get_measures, get_filters, and get_parameters to find valid fields执行阶段基于获取到的参数/字段元数据用looker-query等工具构建并执行查询其中type: unquoted参数的值会被原样替换进 SQL见 lookercommon.go 对 unquoted 参数的转义处理。该工具已纳入 Looker 预构建工具集可在 looker.yaml 的 toolset 列表中找到get_parameters条目说明它与其他 60 个 Looker 工具一起默认向启用该 toolset 的实例开放。实践提示source 必须为 Looker sourcetype: looker-get-parameters仅与 Looker 类型 source 兼容若 source 不实现compatibleSource接口配置校验ValidateSource或运行时会直接报错见 lookergetparameters.godescription 不要留空该字段会作为 LLM 的工具说明决定模型能否在正确时机调用工具也是唯一的必填描述性字段区分参数与过滤字段该工具只返回 LookML 中显式声明为parameter:的字段普通 dimension/measure 也可用作查询过滤条件但不会出现在参数列表中looker.yaml 明确说明This tool *only* returns fields explicitly defined as filter: in LookML隐藏字段可见性若 source 配置show_hidden_fields: false默认值在 looker.go 中为true结果中将自动剔除hidden: yes的参数错误排查401 通常表示认证失败looker API response or its fields object is nil表示 explore 不存在或模型/explore 名称拼写错误。小结looker-get-parameters是 MCP Toolbox Looker 工具集中面向动态 LookML 参数的专用元数据工具它只依赖model与explore两个必填参数通过 Looker v4 SDK 的 explore 元数据端点一次性拉取参数集合并按suggestable、hidden等属性做精细化裁剪后返回结构化 JSON。开发者只需按文档中的 YAML 模板声明工具即可让 LLM 具备发现 explore 内可用参数的能力为后续基于liquid模板的动态查询、仪表盘构建等场景提供元数据支撑。【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考