scraperis-mcp
Version:
Model Context Protocol (MCP) integration for Scraper.is - A web scraping tool for AI assistants
112 lines (111 loc) • 4.64 kB
JavaScript
import fs from 'fs';
import path from 'path';
import os from 'os';
import readline from 'readline';
import { execSync } from 'child_process';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Get the Claude config file path based on OS
let claudeConfigDir;
if (process.platform === 'darwin') {
claudeConfigDir = path.join(os.homedir(), 'Library', 'Application Support', 'Claude');
}
else if (process.platform === 'win32') {
claudeConfigDir = path.join(os.homedir(), 'AppData', 'Roaming', 'Claude');
}
else {
claudeConfigDir = path.join(os.homedir(), '.config', 'Claude');
}
const claudeConfigPath = path.join(claudeConfigDir, 'claude_desktop_config.json');
console.log('Scraperis MCP Setup for Claude');
console.log('-----------------------------');
console.log('This script will help you configure Claude to use the Scraperis MCP.');
// Try to find the full path to the scraperis-mcp executable
let mcpPath = '';
try {
mcpPath = execSync('which scraperis-mcp', { encoding: 'utf8' }).trim();
console.log(`Found scraperis-mcp at: ${mcpPath}`);
}
catch (error) {
console.log('Could not find scraperis-mcp in PATH. Will use command name only.');
}
// Ask for the API key
rl.question('Enter your Scraper.is API key: ', (apiKey) => {
if (!apiKey) {
console.error('API key is required. Please get one from https://www.scraper.is/dashboard/apikeys');
rl.close();
process.exit(1);
}
// Create the MCP configuration
const mcpConfig = {
mcpServers: {
scraperis_scraper: {
command: 'npx',
args: ['-y', 'scraperis-mcp'],
env: {
SCRAPERIS_API_KEY: apiKey,
DEBUG: '*',
NODE_DEBUG: 'mcp,net,http',
NODE_OPTIONS: '--trace-warnings'
}
}
}
};
try {
// Check if Claude config directory exists
if (!fs.existsSync(claudeConfigDir)) {
console.log(`Claude config directory not found at ${claudeConfigDir}`);
console.log('Creating directory...');
fs.mkdirSync(claudeConfigDir, { recursive: true });
}
// Check if Claude config file exists
let existingConfig = {};
if (fs.existsSync(claudeConfigPath)) {
try {
const configContent = fs.readFileSync(claudeConfigPath, 'utf8');
existingConfig = JSON.parse(configContent);
console.log('Found existing Claude configuration.');
}
catch (err) {
console.log('Error reading existing Claude configuration. Creating a new one.');
}
}
// Merge with existing config
const newConfig = {
...existingConfig,
mcpServers: {
...(existingConfig.mcpServers || {}),
...mcpConfig.mcpServers
}
};
// Write the config file
fs.writeFileSync(claudeConfigPath, JSON.stringify(newConfig, null, 2));
console.log(`Configuration saved to ${claudeConfigPath}`);
console.log('\nConfiguration Summary:');
console.log(`- Command: ${mcpConfig.mcpServers.scraperis_scraper.command} ${mcpConfig.mcpServers.scraperis_scraper.args.join(' ')}`);
console.log(`- API Key: ${apiKey.substring(0, 4)}...${apiKey.substring(apiKey.length - 4)}`);
console.log('\nPlease restart Claude for the changes to take effect.');
// Test the configuration
console.log('\nTesting the MCP server...');
try {
execSync(`SCRAPERIS_API_KEY=${apiKey} npx -y scraperis-mcp --version`, { timeout: 5000 });
console.log('✅ MCP server test successful!');
}
catch (testErr) {
console.log('❌ MCP server test failed. This might indicate an issue with your setup.');
console.log(`Error: ${testErr.message}`);
}
console.log('\nIf you continue to experience issues, try the following:');
console.log('1. Make sure you have Node.js installed and npx is available');
console.log('2. Check that your API key is valid at https://www.scraper.is/dashboard/apikeys');
console.log('3. Try running the MCP server manually: SCRAPERIS_API_KEY=your_key npx scraperis-mcp');
console.log('4. Check Claude logs: In Claude, go to Settings > Advanced > View Logs');
}
catch (err) {
console.error('Error setting up Claude configuration:', err.message);
}
rl.close();
});