#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { runWebHarvestTool } from "./tools/runWebHarvest.js";
import { getWebHarvestLeadsTool } from "./tools/getWebHarvestLeads.js";
import { getWebHarvestStatusTool } from "./tools/getWebHarvestStatus.js";
const server = new Server(
{
name: "flashleads-mcp-server",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
}
);
// List available tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "run_web_harvest",
description:
"Search Google and collect company website leads. Automatically creates or updates your web harvest agent. Returns leads with company names, websites, emails, phone numbers, and social media profiles.",
inputSchema: {
type: "object",
properties: {
searchQuery: {
type: "string",
description:
"What to search for (e.g., 'restaurants', 'coffee shops', 'plumbers', 'real estate agents')",
},
location: {
type: "string",
description:
"Geographic location (e.g., 'United States', 'New York', 'London, UK', 'California')",
},
limit: {
type: "number",
description: "Number of leads to collect (default: 10, max: 100)",
default: 10,
},
},
required: ["searchQuery", "location"],
},
},
{
name: "get_web_harvest_leads",
description:
"Get the leads collected by your web harvest agent. Returns detailed information including company names, websites, contact details, and social media profiles.",
inputSchema: {
type: "object",
properties: {
status: {
type: "string",
enum: ["PENDING", "RUNNING", "COMPLETED", "FAILED"],
description:
"Filter by lead status (optional). Use 'COMPLETED' for fully scraped leads with all details.",
},
limit: {
type: "number",
description: "Maximum number of leads to return (default: 50)",
default: 50,
},
},
},
},
{
name: "get_web_harvest_status",
description:
"Check if your web harvest agent is currently running and see how many leads have been collected. Shows total, completed, pending, and failed lead counts.",
inputSchema: {
type: "object",
properties: {},
},
},
],
};
});
// Handle tool calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
const { name, arguments: args } = request.params;
switch (name) {
case "run_web_harvest":
return await runWebHarvestTool(args);
case "get_web_harvest_leads":
return await getWebHarvestLeadsTool(args);
case "get_web_harvest_status":
return await getWebHarvestStatusTool(args);
default:
throw new Error(`Unknown tool: ${name}`);
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [
{
type: "text",
text: `Error: ${errorMessage}`,
},
],
isError: true,
};
}
});
// Start the server
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("FlashLeads MCP Server running on stdio");
}
main().catch((error) => {
console.error("Fatal error in main():", error);
process.exit(1);
});