test_api_endpoint
Test API endpoints by sending HTTP requests with configurable methods, headers, and body to verify functionality and responses.
Instructions
Test an API endpoint with HTTP request
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | API endpoint URL to test | |
| method | No | HTTP method | GET |
| headers | No | HTTP headers | |
| body | No | Request body |
Implementation Reference
- src/scrapers/api-scraper.ts:199-231 (handler)Core handler implementation that performs the actual HTTP request to test the API endpoint using axios.
async testAPIEndpoint( url: string, options?: { method?: string; headers?: Record<string, string>; body?: unknown } ): Promise<{ status: number; statusText: string; headers: Record<string, string>; body?: unknown; responseTime: number; }> { const axios = (await import('axios')).default; const startTime = Date.now(); try { const response = await axios({ url, method: (options?.method as any) || 'GET', headers: options?.headers, data: options?.body, validateStatus: () => true, }); return { status: response.status, statusText: response.statusText, headers: response.headers as Record<string, string>, body: response.data, responseTime: Date.now() - startTime, }; } catch (error) { throw new Error(`Failed to test endpoint: ${error instanceof Error ? error.message : String(error)}`); } } - src/tools/api-discovery.ts:65-88 (schema)Input schema definition for the test_api_endpoint tool, specifying parameters like url, method, headers, and body.
inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'API endpoint URL to test', }, method: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], description: 'HTTP method', default: 'GET', }, headers: { type: 'object', description: 'HTTP headers', }, body: { type: 'object', description: 'Request body', }, }, required: ['url'], }, - src/tools/api-discovery.ts:62-89 (registration)Tool registration in the apiDiscoveryTools array, including name, description, and input schema.
{ name: 'test_api_endpoint', description: 'Test an API endpoint with HTTP request', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'API endpoint URL to test', }, method: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], description: 'HTTP method', default: 'GET', }, headers: { type: 'object', description: 'HTTP headers', }, body: { type: 'object', description: 'Request body', }, }, required: ['url'], }, }, - src/tools/api-discovery.ts:195-202 (handler)Dispatcher handler case in handleAPIDiscoveryTool that extracts parameters and delegates to APIScraper.testAPIEndpoint.
case 'test_api_endpoint': { const url = params.url as string; const method = params.method as string; const headers = params.headers as Record<string, string>; const body = params.body as unknown; const result = await apiScraper.testAPIEndpoint(url, { method, headers, body }); return result; }