Skip to content

Add MCP server to valibot.dev#1550

Open
fabian-hiller wants to merge 2 commits into
mainfrom
mcp-server
Open

Add MCP server to valibot.dev#1550
fabian-hiller wants to merge 2 commits into
mainfrom
mcp-server

Conversation

@fabian-hiller

@fabian-hiller fabian-hiller commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

Adds a Model Context Protocol server at https://valibot.dev/mcp so coding agents can search and read the documentation through first-class tools instead of crawling pages. This addresses the last substantive gap in the Mintlify agent score and isitagentready audits.

MCP server (website/worker/mcp.ts)

  • Stateless Streamable HTTP transport with plain JSON responses — no sessions, no auth, no external dependencies. Hand-rolled JSON-RPC layer (~600 lines) covering initialize, ping, tools/list, tools/call, notifications, batches, CORS for browser-based clients, and protocol version negotiation (2025-06-18 / 2025-03-26).
  • Three tools: search_docs (ranked search over all 794 pages with API-name-first scoring), get_doc (full page Markdown; accepts api/string, full URLs, or bare names like minLength, with typo suggestions on misses), and list_docs (grouped overview).
  • All tool inputs are validated with Valibot itself, and the advertised JSON Schemas are generated from those same schemas via @valibot/to-json-schema (ignoreActions: ['trim']) — validation and declaration cannot drift.
  • Search runs against a build-time index (search-index.json, generated in scripts/llms.ts from the same source as the .md mirrors) cached in isolate memory with precomputed lowercase fields. Deliberately not Algolia: results are always consistent with the deployed .md files, and the endpoint has no third-party runtime dependency.

Discovery

  • MCP server card at /.well-known/mcp/server-card.json (SEP-1649), generated at build time from constants shared with the Worker (worker/mcp-info.ts) so the card and the live handshake cannot diverge.
  • The server is listed in the API catalog linkset, llms.txt, and the visually hidden agent hint on every HTML page.

Guide rename

  • guides/llms-txtguides/coding-agents: a general page covering the MCP server (with Claude Code and Cursor setup snippets), the LLMs.txt routes, Markdown content negotiation, and the agent skill. Moved after the installation guide in the menu. Old URLs (HTML and .md) redirect with 301.

Structure and robustness

  • The Worker is now split into focused modules: index.ts (routing), markdown.ts (content negotiation), headers.ts (merge-aware header utilities), docs.ts (shared area/slug knowledge and the SearchEntry type used by both the Worker and the generator), mcp-info.ts (shared MCP constants).
  • Review findings fixed along the way: 304 revalidation responses keep their negotiation headers, JSON-RPC edge cases (id: null requests, empty batches, id preservation in batch errors), /mcp/ trailing-slash support, #anchor/?query tolerance in get_doc paths, whitespace-only queries rejected via v.trim(), $schema stripped from tool schemas, and the typo-suggestion scan capped (maxLength on inputs plus a prefix ceiling).

Test plan

  • pnpm lint, pnpm format.check, and pnpm build pass
  • JSON-RPC test suite against wrangler dev: handshake, all three tools, invalid arguments, unknown tool/method, parse errors, empty batch, id: null, trailing slash, CORS preflight, 405 on GET
  • End-to-end session with the official @modelcontextprotocol/sdk client: connect, list tools, call all three tools
  • Markdown negotiation, .md caching headers (ETag/304), API catalog, and redirect regressions all re-verified

Summary by CodeRabbit

  • New Features
    • Added an MCP server for searching, listing, and reading documentation (served at /mcp).
    • Generated a searchable documentation index with page metadata and headings.
    • Added a Coding agents guide covering MCP usage, LLMs.txt routes, and Markdown access (including .md URLs).
  • Documentation
    • Added agent discovery support via the API catalog and MCP server card.
    • Updated navigation/help text and redirects to replace the old “LLMs.txt” guide with “Coding agents.”

Provide a Model Context Protocol server at https://valibot.dev/mcp so
that coding agents can search and read the documentation with tools
instead of crawling the website:

- Implement a stateless Streamable HTTP MCP server in the Worker with
  the tools search_docs, get_doc, and list_docs, validated with Valibot
  and with input schemas generated via @valibot/to-json-schema
- Generate a search index from the documentation at build time and
  cache it in isolate memory with precomputed lowercase fields
- Publish an MCP server card at /.well-known/mcp/server-card.json with
  constants shared between the Worker and the build script, and list
  the server in the API catalog, llms.txt, and the hidden HTML hint
- Rename the LLMs.txt guide to the more general "Coding agents" guide,
  document the MCP server there, move it after the installation guide,
  and redirect the old URLs
- Split the Worker into focused modules (routing, Markdown negotiation,
  header utilities, shared docs knowledge) and fix review findings
  (304 handling, JSON-RPC edge cases, trailing slash support, capped
  suggestion scans)
Copilot AI review requested due to automatic review settings July 19, 2026 20:21
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Jul 19, 2026
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f1ef82d-b8b2-44f1-a575-52b2f424b46d

📥 Commits

Reviewing files that changed from the base of the PR and between 9649f47 and eedf6ce.

📒 Files selected for processing (4)
  • website/scripts/agents.ts
  • website/vercel.json
  • website/worker/mcp-info.ts
  • website/worker/mcp.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • website/scripts/agents.ts
  • website/worker/mcp-info.ts
  • website/worker/mcp.ts

Walkthrough

The website now generates a documentation search index and MCP server card, serves Markdown documentation through content negotiation, and exposes a stateless MCP endpoint with search, retrieval, and listing tools. Worker routing and static-asset configuration handle MCP requests. New coding-agent documentation, catalog metadata, redirects, navigation entries, and accessibility text describe the available MCP, Markdown, and LLMs.txt resources.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding an MCP server to valibot.dev.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/valibot@1550

commit: eedf6ce

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a first-class MCP (Model Context Protocol) server endpoint to valibot.dev and expands the existing “docs-for-agents” surface (Markdown negotiation, discovery artifacts, and indexing) so coding agents can search/list/read docs via tools instead of crawling HTML.

Changes:

  • Adds a stateless JSON-RPC MCP server at /mcp with search_docs, get_doc, and list_docs tools backed by a build-generated search-index.json.
  • Refactors the Cloudflare Worker into focused modules (docs, headers, markdown, mcp, mcp-info) and wires /mcp routing + doc markdown negotiation.
  • Renames the “LLMs.txt” guide to “Coding agents”, updates navigation/links, and adds redirects + discovery entries (API catalog + server card).

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
website/wrangler.jsonc Routes /mcp and /mcp/ through the Worker.
website/worker/index.ts Adds /mcp handling and keeps Markdown negotiation + discovery headers for docs pages.
website/worker/mcp.ts Implements the MCP Streamable HTTP JSON-RPC server and the three tools.
website/worker/mcp-info.ts Centralizes MCP constants shared by Worker runtime and build scripts.
website/worker/markdown.ts Extracts Markdown negotiation + .md serving with caching/ETag preservation.
website/worker/headers.ts Adds merge-aware header utilities used by Worker responses.
website/worker/docs.ts Defines doc areas, path regex, search index entry type, and URL helpers.
website/src/routes/guides/menu.md Updates guides menu to include “Coding agents” and remove “LLMs.txt”.
website/src/routes/guides/(get-started)/llms-txt/index.mdx Removes the old LLMs.txt guide page.
website/src/routes/guides/(get-started)/coding-agents/index.mdx Adds the new “Coding agents” guide covering MCP + LLMs.txt + negotiation + skill.
website/src/routes/blog/(posts)/why-migrate-to-valibot/index.mdx Updates internal link from /guides/llms-txt/ to /guides/coding-agents/.
website/src/root.tsx Updates the hidden agent hint to mention the MCP server at /mcp.
website/scripts/utils/transformTextSegments.ts Adds helper to transform Markdown text while preserving fenced code blocks.
website/scripts/utils/index.ts Re-exports the new transformTextSegments utility.
website/scripts/llms.ts Generates public/search-index.json and refactors MDX→MD transforms to reuse transformTextSegments.
website/scripts/agents.ts Generates /.well-known/mcp/server-card.json from shared constants at build time.
website/public/.well-known/api-catalog.json Adds MCP server entry to the API catalog linkset.
website/public/_redirects Adds 301 redirects from /guides/llms-txt* to /guides/coding-agents* (including .md).
website/package.json Adds @valibot/to-json-schema dependency for tool JSON Schema generation.
website/.gitignore Ignores generated MCP/server-card and search index outputs under public/.
pnpm-lock.yaml Locks the added workspace dependency and updates package metadata.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread website/worker/mcp-info.ts Outdated
Comment thread website/scripts/agents.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9649f47665

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread website/public/_redirects

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 21 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread website/scripts/agents.ts
Comment thread website/public/_redirects
Comment thread website/worker/markdown.ts
Comment thread website/worker/mcp.ts Outdated
Comment thread website/worker/mcp.ts
Comment thread website/worker/mcp.ts
Comment thread website/worker/mcp-info.ts Outdated
- Reject requests with an unsupported MCP-Protocol-Version header with
  status 400 as required by the specification
- Validate the type of JSON-RPC message IDs and never echo IDs of an
  invalid type back to the client
- Extend the MCP server card with the fields of the evolving SEP-1649
  draft (name, version, repository, remotes) while keeping the fields
  of the original proposal for older consumers
- Add redirects of the renamed coding agents guide to vercel.json to
  keep Vercel deployments in sync with Cloudflare
- Hyphenate "type-safe" in the MCP instructions and card description

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eedf6ce12f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread website/worker/mcp.ts
input: v.InferOutput<typeof SearchDocsSchema>
): { entry: IndexedEntry; score: number }[] {
// Split query into lowercase search terms
const terms = input.query.toLowerCase().split(/\s+/).filter(Boolean);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize v.-qualified search terms

When a client searches for the documented Valibot spelling like v.string, v.pipe, or v.minLength (the server instructions use this namespace form), the query remains a single term such as v.string, so it does not match index names/titles like string and pipe and search_docs can return no results for common API lookups. Strip a leading v. or tokenize punctuation before scoring so the MCP search works with the API names users and agents actually see.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants