UNPKG

@equidam/mcp-server

Version:

Equidam MCP Server - Bridge between AI assistants and Equidam's company valuation API

149 lines (132 loc) 5.2 kB
/** * Industry Selection Tool for MCP * Handles the select_industry_classification tool calls */ /** * Tool definition for industry selection */ const SELECT_INDUSTRY_TOOL_DEFINITION = { name: "select_industry_classification", description: `Select the final industry classification from multiple options presented by classify_company_industry. PURPOSE: This tool is used when classify_company_industry returns multiple options with similar confidence levels. The user selects their preferred classification. USAGE: - Only use this tool when classify_company_industry returns status 'multiple_options_available' - Present the options to the user clearly with descriptions - Use the industry_code from the user's selection - The result can then be used with get_company_valuation tool WORKFLOW: 1. classify_company_industry returns multiple options 2. Present options to user for selection 3. User chooses an option 4. Use this tool with the selected industry_code 5. Use the confirmed industry_code for valuation`, inputSchema: { type: "object", properties: { industry_code: { type: "string", description: "The selected TRBC industry code from the options presented (REQUIRED, exactly 10 digits). This should be one of the codes from the classify_company_industry response.", pattern: "^[0-9]{10}$" }, user_confirmation: { type: "string", description: "Optional user confirmation or additional context about their selection (max 500 characters). Examples: 'Yes, this matches our business model', 'This is the closest fit'", maxLength: 500 } }, required: ["industry_code"] } }; /** * Handle industry selection tool calls * @param {object} apiClient - Equidam API client instance * @param {Function} debugLog - Debug logging function * @returns {Function} - Tool handler function */ function createSelectIndustryHandler(apiClient, debugLog) { return async (params) => { debugLog('Processing industry selection request:', { industry_code: params.industry_code, has_confirmation: !!params.user_confirmation }); try { // Validate input parameters if (!params.industry_code || typeof params.industry_code !== 'string') { throw new Error('industry_code parameter is required and must be a string'); } if (!/^[0-9]{10}$/.test(params.industry_code)) { throw new Error('industry_code must be exactly 10 digits'); } if (params.user_confirmation && typeof params.user_confirmation !== 'string') { throw new Error('user_confirmation must be a string'); } if (params.user_confirmation && params.user_confirmation.length > 500) { throw new Error('user_confirmation must be less than 500 characters'); } // Call the API const result = await apiClient.selectIndustryClassification({ industry_code: params.industry_code, user_confirmation: params.user_confirmation }); debugLog('Industry selection successful:', { industry_code: result.industry_code, industry_name: result.industry_name, status: result.status }); // Format response for MCP return formatSelectionResponse(result); } catch (error) { debugLog('Industry selection error:', error.message); // Return enhanced error information for LLM return { isError: true, error: error.message, code: 'SELECTION_ERROR', llm_guidance: 'This error indicates an issue with the industry selection. Please verify that the industry_code is valid and exactly 10 digits, matching one of the options provided by classify_company_industry.' }; } }; } /** * Format selection response for MCP * @param {object} result - API response * @returns {object} - Formatted MCP response */ function formatSelectionResponse(result) { return { success: true, status: result.status || 'classification_confirmed', industry_code: result.industry_code, industry_name: result.industry_name, description: result.description, message: result.message || 'Industry classification confirmed and ready for valuation.', usage_note: result.usage_note || `Use the 'industry_code' (${result.industry_code}) as input for the get_company_valuation tool.`, next_step: result.llm_guidance?.next_step || 'You can now use this industry_code with the get_company_valuation tool to calculate the company valuation.', llm_guidance: result.llm_guidance }; } /** * Get example inputs for the selection tool * @returns {Array} - Array of example inputs */ function getSelectionExamples() { return [ { industry_code: "5010201010", user_confirmation: "Yes, this matches our software development services" }, { industry_code: "3510101010", user_confirmation: "This is the closest fit for our food business" }, { industry_code: "5740101010" } ]; } module.exports = { SELECT_INDUSTRY_TOOL_DEFINITION, createSelectIndustryHandler, formatSelectionResponse, getSelectionExamples };