devion-mcp-server
Version:
MCP server for Devion blockchain infrastructure - AI-native blockchain data access for developers and AI agents
90 lines • 3.41 kB
JavaScript
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from '@modelcontextprotocol/sdk/types.js';
import { getAccountBalance } from './tools/balances.js';
import { getTransactionDetails, getTransactions } from './tools/transactions.js';
import { getLatestBlock, getGasPrices } from './tools/blocks.js';
import { callContractFunction, getContractInfo } from './tools/contracts.js';
import { getMultiChainBalances, compareGasCosts } from './tools/multichain.js';
const TOOLS = [
getAccountBalance,
getTransactionDetails,
getTransactions,
getLatestBlock,
getGasPrices,
callContractFunction,
getContractInfo,
getMultiChainBalances,
compareGasCosts,
];
async function createServer() {
const server = new Server({
name: 'devion-mcp-server',
version: '2.0.0',
});
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: TOOLS.map(tool => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema,
})),
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
const tool = TOOLS.find(t => t.name === name);
if (!tool) {
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
}
try {
console.error(`🔧 Executing tool: ${name}`, args);
const result = await tool.handler(args || {});
console.error(`✅ Tool ${name} completed successfully`);
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2),
},
],
};
}
catch (error) {
console.error(`❌ Tool ${name} failed:`, error);
throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
});
return server;
}
async function main() {
console.error('🚀 Starting Devion MCP Server...');
console.error(`📡 Available tools: ${TOOLS.map(t => t.name).join(', ')}`);
console.error('⚠️ Running in development mode - API key validation disabled');
try {
const server = await createServer();
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('✅ Devion MCP Server started successfully');
console.error('🔗 Connected via stdio transport');
console.error('🎯 Growth tier features enabled');
}
catch (error) {
console.error('❌ Failed to start server:', error);
process.exit(1);
}
}
process.on('SIGINT', () => {
console.error('🛑 Received SIGINT, shutting down gracefully...');
process.exit(0);
});
process.on('SIGTERM', () => {
console.error('🛑 Received SIGTERM, shutting down gracefully...');
process.exit(0);
});
main().catch((error) => {
console.error('💥 Fatal error:', error);
process.exit(1);
});
//# sourceMappingURL=index.js.map