mcp-scraper 0.1.7 → 0.1.9
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/README.md +4 -0
- package/dist/bin/api-server.cjs +635 -281
- package/dist/bin/api-server.cjs.map +1 -1
- package/dist/bin/api-server.js +2 -2
- package/dist/bin/mcp-stdio-server.cjs +479 -210
- package/dist/bin/mcp-stdio-server.cjs.map +1 -1
- package/dist/bin/mcp-stdio-server.js +1 -1
- package/dist/bin/paa-harvest.cjs +14 -4
- package/dist/bin/paa-harvest.cjs.map +1 -1
- package/dist/bin/paa-harvest.js +4 -3
- package/dist/bin/paa-harvest.js.map +1 -1
- package/dist/{chunk-3OIRNUF5.js → chunk-JNC32DMS.js} +478 -209
- package/dist/chunk-JNC32DMS.js.map +1 -0
- package/dist/{chunk-LUBDFS67.js → chunk-TM22BLWP.js} +15 -3
- package/dist/chunk-TM22BLWP.js.map +1 -0
- package/dist/index.cjs +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-YNJHP5PU.js → server-MTXAJG5J.js} +84 -31
- package/dist/server-MTXAJG5J.js.map +1 -0
- package/dist/{worker-PBG6LGET.js → worker-AUCXFHEL.js} +4 -3
- package/dist/worker-AUCXFHEL.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-3OIRNUF5.js.map +0 -1
- package/dist/chunk-LUBDFS67.js.map +0 -1
- package/dist/server-YNJHP5PU.js.map +0 -1
- package/dist/worker-PBG6LGET.js.map +0 -1
|
@@ -17,204 +17,12 @@ function harvestTimeoutBudget(maxQuestions, serpOnly = false) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/mcp/paa-mcp-server.ts
|
|
20
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
20
|
+
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
21
|
+
import { readdirSync, readFileSync, statSync } from "fs";
|
|
22
|
+
import { basename, join as join2 } from "path";
|
|
21
23
|
|
|
22
24
|
// src/version.ts
|
|
23
|
-
var PACKAGE_VERSION = "0.1.
|
|
24
|
-
|
|
25
|
-
// src/mcp/mcp-tool-schemas.ts
|
|
26
|
-
import { z } from "zod";
|
|
27
|
-
var HarvestPaaInputSchema = {
|
|
28
|
-
query: z.string().min(1).describe('Core search topic only. If the user says "best hvac company in Denver CO", use query="best hvac company" and location="Denver, CO". Do not include the location in query when it can be separated.'),
|
|
29
|
-
location: z.string().optional().describe('City, region, or country for geo-targeted results, inferred from the user request when present, e.g. "Denver, CO", "Tokyo, Japan", "London, UK".'),
|
|
30
|
-
maxQuestions: z.number().int().min(1).max(200).default(30).describe("Number of PAA questions to extract. Default 30. Maximum 200. Use 10 for quick probes, 30 for normal research, 100-200 when the user asks for everything/full/deep research. Larger harvests get a longer server time budget (151-200 questions \u2192 up to 280s). Credits are charged by extracted question; unused request hold is refunded."),
|
|
31
|
-
gl: z.string().length(2).default("us").describe("Google country code inferred from location or user language. Examples: United States us, United Kingdom gb, Japan jp, Canada ca, Australia au."),
|
|
32
|
-
hl: z.string().default("en").describe("Google interface/content language inferred from the user request. Use en unless the user asks for another language or locale."),
|
|
33
|
-
device: z.enum(["desktop", "mobile"]).default("desktop").describe("SERP device context. Use desktop by default; use mobile only when the user asks for mobile rankings."),
|
|
34
|
-
proxyMode: z.enum(["location", "configured", "none"]).default("location").describe("Proxy targeting mode. Use location by default so city/state searches create or reuse a matching residential proxy. Use configured for the static configured proxy. Use none only for direct-network debugging."),
|
|
35
|
-
proxyZip: z.string().regex(/^\d{5}$/).optional().describe("Optional US ZIP override for residential location proxy targeting. Use only when the user gives a specific ZIP or city-center proxy targeting needs to be forced."),
|
|
36
|
-
debug: z.boolean().default(false).describe("Include sanitized browser/session/location diagnostics in the response. Use true when debugging localization, CAPTCHA, or proxy behavior.")
|
|
37
|
-
};
|
|
38
|
-
var ExtractUrlInputSchema = {
|
|
39
|
-
url: z.string().url().describe("Public http/https URL to extract. Use this when the user provides one specific page URL."),
|
|
40
|
-
screenshot: z.boolean().default(false).describe("Also capture a full-page screenshot of the URL. Saved to ~/Downloads/mcp-scraper/screenshots/ and returned inline. Use when the user asks to see or capture the page visually."),
|
|
41
|
-
screenshotDevice: z.enum(["desktop", "mobile"]).default("desktop").describe("Viewport for screenshot. desktop = 1440\xD7900. mobile = 390\xD7844. Default desktop."),
|
|
42
|
-
extractBranding: z.boolean().default(false).describe("Extract brand colors, fonts, logo, and favicon using a rendered browser session. Returns colorScheme (light/dark), colors (primary/accent/background/text/heading as hex), fonts (heading/body family names), and assets (logo URL, favicon URL). Use when the user asks about brand colors, site theme, or brand assets."),
|
|
43
|
-
downloadMedia: z.boolean().default(false).describe("Extract and download all page media (images, video, audio) to ~/Downloads/mcp-scraper/media/. Ad networks, tracking pixels, and noise URLs are filtered automatically. Use when the user asks to download or harvest assets from a page."),
|
|
44
|
-
mediaTypes: z.array(z.enum(["image", "video", "audio"])).default(["image", "video", "audio"]).describe("Which media types to download. Default all three."),
|
|
45
|
-
allowLocal: z.boolean().default(false).describe("Allow localhost and private-network URLs. For local development only.")
|
|
46
|
-
};
|
|
47
|
-
var MapSiteUrlsInputSchema = {
|
|
48
|
-
url: z.string().url().describe("Public website URL or domain to crawl for internal URLs. Use before extract_site when the user asks to audit/map/crawl a site."),
|
|
49
|
-
maxUrls: z.number().int().min(1).max(500).optional().describe("Maximum URLs to discover. Use 100 for normal maps, higher when the user asks for a full inventory.")
|
|
50
|
-
};
|
|
51
|
-
var ExtractSiteInputSchema = {
|
|
52
|
-
url: z.string().url().describe("Public website URL or domain to extract across multiple pages. Use when the user asks for a site audit, website crawl, or full-site content/schema extraction."),
|
|
53
|
-
maxPages: z.number().int().min(1).max(50).optional().describe("Maximum pages to extract. Use 50 when the user asks for full results or a complete crawl within MCP limits.")
|
|
54
|
-
};
|
|
55
|
-
var YoutubeHarvestInputSchema = {
|
|
56
|
-
mode: z.enum(["search", "channel"]).describe("Use search for topic/keyword requests. Use channel when the user provides @handle, channel ID, or channel URL."),
|
|
57
|
-
query: z.string().optional().describe("Required when mode is search. The YouTube search topic in the user\u2019s words."),
|
|
58
|
-
channelHandle: z.string().optional().describe("YouTube channel handle, channel ID, or URL. Examples: @mkbhd, UC..., https://youtube.com/@mkbhd."),
|
|
59
|
-
maxVideos: z.number().int().min(1).max(500).default(50).describe("Number of videos to return. Default 50. Increase when user asks for full channel/history.")
|
|
60
|
-
};
|
|
61
|
-
var YoutubeTranscribeInputSchema = {
|
|
62
|
-
videoId: z.string().min(1).describe("YouTube video ID, e.g. dQw4w9WgXcQ")
|
|
63
|
-
};
|
|
64
|
-
var FacebookPageIntelInputSchema = {
|
|
65
|
-
pageId: z.string().optional(),
|
|
66
|
-
libraryId: z.string().optional(),
|
|
67
|
-
query: z.string().optional().describe("Advertiser or brand name when pageId/libraryId is not known. One of pageId, libraryId, or query is required."),
|
|
68
|
-
maxAds: z.number().int().min(1).max(200).default(50),
|
|
69
|
-
country: z.string().length(2).default("US")
|
|
70
|
-
};
|
|
71
|
-
var FacebookAdSearchInputSchema = {
|
|
72
|
-
query: z.string().min(1).describe("Advertiser, brand, competitor, niche, or keyword to search in Facebook Ad Library."),
|
|
73
|
-
country: z.string().length(2).default("US"),
|
|
74
|
-
maxResults: z.number().int().min(1).max(20).default(10)
|
|
75
|
-
};
|
|
76
|
-
var FacebookAdTranscribeInputSchema = {
|
|
77
|
-
videoUrl: z.string().url().describe("Facebook CDN video URL from a facebook_page_intel result")
|
|
78
|
-
};
|
|
79
|
-
var MapsPlaceIntelInputSchema = {
|
|
80
|
-
businessName: z.string().min(1).describe('Business name only. If user says "Elite Roofing Denver CO", use businessName="Elite Roofing" and location="Denver, CO".'),
|
|
81
|
-
location: z.string().min(1).describe('City/region/country where the business should be searched, e.g. "Denver, CO". Infer from the user request when possible.'),
|
|
82
|
-
gl: z.string().length(2).default("us").describe("Google country code inferred from location."),
|
|
83
|
-
hl: z.string().length(2).default("en").describe("Language inferred from user request."),
|
|
84
|
-
includeReviews: z.boolean().default(false).describe("Whether to fetch individual review cards"),
|
|
85
|
-
maxReviews: z.number().int().min(1).max(500).default(50).describe("Max review cards to return (requires includeReviews: true)")
|
|
86
|
-
};
|
|
87
|
-
var MapsSearchInputSchema = {
|
|
88
|
-
query: z.string().min(1).describe('Business category, niche, keyword, or search term. If the user says "roofers in Denver CO", use query="roofers" and location="Denver, CO". Do not put the location here when it can be separated.'),
|
|
89
|
-
location: z.string().optional().describe('City, region, country, or service area for the Maps search, e.g. "Denver, CO". Infer from the user request when present.'),
|
|
90
|
-
gl: z.string().length(2).default("us").describe("Google country code inferred from location."),
|
|
91
|
-
hl: z.string().length(2).default("en").describe("Language inferred from user request."),
|
|
92
|
-
maxResults: z.number().int().min(1).max(50).default(10).describe("Number of Google Maps business/profile candidates to return. Default 10. Maximum 50. Use 10 unless the user asks for more.")
|
|
93
|
-
};
|
|
94
|
-
var NullableString = z.string().nullable();
|
|
95
|
-
var MapsSearchOutputSchema = {
|
|
96
|
-
query: z.string(),
|
|
97
|
-
location: z.string().nullable(),
|
|
98
|
-
searchQuery: z.string(),
|
|
99
|
-
searchUrl: z.string().url(),
|
|
100
|
-
extractedAt: z.string(),
|
|
101
|
-
requestedMaxResults: z.number().int().min(1).max(50),
|
|
102
|
-
resultCount: z.number().int().min(0).max(50),
|
|
103
|
-
results: z.array(z.object({
|
|
104
|
-
position: z.number().int().min(1),
|
|
105
|
-
name: z.string(),
|
|
106
|
-
placeUrl: z.string().url(),
|
|
107
|
-
cid: NullableString,
|
|
108
|
-
cidDecimal: NullableString,
|
|
109
|
-
rating: NullableString,
|
|
110
|
-
reviewCount: NullableString,
|
|
111
|
-
category: NullableString,
|
|
112
|
-
address: NullableString,
|
|
113
|
-
websiteUrl: NullableString,
|
|
114
|
-
directionsUrl: NullableString,
|
|
115
|
-
metadata: z.array(z.string())
|
|
116
|
-
})),
|
|
117
|
-
durationMs: z.number().int().min(0)
|
|
118
|
-
};
|
|
119
|
-
var MapSiteUrlsOutputSchema = {
|
|
120
|
-
startUrl: z.string(),
|
|
121
|
-
totalFound: z.number().int().min(0),
|
|
122
|
-
truncated: z.boolean(),
|
|
123
|
-
okCount: z.number().int().min(0),
|
|
124
|
-
redirectCount: z.number().int().min(0),
|
|
125
|
-
brokenCount: z.number().int().min(0),
|
|
126
|
-
urls: z.array(z.object({
|
|
127
|
-
url: z.string(),
|
|
128
|
-
status: z.number().int().nullable()
|
|
129
|
-
})),
|
|
130
|
-
durationMs: z.number().min(0)
|
|
131
|
-
};
|
|
132
|
-
var YoutubeHarvestOutputSchema = {
|
|
133
|
-
mode: z.string(),
|
|
134
|
-
videoCount: z.number().int().min(0),
|
|
135
|
-
channel: z.object({
|
|
136
|
-
title: NullableString,
|
|
137
|
-
subscriberCount: NullableString
|
|
138
|
-
}).nullable(),
|
|
139
|
-
videos: z.array(z.object({
|
|
140
|
-
videoId: z.string(),
|
|
141
|
-
title: z.string(),
|
|
142
|
-
channelName: NullableString,
|
|
143
|
-
views: NullableString,
|
|
144
|
-
duration: NullableString,
|
|
145
|
-
url: NullableString
|
|
146
|
-
}))
|
|
147
|
-
};
|
|
148
|
-
var FacebookAdSearchOutputSchema = {
|
|
149
|
-
query: z.string(),
|
|
150
|
-
advertiserCount: z.number().int().min(0),
|
|
151
|
-
advertisers: z.array(z.object({
|
|
152
|
-
name: NullableString,
|
|
153
|
-
adCount: z.number().int().nullable(),
|
|
154
|
-
libraryId: NullableString
|
|
155
|
-
}))
|
|
156
|
-
};
|
|
157
|
-
var FacebookPageIntelOutputSchema = {
|
|
158
|
-
advertiserName: NullableString,
|
|
159
|
-
totalAds: z.number().int().min(0),
|
|
160
|
-
activeCount: z.number().int().min(0),
|
|
161
|
-
videoCount: z.number().int().min(0),
|
|
162
|
-
imageCount: z.number().int().min(0),
|
|
163
|
-
ads: z.array(z.object({
|
|
164
|
-
libraryId: NullableString,
|
|
165
|
-
status: NullableString,
|
|
166
|
-
creativeType: NullableString,
|
|
167
|
-
headline: NullableString,
|
|
168
|
-
cta: NullableString,
|
|
169
|
-
startDate: NullableString,
|
|
170
|
-
videoUrl: NullableString,
|
|
171
|
-
variations: z.number().int().nullable()
|
|
172
|
-
}))
|
|
173
|
-
};
|
|
174
|
-
var CreditsInfoInputSchema = {
|
|
175
|
-
item: z.string().optional().describe('Optional tool, action, or feature to look up, e.g. "maps reviews", "extract_url", or "YouTube transcription"'),
|
|
176
|
-
includeLedger: z.boolean().default(false).describe("Whether to include recent credit ledger entries")
|
|
177
|
-
};
|
|
178
|
-
var SearchSerpInputSchema = {
|
|
179
|
-
query: z.string().min(1).describe('Core search topic only. Separate location when possible. If user says "best dentist in Brooklyn NY serp", use query="best dentist" and location="Brooklyn, NY".'),
|
|
180
|
-
location: z.string().optional().describe("City, region, or country for geo-targeted results, inferred from user request when present."),
|
|
181
|
-
gl: z.string().length(2).default("us").describe("Google country code inferred from location or user language."),
|
|
182
|
-
hl: z.string().default("en").describe("Google interface/content language inferred from user request."),
|
|
183
|
-
device: z.enum(["desktop", "mobile"]).default("desktop").describe("SERP device context. Use desktop by default; use mobile only when the user asks for mobile rankings."),
|
|
184
|
-
proxyMode: z.enum(["location", "configured", "none"]).default("location").describe("Proxy targeting mode. Use location by default so city/state searches create or reuse a matching residential proxy. Use configured for the static configured proxy. Use none only for direct-network debugging."),
|
|
185
|
-
proxyZip: z.string().regex(/^\d{5}$/).optional().describe("Optional US ZIP override for residential location proxy targeting. Use only when the user gives a specific ZIP or city-center proxy targeting needs to be forced."),
|
|
186
|
-
debug: z.boolean().default(false).describe("Include sanitized browser/session/location diagnostics in the response. Use true when debugging localization, CAPTCHA, or proxy behavior."),
|
|
187
|
-
pages: z.number().int().min(1).max(2).default(1).describe("Number of result pages to fetch (1\u20132)")
|
|
188
|
-
};
|
|
189
|
-
var CaptureSerpSnapshotInputSchema = {
|
|
190
|
-
query: z.string().min(1).describe("Core search query to capture as a structured SERP Intelligence snapshot. Separate the place into location when the user gives a city, region, country, or ZIP."),
|
|
191
|
-
location: z.string().optional().describe("City, region, country, or service area used for localized Google results. MCP Scraper records location evidence; UULE alone is not proof of localization."),
|
|
192
|
-
gl: z.string().length(2).default("us").describe("Google country code inferred from the requested market, e.g. us, gb, ca, au."),
|
|
193
|
-
hl: z.string().default("en").describe("Google interface/content language inferred from the user request."),
|
|
194
|
-
device: z.enum(["desktop", "mobile"]).default("desktop").describe("SERP device context. Use mobile only when the user asks for mobile rankings or mobile SERP evidence."),
|
|
195
|
-
proxyMode: z.enum(["location", "configured", "none"]).default("location").describe("Proxy behavior for capture. Use location for localized residential proxy targeting, configured for the static residential proxy, and none only for direct-network debugging."),
|
|
196
|
-
proxyZip: z.string().regex(/^\d{5}$/).optional().describe("Optional US ZIP override for residential location proxy targeting when a precise city-center or ZIP proxy is needed."),
|
|
197
|
-
pages: z.number().int().min(1).max(2).default(1).describe("Number of Google result pages to capture. Use 1 normally and 2 only when the user needs deeper ranking evidence."),
|
|
198
|
-
debug: z.boolean().default(false).describe("Include sanitized browser, proxy, and location diagnostics. Use true when debugging localization, CAPTCHA, proxy selection, or capture reliability."),
|
|
199
|
-
includePageSnapshots: z.boolean().default(false).describe("Also capture ranking-page snapshots for selected SERP URLs through the same product capture path."),
|
|
200
|
-
pageSnapshotLimit: z.number().int().min(0).max(10).default(0).describe("Maximum ranking-page snapshots to capture when includePageSnapshots is true. Use 0 when only SERP evidence is needed.")
|
|
201
|
-
};
|
|
202
|
-
var ScreenshotInputSchema = {
|
|
203
|
-
url: z.string().url().describe("URL to capture as a full-page screenshot. Use http or https. Pass allowLocal: true to capture localhost or private-network URLs during development."),
|
|
204
|
-
device: z.enum(["desktop", "mobile"]).default("desktop").describe("Viewport profile. desktop = 1440\xD7900. mobile = 390\xD7844. Use desktop by default; use mobile when the user asks for a mobile view."),
|
|
205
|
-
allowLocal: z.boolean().default(false).describe("Allow localhost and private-network URLs (127.x, 192.168.x, 10.x, etc.). For local development only \u2014 not for production use.")
|
|
206
|
-
};
|
|
207
|
-
var CaptureSerpPageSnapshotsInputSchema = {
|
|
208
|
-
urls: z.array(z.string().url()).min(1).max(25).describe("Public HTTP/HTTPS URLs to capture as SERP Intelligence page snapshots. Do not pass localhost, private IPs, file URLs, or internal admin URLs."),
|
|
209
|
-
targets: z.array(z.object({
|
|
210
|
-
url: z.string().url().describe("Public HTTP/HTTPS URL to capture."),
|
|
211
|
-
sourceKind: z.enum(["organic", "ai_citation", "local_pack_website", "configured_target", "site_subject"]).default("configured_target").describe("Why this page is being captured for SERP Intelligence evidence."),
|
|
212
|
-
sourcePosition: z.number().int().min(1).optional().describe("Ranking or citation position when the page came from SERP evidence.")
|
|
213
|
-
}).strict()).min(1).max(25).optional().describe("Structured page snapshot targets. Use this instead of urls when source kind or position should be preserved."),
|
|
214
|
-
maxConcurrency: z.number().int().min(1).max(5).default(2).describe("Parallel page captures. Use 2 normally; higher values can increase proxy/browser pressure."),
|
|
215
|
-
timeoutMs: z.number().int().min(1e3).max(6e4).default(15e3).describe("Per-page capture timeout in milliseconds. Increase for slow pages; timeout artifacts are returned as structured capture failures."),
|
|
216
|
-
debug: z.boolean().default(false).describe("Include sanitized browser/proxy diagnostics for page snapshot debugging. Use true for capture, network, or proxy troubleshooting.")
|
|
217
|
-
};
|
|
25
|
+
var PACKAGE_VERSION = "0.1.9";
|
|
218
26
|
|
|
219
27
|
// src/mcp/mcp-response-formatter.ts
|
|
220
28
|
import { mkdirSync, writeFileSync } from "fs";
|
|
@@ -322,7 +130,7 @@ function debugSection(debug) {
|
|
|
322
130
|
if (!debug || typeof debug !== "object") return "";
|
|
323
131
|
const request = debug.request ?? {};
|
|
324
132
|
const browser = debug.browser ?? {};
|
|
325
|
-
const kernel = browser.kernel ?? {};
|
|
133
|
+
const kernel = browser.browserRuntime ?? browser.kernel ?? {};
|
|
326
134
|
const network = browser.networkLocation ?? {};
|
|
327
135
|
const nav = browser.serpNavigation ?? {};
|
|
328
136
|
const proxyResolution = kernel.proxyResolution ?? {};
|
|
@@ -348,12 +156,14 @@ function errorAttemptsSection(body) {
|
|
|
348
156
|
const lines = attempts.slice(0, 5).map((attempt) => {
|
|
349
157
|
const debug = attempt.debug ?? {};
|
|
350
158
|
const browser = debug.browser ?? {};
|
|
351
|
-
const kernel = browser.kernel ?? {};
|
|
159
|
+
const kernel = browser.browserRuntime ?? browser.kernel ?? {};
|
|
352
160
|
const proxyResolution = kernel.proxyResolution ?? {};
|
|
353
161
|
const network = browser.networkLocation ?? {};
|
|
354
162
|
const nav = browser.serpNavigation ?? {};
|
|
355
163
|
const geo = [network.ip, network.city, network.region].filter(Boolean).join(" / ") || "geo unknown";
|
|
356
|
-
|
|
164
|
+
const sessionId = attempt.browser_session_id ?? attempt.kernel_session_id ?? kernel.sessionId ?? "unknown";
|
|
165
|
+
const cleanupSucceeded = attempt.session_cleanup_succeeded ?? attempt.kernel_delete_succeeded;
|
|
166
|
+
return `- Attempt ${attempt.attempt_number ?? "?"}: ${attempt.outcome ?? attempt.status ?? "unknown"} \xB7 session ${sessionId} \xB7 proxy ${debug.request?.proxyMode ?? kernel.proxyMode ?? "unknown"}${proxyResolution.source ? `/${proxyResolution.source}` : ""} \xB7 ${geo} \xB7 CAPTCHA ${nav.captchaDetected === true ? "yes" : nav.captchaDetected === false ? "no" : "unknown"} \xB7 cleanup ${cleanupSucceeded === true ? "yes" : cleanupSucceeded === false ? "no" : "unknown"}`;
|
|
357
167
|
});
|
|
358
168
|
return `
|
|
359
169
|
|
|
@@ -400,7 +210,31 @@ ${serpRows}` : "";
|
|
|
400
210
|
const full = `# PAA Report: "${input.query}"${input.location ? ` \xB7 ${input.location}` : ""}
|
|
401
211
|
|
|
402
212
|
${paaTable}${serpTable}${entityIdsSection(entityIds)}${aiSection}${statsLine}${debugSection(diagnostics?.debug)}${tips}`;
|
|
403
|
-
return
|
|
213
|
+
return {
|
|
214
|
+
...oneBlock(full),
|
|
215
|
+
structuredContent: {
|
|
216
|
+
query: input.query,
|
|
217
|
+
location: input.location ?? null,
|
|
218
|
+
questionCount: flat.length,
|
|
219
|
+
completionStatus: diagnostics?.completionStatus ?? null,
|
|
220
|
+
questions: flat.map((r) => ({
|
|
221
|
+
question: String(r.question ?? ""),
|
|
222
|
+
answer: r.answer ?? null,
|
|
223
|
+
sourceTitle: r.source_title ?? null,
|
|
224
|
+
sourceSite: r.source_site ?? null
|
|
225
|
+
})),
|
|
226
|
+
organicResults: organic.map((r) => ({
|
|
227
|
+
position: Number(r.position) || 0,
|
|
228
|
+
title: String(r.title ?? ""),
|
|
229
|
+
url: String(r.url ?? ""),
|
|
230
|
+
domain: String(r.domain ?? ""),
|
|
231
|
+
snippet: r.snippet ?? null
|
|
232
|
+
})),
|
|
233
|
+
aiOverview: aiOvw ? { detected: aiOvw.detected === true, text: aiOvw.text ?? null } : null,
|
|
234
|
+
entityIds: entityIds ? { kgIds: entityIds.kgIds ?? [], cids: entityIds.cids ?? [], gcids: entityIds.gcids ?? [] } : null,
|
|
235
|
+
durationMs: durationMs ?? null
|
|
236
|
+
}
|
|
237
|
+
};
|
|
404
238
|
}
|
|
405
239
|
function formatSearchSerp(raw, input) {
|
|
406
240
|
const parsed = parseData(raw);
|
|
@@ -438,7 +272,29 @@ ${localRows}` : "";
|
|
|
438
272
|
const full = `# SERP Report: "${input.query}"${input.location ? ` \xB7 ${input.location}` : ""}
|
|
439
273
|
|
|
440
274
|
${serpTable}${localSection}${entityIdsSection(entityIds)}${aiSection}${debugSection(diagnostics?.debug)}${tips}`;
|
|
441
|
-
return
|
|
275
|
+
return {
|
|
276
|
+
...oneBlock(full),
|
|
277
|
+
structuredContent: {
|
|
278
|
+
query: input.query,
|
|
279
|
+
location: input.location ?? null,
|
|
280
|
+
organicResults: organic.map((r) => ({
|
|
281
|
+
position: Number(r.position) || 0,
|
|
282
|
+
title: String(r.title ?? ""),
|
|
283
|
+
url: String(r.url ?? ""),
|
|
284
|
+
domain: String(r.domain ?? ""),
|
|
285
|
+
snippet: r.snippet ?? null
|
|
286
|
+
})),
|
|
287
|
+
localPack: localPack.map((b) => ({
|
|
288
|
+
position: Number(b.position) || 0,
|
|
289
|
+
name: String(b.name ?? ""),
|
|
290
|
+
rating: b.rating ?? null,
|
|
291
|
+
reviewCount: b.reviewCount ?? null,
|
|
292
|
+
websiteUrl: b.websiteUrl ?? null
|
|
293
|
+
})),
|
|
294
|
+
aiOverview: aiOvw ? { detected: aiOvw.detected === true, text: aiOvw.text ?? null } : null,
|
|
295
|
+
entityIds: entityIds ? { kgIds: entityIds.kgIds ?? [], cids: entityIds.cids ?? [], gcids: entityIds.gcids ?? [] } : null
|
|
296
|
+
}
|
|
297
|
+
};
|
|
442
298
|
}
|
|
443
299
|
function formatExtractUrl(raw, input) {
|
|
444
300
|
const parsed = parseData(raw);
|
|
@@ -507,15 +363,27 @@ ${bodyMd.slice(0, 3e3)}${bodyMd.length > 3e3 ? "\n\n*(truncated)*" : ""}` : "";
|
|
|
507
363
|
**${title}**
|
|
508
364
|
${headingSection}${kpoSection}${brandingSection}${bodySection}${screenshotSection}${mediaSection}${tips}`;
|
|
509
365
|
const textResult = oneBlock(full);
|
|
366
|
+
const structuredContent = {
|
|
367
|
+
url,
|
|
368
|
+
title: d.title ?? null,
|
|
369
|
+
headings: headings.map((h) => ({ level: Number(h.level) || 0, text: String(h.text ?? "") })),
|
|
370
|
+
schemaBlockCount: schemaCount,
|
|
371
|
+
entityName: kpo?.entityName ?? null,
|
|
372
|
+
entityTypes: kpo?.type ?? [],
|
|
373
|
+
napScore: kpo?.napScore ?? null,
|
|
374
|
+
missingSchemaFields: kpo?.missingFields ?? [],
|
|
375
|
+
screenshotSaved: screenshotPath ?? null
|
|
376
|
+
};
|
|
510
377
|
if (screenshotMeta?.base64) {
|
|
511
378
|
return {
|
|
512
379
|
content: [
|
|
513
380
|
...textResult.content,
|
|
514
381
|
{ type: "image", data: screenshotMeta.base64, mimeType: "image/png" }
|
|
515
|
-
]
|
|
382
|
+
],
|
|
383
|
+
structuredContent
|
|
516
384
|
};
|
|
517
385
|
}
|
|
518
|
-
return textResult;
|
|
386
|
+
return { ...textResult, structuredContent };
|
|
519
387
|
}
|
|
520
388
|
function formatMapSiteUrls(raw, input) {
|
|
521
389
|
const parsed = parseData(raw);
|
|
@@ -585,7 +453,19 @@ ${pageRows}`,
|
|
|
585
453
|
- Map URLs first: use \`map_site_urls\`
|
|
586
454
|
- Inspect a single page: use \`extract_url\``
|
|
587
455
|
].join("\n");
|
|
588
|
-
return
|
|
456
|
+
return {
|
|
457
|
+
...oneBlock(full),
|
|
458
|
+
structuredContent: {
|
|
459
|
+
url: input.url,
|
|
460
|
+
pageCount: pages.length,
|
|
461
|
+
pages: pages.map((p) => ({
|
|
462
|
+
url: String(p.url ?? ""),
|
|
463
|
+
title: p.title ?? null,
|
|
464
|
+
schemaTypes: p.kpo?.type ?? []
|
|
465
|
+
})),
|
|
466
|
+
durationMs: d.durationMs ?? 0
|
|
467
|
+
}
|
|
468
|
+
};
|
|
589
469
|
}
|
|
590
470
|
function formatYoutubeHarvest(raw, input) {
|
|
591
471
|
const parsed = parseData(raw);
|
|
@@ -782,7 +662,26 @@ ${costRows}` : "",
|
|
|
782
662
|
|------|-----------|---------|-------------|
|
|
783
663
|
${ledgerRows}` : ""
|
|
784
664
|
].filter(Boolean).join("\n");
|
|
785
|
-
return
|
|
665
|
+
return {
|
|
666
|
+
...oneBlock(full),
|
|
667
|
+
structuredContent: {
|
|
668
|
+
balanceCredits: typeof balance === "number" ? balance : null,
|
|
669
|
+
matchedCost: matched ? { label: matched.label, credits: matched.credits, unit: matched.unit, notes: matched.notes ?? null } : null,
|
|
670
|
+
costs: costs.map((c) => ({
|
|
671
|
+
key: c.key,
|
|
672
|
+
label: c.label,
|
|
673
|
+
credits: c.credits,
|
|
674
|
+
unit: c.unit,
|
|
675
|
+
notes: c.notes ?? null
|
|
676
|
+
})),
|
|
677
|
+
ledger: ledger.map((row) => ({
|
|
678
|
+
createdAt: String(row.created_at ?? ""),
|
|
679
|
+
operation: String(row.operation ?? ""),
|
|
680
|
+
credits: row.amount_mc / 1e3,
|
|
681
|
+
description: row.description ?? null
|
|
682
|
+
}))
|
|
683
|
+
}
|
|
684
|
+
};
|
|
786
685
|
}
|
|
787
686
|
function formatMapsSearch(raw, input) {
|
|
788
687
|
const parsed = parseData(raw);
|
|
@@ -931,7 +830,28 @@ ${entitySection}` : null,
|
|
|
931
830
|
---
|
|
932
831
|
*Extracted in ${(durationMs / 1e3).toFixed(1)}s*` : null
|
|
933
832
|
].filter(Boolean).join("\n");
|
|
934
|
-
return
|
|
833
|
+
return {
|
|
834
|
+
...oneBlock(full),
|
|
835
|
+
structuredContent: {
|
|
836
|
+
name,
|
|
837
|
+
rating: rating ?? null,
|
|
838
|
+
reviewCount: reviewCount ?? null,
|
|
839
|
+
category: category ?? null,
|
|
840
|
+
address: address ?? null,
|
|
841
|
+
phone: phone ?? null,
|
|
842
|
+
website: website ?? null,
|
|
843
|
+
hoursSummary: hoursSummary ?? null,
|
|
844
|
+
bookingUrl: bookingUrl ?? null,
|
|
845
|
+
kgmid: kgmid ?? null,
|
|
846
|
+
cidDecimal: cidDecimal ?? null,
|
|
847
|
+
cidUrl: cidUrl ?? null,
|
|
848
|
+
lat: lat ?? null,
|
|
849
|
+
lng: lng ?? null,
|
|
850
|
+
reviewsStatus,
|
|
851
|
+
reviewsCollected: reviews.length,
|
|
852
|
+
reviewTopics: topics.map((t) => ({ label: String(t.label ?? ""), count: String(t.count ?? "") }))
|
|
853
|
+
}
|
|
854
|
+
};
|
|
935
855
|
}
|
|
936
856
|
function formatFacebookAdTranscribe(raw, input) {
|
|
937
857
|
const parsed = parseData(raw);
|
|
@@ -964,6 +884,314 @@ ${chunkRows}` : "",
|
|
|
964
884
|
return oneBlock(full);
|
|
965
885
|
}
|
|
966
886
|
|
|
887
|
+
// src/mcp/mcp-tool-schemas.ts
|
|
888
|
+
import { z } from "zod";
|
|
889
|
+
var HarvestPaaInputSchema = {
|
|
890
|
+
query: z.string().min(1).describe('Core search topic only. If the user says "best hvac company in Denver CO", use query="best hvac company" and location="Denver, CO". Do not include the location in query when it can be separated.'),
|
|
891
|
+
location: z.string().optional().describe('City, region, or country for geo-targeted results, inferred from the user request when present, e.g. "Denver, CO", "Tokyo, Japan", "London, UK".'),
|
|
892
|
+
maxQuestions: z.number().int().min(1).max(200).default(30).describe("Number of PAA questions to extract. Default 30. Maximum 200. Use 10 for quick probes, 30 for normal research, 100-200 when the user asks for everything/full/deep research. Larger harvests get a longer server time budget (151-200 questions \u2192 up to 280s). Credits are charged by extracted question; unused request hold is refunded."),
|
|
893
|
+
gl: z.string().length(2).default("us").describe("Google country code inferred from location or user language. Examples: United States us, United Kingdom gb, Japan jp, Canada ca, Australia au."),
|
|
894
|
+
hl: z.string().default("en").describe("Google interface/content language inferred from the user request. Use en unless the user asks for another language or locale."),
|
|
895
|
+
device: z.enum(["desktop", "mobile"]).default("desktop").describe("SERP device context. Use desktop by default; use mobile only when the user asks for mobile rankings."),
|
|
896
|
+
proxyMode: z.enum(["location", "configured", "none"]).default("location").describe("Proxy targeting mode. Use location by default so city/state searches create or reuse a matching residential proxy. Use configured for the static configured proxy. Use none only for direct-network debugging."),
|
|
897
|
+
proxyZip: z.string().regex(/^\d{5}$/).optional().describe("Optional US ZIP override for residential location proxy targeting. Use only when the user gives a specific ZIP or city-center proxy targeting needs to be forced."),
|
|
898
|
+
debug: z.boolean().default(false).describe("Include sanitized browser/session/location diagnostics in the response. Use true when debugging localization, CAPTCHA, or proxy behavior.")
|
|
899
|
+
};
|
|
900
|
+
var ExtractUrlInputSchema = {
|
|
901
|
+
url: z.string().url().describe("Public http/https URL to extract. Use this when the user provides one specific page URL."),
|
|
902
|
+
screenshot: z.boolean().default(false).describe("Also capture a full-page screenshot of the URL. Saved to ~/Downloads/mcp-scraper/screenshots/ and returned inline. Use when the user asks to see or capture the page visually."),
|
|
903
|
+
screenshotDevice: z.enum(["desktop", "mobile"]).default("desktop").describe("Viewport for screenshot. desktop = 1440\xD7900. mobile = 390\xD7844. Default desktop."),
|
|
904
|
+
extractBranding: z.boolean().default(false).describe("Extract brand colors, fonts, logo, and favicon using a rendered browser session. Returns colorScheme (light/dark), colors (primary/accent/background/text/heading as hex), fonts (heading/body family names), and assets (logo URL, favicon URL). Use when the user asks about brand colors, site theme, or brand assets."),
|
|
905
|
+
downloadMedia: z.boolean().default(false).describe("Extract and download all page media (images, video, audio) to ~/Downloads/mcp-scraper/media/. Ad networks, tracking pixels, and noise URLs are filtered automatically. Use when the user asks to download or harvest assets from a page."),
|
|
906
|
+
mediaTypes: z.array(z.enum(["image", "video", "audio"])).default(["image", "video", "audio"]).describe("Which media types to download. Default all three."),
|
|
907
|
+
allowLocal: z.boolean().default(false).describe("Allow localhost and private-network URLs. For local development only.")
|
|
908
|
+
};
|
|
909
|
+
var MapSiteUrlsInputSchema = {
|
|
910
|
+
url: z.string().url().describe("Public website URL or domain to crawl for internal URLs. Use before extract_site when the user asks to audit/map/crawl a site."),
|
|
911
|
+
maxUrls: z.number().int().min(1).max(500).optional().describe("Maximum URLs to discover. Use 100 for normal maps, higher when the user asks for a full inventory.")
|
|
912
|
+
};
|
|
913
|
+
var ExtractSiteInputSchema = {
|
|
914
|
+
url: z.string().url().describe("Public website URL or domain to extract across multiple pages. Use when the user asks for a site audit, website crawl, or full-site content/schema extraction."),
|
|
915
|
+
maxPages: z.number().int().min(1).max(50).optional().describe("Maximum pages to extract. Use 50 when the user asks for full results or a complete crawl within MCP limits.")
|
|
916
|
+
};
|
|
917
|
+
var YoutubeHarvestInputSchema = {
|
|
918
|
+
mode: z.enum(["search", "channel"]).describe("Use search for topic/keyword requests. Use channel when the user provides @handle, channel ID, or channel URL."),
|
|
919
|
+
query: z.string().optional().describe("Required when mode is search. The YouTube search topic in the user\u2019s words."),
|
|
920
|
+
channelHandle: z.string().optional().describe("YouTube channel handle, channel ID, or URL. Examples: @mkbhd, UC..., https://youtube.com/@mkbhd."),
|
|
921
|
+
maxVideos: z.number().int().min(1).max(500).default(50).describe("Number of videos to return. Default 50. Increase when user asks for full channel/history.")
|
|
922
|
+
};
|
|
923
|
+
var YoutubeTranscribeInputSchema = {
|
|
924
|
+
videoId: z.string().min(1).describe("YouTube video ID, e.g. dQw4w9WgXcQ")
|
|
925
|
+
};
|
|
926
|
+
var FacebookPageIntelInputSchema = {
|
|
927
|
+
pageId: z.string().optional(),
|
|
928
|
+
libraryId: z.string().optional(),
|
|
929
|
+
query: z.string().optional().describe("Advertiser or brand name when pageId/libraryId is not known. One of pageId, libraryId, or query is required."),
|
|
930
|
+
maxAds: z.number().int().min(1).max(200).default(50),
|
|
931
|
+
country: z.string().length(2).default("US")
|
|
932
|
+
};
|
|
933
|
+
var FacebookAdSearchInputSchema = {
|
|
934
|
+
query: z.string().min(1).describe("Advertiser, brand, competitor, niche, or keyword to search in Facebook Ad Library."),
|
|
935
|
+
country: z.string().length(2).default("US"),
|
|
936
|
+
maxResults: z.number().int().min(1).max(20).default(10)
|
|
937
|
+
};
|
|
938
|
+
var FacebookAdTranscribeInputSchema = {
|
|
939
|
+
videoUrl: z.string().url().describe("Facebook CDN video URL from a facebook_page_intel result")
|
|
940
|
+
};
|
|
941
|
+
var MapsPlaceIntelInputSchema = {
|
|
942
|
+
businessName: z.string().min(1).describe('Business name only. If user says "Elite Roofing Denver CO", use businessName="Elite Roofing" and location="Denver, CO".'),
|
|
943
|
+
location: z.string().min(1).describe('City/region/country where the business should be searched, e.g. "Denver, CO". Infer from the user request when possible.'),
|
|
944
|
+
gl: z.string().length(2).default("us").describe("Google country code inferred from location."),
|
|
945
|
+
hl: z.string().length(2).default("en").describe("Language inferred from user request."),
|
|
946
|
+
includeReviews: z.boolean().default(false).describe("Whether to fetch individual review cards"),
|
|
947
|
+
maxReviews: z.number().int().min(1).max(500).default(50).describe("Max review cards to return (requires includeReviews: true)")
|
|
948
|
+
};
|
|
949
|
+
var MapsSearchInputSchema = {
|
|
950
|
+
query: z.string().min(1).describe('Business category, niche, keyword, or search term. If the user says "roofers in Denver CO", use query="roofers" and location="Denver, CO". Do not put the location here when it can be separated.'),
|
|
951
|
+
location: z.string().optional().describe('City, region, country, or service area for the Maps search, e.g. "Denver, CO". Infer from the user request when present.'),
|
|
952
|
+
gl: z.string().length(2).default("us").describe("Google country code inferred from location."),
|
|
953
|
+
hl: z.string().length(2).default("en").describe("Language inferred from user request."),
|
|
954
|
+
maxResults: z.number().int().min(1).max(50).default(10).describe("Number of Google Maps business/profile candidates to return. Default 10. Maximum 50. Use 10 unless the user asks for more.")
|
|
955
|
+
};
|
|
956
|
+
var NullableString = z.string().nullable();
|
|
957
|
+
var MapsSearchOutputSchema = {
|
|
958
|
+
query: z.string(),
|
|
959
|
+
location: z.string().nullable(),
|
|
960
|
+
searchQuery: z.string(),
|
|
961
|
+
searchUrl: z.string().url(),
|
|
962
|
+
extractedAt: z.string(),
|
|
963
|
+
requestedMaxResults: z.number().int().min(1).max(50),
|
|
964
|
+
resultCount: z.number().int().min(0).max(50),
|
|
965
|
+
results: z.array(z.object({
|
|
966
|
+
position: z.number().int().min(1),
|
|
967
|
+
name: z.string(),
|
|
968
|
+
placeUrl: z.string().url(),
|
|
969
|
+
cid: NullableString,
|
|
970
|
+
cidDecimal: NullableString,
|
|
971
|
+
rating: NullableString,
|
|
972
|
+
reviewCount: NullableString,
|
|
973
|
+
category: NullableString,
|
|
974
|
+
address: NullableString,
|
|
975
|
+
websiteUrl: NullableString,
|
|
976
|
+
directionsUrl: NullableString,
|
|
977
|
+
metadata: z.array(z.string())
|
|
978
|
+
})),
|
|
979
|
+
durationMs: z.number().int().min(0)
|
|
980
|
+
};
|
|
981
|
+
var OrganicResultOutput = z.object({
|
|
982
|
+
position: z.number().int(),
|
|
983
|
+
title: z.string(),
|
|
984
|
+
url: z.string(),
|
|
985
|
+
domain: z.string(),
|
|
986
|
+
snippet: NullableString
|
|
987
|
+
});
|
|
988
|
+
var AiOverviewOutput = z.object({
|
|
989
|
+
detected: z.boolean(),
|
|
990
|
+
text: NullableString
|
|
991
|
+
}).nullable();
|
|
992
|
+
var EntityIdsOutput = z.object({
|
|
993
|
+
kgIds: z.array(z.string()),
|
|
994
|
+
cids: z.array(z.string()),
|
|
995
|
+
gcids: z.array(z.string())
|
|
996
|
+
}).nullable();
|
|
997
|
+
var HarvestPaaOutputSchema = {
|
|
998
|
+
query: z.string(),
|
|
999
|
+
location: NullableString,
|
|
1000
|
+
questionCount: z.number().int().min(0),
|
|
1001
|
+
completionStatus: NullableString,
|
|
1002
|
+
questions: z.array(z.object({
|
|
1003
|
+
question: z.string(),
|
|
1004
|
+
answer: NullableString,
|
|
1005
|
+
sourceTitle: NullableString,
|
|
1006
|
+
sourceSite: NullableString
|
|
1007
|
+
})),
|
|
1008
|
+
organicResults: z.array(OrganicResultOutput),
|
|
1009
|
+
aiOverview: AiOverviewOutput,
|
|
1010
|
+
entityIds: EntityIdsOutput,
|
|
1011
|
+
durationMs: z.number().min(0).nullable()
|
|
1012
|
+
};
|
|
1013
|
+
var SearchSerpOutputSchema = {
|
|
1014
|
+
query: z.string(),
|
|
1015
|
+
location: NullableString,
|
|
1016
|
+
organicResults: z.array(OrganicResultOutput),
|
|
1017
|
+
localPack: z.array(z.object({
|
|
1018
|
+
position: z.number().int(),
|
|
1019
|
+
name: z.string(),
|
|
1020
|
+
rating: NullableString,
|
|
1021
|
+
reviewCount: NullableString,
|
|
1022
|
+
websiteUrl: NullableString
|
|
1023
|
+
})),
|
|
1024
|
+
aiOverview: AiOverviewOutput,
|
|
1025
|
+
entityIds: EntityIdsOutput
|
|
1026
|
+
};
|
|
1027
|
+
var ExtractUrlOutputSchema = {
|
|
1028
|
+
url: z.string(),
|
|
1029
|
+
title: NullableString,
|
|
1030
|
+
headings: z.array(z.object({
|
|
1031
|
+
level: z.number().int(),
|
|
1032
|
+
text: z.string()
|
|
1033
|
+
})),
|
|
1034
|
+
schemaBlockCount: z.number().int().min(0),
|
|
1035
|
+
entityName: NullableString,
|
|
1036
|
+
entityTypes: z.array(z.string()),
|
|
1037
|
+
napScore: z.number().nullable(),
|
|
1038
|
+
missingSchemaFields: z.array(z.string()),
|
|
1039
|
+
screenshotSaved: NullableString
|
|
1040
|
+
};
|
|
1041
|
+
var ExtractSiteOutputSchema = {
|
|
1042
|
+
url: z.string(),
|
|
1043
|
+
pageCount: z.number().int().min(0),
|
|
1044
|
+
pages: z.array(z.object({
|
|
1045
|
+
url: z.string(),
|
|
1046
|
+
title: NullableString,
|
|
1047
|
+
schemaTypes: z.array(z.string())
|
|
1048
|
+
})),
|
|
1049
|
+
durationMs: z.number().min(0)
|
|
1050
|
+
};
|
|
1051
|
+
var MapsPlaceIntelOutputSchema = {
|
|
1052
|
+
name: z.string(),
|
|
1053
|
+
rating: NullableString,
|
|
1054
|
+
reviewCount: NullableString,
|
|
1055
|
+
category: NullableString,
|
|
1056
|
+
address: NullableString,
|
|
1057
|
+
phone: NullableString,
|
|
1058
|
+
website: NullableString,
|
|
1059
|
+
hoursSummary: NullableString,
|
|
1060
|
+
bookingUrl: NullableString,
|
|
1061
|
+
kgmid: NullableString,
|
|
1062
|
+
cidDecimal: NullableString,
|
|
1063
|
+
cidUrl: NullableString,
|
|
1064
|
+
lat: z.number().nullable(),
|
|
1065
|
+
lng: z.number().nullable(),
|
|
1066
|
+
reviewsStatus: z.string(),
|
|
1067
|
+
reviewsCollected: z.number().int().min(0),
|
|
1068
|
+
reviewTopics: z.array(z.object({
|
|
1069
|
+
label: z.string(),
|
|
1070
|
+
count: z.string()
|
|
1071
|
+
}))
|
|
1072
|
+
};
|
|
1073
|
+
var CreditsInfoOutputSchema = {
|
|
1074
|
+
balanceCredits: z.number().nullable(),
|
|
1075
|
+
matchedCost: z.object({
|
|
1076
|
+
label: z.string(),
|
|
1077
|
+
credits: z.number(),
|
|
1078
|
+
unit: z.string(),
|
|
1079
|
+
notes: NullableString
|
|
1080
|
+
}).nullable(),
|
|
1081
|
+
costs: z.array(z.object({
|
|
1082
|
+
key: z.string(),
|
|
1083
|
+
label: z.string(),
|
|
1084
|
+
credits: z.number(),
|
|
1085
|
+
unit: z.string(),
|
|
1086
|
+
notes: NullableString
|
|
1087
|
+
})),
|
|
1088
|
+
ledger: z.array(z.object({
|
|
1089
|
+
createdAt: z.string(),
|
|
1090
|
+
operation: z.string(),
|
|
1091
|
+
credits: z.number(),
|
|
1092
|
+
description: NullableString
|
|
1093
|
+
}))
|
|
1094
|
+
};
|
|
1095
|
+
var MapSiteUrlsOutputSchema = {
|
|
1096
|
+
startUrl: z.string(),
|
|
1097
|
+
totalFound: z.number().int().min(0),
|
|
1098
|
+
truncated: z.boolean(),
|
|
1099
|
+
okCount: z.number().int().min(0),
|
|
1100
|
+
redirectCount: z.number().int().min(0),
|
|
1101
|
+
brokenCount: z.number().int().min(0),
|
|
1102
|
+
urls: z.array(z.object({
|
|
1103
|
+
url: z.string(),
|
|
1104
|
+
status: z.number().int().nullable()
|
|
1105
|
+
})),
|
|
1106
|
+
durationMs: z.number().min(0)
|
|
1107
|
+
};
|
|
1108
|
+
var YoutubeHarvestOutputSchema = {
|
|
1109
|
+
mode: z.string(),
|
|
1110
|
+
videoCount: z.number().int().min(0),
|
|
1111
|
+
channel: z.object({
|
|
1112
|
+
title: NullableString,
|
|
1113
|
+
subscriberCount: NullableString
|
|
1114
|
+
}).nullable(),
|
|
1115
|
+
videos: z.array(z.object({
|
|
1116
|
+
videoId: z.string(),
|
|
1117
|
+
title: z.string(),
|
|
1118
|
+
channelName: NullableString,
|
|
1119
|
+
views: NullableString,
|
|
1120
|
+
duration: NullableString,
|
|
1121
|
+
url: NullableString
|
|
1122
|
+
}))
|
|
1123
|
+
};
|
|
1124
|
+
var FacebookAdSearchOutputSchema = {
|
|
1125
|
+
query: z.string(),
|
|
1126
|
+
advertiserCount: z.number().int().min(0),
|
|
1127
|
+
advertisers: z.array(z.object({
|
|
1128
|
+
name: NullableString,
|
|
1129
|
+
adCount: z.number().int().nullable(),
|
|
1130
|
+
libraryId: NullableString
|
|
1131
|
+
}))
|
|
1132
|
+
};
|
|
1133
|
+
var FacebookPageIntelOutputSchema = {
|
|
1134
|
+
advertiserName: NullableString,
|
|
1135
|
+
totalAds: z.number().int().min(0),
|
|
1136
|
+
activeCount: z.number().int().min(0),
|
|
1137
|
+
videoCount: z.number().int().min(0),
|
|
1138
|
+
imageCount: z.number().int().min(0),
|
|
1139
|
+
ads: z.array(z.object({
|
|
1140
|
+
libraryId: NullableString,
|
|
1141
|
+
status: NullableString,
|
|
1142
|
+
creativeType: NullableString,
|
|
1143
|
+
headline: NullableString,
|
|
1144
|
+
cta: NullableString,
|
|
1145
|
+
startDate: NullableString,
|
|
1146
|
+
videoUrl: NullableString,
|
|
1147
|
+
variations: z.number().int().nullable()
|
|
1148
|
+
}))
|
|
1149
|
+
};
|
|
1150
|
+
var CreditsInfoInputSchema = {
|
|
1151
|
+
item: z.string().optional().describe('Optional tool, action, or feature to look up, e.g. "maps reviews", "extract_url", or "YouTube transcription"'),
|
|
1152
|
+
includeLedger: z.boolean().default(false).describe("Whether to include recent credit ledger entries")
|
|
1153
|
+
};
|
|
1154
|
+
var SearchSerpInputSchema = {
|
|
1155
|
+
query: z.string().min(1).describe('Core search topic only. Separate location when possible. If user says "best dentist in Brooklyn NY serp", use query="best dentist" and location="Brooklyn, NY".'),
|
|
1156
|
+
location: z.string().optional().describe("City, region, or country for geo-targeted results, inferred from user request when present."),
|
|
1157
|
+
gl: z.string().length(2).default("us").describe("Google country code inferred from location or user language."),
|
|
1158
|
+
hl: z.string().default("en").describe("Google interface/content language inferred from user request."),
|
|
1159
|
+
device: z.enum(["desktop", "mobile"]).default("desktop").describe("SERP device context. Use desktop by default; use mobile only when the user asks for mobile rankings."),
|
|
1160
|
+
proxyMode: z.enum(["location", "configured", "none"]).default("location").describe("Proxy targeting mode. Use location by default so city/state searches create or reuse a matching residential proxy. Use configured for the static configured proxy. Use none only for direct-network debugging."),
|
|
1161
|
+
proxyZip: z.string().regex(/^\d{5}$/).optional().describe("Optional US ZIP override for residential location proxy targeting. Use only when the user gives a specific ZIP or city-center proxy targeting needs to be forced."),
|
|
1162
|
+
debug: z.boolean().default(false).describe("Include sanitized browser/session/location diagnostics in the response. Use true when debugging localization, CAPTCHA, or proxy behavior."),
|
|
1163
|
+
pages: z.number().int().min(1).max(2).default(1).describe("Number of result pages to fetch (1\u20132)")
|
|
1164
|
+
};
|
|
1165
|
+
var CaptureSerpSnapshotInputSchema = {
|
|
1166
|
+
query: z.string().min(1).describe("Core search query to capture as a structured SERP Intelligence snapshot. Separate the place into location when the user gives a city, region, country, or ZIP."),
|
|
1167
|
+
location: z.string().optional().describe("City, region, country, or service area used for localized Google results. MCP Scraper records location evidence; UULE alone is not proof of localization."),
|
|
1168
|
+
gl: z.string().length(2).default("us").describe("Google country code inferred from the requested market, e.g. us, gb, ca, au."),
|
|
1169
|
+
hl: z.string().default("en").describe("Google interface/content language inferred from the user request."),
|
|
1170
|
+
device: z.enum(["desktop", "mobile"]).default("desktop").describe("SERP device context. Use mobile only when the user asks for mobile rankings or mobile SERP evidence."),
|
|
1171
|
+
proxyMode: z.enum(["location", "configured", "none"]).default("location").describe("Proxy behavior for capture. Use location for localized residential proxy targeting, configured for the static residential proxy, and none only for direct-network debugging."),
|
|
1172
|
+
proxyZip: z.string().regex(/^\d{5}$/).optional().describe("Optional US ZIP override for residential location proxy targeting when a precise city-center or ZIP proxy is needed."),
|
|
1173
|
+
pages: z.number().int().min(1).max(2).default(1).describe("Number of Google result pages to capture. Use 1 normally and 2 only when the user needs deeper ranking evidence."),
|
|
1174
|
+
debug: z.boolean().default(false).describe("Include sanitized browser, proxy, and location diagnostics. Use true when debugging localization, CAPTCHA, proxy selection, or capture reliability."),
|
|
1175
|
+
includePageSnapshots: z.boolean().default(false).describe("Also capture ranking-page snapshots for selected SERP URLs through the same product capture path."),
|
|
1176
|
+
pageSnapshotLimit: z.number().int().min(0).max(10).default(0).describe("Maximum ranking-page snapshots to capture when includePageSnapshots is true. Use 0 when only SERP evidence is needed.")
|
|
1177
|
+
};
|
|
1178
|
+
var ScreenshotInputSchema = {
|
|
1179
|
+
url: z.string().url().describe("URL to capture as a full-page screenshot. Use http or https. Pass allowLocal: true to capture localhost or private-network URLs during development."),
|
|
1180
|
+
device: z.enum(["desktop", "mobile"]).default("desktop").describe("Viewport profile. desktop = 1440\xD7900. mobile = 390\xD7844. Use desktop by default; use mobile when the user asks for a mobile view."),
|
|
1181
|
+
allowLocal: z.boolean().default(false).describe("Allow localhost and private-network URLs (127.x, 192.168.x, 10.x, etc.). For local development only \u2014 not for production use.")
|
|
1182
|
+
};
|
|
1183
|
+
var CaptureSerpPageSnapshotsInputSchema = {
|
|
1184
|
+
urls: z.array(z.string().url()).min(1).max(25).describe("Public HTTP/HTTPS URLs to capture as SERP Intelligence page snapshots. Do not pass localhost, private IPs, file URLs, or internal admin URLs."),
|
|
1185
|
+
targets: z.array(z.object({
|
|
1186
|
+
url: z.string().url().describe("Public HTTP/HTTPS URL to capture."),
|
|
1187
|
+
sourceKind: z.enum(["organic", "ai_citation", "local_pack_website", "configured_target", "site_subject"]).default("configured_target").describe("Why this page is being captured for SERP Intelligence evidence."),
|
|
1188
|
+
sourcePosition: z.number().int().min(1).optional().describe("Ranking or citation position when the page came from SERP evidence.")
|
|
1189
|
+
}).strict()).min(1).max(25).optional().describe("Structured page snapshot targets. Use this instead of urls when source kind or position should be preserved."),
|
|
1190
|
+
maxConcurrency: z.number().int().min(1).max(5).default(2).describe("Parallel page captures. Use 2 normally; higher values can increase proxy/browser pressure."),
|
|
1191
|
+
timeoutMs: z.number().int().min(1e3).max(6e4).default(15e3).describe("Per-page capture timeout in milliseconds. Increase for slow pages; timeout artifacts are returned as structured capture failures."),
|
|
1192
|
+
debug: z.boolean().default(false).describe("Include sanitized browser/proxy diagnostics for page snapshot debugging. Use true for capture, network, or proxy troubleshooting.")
|
|
1193
|
+
};
|
|
1194
|
+
|
|
967
1195
|
// src/mcp/paa-mcp-server.ts
|
|
968
1196
|
function liveWebToolAnnotations(title) {
|
|
969
1197
|
return {
|
|
@@ -974,27 +1202,65 @@ function liveWebToolAnnotations(title) {
|
|
|
974
1202
|
openWorldHint: true
|
|
975
1203
|
};
|
|
976
1204
|
}
|
|
1205
|
+
function listSavedReports() {
|
|
1206
|
+
try {
|
|
1207
|
+
const dir = outputBaseDir();
|
|
1208
|
+
return readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => ({ filename: f, mtimeMs: statSync(join2(dir, f)).mtimeMs })).sort((a, b) => b.mtimeMs - a.mtimeMs).slice(0, 100);
|
|
1209
|
+
} catch {
|
|
1210
|
+
return [];
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
function registerSavedReportResources(server) {
|
|
1214
|
+
server.registerResource(
|
|
1215
|
+
"saved-report",
|
|
1216
|
+
new ResourceTemplate("report://{filename}", {
|
|
1217
|
+
list: () => ({
|
|
1218
|
+
resources: listSavedReports().map((r) => ({
|
|
1219
|
+
uri: `report://${encodeURIComponent(r.filename)}`,
|
|
1220
|
+
name: r.filename,
|
|
1221
|
+
mimeType: "text/markdown"
|
|
1222
|
+
}))
|
|
1223
|
+
})
|
|
1224
|
+
}),
|
|
1225
|
+
{
|
|
1226
|
+
title: "Saved MCP Scraper Reports",
|
|
1227
|
+
description: "Markdown research reports saved by previous MCP Scraper tool calls. Read a report to reuse prior research without re-scraping or spending credits.",
|
|
1228
|
+
mimeType: "text/markdown"
|
|
1229
|
+
},
|
|
1230
|
+
async (uri, variables) => {
|
|
1231
|
+
const requested = Array.isArray(variables.filename) ? variables.filename[0] : variables.filename;
|
|
1232
|
+
const filename = basename(decodeURIComponent(String(requested ?? "")));
|
|
1233
|
+
if (!filename.endsWith(".md")) throw new Error("Only saved .md reports can be read");
|
|
1234
|
+
const text = readFileSync(join2(outputBaseDir(), filename), "utf8");
|
|
1235
|
+
return { contents: [{ uri: uri.href, mimeType: "text/markdown", text }] };
|
|
1236
|
+
}
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
977
1239
|
function buildPaaExtractorMcpServer(executor, options = {}) {
|
|
978
1240
|
const savesReports = options.savesReportsLocally !== false;
|
|
979
1241
|
const reportNote = savesReports ? " Saves a full Markdown report locally." : " Reports are returned inline; no files are saved on this hosted endpoint.";
|
|
980
1242
|
const withReportNote = (description) => `${description}${reportNote}`;
|
|
981
1243
|
const server = new McpServer({ name: "mcp-scraper", version: PACKAGE_VERSION });
|
|
1244
|
+
if (savesReports) registerSavedReportResources(server);
|
|
982
1245
|
server.registerTool("harvest_paa", {
|
|
983
1246
|
title: "Google PAA + SERP Harvest",
|
|
984
|
-
description: withReportNote('Best default tool for Google search research. Extracts People Also Ask questions plus answers/source URLs, organic SERP, local pack when present, entity IDs (CID/GCID/KG MID), and AI Overview. Infer the user language: split topic from location (e.g. "best hvac company in Denver CO" => query "best hvac company", location "Denver, CO", gl "us", hl "en"). Use maxQuestions 30 normally, 100-
|
|
1247
|
+
description: withReportNote('Best default tool for Google search research. Extracts People Also Ask questions plus answers/source URLs, organic SERP, local pack when present, entity IDs (CID/GCID/KG MID), and AI Overview. Infer the user language: split topic from location (e.g. "best hvac company in Denver CO" => query "best hvac company", location "Denver, CO", gl "us", hl "en"). Use maxQuestions 30 normally, 100-200 for "full", "deep", "all", or comprehensive research. Deep harvests above 100 questions can run for several minutes with no interim progress \u2014 warn the user before starting one and keep maxQuestions at or below 100 unless they explicitly want a deep harvest. Credits are charged by extracted question; unused request hold is refunded.'),
|
|
985
1248
|
inputSchema: HarvestPaaInputSchema,
|
|
1249
|
+
outputSchema: HarvestPaaOutputSchema,
|
|
986
1250
|
annotations: liveWebToolAnnotations("Google PAA + SERP Harvest")
|
|
987
1251
|
}, async (input) => formatHarvestPaa(await executor.harvestPaa(input), input));
|
|
988
1252
|
server.registerTool("search_serp", {
|
|
989
1253
|
title: "Google SERP Lookup",
|
|
990
1254
|
description: withReportNote("Fast Google SERP lookup without PAA expansion. Use when the user asks for rankings, organic results, local pack, quick SERP, or positions. Split topic from location and infer gl/hl from the user request."),
|
|
991
1255
|
inputSchema: SearchSerpInputSchema,
|
|
1256
|
+
outputSchema: SearchSerpOutputSchema,
|
|
992
1257
|
annotations: liveWebToolAnnotations("Google SERP Lookup")
|
|
993
1258
|
}, async (input) => formatSearchSerp(await executor.searchSerp(input), input));
|
|
994
1259
|
server.registerTool("extract_url", {
|
|
995
1260
|
title: "Single URL Extract",
|
|
996
1261
|
description: withReportNote("Extract structured data from one public URL: page content as Markdown, heading structure, JSON-LD schema, entity details, NAP score, metadata, and missing schema fields. Use when the user provides a single URL or asks to inspect/scrape one page."),
|
|
997
1262
|
inputSchema: ExtractUrlInputSchema,
|
|
1263
|
+
outputSchema: ExtractUrlOutputSchema,
|
|
998
1264
|
annotations: liveWebToolAnnotations("Single URL Extract")
|
|
999
1265
|
}, async (input) => formatExtractUrl(await executor.extractUrl(input), input));
|
|
1000
1266
|
server.registerTool("map_site_urls", {
|
|
@@ -1008,6 +1274,7 @@ function buildPaaExtractorMcpServer(executor, options = {}) {
|
|
|
1008
1274
|
title: "Multi-Page Site Extract",
|
|
1009
1275
|
description: withReportNote("Run multi-page extraction across a public website. Returns per-page titles, H1s, metadata, headings, schema/entity data, canonical URLs, and content. Use for website audits, competitor audits, and full-site extraction."),
|
|
1010
1276
|
inputSchema: ExtractSiteInputSchema,
|
|
1277
|
+
outputSchema: ExtractSiteOutputSchema,
|
|
1011
1278
|
annotations: liveWebToolAnnotations("Multi-Page Site Extract")
|
|
1012
1279
|
}, async (input) => formatExtractSite(await executor.extractSite(input), input));
|
|
1013
1280
|
server.registerTool("youtube_harvest", {
|
|
@@ -1047,6 +1314,7 @@ function buildPaaExtractorMcpServer(executor, options = {}) {
|
|
|
1047
1314
|
title: "Google Maps Business Profile Details",
|
|
1048
1315
|
description: withReportNote('Extract Google Maps business intelligence for one known/named business: rating, review count, category, address, phone, website, hours, booking URL, review histogram, review topics, about attributes, entity IDs, and optional review cards. Do not use this for category searches, local market prospect lists, or requests for multiple GMB/GBP profiles; use maps_search first for those. Split business name from location (e.g. "Elite Roofing Denver CO" => businessName "Elite Roofing", location "Denver, CO"). Pass includeReviews true when the user asks for reviews/customer pain.'),
|
|
1049
1316
|
inputSchema: MapsPlaceIntelInputSchema,
|
|
1317
|
+
outputSchema: MapsPlaceIntelOutputSchema,
|
|
1050
1318
|
annotations: liveWebToolAnnotations("Google Maps Business Profile Details")
|
|
1051
1319
|
}, async (input) => formatMapsPlaceIntel(await executor.mapsPlaceIntel(input), input));
|
|
1052
1320
|
server.registerTool("maps_search", {
|
|
@@ -1060,6 +1328,7 @@ function buildPaaExtractorMcpServer(executor, options = {}) {
|
|
|
1060
1328
|
title: "MCP Scraper Credits & Costs",
|
|
1061
1329
|
description: "Answer questions about MCP Scraper credits: current credit balance, what a specific tool/action costs, the full cost table, and optionally recent credit ledger entries. Does not expose payment methods or credit card information.",
|
|
1062
1330
|
inputSchema: CreditsInfoInputSchema,
|
|
1331
|
+
outputSchema: CreditsInfoOutputSchema,
|
|
1063
1332
|
annotations: {
|
|
1064
1333
|
title: "MCP Scraper Credits & Costs",
|
|
1065
1334
|
readOnlyHint: true,
|
|
@@ -1176,11 +1445,11 @@ var HttpMcpToolExecutor = class {
|
|
|
1176
1445
|
|
|
1177
1446
|
export {
|
|
1178
1447
|
harvestTimeoutBudget,
|
|
1448
|
+
configureReportSaving,
|
|
1179
1449
|
CaptureSerpSnapshotInputSchema,
|
|
1180
1450
|
CaptureSerpPageSnapshotsInputSchema,
|
|
1181
|
-
configureReportSaving,
|
|
1182
1451
|
liveWebToolAnnotations,
|
|
1183
1452
|
buildPaaExtractorMcpServer,
|
|
1184
1453
|
HttpMcpToolExecutor
|
|
1185
1454
|
};
|
|
1186
|
-
//# sourceMappingURL=chunk-
|
|
1455
|
+
//# sourceMappingURL=chunk-JNC32DMS.js.map
|