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
31 changes: 25 additions & 6 deletions scripts/check-cross-rail-v2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -877,18 +877,37 @@ try {
assert.ok(spec.paths["/v1/history"]?.post);
assert.ok(!openapi.body.includes("evil.example.com"));

// Plain web/LLM GET /mcp returns 200 + live setup instructions so web fetchers never treat it as dead
const mcpGet = await httpReq("/mcp", { headers: hdrs });
assert.equal(mcpGet.status, 405);
const mcpJson = JSON.parse(mcpGet.body);
assert.equal(mcpGet.status, 200);
assert.match(mcpGet.headers["content-type"], /text\/plain/);
assert.ok(mcpGet.body.includes(`Live Remote MCP Server — ${origin}/mcp`));
assert.ok(mcpGet.body.includes("Settings -> Connectors"));
assert.ok(mcpGet.body.includes(`# Agent Wallet (${expectedHost})`));

// Streamable HTTP MCP SSE probe (Accept: text/event-stream) still receives 405 per MCP spec
const mcpSse = await httpReq("/mcp", { headers: { ...hdrs, Accept: "text/event-stream" } });
assert.equal(mcpSse.status, 405);
const mcpJson = JSON.parse(mcpSse.body);
assert.equal(mcpJson.hint, `POST JSON-RPC to this URL. Start: ${origin}/llms.txt`);

const restGet = await httpReq("/v1/wallet", { headers: hdrs });
assert.equal(restGet.status, 405);
const restGetJson = JSON.parse(restGet.body);
assert.ok(restGetJson.hint.includes(`${origin}/openapi.json`));
assert.equal(restGet.status, 200);
assert.match(restGet.headers["content-type"], /text\/plain/);
assert.ok(restGet.body.includes(`${origin}/v1/wallet`));
assert.ok(restGet.body.includes(`# Agent Wallet (${expectedHost})`));

const robots = await httpReq("/robots.txt", { headers: hdrs });
assert.equal(robots.status, 200);
assert.ok(robots.body.includes(`Sitemap: ${origin}/sitemap.xml`));

const sitemap = await httpReq("/sitemap.xml", { headers: hdrs });
assert.equal(sitemap.status, 200);
assert.ok(sitemap.body.includes(`<loc>${origin}/</loc>`));
assert.ok(sitemap.body.includes(`<loc>${origin}/llms.txt</loc>`));
}

for (const p of ["/", "/llms.txt", "/skill.md", "/openapi.json"]) {
for (const p of ["/", "/llms.txt", "/skill.md", "/openapi.json", "/robots.txt", "/sitemap.xml", "/mcp", "/v1/wallet"]) {
const headRes = await httpReq(p, { method: "HEAD", headers: { Host: "wallet.nuri.com" } });
assert.equal(headRes.status, 200);
assert.equal(headRes.body, "");
Expand Down
40 changes: 38 additions & 2 deletions src/wallet-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ const server = http.createServer(async (req, res) => {
const origin = resolveWalletOrigin(req);
return writeText(req, res, 200, OPENAPI_BY_ORIGIN.get(origin) || JSON.stringify(walletOpenApiJson(origin), null, 2), "application/json; charset=utf-8");
}
if ((req.method === "GET" || req.method === "HEAD") && url.pathname === "/robots.txt") {
const origin = resolveWalletOrigin(req);
return writeText(req, res, 200, `User-agent: *\nAllow: /\nSitemap: ${origin}/sitemap.xml\n`, "text/plain; charset=utf-8");
}
if ((req.method === "GET" || req.method === "HEAD") && url.pathname === "/sitemap.xml") {
const origin = resolveWalletOrigin(req);
const urls = ["/", "/llms.txt", "/skill.md", "/openapi.json"]
.map((p) => ` <url><loc>${origin}${p}</loc></url>`).join("\n");
return writeText(req, res, 200, `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>\n`, "application/xml; charset=utf-8");
}
if (REST_ACTION_ROUTES.has(url.pathname)) {
return await handleRestWallet(req, res, REST_ACTION_ROUTES.get(url.pathname));
}
Expand Down Expand Up @@ -291,8 +301,17 @@ server.listen(PORT, HOST, () => {

async function handleRestWallet(req, res, fixedAction) {
const reqOrigin = resolveWalletOrigin(req);
if (req.method === "GET" || req.method === "HEAD") {
return writeText(
req,
res,
200,
`# Plain HTTP REST Wallet Endpoint (${reqOrigin}${req.url || "/v1/wallet"})\n\nSend POST JSON here (no OAuth, no MCP required). Full instructions:\n\n${LLMS_BY_ORIGIN.get(reqOrigin) || walletLlmsTxt(reqOrigin)}`,
"text/plain; charset=utf-8",
);
}
if (req.method !== "POST") {
res.setHeader("Allow", "POST, OPTIONS");
res.setHeader("Allow", "GET, POST, OPTIONS");
return writeJson(req, res, 405, { ok: false, error: "method_not_allowed", hint: `POST JSON to this URL. Docs: ${reqOrigin}/llms.txt | OpenAPI: ${reqOrigin}/openapi.json` });
}
const body = await readJson(req);
Expand Down Expand Up @@ -327,8 +346,25 @@ async function handleRestWallet(req, res, fixedAction) {

async function handleMcp(req, res) {
const reqOrigin = resolveWalletOrigin(req);
if (req.method === "GET" || req.method === "HEAD") {
const accept = String(req.headers.accept || "").toLowerCase();
// Streamable HTTP MCP clients probing GET SSE stream expect 405 when SSE is unsupported.
// Web fetchers / LLMs / browsers (Accept: */*, text/html, text/plain) get 200 + full setup instructions.
const wantsSseOnly = accept.includes("text/event-stream") && !accept.includes("text/html") && !accept.includes("*/*");
if (wantsSseOnly) {
res.setHeader("Allow", "POST, OPTIONS");
return writeJson(req, res, 405, { ok: false, error: "method_not_allowed", hint: `POST JSON-RPC to this URL. Start: ${reqOrigin}/llms.txt` });
}
return writeText(
req,
res,
200,
`# Live Remote MCP Server — ${reqOrigin}/mcp\n\nThis URL is a real, live, authless Streamable HTTP MCP endpoint (POST JSON-RPC, Auth: None, no OAuth).\nTo connect in Claude or ChatGPT: Settings -> Connectors / Apps -> Add Custom Connector -> URL: ${reqOrigin}/mcp (Auth: None).\n\n${LLMS_BY_ORIGIN.get(reqOrigin) || walletLlmsTxt(reqOrigin)}`,
"text/plain; charset=utf-8",
);
}
if (req.method !== "POST") {
res.setHeader("Allow", "POST, OPTIONS");
res.setHeader("Allow", "GET, POST, OPTIONS");
return writeJson(req, res, 405, { ok: false, error: "method_not_allowed", hint: `POST JSON-RPC to this URL. Start: ${reqOrigin}/llms.txt` });
}
const message = await readJson(req);
Expand Down
Loading