Skip to main content
Glama
portel-dev

NCP - Natural Context Provider

by portel-dev
parameter-predictor.ts6.45 kB
/** * Parameter Predictor * * Utility for predicting parameter values based on parameter name, type, and context. * Used by usage tips generator to provide smart examples. */ export class ParameterPredictor { predictValue(paramName: string, paramType: string, toolContext: string, description?: string, toolName?: string): any { const name = paramName.toLowerCase(); const desc = (description || '').toLowerCase(); const tool = (toolName || '').toLowerCase(); // String type predictions if (paramType === 'string') { return this.predictStringValue(name, desc, toolContext, tool); } // Number type predictions if (paramType === 'number' || paramType === 'integer') { return this.predictNumberValue(name, desc, toolContext); } // Boolean type predictions if (paramType === 'boolean') { return this.predictBooleanValue(name, desc); } // Array type predictions if (paramType === 'array') { return this.predictArrayValue(name, desc, toolContext); } // Object type predictions if (paramType === 'object') { return this.predictObjectValue(name, desc); } // Default fallback return this.getDefaultForType(paramType); } private predictStringValue(name: string, desc: string, context: string, tool?: string): string { // File and path patterns if (name.includes('path') || name.includes('file') || desc.includes('path') || desc.includes('file')) { // Check if tool name suggests directory operations const isDirectoryTool = tool && ( tool.includes('list_dir') || tool.includes('list_folder') || tool.includes('read_dir') || tool.includes('scan_dir') || tool.includes('get_dir') ); // Check if parameter or description suggests directory const isDirectoryParam = name.includes('dir') || name.includes('folder') || desc.includes('directory') || desc.includes('folder'); // Smart detection: if it's just "path" but tool is clearly for directories if (name === 'path' && isDirectoryTool) { return context === 'filesystem' ? '/home/user/documents' : './'; } if (context === 'filesystem') { if (isDirectoryParam || isDirectoryTool) { return '/home/user/documents'; } if (name.includes('config') || desc.includes('config')) { return '/etc/config.json'; } return '/home/user/document.txt'; } // Default based on whether it's likely a directory or file if (isDirectoryParam || isDirectoryTool) { return './'; } return './file.txt'; } // URL patterns if (name.includes('url') || name.includes('link') || desc.includes('url') || desc.includes('http')) { if (context === 'web') { return 'https://api.example.com/data'; } return 'https://example.com'; } // Email patterns if (name.includes('email') || name.includes('mail') || desc.includes('email')) { return 'user@example.com'; } // Name patterns if (name.includes('name') || name === 'title' || name === 'label') { if (context === 'filesystem') { return 'my-file'; } return 'example-name'; } // Content/text patterns if (name.includes('content') || name.includes('text') || name.includes('message') || name.includes('body')) { return 'Hello, world!'; } // Query/search patterns if (name.includes('query') || name.includes('search') || name.includes('term')) { return 'search term'; } // Key/ID patterns if (name.includes('key') || name.includes('id') || name.includes('token')) { if (context === 'payment') { return 'sk_test_...'; } return 'abc123'; } // Command patterns if (name.includes('command') || name.includes('cmd')) { if (context === 'system') { return 'ls -la'; } return 'echo hello'; } // Default string return 'example'; } private predictNumberValue(name: string, desc: string, context: string): number { // Process ID patterns if (name.includes('pid') || desc.includes('process') || desc.includes('pid')) { return 1234; } // Port patterns if (name.includes('port') || desc.includes('port')) { return 8080; } // Size/length patterns if (name.includes('size') || name.includes('length') || name.includes('limit') || name.includes('count')) { return 10; } // Line number patterns if (name.includes('line') || name.includes('head') || name.includes('tail')) { return 5; } // Timeout patterns if (name.includes('timeout') || name.includes('delay') || desc.includes('timeout')) { return 5000; } // Default number return 1; } private predictBooleanValue(name: string, desc: string): boolean { // Negative patterns default to false if (name.includes('disable') || name.includes('skip') || name.includes('ignore')) { return false; } // Most booleans default to true for examples return true; } private predictArrayValue(name: string, desc: string, context: string): any[] { // File paths array if (name.includes('path') || name.includes('file') || desc.includes('path')) { return ['/path/to/file1.txt', '/path/to/file2.txt']; } // Arguments array if (name.includes('arg') || name.includes('param') || desc.includes('argument')) { return ['--verbose', '--output', 'result.txt']; } // Tags/keywords if (name.includes('tag') || name.includes('keyword') || name.includes('label')) { return ['tag1', 'tag2']; } // Default array return ['item1', 'item2']; } private predictObjectValue(name: string, desc: string): object { // Options/config object if (name.includes('option') || name.includes('config') || name.includes('setting')) { return { enabled: true, timeout: 5000 }; } // Default object return { key: 'value' }; } private getDefaultForType(type: string): any { switch (type) { case 'string': return 'value'; case 'number': case 'integer': return 0; case 'boolean': return true; case 'array': return []; case 'object': return {}; default: return null; } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/portel-dev/ncp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server