Files
mcp-tool/test-provider.js
nasir@endelospay.com 8c74b0e23f first
2025-07-11 20:22:12 +05:00

111 lines
4.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Test Provider authentication and endpoints
*/
import { ConfigManager } from './src/config/ConfigManager.js';
import { ToolGenerator } from './src/tools/ToolGenerator.js';
import { PUBLIC_ENDPOINTS, PROVIDER_ENDPOINTS, AUTH_TYPES } from './src/config/endpoints.js';
async function testProviderFeatures() {
console.log('🧪 Provider Authentication Test\n');
try {
// Test 1: Environment setup with Provider credentials
console.log('1. Testing Provider environment setup...');
process.env.LARAVEL_API_BASE_URL = 'https://example.com';
process.env.PROVIDER_USERNAME = 'test@provider.com';
process.env.PROVIDER_PASSWORD = 'testpass';
console.log('✅ Provider environment variables set');
// Test 2: Configuration loading
console.log('2. Testing configuration with Provider...');
const config = new ConfigManager();
console.log('✅ Configuration loaded successfully');
console.log(` Provider Username: ${config.get('PROVIDER_USERNAME')}`);
console.log(` Provider Endpoint: ${config.get('PROVIDER_LOGIN_ENDPOINT')}`);
// Test 3: Endpoint registry
console.log('3. Testing endpoint registries...');
console.log(`${PUBLIC_ENDPOINTS.length} public endpoints loaded`);
console.log(`${PROVIDER_ENDPOINTS.length} provider endpoints loaded`);
// List provider endpoints
console.log(' Provider endpoints:');
PROVIDER_ENDPOINTS.forEach((endpoint, index) => {
console.log(` ${index + 1}. ${endpoint.method} ${endpoint.path} - ${endpoint.description}`);
});
// Test 4: Tool generation with Provider
console.log('4. Testing tool generation with Provider...');
const mockApiClient = {
get: () => Promise.resolve({}),
post: () => Promise.resolve({}),
put: () => Promise.resolve({}),
delete: () => Promise.resolve({}),
patch: () => Promise.resolve({})
};
const toolGenerator = new ToolGenerator(mockApiClient);
const tools = toolGenerator.generateAllTools();
console.log(`${tools.length} total MCP tools generated`);
// Count tools by auth type
const publicTools = tools.filter(tool => {
const toolDef = toolGenerator.getTool(tool.name);
return toolDef && toolDef.authType === AUTH_TYPES.PUBLIC;
});
const providerTools = tools.filter(tool => {
const toolDef = toolGenerator.getTool(tool.name);
return toolDef && toolDef.authType === AUTH_TYPES.PROVIDER;
});
console.log(` • Public tools: ${publicTools.length}`);
console.log(` • Provider tools: ${providerTools.length}`);
// Test 5: Provider tool structure
console.log('5. Testing Provider tool structure...');
if (providerTools.length > 0) {
const firstProviderTool = providerTools[0];
console.log(`✅ Sample Provider tool: ${firstProviderTool.name}`);
console.log(` Description: ${firstProviderTool.description}`);
// List all provider tools
console.log(' All Provider tools:');
providerTools.forEach((tool, index) => {
console.log(` ${index + 1}. ${tool.name}`);
});
} else {
throw new Error('No Provider tools generated');
}
// Test 6: Authentication types
console.log('6. Testing authentication types...');
const summary = config.getSummary();
console.log(`✅ Total auth types configured: ${summary.authTypesConfigured.length}`);
console.log(` Configured types: ${summary.authTypesConfigured.join(', ')}`);
console.log('\n🎉 All Provider tests passed!');
console.log('\n📋 Provider Summary:');
console.log(` • Provider Endpoints: ✅ ${PROVIDER_ENDPOINTS.length} endpoints`);
console.log(` • Provider Tools: ✅ ${providerTools.length} MCP tools`);
console.log(` • Authentication: ✅ Provider auth type supported`);
console.log(` • Total Tools: ✅ ${tools.length} (${publicTools.length} public + ${providerTools.length} provider)`);
console.log('\n🚀 Provider authentication is ready!');
console.log('\nProvider tools available:');
providerTools.forEach(tool => {
console.log(`${tool.name}: ${tool.description}`);
});
} catch (error) {
console.error('\n❌ Provider test failed:', error.message);
console.error('Stack trace:', error.stack);
process.exit(1);
}
}
testProviderFeatures();