MCP Toolbox 的 looker-update-project-file 工具:通过 Looker API 更新项目 LookML 文件内容 MCP Toolbox 的 looker-update-project-file 工具通过 Looker API 更新项目 LookML 文件内容【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox导读looker-update-project-file是 MCP Toolbox for Databases 中 Looker 集成工具集Looker toolset提供的文件管理工具之一用于在 Looker 实例的指定项目中覆盖更新一个 LookML 文件的完整内容。本文以官方工具文档 looker-update-project-file.md 为主体结合该工具的 Go 源码实现、预置配置与测试用例讲解其功能定位、YAML 配置方式、运行时参数、底层 API 调用链与失败场景帮助开发者与 LLM Agent 准确理解并正确使用这一写操作型工具。工具功能定位在开发模式下更新 LookML 文件looker-update-project-file的功能是更新项目中一个 LookML 文件的内容官方文档。与只读型工具不同它会向 Looker 实例发起一次覆盖写操作因此需要满足明确的前提条件必须传入project_id参数用于定位 LookML 项目必须传入file_path参数指明项目中待修改文件的精确路径必须传入新的文件内容用于整体覆盖该文件的现有内容前置条件Looker 会话必须处于 Development Mode开发模式。官方文档与预置配置均明确提示The Looker session must be in Development Mode. Use dev_mode: true first.即 Agent 在使用本工具之前应先用开发模式工具looker-dev-mode将会话切换为开发模式否则 API 写入会被拒绝。这一工具与 Looker 文件管理工具族中的其他成员协同工作looker-create-project-file负责新建文件、looker-get-project-file/looker-get-project-files负责读取文件、looker-delete-project-file负责删除文件而looker-update-project-file则专门负责对既有文件做全量内容覆盖常用于模型迭代、字段增改、修正 LookML 语法等场景。在 MCP 配置中注册该工具looker-update-project-file以工具tool的形式声明在 MCP Toolbox 的配置文件中与 Looker 数据源source绑定使用。以下是官方文档给出的标准 YAML 配置示例kind: tool name: update_project_file type: looker-update-project-file source: looker-source description: | This tool modifies the content of an existing LookML file within a specified project. Prerequisite: The Looker session must be in Development Mode. Use dev_mode: true first. Parameters: - project_id (required): The unique ID of the LookML project. - file_path (required): The exact path to the LookML file to modify within the project. - content (required): The new, complete LookML content to overwrite the existing file. Output: A confirmation message upon successful file modification.该示例同样出现在仓库预置配置 looker-dev.yaml 中并已加入该配置的 Looker 开发工具集合looker-dev.yaml 中工具列表包含update_project_file。在配置项中kind固定为tool声明这是一个工具资源name是工具在 MCP 服务器中的注册名本例为update_project_file供模型按名调用type固定为looker-update-project-file标识工具类型source指向 Looker 数据源的名称本例为looker-source工具运行时通过该数据源获得连接信息与认证description是传给 LLM 的工具说明用于让模型理解工具用途、参数语义与前置条件因此应写清参数清单与输出形态。参考字段表根据官方文档该工具配置的顶层字段如下fieldtyperequireddescriptiontypestringtrueMust be looker-update-project-file.sourcestringtrueName of the source Looker instance.descriptionstringtrueDescription of the tool that is passed to the LLM.从源码角度看上述字段在 lookerupdateprojectfile.go 中对应Config结构体其中type与source均带validate:required校验约束description为空时工具初始化会直接报错description is required for tool %qlookerupdateprojectfile.go。这意味着配置描述不仅是给 LLM 的提示词也是工具可用的硬性校验条件。运行时参数解析与校验工具真正暴露给 LLM 的三个运行时参数由Initialize方法定义lookerupdateprojectfile.go参数名类型是否必填说明project_idstring是包含待修改文件的 LookML 项目 IDfile_pathstring是项目内文件的路径file_contentstring是文件的新内容注意配置示例中的description写作content而源码中实际接收的参数名为file_contentlookerupdateprojectfile.go。description中的参数名是给 LLM 阅读的自然语言说明模型在真正调用时须以 MCP 工具清单中声明的参数名为准二者语义一致都表示文件的新完整内容。在Invoke执行阶段lookerupdateprojectfile.go三个参数会逐一从params.AsMap()中取出并做类型断言若任一参数缺失或类型不是 string工具会返回 Agent 级错误如project_id must be a string, got %T不会发起任何 API 请求。底层实现PUT /projects/{project_id}/files 调用链工具的核心逻辑并不直接内联在工具文件中而是委托给 Looker 公共实现包lookercommon的UpdateProjectFile函数lookercommon.gofunc UpdateProjectFile(l *v4.LookerSDK, projectId string, fileContent FileContent, options *rtl.ApiSettings) error { path : fmt.Sprintf(/projects/%s/files, url.PathEscape(projectId)) err : l.AuthSession.Do(nil, PUT, /4.0, path, nil, fileContent, options) return err }这里可以看到完整的底层调用链工具通过数据源的GetLookerSDK获取 Looker SDK v4 客户端lookerupdateprojectfile.go连接信息与 API 设置取自数据源的LookerApiSettings()将file_path与file_content组装为FileContent结构体lookercommon.goJSON 字段名为path与content调用 Looker API 4.0 的PUT /projects/{project_id}/files接口project_id经过url.PathEscape转义后拼入路径file_content作为请求体发送该接口即 Looker 官方 API 中更新项目文件的端点要求会话处于开发模式且文件须已存在新建文件应使用同族的POST /projects/{project_id}/files即CreateProjectFilelookercommon.go。成功返回后工具输出一条文本确认消息lookerupdateprojectfile.go{ type: text, text: updated file {file_path} in project {project_id} }即文档中所述修改成功后的确认消息。失败场景与错误处理工具的 API 调用错误处理集中在 lookerupdateprojectfile.go401 未授权当错误信息包含status401时工具返回401 Unauthorized的客户端/服务器错误提示认证或授权失败例如开发模式下凭据无效、权限不足其他错误统一交给util.ProcessGeneralError归类处理。从源码结构可以推断由于这是写操作型工具其默认注解annotation为破坏性工具注解tools.NewDestructiveAnnotationslookerupdateprojectfile.goMCP 服务器会据此在工具清单中标注其破坏性语义提醒调用方谨慎执行用户也可以在配置中通过annotations字段覆盖默认注解。配置解析与测试验证工具注册在init()中完成通过tools.Register(looker-update-project-file, newConfig)注册到 MCP Toolbox 的全局工具注册表lookerupdateprojectfile.go配置解析器将 YAML 解码到Config结构体。仓库配套测试 lookerupdateprojectfile_test.go 覆盖了两类场景合法配置解析TestParseFromYamlLookerUpdateProjectFile一个包含kind/name/type/source/description的基础 YAML 示例断言能正确解析出Type: looker-update-project-file、Source: my-instance且AuthRequired默认为空数组非法配置拒绝TestFailParseFromYamlLookerUpdateProjectFile当配置中出现未知字段如method: GOT时解析会报unknown field method错误印证了该工具配置的字段白名单是严格校验的——type、source、description以及可选的name、annotations、authRequired之外的多余字段会导致整个工具配置解析失败。与 Looker 文件工具族的配合使用looker-update-project-file在 Looker 集成中通常与其他文件管理工具组合成完整工作流。参照同一工具目录docs/en/integrations/looker/tools与预置配置 looker-dev.yaml典型流程为先用looker-get-projects/looker-get-project-files查询项目与文件清单拿到确切的project_id与file_path用looker-get-project-file读取文件当前内容作为修改基线使用looker-dev-mode将会话切到开发模式dev_mode: true调用looker-update-project-file提交新的完整文件内容如需校验可继续调用looker-validate-project对修改后的 LookML 项目做整体校验。整个链路与 Looker 的项目文件版本化机制一致在开发模式下的文件修改会落到本地 Git 分支之后可通过looker-create-git-branch、looker-switch-git-branch等 Git 工具管理分支提交最终合并发布实现代码即模型LookML as Code的 Agent 化迭代闭环。总结looker-update-project-file是 MCP Toolbox Looker 集成中一个职责单一、边界清晰的写操作工具它接受project_id、file_path、file_content三个必填字符串参数在 Looker 会话处于开发模式的前提下通过 Looker API 4.0 的PUT /projects/{project_id}/files端点整体覆盖目标 LookML 文件并返回文本确认消息。其配置侧校验严格、参数类型强校验、错误处理区分授权失败与一般失败同时配套完整的预置配置与解析测试既适合 LLM Agent 直接调用也为开发者二次集成提供了可参考的实现范式。【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考