starlight-mcp

starlight-mcp

MCP server for Astro/Starlight docs sites, providing search, get, and list tools for documentation content.

Category
访问服务器

README

starlight-mcp

Give your Astro or Starlight docs site an MCP server.

Agents connect to https://your-site.com/mcp and get three tools — search_docs, get_doc, list_docs — answered straight from your docs content collection. No database, no embeddings, no separate service: the corpus is a JSON file emitted at build time, and the server is a stateless JSON-RPC handler small enough to read in one sitting.

npm install starlight-mcp

Live demo: the discountkit docs serve theirs at https://next.discountkit.app/mcp —

claude mcp add --transport http discountkit-docs https://next.discountkit.app/mcp

How it works

  1. Build time — the Astro integration injects two prerendered routes into your site:
    • /mcp/docs-index.json — every page of your docs collection (title, description, URL, cleaned markdown body)
    • /mcp-schema.json — a machine-readable tool catalog agents can discover before connecting (link it from your llms.txt)
  2. Runtime — a dependency-free handler speaks stateless streamable HTTP: plain JSON-RPC over POST. It loads the corpus once per isolate and answers initialize, tools/list and tools/call. On SSR sites the integration injects this for you; on static sites you add one tiny shim on your host (Cloudflare recipe below).

Because the transport is stateless HTTP, it works from Claude Code, Cursor, VS Code, Windsurf and anything else that speaks MCP — no SSE, no sessions, no sticky routing.

Quickstart

1. Add the integration

// astro.config.mjs
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import starlightMcp from "starlight-mcp";

export default defineConfig({
  site: "https://your-site.com", // required — URLs in results are absolute
  integrations: [
    starlight({ title: "My Docs" }),
    starlightMcp({
      serverName: "my-docs",
      siteLabel: "My Product",
      docsRedirect: "/docs/ai-tools/", // where humans land if they open /mcp in a browser
    }),
  ],
});

That's the whole setup for SSR sites (output: "server"): the live endpoint is injected at /mcp.

For static sites the build emits the corpus and schema, and you serve the endpoint with a few lines of host glue:

2. Static sites on Cloudflare Workers

// worker/index.ts
import { createStaticMcpWorker } from "starlight-mcp/cloudflare";

export default createStaticMcpWorker({
  serverName: "my-docs",
  siteLabel: "My Product",
  docsRedirect: "/docs/ai-tools/",
});
// wrangler.jsonc
{
  "name": "my-docs-site",
  "main": "worker/index.ts",
  "compatibility_date": "2025-06-01",
  "assets": {
    "directory": "./dist",
    "binding": "ASSETS",
    "run_worker_first": ["/mcp"] // script wakes up ONLY for /mcp
  }
}

Every other request is served from the static assets layer without invoking the Worker — you pay for script execution only on MCP traffic.

3. Any other host

starlight-mcp/handler is a pure (Request) => Promise<Response> with zero dependencies — wire it into whatever speaks fetch:

import { createMcpHandler } from "starlight-mcp/handler";

const handler = createMcpHandler({
  serverInfo: { name: "my-docs", version: "1.0.0" },
  siteLabel: "My Product",
  loadIndex: async () => {
    // return DocEntry[] from wherever your build put docs-index.json
    const res = await fetch("https://your-site.com/mcp/docs-index.json");
    return res.json();
  },
});

Connecting clients

# Claude Code
claude mcp add --transport http my-docs https://your-site.com/mcp
// Cursor — .cursor/mcp.json
{
  "mcpServers": {
    "my-docs": { "url": "https://your-site.com/mcp" }
  }
}

Clients that only speak stdio can bridge with mcp-remote:

{
  "mcpServers": {
    "my-docs": {
      "command": "npx",
      "args": ["mcp-remote", "https://your-site.com/mcp"]
    }
  }
}

Tools

Tool Arguments Returns
search_docs query Top 5 pages by weighted term match (title ×6, description ×3, body occurrences), each with URL, description and a snippet around the first hit
get_doc path (doc id or URL) One full page as markdown with its source URL
list_docs — Every page with title, description and URL

Options

All options are optional.

Option Default What it does
serverName <site-host>-docs MCP server name reported to clients
serverVersion "0.1.0" Version reported to clients
path "/mcp" Endpoint path; corpus lands at ${path}/docs-index.json, catalog at ${path}-schema.json
collection "docs" Which content collection to index (Starlight's is docs)
siteLabel site host Human-readable product name used in tool descriptions and initialize instructions
instructions generated The instructions string agents see on connect
include all Only index docs whose id starts with one of these prefixes
exclude none Drop docs whose id starts with one of these prefixes
docsRedirect — 302 humans who open the endpoint in a browser to this page (otherwise: a polite 405 JSON explainer)
toolDescriptions generated Replace the description of any tool, e.g. { search_docs: "Search the Acme docs (billing, webhooks, SDKs)…" } — worth hand-tuning so agents know when to reach for it. Object form also overrides argument descriptions: { search_docs: { description: "…", args: { query: "e.g. 'webhook retries'" } } }

MDX noise (import statements, standalone <Component> tag lines) is stripped from indexed bodies automatically.

Make it discoverable

Two cheap tricks that make agents actually find the server:

  • llms.txt — lead with the MCP endpoint before your page list, e.g.
    ## MCP server
    Connect for structured search instead of scraping:
    claude mcp add --transport http my-docs https://your-site.com/mcp
    Tool catalog: https://your-site.com/mcp-schema.json
    
  • A docs page for humans — an "AI tools" page with per-editor install snippets, and point docsRedirect at it so people who open /mcp in a browser land somewhere useful.

Notes

  • Ships TypeScript source. The package is consumed through bundlers — Astro/Vite, wrangler's esbuild, Bun, tsx — which all eat .ts natively. Plain node without a bundler needs a transpile step (compiled dist is on the roadmap).
  • Protocol — implements stateless streamable HTTP for protocol versions 2025-06-18 and 2025-03-26: initialize, ping, notifications/* (202), tools/list, tools/call; CORS is open so browser-based clients work.
  • State — none. No sessions, no KV, no cookies. The corpus is cached per isolate/process and refreshes on deploy.

Roadmap

  • Compiled dist/ + .d.ts for bundler-free Node consumers
  • Optional MiniSearch-backed index for large doc sets
  • extraTools escape hatch for site-specific tools
  • Custom clean function for exotic MDX
  • Conformance tests against the official MCP SDK client
  • llms.txt / llms-full.txt generation from the same corpus

Prior art

  • Varity's docs — the /mcp-schema.json + llms.txt recruiting pattern
  • mcpdoc — llms.txt-driven docs MCP as a local stdio server
  • Built for (and proven on) the discountkit docs

License

MIT © bkspace

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选