#!/usr/bin/env node
import { FastMCP } from "fastmcp";
import { dataiClient } from "./utils/api-client.js";
import { registerAllTools } from "./tools/index.js";
// Create FastMCP server with enhanced configuration
const server = new FastMCP({
name: "datai FastMCP Server",
version: "1.0.0",
instructions: `
datai MCP Server provides comprehensive blockchain data tools for DeFi analysis.
Features:
- 8 specialized tools for DeFi positions, balances, and protocol data
- Support for Ethereum and Solana wallet addresses
- Multi-chain support: Ethereum, Arbitrum, Polygon, Avalanche, BSC, Base, Optimism
- Real-time blockchain data from datai API
Usage:
- Provide wallet addresses in Ethereum (0x...) or Solana (Base58) format
- Specify blockchain networks using supported chain identifiers
- Tools return comprehensive DeFi position and balance data
`.trim(),
// Configure ping for better connection stability
ping: {
enabled: false, // Disable ping to reduce connection noise
intervalMs: 60000, // 1 minute if enabled
logLevel: "error" // Only log errors, not debug info
},
// Configure roots capability
roots: {
enabled: true
}
});
// Initialize API client
const apiClient = dataiClient;
// Register all tools with error handling (stdout silent)
try {
registerAllTools(server, apiClient);
} catch {
process.exit(1);
}
// Start FastMCP (no stdout/stderr after this call)
async function startServer() {
try {
await server.start({ transportType: "stdio" });
} catch {
process.exit(1);
}
}
// Handle graceful shutdown
process.on('SIGINT', async () => {
// Silent shutdown - NO console output during MCP protocol
try {
await server.stop();
process.exit(0);
} catch (error) {
// Only during shutdown when MCP protocol is stopping
process.stderr.write(`Error during shutdown: ${error}\n`);
process.exit(1);
}
});
process.on('SIGTERM', async () => {
// Silent shutdown - NO console output during MCP protocol
try {
await server.stop();
process.exit(0);
} catch (error) {
// Only during shutdown when MCP protocol is stopping
process.stderr.write(`Error during shutdown: ${error}\n`);
process.exit(1);
}
});
// Start the server
startServer();
export default server;