- READMEs added: asana, close, freshdesk, google-console, gusto, square - main.ts + server.ts (lazy loading): activecampaign, clickup, klaviyo, mailchimp, pipedrive, trello, touchbistro, closebot, close, google-console - All 13 compile with 0 TSC errors
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Google Search Console MCP Server - Main Entry Point
|
|
* Initializes authentication, client, cache, and starts server
|
|
*/
|
|
|
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
import { getAuthClient } from './auth/index.js';
|
|
import { GSCClient } from './lib/gsc-client.js';
|
|
import { Cache } from './lib/cache.js';
|
|
import { RateLimiter } from './lib/rate-limit.js';
|
|
import { GSCServer } from './server.js';
|
|
|
|
async function main() {
|
|
try {
|
|
console.error('Starting Google Search Console MCP server...');
|
|
|
|
// Initialize authentication
|
|
console.error('Authenticating...');
|
|
const authClient = await getAuthClient();
|
|
|
|
if (!authClient) {
|
|
console.error('Error: Failed to authenticate with Google Search Console');
|
|
console.error('');
|
|
console.error('To set up authentication:');
|
|
console.error('1. Visit: https://console.cloud.google.com/apis/credentials');
|
|
console.error('2. Create OAuth 2.0 credentials');
|
|
console.error('3. Download credentials.json');
|
|
console.error('4. Follow the authentication flow on first run');
|
|
process.exit(1);
|
|
}
|
|
|
|
// Initialize GSC client
|
|
const gscClient = new GSCClient(authClient as any);
|
|
|
|
// Initialize cache with optional TTL from env
|
|
const cacheTTL = process.env.GSC_CACHE_TTL
|
|
? parseInt(process.env.GSC_CACHE_TTL) * 1000
|
|
: undefined;
|
|
|
|
const cache = new Cache({
|
|
analyticsTTL: cacheTTL,
|
|
});
|
|
|
|
// Initialize rate limiter
|
|
const rateLimiter = new RateLimiter();
|
|
|
|
// Start periodic cache pruning (every 5 minutes)
|
|
const pruneInterval = setInterval(() => {
|
|
cache.prune();
|
|
}, 5 * 60 * 1000);
|
|
|
|
// Create server instance
|
|
const server = new GSCServer({
|
|
gscClient,
|
|
cache,
|
|
rateLimiter,
|
|
});
|
|
|
|
// Graceful shutdown handlers
|
|
const cleanup = () => {
|
|
console.error('\nShutting down Google Search Console MCP server...');
|
|
clearInterval(pruneInterval);
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on('SIGINT', cleanup);
|
|
process.on('SIGTERM', cleanup);
|
|
|
|
// Start server (transport created internally)
|
|
await server.connect();
|
|
} catch (error: any) {
|
|
console.error('Fatal error:', error.message);
|
|
console.error(error.stack);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|