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

81 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Debug parameter extraction
*/
import fs from 'fs';
import path from 'path';
// Test parameter extraction
const testParameterText = `
username: { type: "string", required: true, description: "Username" },
password: { type: "string", required: true, description: "Password" },
`;
console.log('Testing parameter extraction...');
console.log('Input text:', testParameterText);
// Current regex
const paramRegex = /(\w+):\s*\{([^}]*)\}/g;
let match;
const parameters = [];
while ((match = paramRegex.exec(testParameterText)) !== null) {
const [, name, paramContent] = match;
console.log(`Found parameter: ${name}`);
console.log(`Content: ${paramContent}`);
// Extract type
const typeMatch = paramContent.match(/type:\s*["']([^"']+)["']/);
const type = typeMatch ? typeMatch[1] : 'string';
// Extract required
const requiredMatch = paramContent.match(/required:\s*(true|false)/);
const required = requiredMatch ? requiredMatch[1] === 'true' : false;
// Extract description
const descMatch = paramContent.match(/description:\s*["']([^"']*?)["']/);
const description = descMatch ? descMatch[1] : '';
console.log(`Extracted - Type: ${type}, Required: ${required}, Description: ${description}`);
parameters.push({
name: name.trim(),
type: type.trim(),
required,
description: description.trim(),
});
}
console.log('Final parameters:', parameters);
// Test with actual endpoint
const endpointsPath = path.join(process.cwd(), 'src/config/endpoints.js');
const content = fs.readFileSync(endpointsPath, 'utf8');
// Find the login endpoint
const loginMatch = content.match(/\{[\s\S]*?path:\s*["']\/api\/login["'][\s\S]*?\}/);
if (loginMatch) {
console.log('\nFound login endpoint:');
console.log(loginMatch[0]);
// Extract parameters section
const paramMatch = loginMatch[0].match(/parameters:\s*\{([\s\S]*?)\}/);
if (paramMatch) {
console.log('\nParameters section:');
console.log(paramMatch[1]);
// Test extraction
const paramText = paramMatch[1];
const testRegex = /(\w+):\s*\{([^}]*)\}/g;
console.log('\nTesting extraction on actual data:');
let testMatch;
while ((testMatch = testRegex.exec(paramText)) !== null) {
console.log(`Parameter: ${testMatch[1]}, Content: ${testMatch[2]}`);
}
}
}