@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 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
- const server = createServer(apiKey);
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
- ...(clientName ? { "x-mcp-client-name": clientName } : {}),
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, server);
271
+ registerBrowserTools(server, apiKey, BROWSER_URL, getClientName);
270
272
  return server;
271
273
  }
@@ -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, mcpServer: McpServer): void;
2
+ export declare function registerBrowserTools(server: McpServer, apiKey: string, browserUrl: string, getClientName: () => string | undefined): void;
@@ -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, mcpServer) {
14
- const tfetch = (toolName) => (method, path, body) => browserFetch(method, path, apiKey, browserUrl, body, mcpServer.server.getClientVersion()?.name, toolName);
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 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenrows/mcp",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "ZenRows MCP server — Universal Scraper API for AI coding assistants",
5
5
  "type": "module",
6
6
  "bin": {