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

next-sitecore-ai

v0.1.1

Published

AI toolkit for Sitecore XM Cloud + Next.js — RAG, semantic search, content suggestions, and MCP server

Readme

next-sitecore-ai

An open-source AI toolkit that brings RAG, semantic search, and content suggestions to Sitecore XM Cloud + Next.js projects.

npm version license PRs Welcome

Live Demo · npm

Why this exists

Sitecore developers who want to add AI to their XM Cloud projects have no starting point. Experience Edge, embeddings, vector storage, and streaming LLM routes are all wired differently on every team.

Every team builds the same RAG pipeline, the same embedding infrastructure, the same hooks from scratch. This package eliminates that.

What is included

| Package | Description | | --- | --- | | Core hooks | useContentSuggestion, useSearchEnhance, usePersonalize | | RAG pipeline | Experience Edge ingestion, pgvector storage, semantic query | | MCP server | Five tools exposing XM Cloud to AI agents like Cursor and Claude | | CLI | create-sitecore-ai-app starter (coming soon) |

Quick start

1. Install the package

npm install next-sitecore-ai

2. Set up environment variables

Add these to .env.local:

| Variable | Description | | --- | --- | | SITECORE_EDGE_URL | Experience Edge GraphQL endpoint URL | | SITECORE_EDGE_TOKEN | Experience Edge API key | | SITECORE_SITE_NAME | Site name configured in XM Cloud | | SITECORE_DEFAULT_LANGUAGE | Default content language (e.g. en) | | OPENAI_API_KEY | OpenAI API key for embeddings and LLM calls | | SUPABASE_URL | Supabase project URL for pgvector storage | | SUPABASE_SERVICE_ROLE_KEY | Supabase service role key for server-side writes and queries |

3. Run the ingestion script

Copy scripts/ingest.ts into your project. Update the ROOT_PATHS array with your own Sitecore content paths:

const ROOT_PATHS = [
  '/sitecore/content/YourSite/yoursite/Home/Data',
  '/sitecore/content/YourSite/yoursite/Home/About',
  // add any root paths you want to crawl recursively
]

The script discovers all content items recursively under each root path, skips items with no meaningful text, and caps at 50 items per run to avoid rate limits. Then run:

npx tsx scripts/ingest.ts

4. Use a hook

'use client';

import { useContentSuggestion } from 'next-sitecore-ai/client';

export function SuggestButton({ itemPath }: { itemPath: string }) {
  const { suggestion, suggest, isLoading } = useContentSuggestion(itemPath);

  return (
    <div>
      <button onClick={() => suggest()} disabled={isLoading}>
        Suggest improvements
      </button>
      {suggestion && <p>{suggestion}</p>}
    </div>
  );
}

You also need a matching API route at /api/ai/suggest. See the demo app for a full example.

Hooks

Import hooks from next-sitecore-ai/client. Each hook calls a Next.js API route that you provide.

useContentSuggestion

Streams AI-generated suggestions for a Sitecore item field. Posts { itemPath, fieldName? } to /api/ai/suggest.

'use client';

import { useContentSuggestion } from 'next-sitecore-ai/client';

const { suggestion, suggest, isLoading, error } = useContentSuggestion(
  '/sitecore/content/Site/home',
);

// Optional: pass a field name to focus the suggestion
suggest('Title');

useSearchEnhance

Enhances search with AI-ranked semantic results. Posts { query } to /api/ai/search and returns both enhanced and original result sets.

'use client';

import { useSearchEnhance } from 'next-sitecore-ai/client';

const { results, search, isLoading } = useSearchEnhance();

await search('corporate litigation services');

usePersonalize

Resolves a personalized content variant for a guest based on audience segments. Posts { guestId, variants } to /api/ai/personalize.

'use client';

import { usePersonalize, type ContentVariant } from 'next-sitecore-ai/client';

const variants: ContentVariant[] = [
  { itemPath: '/sitecore/content/Site/home', segmentName: 'Enterprise' },
  { itemPath: '/sitecore/content/Site/home-alt', segmentName: 'SMB' },
];

const { variant, segment, isLoading } = usePersonalize('guest-123', variants);

RAG pipeline

The pipeline pulls text content from Experience Edge, chunks and embeds it with OpenAI, stores vectors in Supabase pgvector, and answers questions via semantic similarity search. Run ingestion once (or on a schedule) to keep the vector index in sync with published content.

npx tsx scripts/ingest.ts

Add a route handler that queries ingested content:

// app/api/ai/chat/route.ts
import { createRAGQuery } from 'next-sitecore-ai/server';

export async function POST(request: Request) {
  const { question } = await request.json();

  const rag = createRAGQuery({
    supabaseUrl: process.env.SUPABASE_URL!,
    supabaseServiceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY!,
    openAiApiKey: process.env.OPENAI_API_KEY!,
    siteName: process.env.SITECORE_SITE_NAME!,
  });

  const { answer, sources } = await rag.query(question);

  return new Response(answer, {
    headers: { 'X-Sources': JSON.stringify(sources) },
  });
}

MCP server

The MCP server exposes your XM Cloud content and vector index to AI coding agents. Install @next-sitecore-ai/mcp-server and add it to your MCP client configuration. It reads the same .env.local variables as the rest of the toolkit.

{
  "mcpServers": {
    "sitecore": {
      "command": "node",
      "args": ["./node_modules/@next-sitecore-ai/mcp-server/dist/index.js"],
      "env": {
        "SITECORE_EDGE_URL": "https://your-edge-url",
        "SITECORE_EDGE_TOKEN": "your-edge-token",
        "SITECORE_SITE_NAME": "your-site-name",
        "SITECORE_DEFAULT_LANGUAGE": "en",
        "OPENAI_API_KEY": "your-openai-key",
        "SUPABASE_URL": "https://your-project.supabase.co",
        "SUPABASE_SERVICE_ROLE_KEY": "your-service-role-key"
      }
    }
  }
}

Tools

| Tool | Description | | --- | --- | | get_item | Fetch a Sitecore content item and all its fields by item path | | get_text_content | Get plain text from an item with HTML stripped and system fields removed | | search_content | Semantically search ingested content for a natural language query | | list_site_pages | List top-level pages under a Sitecore root path | | get_site_info | Return configured site name, language, and Edge endpoint |

Requirements

  • Next.js 14+
  • React 18+
  • Sitecore XM Cloud with Experience Edge
  • OpenAI API key
  • Supabase project with pgvector

Contributing

Contributions are welcome — bug reports, feature requests, and pull requests all help. Open an issue to discuss changes before submitting a PR.

License

MIT