UNPKG

cdi-mcp-server

Version:

CDI (Chemical Distribution Institute) MCP Server for retrieving and processing maritime inspection data with full CDI authentication support

101 lines 3.59 kB
#!/usr/bin/env node 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 { cdiDataMain } from './tools.js'; // Create server instance const server = new Server({ name: 'cdi-mcp-server', version: '1.0.0', }, { capabilities: { tools: {}, }, }); // List available tools server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'cdi_data_main', description: `Return CDI inspection rows and local PDF paths for a Synergy doc‑name. Get the doc_name from get_vessel_info tool and pass it to this tool doc_name=shippalmDoc. Optionally provide username and password to override environment variables.`, inputSchema: { type: 'object', properties: { doc_name: { type: 'string', description: 'The document name identifier for the vessel' }, username: { type: 'string', description: 'CDI username (optional, overrides environment variable)' }, password: { type: 'string', description: 'CDI password (optional, overrides environment variable)' }, }, required: ['doc_name'], }, }, ], }; }); // Handle tool calls server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { if (name === 'cdi_data_main') { const toolArgs = args; if (!toolArgs || !toolArgs.doc_name) { throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: doc_name'); } const results = await cdiDataMain(toolArgs.doc_name, { username: toolArgs.username, password: toolArgs.password }); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } else { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); if (error instanceof McpError) { throw error; } throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${errorMessage}`); } }); // Start the server async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error('CDI Data MCP Server running on stdio'); } // Handle process termination process.on('SIGINT', async () => { await server.close(); process.exit(0); }); process.on('SIGTERM', async () => { await server.close(); process.exit(0); }); if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { console.error('Server failed to start:', error); process.exit(1); }); } //# sourceMappingURL=index.js.map