#!/usr/bin/env node
import { parseArgs } from 'node:util';
import { version } from './version.js';
import { initSuccinctProver } from './cli/init.js';
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 * as dotenv from 'dotenv';
export async function handleCliArguments(): Promise<boolean> {
try {
const { values } = parseArgs({
options: {
help: { type: 'boolean', short: 'h' },
version: { type: 'boolean', short: 'v' },
init: { type: 'boolean', short: 'i' },
test: { type: 'boolean', short: 't' },
},
});
if (values.help) {
showHelp();
return false;
}
if (values.version) {
console.log(`prover-mcp v${version}`);
return false;
}
if (values.init) {
initSuccinctProver();
return false;
}
if (values.test) {
await testConnection();
return false;
}
// Default: Allow MCP server to start
return true;
} catch (err) {
console.error('Unrecognized argument. For help, run `prover-mcp --help`.');
return false;
}
}
function showHelp() {
console.log(`
๐ Prover MCP - Prover Network Monitor
USAGE:
prover-mcp [OPTIONS]
OPTIONS:
--init Complete setup for Claude Desktop & Cursor IDE with secure credential management
--test Test network connectivity and MCP functionality
--version, -v Show version information
--help, -h Show this help message
EXAMPLES:
prover-mcp --init # Complete setup (credentials + AI clients)
prover-mcp # Start MCP server
prover-mcp --test # Test your configuration
DOCUMENTATION:
README.md Overview and setup guide
QUICK_START.md 3-step quick setup
SUPPORT:
Ask your AI assistant: "Help me with Prover MCP"
GitHub: https://github.com/d3lta02/prover-mcp
`);
}
async function testConnection() {
console.log('๐งช Testing Succinct Prover MCP...\n');
try {
// Basic environment check
const rpcUrl = process.env.SUCCINCT_RPC_URL || 'https://rpc-production.succinct.xyz';
const privateKey = process.env.PRIVATE_KEY || process.env.PROVER_PRIVATE_KEY;
const proverAddress = process.env.PROVER_ADDRESS;
console.log('๐ Configuration Status:');
console.log(` RPC URL: ${rpcUrl}`);
console.log(` Mode: ${privateKey && proverAddress ? 'Full Prover' : 'Monitor Only'}`);
console.log(` Tools: ${privateKey && proverAddress ? 'โ
All Available' : 'โ ๏ธ Limited (need credentials)'}`);
console.log('\n๐ MCP Server Ready!');
console.log('\n๐ก Try these commands in your AI client:');
console.log(' "Get network status"');
console.log(' "Run Succinct Prover"');
console.log(' "Show available proof requests"');
} catch (error) {
console.error('โ Test failed:', error);
process.exit(1);
}
}
export async function main() {
// Load environment variables first (Base MCP approach)
dotenv.config();
// Handle CLI arguments first
const shouldContinue = await handleCliArguments();
if (shouldContinue) {
// Validate critical environment variables only if starting MCP server
const proverAddress = process.env.PROVER_ADDRESS;
const privateKey = process.env.PRIVATE_KEY || process.env.PROVER_PRIVATE_KEY;
if (!proverAddress || !privateKey) {
console.error('Missing required environment variables:');
if (!proverAddress) console.error('- PROVER_ADDRESS is required');
if (!privateKey) console.error('- PRIVATE_KEY or PROVER_PRIVATE_KEY is required');
console.error('\nPlease create your .env file or configure via MCP client config.');
process.exit(1);
}
// Import and start the MCP server dynamically to avoid circular imports
const { startMcpServer } = await import('./index.js');
await startMcpServer();
}
}
// Run if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch((error) => {
console.error('โ Failed to start:', error);
process.exit(1);
});
}