@bratcliffe909/mcp-server-segmind
Version:
Model Context Protocol server for Segmind API - Generate images and videos using AI models
102 lines โข 3.72 kB
JavaScript
if (process.argv[2] !== 'test-api') {
process.env.MCP_MODE = 'true';
}
import { server } from './server.js';
import { config } from './utils/config.js';
function testApiConfig() {
if (process.env.MCP_MODE === 'true') {
process.exit(1);
}
console.log('๐งช Testing Segmind API Configuration...\n');
const apiKey = config.apiKey || process.env.SEGMIND_API_KEY;
if (!apiKey) {
console.error('โ Error: SEGMIND_API_KEY not found');
console.error(' Please set it in your MCP configuration or environment');
process.exit(1);
}
console.log(`๐ API Key: ${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}`);
console.log('\n1๏ธโฃ Checking API key format...');
if (apiKey.match(/^(sg_|SG_)[a-zA-Z0-9]{12,}$/)) {
console.log('โ
API key format is valid!');
console.log('\nโจ Configuration test passed! Your Segmind MCP Server is ready to use.');
process.exit(0);
}
else {
console.error('โ Invalid API key format');
console.error(' API key should start with sg_ or SG_ followed by alphanumeric characters');
process.exit(1);
}
}
async function main() {
if (process.argv[2] === 'test-api') {
testApiConfig();
return;
}
try {
if (process.env.DEBUG) {
console.error('[Debug] Environment check:');
console.error(`[Debug] SEGMIND_API_KEY exists: ${!!process.env.SEGMIND_API_KEY}`);
console.error(`[Debug] SEGMIND_API_KEY length: ${process.env.SEGMIND_API_KEY?.length || 0}`);
console.error(`[Debug] First 10 chars: ${process.env.SEGMIND_API_KEY?.substring(0, 10) || 'N/A'}`);
}
const hasApiKey = !!process.env.SEGMIND_API_KEY;
if (!hasApiKey && process.env.DEBUG) {
console.error('[Segmind MCP] Warning: SEGMIND_API_KEY not found.');
console.error('[Segmind MCP] Server will start but API calls will fail.');
console.error('[Segmind MCP] Please set SEGMIND_API_KEY in your environment or MCP configuration.');
}
const shutdown = async () => {
try {
await server.shutdown();
process.exit(0);
}
catch (error) {
process.exit(1);
}
};
process.on('SIGTERM', () => shutdown());
process.on('SIGINT', () => shutdown());
process.on('uncaughtException', async (error) => {
if (process.env.DEBUG) {
console.error('Uncaught exception:', error);
}
try {
await server.sendMCPLog('critical', 'Uncaught exception in server', {
error: error.message,
stack: error.stack,
});
}
catch {
}
});
process.on('unhandledRejection', async (reason) => {
if (process.env.DEBUG) {
console.error('Unhandled rejection:', reason);
}
try {
await server.sendMCPLog('critical', 'Unhandled promise rejection', {
reason: String(reason),
});
}
catch {
}
});
await server.start();
await new Promise(() => {
});
}
catch (error) {
if (process.env.DEBUG) {
console.error('Failed to start server:', error);
}
setTimeout(() => process.exit(1), 100);
}
}
main().catch((error) => {
if (process.env.DEBUG) {
console.error('Fatal error:', error);
}
process.exit(1);
});
//# sourceMappingURL=index.js.map