ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

在 MCP Toolbox 中使用 looker-delete-agent:删除 Looker Conversation Analytics Agent 的完整指南

在 MCP Toolbox 中使用 looker-delete-agent:删除 Looker Conversation Analytics Agent 的完整指南 在 MCP Toolbox 中使用 looker-delete-agent删除 Looker Conversation Analytics Agent 的完整指南【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox本指南聚焦 MCP Toolbox 项目中looker-delete-agent工具讲解如何让 LLM大语言模型通过 Looker Go SDK 删除 Looker Conversation Analytics Agent涵盖工具调用格式、server.yaml配置方式、与 Looker source 的配合要点并结合仓库源码剖析其参数校验、SDK 调用链与安全性设计。读完本文你将能够在自己的 MCP Toolbox 配置中安全地接入并调用删除 Agent 的能力。工具概述为 LLM 提供的 Agent 删除能力looker-delete-agent是 MCP Toolbox 为 Looker 集成提供的一组 Conversation Analytics对话式分析Agent 管理工具之一其功能定义见 looker-delete-agent.mdThelooker-delete-agenttool allows LLMs to delete a Looker Agent using the Looker Go SDK.在 MCPModel Context Protocol架构中工具是暴露给 LLM 的可调用能力。LLM 通过 JSON-RPC 请求调用工具MCP Toolbox 作为服务端接收请求、完成鉴权并最终通过 Looker 官方 Go SDKgithub.com/looker-open-source/sdk-codegen/go/sdk/v4将操作落到 Looker 实例上。looker-delete-agent承担的就是其中删除 Agent这一破坏性操作。从仓库中同目录的工具文档可以看出该工具属于一个完整的 Agent 生命周期管理工具族全部位于 docs/en/integrations/looker/tools/ 下配套工具包括looker-create-agent创建 Agentlooker-get-agent获取单个 Agent 详情looker-list-agents列出全部 Agentlooker-update-agent更新 Agentlooker-delete-agent删除 Agent本文主题。在实际使用中典型的生命周期通常是先用looker-list-agents获取 Agent ID再用looker-delete-agent按 ID 删除或者在looker-get-agent确认目标后执行删除。LLM 调用格式工具参数与 JSON 请求looker-delete-agent向 LLM 暴露的唯一参数是agent_id。原文档给出的调用示例为{ name: looker-delete-agent, parameters: { agent_id: 123 } }字段含义如下nameMCP 请求中调用的工具名固定为looker-delete-agentparameters.agent_id要删除的 Looker Agent 的 ID类型为字符串。该 ID 通常来自looker-list-agents或looker-get-agent的返回结果。从源码看agent_id参数在工具初始化时被定义为一个字符串参数并带空字符串默认值agentIdParameter : parameters.NewStringParameter(agent_id, The ID of the agent., parameters.WithStringDefault())也就是说LLM 在决定删除哪个 Agent 之前应当先通过列表类工具拿到目标agent_id再发起删除调用。配置方式在 server.yaml 中声明工具要在 MCP Toolbox 中使用该工具必须在server.yaml中把它声明为一个kind: tool的配置项。原文档给出的示例配置如下kind: tool name: delete_agent type: looker-delete-agent source: my-looker-instance description: | Delete a Looker agent. - agent_id (string): The ID of the agent.配置字段说明即原文档的 Reference 表格fieldtyperequireddescriptiontypestringtrueMust be looker-delete-agent.sourcestringtrueName of the Looker source.descriptionstringtrueDescription of the tool that is passed to the LLM.几点实践要点name是工具在 MCP 会话中注册的别名可以自行命名如delete_agent但type必须严格等于looker-delete-agent否则不会被注册为该工具source必须指向一个已定义的 Looker sourcetype: looker工具运行时才会拿到可用的 Looker SDK 与连接配置description会作为工具描述原样传给 LLM见下方源码分析因此应当写清楚用途与参数含义帮助 LLM 正确调用。字段校验的源码佐证从 lookerdeleteagent.go 的源码结构看配置解析与校验包含以下关键点类型注册包级init()中调用tools.Register(looker-delete-agent, newConfig)若类型重复注册会直接 panic确保工具类型全局唯一必填字段Config结构体为Type和Source两个字段打上了validate:required标签YAML 解析时缺少任一字段都会报错description 非空校验在Initialize中如果cfg.Description 会返回错误description is required for tool ...这正是上面表格中description标为必填的原因未知字段拒绝lookerdeleteagent_test.go 中的TestFailParseFromYaml用例验证了在配置中写入未知字段如method时解析会报unknown field method错误说明配置解析是严格的白名单模式。对应的 YAML 解析测试用例TestParseFromYaml也验证了type: looker-delete-agent与source: my-instance会被正确解析为对应的Config结构说明上述配置写法与源码实现完全一致。配合 Looker Source前置条件与配置示例looker-delete-agent本身不关心连接细节它依赖一个type: looker的 source 来获得 SDK 实例。Looker source 的完整说明见 source.md其基本配置形如kind: source name: my-looker-source type: looker base_url: ${LOOKER_BASE_URL} client_id: ${LOOKER_CLIENT_ID:} client_secret: ${LOOKER_CLIENT_SECRET:} verify_ssl: ${LOOKER_VERIFY_SSL:true} timeout: 600s use_client_oauth: ${LOOKER_USE_CLIENT_OAUTH:false} show_hidden_models: ${LOOKER_SHOW_HIDDEN_MODELS:true} show_hidden_explores: ${LOOKER_SHOW_HIDDEN_EXPLORES:true} show_hidden_fields: ${LOOKER_SHOW_HIDDEN_FIELDS:true}使用前提API 用户Looker source 仅使用 API 鉴权需要先在 Looker 中创建 API 用户API3 key获得client_id/client_secretConversational Analytics API要使用 Agent 相关能力需要在 Google Cloud 项目中启用geminidataanalytics.googleapis.com与cloudaicompanion.googleapis.com两个 API并为 IAM 身份授予roles/looker.instanceUser、roles/cloudaicompanion.user、roles/geminidataanalytics.dataAgentStatelessUser角色同时通过gcloud auth login --update-adc初始化 ADC 凭证base_url 规范格式如https://looker.example.com不要带结尾/本地部署的 Looker 可能需要附带 API 端口例如https://looker.example.com:19999敏感信息官方推荐用${ENV_NAME}环境变量替换方式注入client_id、client_secret等密钥而不是硬编码进配置文件。一个可运行的完整示例将 source 与 tool 组合后server.yaml的完整片段大致如下kind: source name: my-looker-instance type: looker base_url: ${LOOKER_BASE_URL} client_id: ${LOOKER_CLIENT_ID:} client_secret: ${LOOKER_CLIENT_SECRET:} verify_ssl: ${LOOKER_VERIFY_SSL:true} timeout: 600s use_client_oauth: ${LOOKER_USE_CLIENT_OAUTH:false} show_hidden_models: ${LOOKER_SHOW_HIDDEN_MODELS:true} show_hidden_explores: ${LOOKER_SHOW_HIDDEN_EXPLORES:true} show_hidden_fields: ${LOOKER_SHOW_HIDDEN_FIELDS:true} --- kind: tool name: delete_agent type: looker-delete-agent source: my-looker-instance description: | Delete a Looker agent. - agent_id (string): The ID of the agent.源码级原理一次删除操作如何被真正执行理解配置之后我们再从 lookerdeleteagent.go 出发梳理一次调用在 MCP Toolbox 内部的处理链路。1. 兼容 source 检查工具定义了一个compatibleSource接口要求 source 必须提供UseClientAuthorization() bool是否使用客户端授权GetAuthTokenHeaderName() string授权 token 所在 header 名称LookerApiSettings() *rtl.ApiSettingsLooker SDK 运行所需的 API 设置GetLookerSDK(context.Context, string) (*v4.LookerSDK, error)基于访问 token 创建 Looker v4 SDK 实例。在ValidateSource与Invoke中都会做类型断言若配置的 source 不兼容会返回类似invalid source for looker-delete-agent tool: source ... is not a compatible type的错误。这保证了工具只能与type: looker的 source 组合使用。2. 参数提取与必填校验Invoke中从params.AsMap()提取agent_id并做显式校验if agentId { return nil, util.NewClientServerError( fmt.Sprintf(%s operation: agent_id must be specified, t.Cfg.Type), http.StatusBadRequest, nil) }对应测试 lookerdeleteagent_test.go 中TestInvokeValidation验证了缺少agent_id时调用会失败并报错agent_id must be specified。也就是说即使agent_id参数声明了空字符串默认值真正执行删除前仍会强制要求非空值。3. 底层 SDK 调用校验通过后工具调用 Looker v4 SDK 的DeleteAgent方法resp, err : sdk.DeleteAgent(agentId, , source.LookerApiSettings())其中第二个参数为 API 版本此处传空字符串使用默认版本。返回的resp会原样作为工具结果返回给 LLM。4. 错误处理与状态码映射若 SDK 错误信息中包含status401则映射为 HTTP 401未授权其他错误走util.ProcessGeneralError统一处理。5. 注解与 MCP Manifest工具在Initialize阶段会强制注入两个 MCP 注解readOnlyHint : false destructiveHint : true annotations.ReadOnlyHint readOnlyHint annotations.DestructiveHint destructiveHint即ReadOnlyHint恒为false、DestructiveHint恒为true。这些注解会通过 MCP Manifesttools.Manifest{Description: cfg.Description, ...}暴露给客户端明确告知 LLM这是一个具有破坏性的操作。TestAnnotations用例对这两个注解的默认值做了断言ReadOnlyHint false、DestructiveHint true并从TestManifest用例可见Manifest 中注册的参数正是agent_id。这提醒调用方删除操作不可回滚LLM 应在删除前再次确认agent_id的正确性。实战使用流程与最佳实践综合以上内容推荐的使用流程如下确认前置条件按 source.md 完成 Looker API 用户创建、GCP API 启用与 IAM 授权并设置好LOOKER_BASE_URL等环境变量配置 source 与 tool在server.yaml中声明type: looker的 source以及type: looker-delete-agent的 toolsource字段指向该 sourcedescription中写清agent_id参数说明列出并确认目标优先调用looker-list-agents获取 Agent ID 列表结合looker-get-agent确认要删除的 Agent避免误删发起删除调用looker-delete-agent传入确认过的agent_id处理结果删除成功后返回 SDK 响应若收到 401需检查 Looker API 凭证与 IAM 权限是否有效。需要注意的限制与风险该工具是破坏性操作DestructiveHint为true删除后无法恢复配置时可利用description明确约束 LLM 的使用方式agent_id必须非空否则请求会被拒绝工具依赖 Looker 的 Conversation Analytics API需要对应的 GCP API 与 IAM 角色详见 source.md 的 Requirements 部分若你的 Looker 使用自签名 SSL 证书可将verify_ssl设为非true的值例如false否则建议保持true。通过上述配置与调用链路的配合你可以让 LLM 安全、受控地完成 Looker Conversation Analytics Agent 的删除操作并借助looker-create-agent、looker-update-agent、looker-list-agents等配套工具构建完整的 Agent 生命周期管理能力。【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表