Connect Product Metrics MCP from a coding agent
Add the Product Metrics MCP server to Claude Code, Codex, Cursor or VS Code from the terminal, then give the agent the skills, the productmetrics CLI and a starter prompt.
Add the server
Server URL (remote HTTP; the client starts the browser sign-in): https://www.productmetrics.io/mcp
- Claude Code:
claude mcp add --transport http product-metrics https://www.productmetrics.io/mcp, then sign in through/mcp - Codex:
codex mcp add product-metrics --url https://www.productmetrics.io/mcp, thencodex mcp login product-metrics - Cursor or any JSON-config client:
{"mcpServers": {"product-metrics": {"url": "https://www.productmetrics.io/mcp"}}} - VS Code (
.vscode/mcp.json):{"servers": {"product-metrics": {"type": "http", "url": "https://www.productmetrics.io/mcp"}}}
Claude and ChatGPT add the server in the browser instead: see For humans.
A person finishes the sign-in once, in a browser: the agent can’t, and there is no API key or header to set. One connection covers every workspace you can open and lasts 30 days from approval.
https://www.productmetrics.io/mcp is a server URL for your MCP client, not a page to open in a browser.
Print the setup with the CLI
productmetrics mcp-config prints the URL and the steps for one client, or for all of them without --client:
npm install -g @productmetrics/cli
productmetrics mcp-config --client claude # or chatgpt, cursorIt prints https://prod-backend.productmetrics.io/mcp, the same server on the API’s own origin. Either URL works.
Verify your connection
Open your client’s MCP list (/mcp in Claude Code) and check that product-metrics is connected. Then try:
Which Product Metrics stores can I open, and what is left to set up?The agent calls list_properties, then execute with GET /setup/status. If no Product Metrics tools appear, restart or reload the client after saving its MCP configuration.
Give the agent skills
Skills are task instructions an agent loads when it needs them: which tools to call, in which order, and what to check. From the project where the agent works:
npx skills add https://www.productmetrics.io/docs \
--skill '*' \
--agent claude-code \
-yUse --agent codex or --agent cursor for those agents, and add --global for every project. This installs set-up-tracking, connect-google-ads, check-tracking, bid-on-profit and analyse-google-ads. Needs Node.js 22.20 or later. See Install skills.
The index for agents is at https://www.productmetrics.io/docs/.well-known/agent-skills/index.json.
Give the agent the CLI
productmetrics calls the same API as the MCP server’s search and execute tools. Every API operation is a command, productmetrics <group> <command>, and its flags are the operation’s fields.
# install (Node.js 22 or later), or run once with npx @productmetrics/cli
npm install -g @productmetrics/cli
# sign in in the browser: run this yourself, not through the agent
productmetrics login
# the short guide for AI agents
productmetrics help agents
# where setup stands, and the next step
productmetrics setup get-status --company-id <company_id> --jsonWhat an agent needs to know:
- Pass
--json. stdout then holds exactly one JSON document.--select '.data.properties[].property_id'prints only part of it. - No prompts. Without a terminal, or with
PM_AGENT=1,CIor--no-input,productmetricsnever prompts, never opens a browser and prints no colours. - Discover, never guess.
productmetrics <group> <command> --help --jsongives the exact flags, types and allowed values. Ids come from earlier results. - Retries are safe where
--helplists--auto-idempotency-key. After any other failed write, read the state before retrying.--dry-runprints the request without sending it. - Deletes need
--yes. Ask the person first. - Exit code
4means a person must finish a step in a browser: the URL is innext_action.url.
When productmetrics status --json shows signed_in: false, the agent asks you to run productmetrics login in your own terminal. In CI, set PM_TOKEN. More in CLI for agents and JSON and exit codes.
Search the docs
The docs MCP lets the agent search these docs while it works. It reads documentation only: for your own data, use the server above.
claude mcp add --transport http product-metrics-docs \
https://www.productmetrics.io/docs/api/mcpOther clients take https://www.productmetrics.io/docs/api/mcp the same way as the Product Metrics server. https://www.productmetrics.io/docs/llms.txt lists every docs page with a one-line description: point the agent at it before it reads further.
Starter prompt
Paste this into your coding agent to set up Product Metrics:
You are setting up Product Metrics for my store.
- Read https://www.productmetrics.io/docs/llms.txt (or use the
product-metrics-docs MCP) before you act.
- Use the Product Metrics MCP server if it is connected. Otherwise use
the productmetrics CLI with --json: run `productmetrics help agents`
first, then `productmetrics status --json`. If I am not signed in,
ask me to run `productmetrics login` in my own terminal.
- Read the setup state with
`productmetrics setup get-status --company-id <id> --json` and follow
hub.company.next_action and hub.property.next_action, one step
at a time.
- Never guess a command or flag: run
`productmetrics <group> <command> --help --json`. Ids come from earlier
results.
- Exit code 4 means I must finish a step: give me next_action.url
(or the store setup token) and wait for me.
- Pass --auto-idempotency-key where --help lists it. Ask me before
anything that needs --yes.
- Never ask me for a password or an API key; ask me for store
credentials only when a step needs them.