@zenrows/mcp 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/http.js +12 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +6 -4
- package/dist/tools/browser.d.ts +1 -1
- package/dist/tools/browser.js +2 -2
- package/package.json +1 -1
package/dist/http.js
CHANGED
|
@@ -5,6 +5,9 @@ import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/
|
|
|
5
5
|
import { createServer } from "./server.js";
|
|
6
6
|
// ─── app ──────────────────────────────────────────────────────────────────────
|
|
7
7
|
const app = new Hono();
|
|
8
|
+
// Cache MCP client name per API key across invocations.
|
|
9
|
+
// Populated from the clientInfo field in MCP initialize requests.
|
|
10
|
+
const mcpClientCache = new Map();
|
|
8
11
|
// CORS — required for browser-side MCP clients (Claude.ai, Cursor web, etc.)
|
|
9
12
|
// All origins allowed: the API key is the auth mechanism, not the origin.
|
|
10
13
|
app.use(cors({
|
|
@@ -93,9 +96,17 @@ app.all("/mcp", async (c) => {
|
|
|
93
96
|
sessionIdGenerator: undefined, // stateless — no session tracking between requests
|
|
94
97
|
enableJsonResponse: true, // return JSON instead of SSE (simpler for Lambda + most MCP clients)
|
|
95
98
|
});
|
|
96
|
-
|
|
99
|
+
// Use cached client name from a prior initialize request (stateless transport
|
|
100
|
+
// creates a new server per request, so getClientVersion() is only set during
|
|
101
|
+
// the initialize request itself, not during subsequent tool calls).
|
|
102
|
+
const server = createServer(apiKey, mcpClientCache.get(apiKey));
|
|
97
103
|
await server.connect(transport);
|
|
98
104
|
const response = await transport.handleRequest(c.req.raw);
|
|
105
|
+
// If this was an initialize request, getClientVersion() is now set — cache it
|
|
106
|
+
// so subsequent tool call requests can include x-mcp-client-name.
|
|
107
|
+
const resolvedName = server.server.getClientVersion()?.name;
|
|
108
|
+
if (resolvedName)
|
|
109
|
+
mcpClientCache.set(apiKey, resolvedName);
|
|
99
110
|
await transport.close();
|
|
100
111
|
return response;
|
|
101
112
|
});
|
package/dist/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
export declare function createServer(apiKey: string): McpServer;
|
|
2
|
+
export declare function createServer(apiKey: string, clientName?: string): McpServer;
|
package/dist/server.js
CHANGED
|
@@ -8,11 +8,14 @@ const ZENROWS_API_URL = "https://api.zenrows.com/v1/";
|
|
|
8
8
|
const DEFAULT_JS_RENDER = process.env.ZENROWS_JS_RENDER === "true";
|
|
9
9
|
const DEFAULT_PREMIUM_PROXY = process.env.ZENROWS_PREMIUM_PROXY === "true";
|
|
10
10
|
const DEFAULT_RESPONSE_TYPE = process.env.ZENROWS_RESPONSE_TYPE ?? "markdown";
|
|
11
|
-
export function createServer(apiKey) {
|
|
11
|
+
export function createServer(apiKey, clientName) {
|
|
12
12
|
const server = new McpServer({
|
|
13
13
|
name: "zenrows",
|
|
14
14
|
version: pkg.version,
|
|
15
15
|
});
|
|
16
|
+
// Resolve client name: prefer explicit value (HTTP stateless path),
|
|
17
|
+
// fall back to MCP handshake (stdio/persistent connection path).
|
|
18
|
+
const getClientName = () => clientName ?? server.server.getClientVersion()?.name;
|
|
16
19
|
// ─── scrape ────────────────────────────────────────────────────────────────
|
|
17
20
|
server.registerTool("scrape", {
|
|
18
21
|
annotations: {
|
|
@@ -163,11 +166,10 @@ Examples:
|
|
|
163
166
|
}
|
|
164
167
|
let response;
|
|
165
168
|
try {
|
|
166
|
-
const clientName = server.server.getClientVersion()?.name;
|
|
167
169
|
response = await fetch(`${ZENROWS_API_URL}?${searchParams}`, {
|
|
168
170
|
headers: {
|
|
169
171
|
"User-Agent": `zenrows/mcp ${pkg.version}`,
|
|
170
|
-
...(
|
|
172
|
+
...(getClientName() ? { "x-mcp-client-name": getClientName() } : {}),
|
|
171
173
|
"x-mcp-tool": "scrape",
|
|
172
174
|
},
|
|
173
175
|
});
|
|
@@ -266,6 +268,6 @@ Examples:
|
|
|
266
268
|
],
|
|
267
269
|
}));
|
|
268
270
|
const BROWSER_URL = process.env.ZENROWS_BROWSER_URL ?? "https://mcp.zenrows.com";
|
|
269
|
-
registerBrowserTools(server, apiKey, BROWSER_URL,
|
|
271
|
+
registerBrowserTools(server, apiKey, BROWSER_URL, getClientName);
|
|
270
272
|
return server;
|
|
271
273
|
}
|
package/dist/tools/browser.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
export declare function registerBrowserTools(server: McpServer, apiKey: string, browserUrl: string,
|
|
2
|
+
export declare function registerBrowserTools(server: McpServer, apiKey: string, browserUrl: string, getClientName: () => string | undefined): void;
|
package/dist/tools/browser.js
CHANGED
|
@@ -10,8 +10,8 @@ function json(data) {
|
|
|
10
10
|
return { content: [{ type: "text", text: JSON.stringify(data) }] };
|
|
11
11
|
}
|
|
12
12
|
const sessionId = z.string().describe("Session ID returned by browser_navigate");
|
|
13
|
-
export function registerBrowserTools(server, apiKey, browserUrl,
|
|
14
|
-
const tfetch = (toolName) => (method, path, body) => browserFetch(method, path, apiKey, browserUrl, body,
|
|
13
|
+
export function registerBrowserTools(server, apiKey, browserUrl, getClientName) {
|
|
14
|
+
const tfetch = (toolName) => (method, path, body) => browserFetch(method, path, apiKey, browserUrl, body, getClientName(), toolName);
|
|
15
15
|
// ─── Session ─────────────────────────────────────────────────────────────
|
|
16
16
|
server.registerTool("browser_navigate", {
|
|
17
17
|
annotations: { title: "Open Browser & Navigate", readOnlyHint: false, destructiveHint: false },
|