Skip to content

Commit c7b58ad

Browse files
添加configSchema
1 parent 4d0a2a0 commit c7b58ad

1 file changed

Lines changed: 34 additions & 15 deletions

File tree

src/server-http.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
*/
99
import { createServer as createHttpServer } from "node:http";
1010
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
11-
import { zodToJsonSchema } from "zod-to-json-schema";
12-
import createServer, { configSchema, createSandboxServer } from "./index.js";
11+
import createServer, { createSandboxServer } from "./index.js";
1312
import type { IncomingMessage, ServerResponse } from "node:http";
1413

1514
const PORT = parseInt(process.env.PORT || "10000", 10);
@@ -52,18 +51,20 @@ function getConfig(req: IncomingMessage): { mineruApiKey?: string } {
5251
}
5352

5453
// ---------------------------------------------------------------------------
55-
// /.well-known/mcp-config — exposes config schema for Smithery form generation
54+
// Config schema for Smithery — must match Session Config format exactly
55+
// https://smithery.ai/docs/build/session-config
5656
// ---------------------------------------------------------------------------
57-
const configSchemaJson = zodToJsonSchema(configSchema, {
58-
target: "openApi3",
59-
$refStrategy: "none",
60-
}) as Record<string, unknown>;
61-
62-
// Smithery: x-from tells gateway to pass mineruApiKey via header (for secrets)
63-
const props = (configSchemaJson.properties ?? {}) as Record<string, Record<string, unknown>>;
64-
if (props.mineruApiKey) {
65-
props.mineruApiKey["x-from"] = { header: "x-mineru-api-key" };
66-
}
57+
const configSchemaJson: Record<string, unknown> = {
58+
type: "object",
59+
properties: {
60+
mineruApiKey: {
61+
type: "string",
62+
title: "MinerU API Key",
63+
description: "Your MinerU API Key (obtain from https://mineru.net/apiManage/token)",
64+
"x-from": { header: "x-mineru-api-key" },
65+
},
66+
},
67+
};
6768

6869
const MCP_CONFIG_JSON = JSON.stringify({
6970
configSchema: configSchemaJson,
@@ -185,17 +186,35 @@ async function handleRequest(req: IncomingMessage, res: ServerResponse) {
185186
const method = req.method ?? "GET";
186187
const path = (req.url ?? "/").split("?")[0];
187188

188-
// /.well-known/mcp/server-card.json — Smithery server scanning
189+
const corsHeaders = {
190+
"Access-Control-Allow-Origin": "*",
191+
"Access-Control-Allow-Methods": "GET",
192+
"Access-Control-Allow-Headers": "Content-Type",
193+
};
194+
195+
// /.well-known/mcp/server-card.json — Smithery server scanning (includes configSchema)
189196
if (method === "GET" && path === "/.well-known/mcp/server-card.json") {
190197
res.writeHead(200, {
191198
"Content-Type": "application/json",
192199
"Cache-Control": "public, max-age=300",
200+
...corsHeaders,
201+
});
202+
res.end(SERVER_CARD_JSON);
203+
return;
204+
}
205+
206+
// /.well-known/mcp.json — alternate discovery path (SEP-1649)
207+
if (method === "GET" && path === "/.well-known/mcp.json") {
208+
res.writeHead(200, {
209+
"Content-Type": "application/json",
210+
"Cache-Control": "public, max-age=300",
211+
...corsHeaders,
193212
});
194213
res.end(SERVER_CARD_JSON);
195214
return;
196215
}
197216

198-
// /.well-known/mcp-config — config schema (legacy)
217+
// /.well-known/mcp-config — config schema only (legacy)
199218
if (method === "GET" && path === "/.well-known/mcp-config") {
200219
res.writeHead(200, {
201220
"Content-Type": "application/json",

0 commit comments

Comments
 (0)