Skip to content

Commit 30da53e

Browse files
修复连接;在 smithery.yaml 中加入 configSchema
1 parent 282c17d commit 30da53e

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

smithery.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
runtime: typescript
2+
3+
# Config schema for Smithery to show API Key form when users connect
4+
configSchema:
5+
type: object
6+
properties:
7+
mineruApiKey:
8+
type: string
9+
title: MinerU API Key
10+
description: Your MinerU API Key (obtain from https://mineru.net/apiManage/token)
11+
x-from:
12+
header: x-mineru-api-key

src/index.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,15 @@ export default function createServer(
113113
config: z.infer<typeof configSchema>
114114
) {
115115
const apiToken = config.mineruApiKey || process.env.MINERU_API_KEY || "";
116-
if (!apiToken) {
117-
throw new Error(
118-
"MinerU API Key is required. Provide it via configSchema or set MINERU_API_KEY environment variable."
119-
);
120-
}
116+
117+
const requireApiKey = () => {
118+
if (!apiToken || apiToken === SANDBOX_PLACEHOLDER_KEY) {
119+
throw new Error(
120+
"MinerU API Key is required. Please configure your API key in Smithery/Cursor settings. " +
121+
"Get your key from https://mineru.net/apiManage/token"
122+
);
123+
}
124+
};
121125

122126
const server = new McpServer({
123127
name: "mineru-markdown-converter",
@@ -208,6 +212,7 @@ export default function createServer(
208212
.describe("Enable table recognition"),
209213
},
210214
async ({ url, model_version, is_ocr, enable_formula, enable_table }) => {
215+
requireApiKey();
211216
const ext = guessExtFromUrl(url);
212217
const params = autoConfigureParams(ext, model_version, is_ocr);
213218

@@ -242,6 +247,7 @@ export default function createServer(
242247
.describe("Batch ID returned from create_parse_task (file upload)"),
243248
},
244249
async ({ task_id, batch_id }) => {
250+
requireApiKey();
245251
if (!task_id && !batch_id) {
246252
return {
247253
content: [
@@ -294,6 +300,7 @@ export default function createServer(
294300
max_wait_seconds: number,
295301
poll_interval: number
296302
) {
303+
requireApiKey();
297304
const ext = guessExtFromUrl(url);
298305
const params = autoConfigureParams(ext, model_version);
299306

@@ -450,10 +457,14 @@ export default function createServer(
450457
return server;
451458
}
452459

460+
/** Placeholder key for sandbox mode — connection works, tools return friendly error */
461+
export const SANDBOX_PLACEHOLDER_KEY = "sandbox-placeholder-key";
462+
453463
/**
454-
* Sandbox server for Smithery scanning.
455-
* Uses a dummy key so Smithery can discover tools without real credentials.
464+
* Sandbox server for Smithery scanning and connection handshake.
465+
* Uses a dummy key so Smithery can discover tools and connect without real credentials.
466+
* Tool calls return a friendly error asking the user to configure their API key.
456467
*/
457468
export function createSandboxServer() {
458-
return createServer({ mineruApiKey: "sandbox-placeholder-key" });
469+
return createServer({ mineruApiKey: SANDBOX_PLACEHOLDER_KEY });
459470
}

src/server-http.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { createServer as createHttpServer } from "node:http";
1010
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
1111
import { zodToJsonSchema } from "zod-to-json-schema";
12-
import createServer, { configSchema } from "./index.js";
12+
import createServer, { configSchema, createSandboxServer } from "./index.js";
1313
import type { IncomingMessage, ServerResponse } from "node:http";
1414

1515
const PORT = parseInt(process.env.PORT || "10000", 10);
@@ -216,7 +216,12 @@ async function handleRequest(req: IncomingMessage, res: ServerResponse) {
216216
if ((method === "GET" || method === "POST") && path === "/mcp") {
217217
const config = getConfig(req);
218218
try {
219-
const server = createServer(config);
219+
// Use sandbox server when no API key: allows Smithery connection handshake
220+
// to succeed (initialize, tools/list). Tool calls will fail with friendly error.
221+
const server =
222+
config.mineruApiKey || process.env.MINERU_API_KEY
223+
? createServer(config)
224+
: createSandboxServer();
220225
const transport = new StreamableHTTPServerTransport({
221226
sessionIdGenerator: undefined,
222227
});

0 commit comments

Comments
 (0)