npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@knownagents/sdk

v2.2.0

Published

The official Node.js SDK for Known Agents: AI agent analytics (bot traffic), LLM referral tracking, automatic robots.txt, agent identification

Readme

Known Agents SDK

NPM version

This library provides convenient access to Known Agents from server-side Node.js applications written in TypeScript or JavaScript.

Install the Package

Download and include the package via NPM:

npm install @knownagents/sdk

Initialize the Client

Sign up for Known Agents, create a project, and copy your access token from the project's settings page. Then, create a new instance of KnownAgents.

import { KnownAgents } from "@knownagents/sdk"

const knownAgents = new KnownAgents("YOUR_ACCESS_TOKEN")

To batch visits, set the visit event queue size and flush interval:

const knownAgents = new KnownAgents("YOUR_ACCESS_TOKEN", {
    flushQueueSize: 1000,
    flushIntervalInMilliseconds: 10000
})

The entire visit event queue is uploaded when it reaches flushQueueSize or when the flush interval elapses after the first visit event enters an empty queue.

Send Visit Events (Agent Analytics, LLM Referral Tracking)

Get realtime insight into how AI agents and other bots browse your web pages, call your MCP (Model Context Protocol) endpoints, and purchase products through your ACP (Agentic Commerce Protocol) and UCP (Universal Commerce Protocol) shopping flows. Measure human traffic from AI chat and search platforms like ChatGPT, Claude, and Gemini.

Pageviews and REST Calls

Call trackPageviewOrRESTCall with the incoming request and outgoing response. If you can, do this in middleware. This method skips MCP calls automatically.

knownAgents.trackPageviewOrRESTCall(request, response)

MCP Calls (Optional)

For MCP servers that use StreamableHTTPServerTransport, call trackMCPCall after connecting the transport and before the transport handles the request.

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js"

// ...

const mcpServer = new McpServer({
    name: SERVER_NAME,
    version: SERVER_VERSION,
})

const transport = new StreamableHTTPServerTransport({
    sessionIdGenerator: undefined
})

// ...

await mcpServer.connect(transport)

knownAgents.trackMCPCall(request, response, transport)

await transport.handleRequest(request, response, parsedBody)

Agentic Commerce Interactions (Optional)

For REST implementations of ACP and UCP, include the response body in trackPageviewOrRESTCall.

// For ACP calls ...

knownAgents.trackPageviewOrRESTCall(request, response, {
    acpResponseBody: acpResponseBody
})
// For UCP calls ...

knownAgents.trackPageviewOrRESTCall(request, response, {
    ucpResponseBody: ucpResponseBody
})

trackMCPCall will track MCP implementations of ACP and UCP automatically.

Test Your Integration

  • Open your project's settings page
  • Click Send a Test Visit
  • Click Realtime

If your website is correctly connected, you should see visits from a test agent in the realtime timeline within a few seconds.

Set Up Automatic Robots.txt (Automatic Robots.txt)

Serve a robots.txt that continuously updates with rules for new crawlers, scrapers, AI agents, and other bots as they're discovered.

Use the generateRobotsTXT method. Select which AgentTypes you want to block, and a string specifying which URLs are disallowed (e.g. "/" to disallow all paths).

import { AgentType } from "@knownagents/sdk"

const robotsTxt = await knownAgents.generateRobotsTXT([
    AgentType.AIDataScraper,
    AgentType.AIDataProvider,
    AgentType.Scraper,
    AgentType.SEOCrawler
], "/")

The return value is a plain text robots.txt string. Generate a robotsTxt periodically (e.g. once per day, using a cron job). Then, serve it from your website's /robots.txt endpoint.

Use the Agent Identification API (Agent Identification API)

Identify and verify AI agents and other bots in your own products, from incoming network requests. Authentication uses Web Bot Auth (HTTP message signatures), IP matching, or other available methods. This API can be useful for implementing access policies based on verified agent identity or enriching your own datasets.

Call identifyAgent to identify a single incoming request:

const identification = await knownAgents.identifyAgent(request)

Call identifyAgents to identify multiple requests at once:

const identifications = await knownAgents.identifyAgents([
    {
        id: "request-1",
        request_headers: request1.headers
    },
    {
        id: "request-2",
        request_headers: request2.headers
    }
])

These methods return an object (or array of objects) with the following fields:

  • id: The identifier from the request (if provided)
  • result: The identification result:
    • "verified": The agent was identified and verified
    • "verification_failed": The agent was identified but failed verification (it was spoofed)
    • "not_verifiable": The agent was identified but could not be verified (no method available)
    • "unknown_agent": Not an agent, or the agent is not in the database
  • agent_id: The unique ID of the agent (if identified)
  • agent_token: The name of the agent (e.g. "Claude-User") (if identified)
  • agent_url: The documentation URL of the agent (if identified)
  • agent_type_name: The type of agent (e.g. "AI Assistant") (if identified)
  • operator_name: The company operating the agent (e.g. "Anthropic") (if identified)

Requirements

TypeScript >= 4.7 is supported.

The following runtimes are supported:

Support

Please open an issue with questions, bugs, or suggestions.