跳到主内容
智客 ZICQ

技能库 智客分类:运维与云 testing-mcp-tools-locally

Testing Mcp Tools Locally

设置本地 Dev 环境,种子数据和 API 密钥以测试仅由员工管理的迁移 MCP 工具(管理-迁移-支持列表,管理-迁移-支持-get)结束. 当测试批量导入支持工具时使用,调试MCP工具响应或发现(工具没有出现),或在部署前验证支持 API. 覆盖了发现门:隐藏范围,是_staff,用户:read,以及为什么通配键和OAuth从不工作.

59 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

设置本地 Dev 环境、种子数据和 API 密钥, 以测试仅由员工管理的迁移 MCP 工具( 管理- 迁移- 支持列表, 管理- 迁移- 支持get) 结束

何时用

测试批量导入支持工具,调试 MCP 工具响应或发现(工具没有出现),或者在部署前验证支持 API. 覆盖发现门:隐藏范围,是_staff,用户:读取,以及为什么通配符键和OAuth从不工作

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Testing managed migrations MCP tools locally、Prerequisites、1. Start the dev environment、2. Run Postgres migrations、3. Verify DB connectivity from the Django shell、4. Seed batch import test data。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/seed-data.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Set up the local dev environment, seed data, and API keys to test the staff-only managed migrations MCP tools (managed-migrations-support-list, managed-migrations-support-get) end to end. Use when testing batch import support tooling, debugging MCP tool responses or discovery (tools not appearing), or verifying the support API before deploying. Covers the discovery gate: hidden scope, is_staff, user:read, and why wildcard keys and OAuth never work.

Testing managed migrations MCP tools locallyPrerequisites1. Start the dev environment2. Run Postgres migrations3. Verify DB connectivity from the Django shell4. Seed batch import test data5. Make your user staff and mint test keys6. Test the API directlyList all batch importsGet detail for a specific import7. Test via MCPDiscovery — should list both support tools for the staff key, none for the others

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
testing-mcp-tools-locally
description
Set up the local dev environment, seed data, and API keys to test the staff-only managed migrations MCP tools (managed-migrations-support-list, managed-migrations-support-get) end to end. Use when testing batch import support tooling, debugging MCP tool responses or discovery (tools not appearing), or verifying the support API before deploying. Covers the discovery gate: hidden scope, is_staff, user:read, and why wildcard keys and OAuth never work.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 1
  • references/seed-data.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「testing-mcp-tools-locally」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-ce5020651abf308b-%E6%9C%AC%E5%9C%B0%E6%B5%8B%E8%AF%95-McP-%E5%B7%A5%E5%85%B7.html
请存为 .cursor/skills/testing-mcp-tools-locally/SKILL.md 或 .claude/skills/testing-mcp-tools-locally/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/posthog/ai-plugin 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/posthog/ai-plugin' --list

npx skills add 'https://github.com/posthog/ai-plugin' --skill 'testing-mcp-tools-locally'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: testing-mcp-tools-locally description: > Set up the local dev environment, seed data, and API keys to test the staff-only managed migrations MCP tools (managed-migrations-support-list, managed-migrations-support-get) end to end. Use when testing batch import support tooling, debugging MCP tool responses or discovery (tools not appearing), or verifying the support API before deploying. Covers the discovery gate: hidden scope, is_staff, user:read, and why wildcard keys and OAuth never work. --- # Testing managed migrations MCP tools locally ## Prerequisites The dev environment must be running with Docker services healthy. The batch import support API and MCP tools require: - A staff user (`is_staff = True`) - A Personal API Key carrying **both** `batch_import_support:read` and `user:read`, explicitly - Postgres migrations applied (ClickHouse not required) Why both scopes: the backend accepts `batch_import_support:read` alone, but MCP tool discovery verifies staffness via `/api/users/@me/` and hides the tools (fail-closed) when the key cannot make that call. A `*` wildcard does **not** substitute for either — the discovery gate requires the hidden scope explicitly, and the backend's `INTERNAL` scope handling rejects wildcard keys outright. For the production setup flow, see [docs/support-mcp-tools.md](../../docs/support-mcp-tools.md). ## 1. Start the dev environment ```bash hogli start -d hogli wait ``` If `hogli wait` fails on `migrate-persons-db` or `migrate-behavioral-cohorts`, those are optional separate databases — ignore them. If it fails on `migrate-postgres`, check Docker port forwarding (see troubleshooting below). ## 2. Run Postgres migrations ```bash hogli migrations:run ``` ClickHouse migration failures are fine — batch imports only need Postgres. ## 3. Verify DB connectivity from the Django shell ```bash hogli dev:shell-plus -y -- -c " from posthog.models import Team, User print(Team.objects.first(), User.objects.first()) " ``` If this fails with `connection refused` on port 5432, see troubleshooting below. ## 4. Seed batch import test data Use `hogli dev:shell-plus` to create `BatchImport` records in various states. The `secrets` field is an `EncryptedJSONStringField` — empty `{}` serializes to null and violates the NOT NULL constraint; always pass a non-empty dict. ```python from products.managed_migrations.backend.models.batch_imports import BatchImport BatchImport.objects.create( team=team, created_by_id=user.id, status=BatchImport.Status.PAUSED, import_config={ 'source': {'type': 's3', 'bucket': 'test', 'region': 'us-east-1', 'prefix': 'data/'}, 'data_format': {'type': 'json_lines', 'skip_blanks': True, 'content': {'type': 'mixpanel'}}, 'sink': {'type': 'capture'}, }, secrets={'access_key': 'test', 'secret_key': 'test'}, state={'parts': [ {'key': 'part-1', 'current_offset': 50000, 'total_size': 50000}, {'key': 'part-2', 'current_offset': 10000, 'total_size': 50000}, {'key': 'part-3'}, ]}, ) ``` See `references/seed-data.md` for a full seeding script covering all statuses. **Important:** the local `batch-import-worker` process will pick up `RUNNING` records and may modify their status (e.g. pausing them due to config validation errors). To keep records stable for testing, either stop the worker or use `COMPLETED`/`FAILED`/`PAUSED` statuses. ## 5. Make your user staff and mint test keys Mint **fresh** keys rather than editing scopes on an existing one — the MCP server caches a key's scopes per token, so edited scopes can serve stale results. ```python from posthog.models import User from posthog.models.personal_api_key import PersonalAPIKey from posthog.models.utils import generate_random_token_personal, hash_key_value me = User.objects.first() me.is_staff = True; me.save() def mint(user, scopes): token = generate_random_token_personal() PersonalAPIKey.objects.create(user=user, label=str(scopes)[:40], secure_value=hash_key_value(token), scopes=scopes) return token print(mint(me, ["batch_import_support:read", "user:read"])) ``` To test the negative cases of the discovery gate, also mint: a `["*"]` key (tools must NOT appear), a `["batch_import_support:read"]` key without `user:read` (tools must NOT appear — staff lookup fails closed), and the full pair on a non-staff user (tools must NOT appear). ## 6. Test the API directly ```bash # List all batch imports curl -H "Authorization: Bearer " \ http://localhost:8010/api/managed_migrations_support/ | jq # Get detail for a specific import curl -H "Authorization: Bearer " \ http://localhost:8010/api/managed_migrations_support// | jq ``` ## 7. Test via MCP **Run the Hono server, not `pnpm run dev`.** The wrangler worker (`pnpm run dev`, port 8787) proxies `/mcp` to **production** `mcp.us.posthog.com` unless `MCP_HONO_URL` is set, so local keys get `401 Invalid API key`. The Hono server serves MCP directly against the local API: ```bash cd services/mcp cp .dev.vars.example .dev.vars # POSTHOG_API_BASE_URL=http://localhost:8010 pnpm run dev:hono # serves http://localhost:3001/mcp ``` **Authenticate with the PAT as a Bearer header, never the OAuth flow.** The hidden scope is structurally absent from OAuth — signing in through the inspector's OAuth login can never surface these tools. The Hono server runs exec mode: `tools/list` returns a single `exec` tool, and real tools are discovered and invoked through it. Test with the MCP Inspector CLI: ```bash # Discovery — should list both support tools for the staff key, none for the others npx @modelcontextprotocol/inspector --cli http://localhost:3001/mcp \ --header "Authorization: Bearer " \ --method tools/call --tool-name exec --tool-arg "command=search managed-migrations-support" # Invocation — end-to-end through Django npx @modelcontextprotocol/inspector --cli http://localhost:3001/mcp \ --header "Authorization: Bearer " \ --method tools/call --tool-name exec --tool-arg "command=call managed-migrations-support-list {}" ``` Expected discovery matrix: | key | tools visible | | ----------------------------------------------------------- | -------------------------------- | | staff user, `batch_import_support:read` + `user:read` | both | | staff user, `*` only | none | | staff user, `batch_import_support:read` without `user:read` | none (staff lookup fails closed) | | non-staff user, both scopes | none (and direct API calls 403) | The interactive Inspector UI (`http://localhost:6274`) also works — paste the PAT as the Bearer token in connection settings instead of using its OAuth login. ## Troubleshooting ### 401 "Invalid API key" from localhost:8787 You're talking to the wrangler worker, which proxies `/mcp` to production — your local key is invalid there. Use the Hono server on port 3001 (see step 7), or set `MCP_HONO_URL=http://localhost:3001` in `.dev.vars`. ### Tools don't appear for a key that should see them Check, in order: 1. The key carries `batch_import_support:read` **explicitly** — `*` does not match hidden scopes. 2. The key also carries `user:read` (or `*`) — the discovery staff check reads `/api/users/@me/` and fails closed. 3. The key's user has `is_staff = True`. 4. The key was minted with those scopes from the start — the MCP server caches scopes per token, so mint a fresh key instead of editing an existing one. ### Port 5432 not reachable from host The `posthog-db-1` Docker container may have stale port mappings (container created days ago without the current port binding config). Fix by force-recreating: ```bash docker compose -f docker-compose.dev.yml -f docker-compose.profiles.yml \ up -d --force-recreate db ``` Verify: `nc -z 127.0.0.1 5432` should succeed. ### `secrets={}` causes NOT NULL violation `EncryptedJSONStringField` encrypts the value — an empty dict serializes to null. Always pass a non-empty dict: `secrets={'placeholder': 'true'}`. ### Batch import worker modifies seeded records The local `batch-import-worker` process automatically claims `RUNNING` records. If it encounters a config validation error (e.g. missing `skip_blanks`), it will pause the import with a detailed Rust backtrace in `status_message`. Stop the worker or seed with non-`RUNNING` statuses to prevent this. ### The gates, end to end A request passes through two independent layers: 1. **MCP discovery** (presentation): a tool requiring an OAuth-hidden scope surfaces only when the key explicitly carries the scope AND `/api/users/@me/` confirms `is_staff` — otherwise it is hidden, fail-closed (`services/mcp/src/lib/staff-only-tools.ts`). 2. **Django enforcement** (the security boundary): `IsAuthenticated` + `IsStaffUser` + `APIScopePermission` with `scope_object = "INTERNAL"` and `batch_import_support:read`. Sessions need staffness only; PATs need staffness plus the explicit scope; `*`-only keys always 403.

相关技能

运维与云

Docker Essentials

用于容器管理,图像操作,调试的基本道克命令和工作流程.

运维与云

Find Skills

从开放的代理技能生态系统中发现并安装技能. 使用时:(1)用户问"我如何做X",X可能拥有现有技能,(2)用户说"为X找到技能"或"是否为X有技能",(3)用户问"你能否做X",X是专门能力,(4)用户想扩展代理能力,(5)用户想搜索工具,模板,或工作流程,(6)用户提到他们希望…

运维与云

Microsoft Foundry

构建,部署,评价,优化,微调,管理微软创始代理,模型,资源最终结束. 用法:铸造、azd ai代理、azd 提供/部署、托管代理脚手架/开发/运行/部署/拖放、即时代理创建、创建代理、更新代理、添加代理工具、援引代理、代理.yaml、评估代理、批量活化、连续活化、持续监测、代理C…

运维与云

Azure Deploy

执行已有.azure/部署计划.md和基础设施文件的ALREADY-PREPARED应用程序的Azure部署。 当用户向 CREATE 请求新应用程序时, 请不要使用此技能 。 这种技能运行了 azd上行, azd 部署, trarraform 应用, 和 az 部署命令带有内置…