# AgentStats > Analytics for WebMCP. AgentStats shows which tools AI agents call on a website, what they send, how long calls take, where they fail, and whether agents finish multi-step workflows. ## Install AgentStats (npm) AgentStats records every WebMCP tool call agents make on a website (name, arguments, duration, outcome) by patching `document.modelContext.registerTool`. Existing tools do not need to change. ### 1. Install the package Use the project's package manager: `npm i @agentstats/sdk` · `pnpm add @agentstats/sdk` · `yarn add @agentstats/sdk` · `bun add @agentstats/sdk` ### 2. Initialise before tools are registered Call init once on the client, before any code calls `document.modelContext.registerTool()`: ```ts import { AgentStats } from '@agentstats/sdk' AgentStats.init({ key: 'al_pub_…', }) ``` Replace `al_pub_…` with the website's public key (AgentStats dashboard → website → Setup). If the user has not given you one, ask for it. Public keys are safe to commit. Rules: - Browser only. Never call init during server-side rendering. - Init must run before `registerTool`. If a tool is registered earlier, wrap it: `registerTool(AgentStats.wrap(tool))`. - Arguments are captured as-is; nothing is redacted by default. If a tool takes passwords, card numbers, emails or other personal data, add those keys with `redactKeys: ['password', 'card_number', 'email']` (case-insensitive substring match), pass a `captureArgs(tool, args)` function, or disable with `captureArgs: false`. ### 3. Optional: conversions ```ts AgentStats.track('order_completed', { value: 42.5 }) ``` ### 4. Verify Run the site, trigger any WebMCP tool, then check the website's Live view in the dashboard (https://agentstats.io/dashboard). Pass `debug: true` to init to log batches to the console. ## Options ```ts AgentStats.init({ key: 'al_pub_…', captureArgs: true, // false, or (tool, args) => value to store captureResults: false, // true, or (tool, result) => value to store captureErrors: true, // false, or ({ tool, message, name, code }) => text to store, or null redactKeys: ['email'], // nothing is redacted unless listed here metadata: { app: 'storefront', version: '1.2.3' }, sessionTimeoutMs: 1800000, debug: false, }) ``` ## MCP server https://agentstats.io/mcp (Streamable HTTP). Without a key it serves setup instructions and a WebMCP readiness scorer. With `Authorization: Bearer al_sk_…` (team API key, Dashboard → Settings → API keys) it can also query analytics: sites, overview, tools, errors, schema, funnels, sessions. ```bash claude mcp add --transport http agentstats https://agentstats.io/mcp --header "Authorization: Bearer al_sk_…" ``` ## Links - [Docs](https://agentstats.io/docs) - [Export API](https://agentstats.io/docs/api/export): read-only REST at https://agentstats.io/api/v1, same bearer key - [Readiness inspector](https://agentstats.io/inspect): enter a URL for an agent-readiness score (WebMCP tools, robots.txt, llms.txt, structured data) with copy-paste fixes - [Pricing](https://agentstats.io/pricing) - [WebMCP spec](https://webmachinelearning.github.io/webmcp/)