mcp-scraper 0.75.1 → 0.77.0

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.
@@ -1,6 +1,6 @@
1
1
  // release-message.json
2
2
  var release_message_default = {
3
- message: "X-Ray now provides a production customer loop for consent-aware identity, journeys, event verification, attribution, CRM and call evidence, governed data movement, activation receipts, and durable automation."
3
+ message: "X-Ray Pixels can now render a published consent gateway on approved sites, and the visual event picker clearly confirms selected targets and editable drafts."
4
4
  };
5
5
 
6
6
  // src/install-terminal.ts
@@ -0,0 +1,223 @@
1
+ import {
2
+ HttpMcpToolExecutor,
3
+ MEMORY_TOOL_REGISTRY,
4
+ SERVER_INSTRUCTIONS,
5
+ ScheduledResultsMcpExecutor,
6
+ hashOwnerId,
7
+ installInputFieldDescriptions,
8
+ permitsLocalNetworkAccess,
9
+ registerBrowserAgentMcpTools,
10
+ registerMemoryMcpTools,
11
+ registerPaaExtractorMcpTools,
12
+ registerScheduledResultsMcpTools,
13
+ registerSerpIntelligenceCaptureTools,
14
+ resolveDeploymentProfile
15
+ } from "./chunk-DTJ56S5B.js";
16
+ import {
17
+ renderInstallTerminal
18
+ } from "./chunk-GT6MP4SU.js";
19
+ import {
20
+ PACKAGE_VERSION
21
+ } from "./chunk-7HF3T7P2.js";
22
+
23
+ // src/mcp/stdio-runtime.ts
24
+ import { readFileSync } from "fs";
25
+ import { homedir } from "os";
26
+ import { join } from "path";
27
+ import { serveStdio } from "@modelcontextprotocol/server/stdio";
28
+ import { McpServer } from "@modelcontextprotocol/server";
29
+
30
+ // src/mcp/hosted-memory-mcp-tool-executor.ts
31
+ var publicToolNameByUpstreamName = new Map(
32
+ MEMORY_TOOL_REGISTRY.map((schema) => [schema.upstreamName, schema.id])
33
+ );
34
+ function parseJsonRpcEnvelope(text) {
35
+ const payloads = text.split("\n").filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trim()).filter(Boolean);
36
+ if (!payloads.length) return JSON.parse(text);
37
+ for (const payload of payloads) {
38
+ const parsed = JSON.parse(payload);
39
+ if (parsed.result || parsed.error) return parsed;
40
+ }
41
+ throw new Error("hosted MCP returned no JSON-RPC result");
42
+ }
43
+ function errorResult(message) {
44
+ return {
45
+ content: [{ type: "text", text: JSON.stringify({ ok: false, error: message }) }],
46
+ isError: true
47
+ };
48
+ }
49
+ var HostedMemoryMcpToolExecutor = class {
50
+ baseUrl;
51
+ apiKey;
52
+ constructor(baseUrl, apiKey) {
53
+ this.baseUrl = baseUrl.replace(/\/$/, "");
54
+ this.apiKey = apiKey;
55
+ }
56
+ async callMemoryTool(upstreamName, args) {
57
+ const publicToolName = publicToolNameByUpstreamName.get(upstreamName);
58
+ if (!publicToolName) return errorResult(`unknown memory tool: ${upstreamName}`);
59
+ try {
60
+ const res = await fetch(`${this.baseUrl}/mcp`, {
61
+ method: "POST",
62
+ headers: {
63
+ "content-type": "application/json",
64
+ accept: "application/json, text/event-stream",
65
+ "x-api-key": this.apiKey
66
+ },
67
+ body: JSON.stringify({
68
+ jsonrpc: "2.0",
69
+ id: `memory:${publicToolName}`,
70
+ method: "tools/call",
71
+ params: { name: publicToolName, arguments: args }
72
+ })
73
+ });
74
+ const text = await res.text();
75
+ if (!res.ok) return errorResult(`hosted memory ${publicToolName} failed (HTTP ${res.status})`);
76
+ const envelope = parseJsonRpcEnvelope(text);
77
+ if (envelope.error) {
78
+ return errorResult(envelope.error.message ?? `hosted memory ${publicToolName} failed`);
79
+ }
80
+ return envelope.result ?? errorResult(`hosted memory ${publicToolName} returned no result`);
81
+ } catch (err) {
82
+ return errorResult(err instanceof Error ? err.message : `hosted memory ${publicToolName} call failed`);
83
+ }
84
+ }
85
+ };
86
+
87
+ // src/mcp/exact-tool-registration.ts
88
+ function installExactToolRegistrationGuard(server, requiredToolNames) {
89
+ if (requiredToolNames.length === 0) {
90
+ throw new Error("Restricted MCP tool allowlist must contain at least one tool name");
91
+ }
92
+ const required = /* @__PURE__ */ new Set();
93
+ for (const rawName of requiredToolNames) {
94
+ if (typeof rawName !== "string" || rawName.trim() !== rawName || rawName.length === 0) {
95
+ throw new Error("Restricted MCP tool allowlist contains a malformed tool name");
96
+ }
97
+ if (required.has(rawName)) {
98
+ throw new Error(`Restricted MCP tool allowlist contains duplicate tool name: ${rawName}`);
99
+ }
100
+ required.add(rawName);
101
+ }
102
+ const registered = /* @__PURE__ */ new Set();
103
+ const mutableServer = server;
104
+ const registerTool = mutableServer.registerTool.bind(server);
105
+ mutableServer.registerTool = (name, config, callback) => {
106
+ if (!required.has(name)) return void 0;
107
+ registered.add(name);
108
+ return registerTool(name, config, callback);
109
+ };
110
+ return {
111
+ assertComplete() {
112
+ const missing = [...required].filter((name) => !registered.has(name));
113
+ if (missing.length > 0) {
114
+ throw new Error(`Restricted MCP tool allowlist contains unknown or unavailable tool names: ${missing.join(", ")}`);
115
+ }
116
+ },
117
+ registeredToolNames() {
118
+ return [...registered];
119
+ }
120
+ };
121
+ }
122
+
123
+ // src/mcp/stdio-runtime.ts
124
+ var ALL_STDIO_TOOLSETS = /* @__PURE__ */ new Set([
125
+ "paa",
126
+ "serp",
127
+ "browser-agent",
128
+ "scheduled-results",
129
+ "memory"
130
+ ]);
131
+ function readApiKeyFile() {
132
+ const explicitPath = process.env.MCP_SCRAPER_KEY_PATH?.trim();
133
+ const fileNames = [explicitPath, join(homedir(), ".mcp-scraper-key")].filter(Boolean);
134
+ for (const fileName of fileNames) {
135
+ try {
136
+ const value = readFileSync(fileName, "utf8").trim();
137
+ if (value) return value;
138
+ } catch {
139
+ }
140
+ }
141
+ return void 0;
142
+ }
143
+ function buildStdioServer(requiredApiKey, options = {}) {
144
+ const toolsets = options.toolsets ?? ALL_STDIO_TOOLSETS;
145
+ const baseUrl = process.env.MCP_SCRAPER_BASE_URL?.trim() || process.env.MCP_BASE_URL?.trim() || "https://mcpscraper.dev";
146
+ const deploymentProfile = resolveDeploymentProfile();
147
+ const localNetworkAccess = permitsLocalNetworkAccess({
148
+ deploymentProfile,
149
+ transportProfile: "stdio",
150
+ baseUrl,
151
+ explicitlyEnabled: process.env.MCP_SCRAPER_ALLOW_PRIVATE_NETWORK === "1"
152
+ });
153
+ const consoleBaseUrl = process.env.BROWSER_AGENT_CONSOLE_URL?.trim() || baseUrl;
154
+ const server = new McpServer({ name: "mcp-scraper", version: PACKAGE_VERSION }, {
155
+ instructions: SERVER_INSTRUCTIONS,
156
+ cacheHints: {
157
+ "server/discover": { ttlMs: 3e5, cacheScope: "private" },
158
+ "tools/list": { ttlMs: 3e5, cacheScope: "private" },
159
+ "resources/list": { ttlMs: 3e5, cacheScope: "private" },
160
+ "resources/templates/list": { ttlMs: 3e5, cacheScope: "private" },
161
+ "resources/read": { ttlMs: 6e4, cacheScope: "private" }
162
+ }
163
+ });
164
+ installInputFieldDescriptions(server);
165
+ const registrationGuard = options.allowedToolNames ? installExactToolRegistrationGuard(server, options.allowedToolNames) : void 0;
166
+ const httpExecutor = options.httpExecutor ?? new HttpMcpToolExecutor(baseUrl, requiredApiKey, { localNetworkAccess });
167
+ if (toolsets.has("paa")) {
168
+ registerPaaExtractorMcpTools(server, httpExecutor, {
169
+ ownerId: hashOwnerId(requiredApiKey),
170
+ deploymentProfile,
171
+ transportProfile: "stdio",
172
+ baseUrl,
173
+ localNetworkAccess,
174
+ taskHandleSecret: requiredApiKey
175
+ });
176
+ }
177
+ if (toolsets.has("serp")) {
178
+ registerSerpIntelligenceCaptureTools(server, httpExecutor, {
179
+ exposeDevelopmentDiagnostics: deploymentProfile === "development" || deploymentProfile === "test"
180
+ });
181
+ }
182
+ if (toolsets.has("browser-agent")) {
183
+ registerBrowserAgentMcpTools(server, { baseUrl, apiKey: requiredApiKey, consoleBaseUrl });
184
+ }
185
+ if (toolsets.has("scheduled-results")) {
186
+ registerScheduledResultsMcpTools(server, new ScheduledResultsMcpExecutor(baseUrl, requiredApiKey));
187
+ }
188
+ if (toolsets.has("memory")) {
189
+ registerMemoryMcpTools(server, new HostedMemoryMcpToolExecutor(baseUrl, requiredApiKey));
190
+ }
191
+ registrationGuard?.assertComplete();
192
+ return server;
193
+ }
194
+ function runMcpScraperStdio(options = {}) {
195
+ const forceStdio = process.argv.includes("--stdio") || process.env.MCP_SCRAPER_FORCE_STDIO === "1";
196
+ const interactiveTerminal = Boolean(process.stdin.isTTY && process.stdout.isTTY);
197
+ const wantsHelp = process.argv.includes("--help") || process.argv.includes("-h");
198
+ if (!forceStdio && (interactiveTerminal || wantsHelp)) {
199
+ const noColor = process.argv.includes("--no-color") || process.env.NO_COLOR !== void 0 || process.env.FORCE_COLOR === "0" || !process.stdout.isTTY;
200
+ process.stdout.write(renderInstallTerminal({
201
+ version: PACKAGE_VERSION,
202
+ color: !noColor,
203
+ apiKeyConfigured: Boolean(process.env.MCP_SCRAPER_API_KEY?.trim())
204
+ }));
205
+ process.exit(0);
206
+ }
207
+ const apiKey = (process.env.MCP_SCRAPER_API_KEY ?? process.env.MCP_SCRAPER_KEY ?? process.env.MCP_API_KEY ?? readApiKeyFile())?.trim();
208
+ if (!apiKey) {
209
+ process.stderr.write("MCP_SCRAPER_API_KEY env var or ~/.mcp-scraper-key is required\n");
210
+ process.exit(1);
211
+ }
212
+ serveStdio(() => buildStdioServer(apiKey, options), {
213
+ legacy: "serve",
214
+ onerror(error) {
215
+ process.stderr.write(`${error.message}
216
+ `);
217
+ }
218
+ });
219
+ }
220
+
221
+ export {
222
+ runMcpScraperStdio
223
+ };
@@ -7,11 +7,11 @@ import {
7
7
  GmailServiceError,
8
8
  normalizeGmailMessage,
9
9
  parseGmailAddresses
10
- } from "./chunk-GLVWJCNU.js";
10
+ } from "./chunk-E6Y3VCOJ.js";
11
11
  import "./chunk-PJEEKOUM.js";
12
12
  import "./chunk-T3MZISOF.js";
13
- import "./chunk-CXY5WV45.js";
14
13
  import "./chunk-6W4ADSWE.js";
14
+ import "./chunk-CXY5WV45.js";
15
15
  import "./chunk-WEFPBAAG.js";
16
16
  export {
17
17
  GMAIL_ATTACHMENT_REF_TTL_MS,