Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/web/app/api/mcp/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createMcpRoute } from "@vercel/geistdocs/routes/mcp";
import { config } from "@/lib/geistdocs/config";
import { GET as search } from "../search/route";

const handler = createMcpRoute({ config, search });

export { handler as GET, handler as POST };
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@upstash/ratelimit": "^2.0.8",
"@upstash/redis": "^1.36.1",
"@vercel/analytics": "^1.6.1",
"@vercel/geistdocs": "2.4.1",
"@vercel/geistdocs": "2.7.5",
"@vercel/speed-insights": "^1.3.1",
"@visual-json/react": "0.1.1",
"ai": "^6.0.33",
Expand Down
62 changes: 62 additions & 0 deletions apps/web/scripts/test-routes.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from "node:assert/strict";
import process from "node:process";
import { spawn } from "node:child_process";
import { createServer } from "node:net";
Expand Down Expand Up @@ -95,6 +96,67 @@ try {
"Docs server did not become ready. Run the docs build first.",
);
if (!stopping) {
const bridge = await fetch(`${url}/api/mcp?webmcp-script`, {
signal: AbortSignal.timeout(30000),
});
assert.equal(bridge.status, 200);
assert.match(bridge.headers.get("content-type") ?? "", /javascript/);
assert.match(await bridge.text(), /registerTool/);
console.log("PASS native WebMCP bridge returns JavaScript (200)");

const rpc = async (method, params = {}) => {
const response = await fetch(`${url}/api/mcp`, {
method: "POST",
headers: {
"content-type": "application/json",
accept: "application/json, text/event-stream",
},
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
signal: AbortSignal.timeout(30000),
});
assert.equal(response.status, 200);
const type = response.headers.get("content-type")?.split(";")[0];
assert.ok(["application/json", "text/event-stream"].includes(type));
const body = await response.text();
const messages =
type === "application/json"
? [JSON.parse(body)]
: body
.split(/\r?\n\r?\n/)
.map((event) =>
event
.split(/\r?\n/)
.filter((line) => line.startsWith("data:"))
.map((line) => line.slice(5).replace(/^ /, ""))
.join("\n"),
)
.filter(Boolean)
.map((data) => JSON.parse(data));
const replies = messages.filter((message) => message.id === 1);
assert.equal(replies.length, 1);
const [message] = replies;
assert.equal(message.jsonrpc, "2.0");
assert.equal(message.error, undefined);
return message.result;
};
const { tools } = await rpc("tools/list");
assert.deepEqual(
tools.map((tool) => tool.name),
["search_docs"],
);
console.log("PASS MCP tools/list exposes search_docs");

const result = await rpc("tools/call", {
name: "search_docs",
arguments: { query: "StateProvider", locale: "en" },
});
assert.notEqual(result.isError, true);
const matches = JSON.parse(
result.content.find((item) => item.type === "text").text,
);
assert.ok(matches.some((item) => item.url.startsWith("/docs/")));
console.log("PASS MCP tools/call returns actual docs search results");

tests = launch(["--test", "tests/docs-routes.test.mjs"], {
...process.env,
DOCS_TEST_URL: url,
Expand Down
11 changes: 9 additions & 2 deletions apps/web/source.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import {
geistdocsFrontmatterSchema,
geistdocsMetaSchema,
} from "@vercel/geistdocs/source-config";
import { defineConfig, defineDocs } from "fumadocs-mdx/config";
import {
defineConfig,
defineDocs,
type DocsCollection,
} from "fumadocs-mdx/config";
import { remarkLegacyHeadings } from "./lib/remark-legacy-headings";

export const docs = defineDocs({
export const docs: DocsCollection<
typeof geistdocsFrontmatterSchema,
typeof geistdocsMetaSchema
> = defineDocs({
dir: "content/docs",
docs: {
schema: geistdocsFrontmatterSchema,
Expand Down
Loading
Loading