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

@markdown-for-agents/fastify

v1.3.3

Published

Fastify plugin — serve Markdown to AI agents via content negotiation

Readme

@markdown-for-agents/fastify

npm version npm downloads types license

Fastify plugin for markdown-for-agents — a runtime-agnostic HTML to Markdown converter built for AI agents.

markdown-for-agents + Fastify

markdown-for-agents converts HTML to clean, token-efficient Markdown for AI agents — typically saving 80–90% of tokens. This package adds automatic content negotiation to your Fastify app via Accept: text/markdown. Try the playground to see the core conversion in action.

Add one line to your Fastify app and AI agents get clean, token-efficient Markdown instead of HTML. Normal browser requests pass through untouched.

How it works

The plugin uses content negotiation. When a client sends Accept: text/markdown, HTML responses are automatically converted to Markdown. The response includes:

  • Content-Type: text/markdown; charset=utf-8
  • x-markdown-tokens header with the token count
  • ETag header with a content hash for cache validation
  • Vary: Accept header so CDNs cache HTML and Markdown separately
  • content-signal header with publisher consent signals (when configured)

Install

npm install @markdown-for-agents/fastify markdown-for-agents

markdown-for-agents is a peer dependency — you may already have it installed.

Usage

import Fastify from 'fastify';
import { markdown } from '@markdown-for-agents/fastify';

const fastify = Fastify();
fastify.register(markdown({ extract: true }));

fastify.get('/', async (request, reply) => {
    reply.type('text/html');
    return '<h1>Hello</h1>';
});

fastify.listen({ port: 3000 });
# Normal HTML response
curl http://localhost:3000

# Markdown response for AI agents
curl -H "Accept: text/markdown" http://localhost:3000

Full working example: See examples/fastify/ for a complete Fastify app with integration tests.

Options

Accepts all markdown-for-agents options:

fastify.register(
    markdown({
        // Strip nav, ads, sidebars, cookie banners
        extract: true,

        // Resolve relative URLs
        baseUrl: 'https://example.com',

        // Remove duplicate content blocks
        deduplicate: true,

        // Custom token counter (e.g. tiktoken)
        tokenCounter: text => ({ tokens: enc.encode(text).length, characters: text.length, words: text.split(/\s+/).filter(Boolean).length }),

        // Publisher consent signal header
        contentSignal: { aiTrain: true, search: true, aiInput: true }
    })
);

Other frameworks

| Package | Framework | | -------------------------------------------------------------------------------------------- | -------------------------------------------- | | @markdown-for-agents/express | Express | | @markdown-for-agents/hono | Hono | | @markdown-for-agents/nextjs | Next.js | | @markdown-for-agents/web | Web Standard (Cloudflare Workers, Deno, Bun) |

License

MIT