test_endpoint
Test and analyze Azure Function App endpoints by simulating HTTP methods (GET, POST, PUT, DELETE) and inspecting detailed responses. Prepends the base URL http://localhost:7071/api for easy endpoint validation.
Instructions
Test a Function App endpoint and get detailed response information. The endpoint will be prepended to the base url which is: http://localhost:7071/api
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | Optional request body for POST/PUT requests | |
| endpoint | Yes | Endpoint path (e.g. "/users"). Will be appended to base URL. | |
| headers | No | Optional request headers | |
| method | Yes | HTTP method to use |
Implementation Reference
- src/index.ts:105-185 (handler)The MCP CallToolRequestSchema handler that dispatches to and implements the 'test_endpoint' tool. It validates arguments, configures an Axios request with authentication, normalizes the endpoint, executes the HTTP request, and returns a formatted response including status, headers, and body.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== 'test_endpoint') { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!isValidTestEndpointArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid test endpoint arguments' ); } try { const config: AxiosRequestConfig = { method: request.params.arguments.method as Method, url: request.params.arguments.endpoint, headers: request.params.arguments.headers || {}, }; if (['POST', 'PUT'].includes(request.params.arguments.method) && request.params.arguments.body) { config.data = request.params.arguments.body; } // Handle authentication based on environment variables if (hasBasicAuth()) { const base64Credentials = Buffer.from(`${AUTH_BASIC_USERNAME}:${AUTH_BASIC_PASSWORD}`).toString('base64'); config.headers = { ...config.headers, 'Authorization': `Basic ${base64Credentials}` }; } else if (hasBearerAuth()) { config.headers = { ...config.headers, 'Authorization': `Bearer ${AUTH_BEARER}` }; } else if (hasApiKeyAuth()) { config.headers = { ...config.headers, [AUTH_APIKEY_HEADER_NAME as string]: AUTH_APIKEY_VALUE }; } // Ensure endpoint starts with / and remove any trailing slashes const normalizedEndpoint = `/${request.params.arguments.endpoint.replace(/^\/+|\/+$/g, '')}`; config.url = normalizedEndpoint; const response = await this.axiosInstance.request(config); const fullUrl = `${BASE_URL}${normalizedEndpoint}`; return { content: [ { type: 'text', text: JSON.stringify({ url: fullUrl, // Include the actual URL called statusCode: response.status, statusText: response.statusText, headers: response.headers, body: response.data, }, null, 2), }, ], }; } catch (error) { if (axios.isAxiosError(error)) { return { content: [ { type: 'text', text: `Request failed: ${error.message}`, }, ], isError: true, }; } throw error; } });
- src/index.ts:70-103 (registration)Registration of the 'test_endpoint' tool in the ListToolsRequestSchema handler, including name, description, and input schema.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'test_endpoint', description: `Test a Function App endpoint and get detailed response information. The endpoint will be prepended to the base url which is: ${BASE_URL}`, inputSchema: { type: 'object', properties: { method: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE'], description: 'HTTP method to use', }, endpoint: { type: 'string', description: 'Endpoint path (e.g. "/users"). Will be appended to base URL.', }, body: { type: 'object', description: 'Optional request body for POST/PUT requests', }, headers: { type: 'object', description: 'Optional request headers', additionalProperties: { type: 'string', }, }, }, required: ['method', 'endpoint'], }, }, ], }));
- src/index.ts:75-100 (schema)JSON Schema defining the input parameters for the 'test_endpoint' tool, including method, endpoint, optional body, and headers.inputSchema: { type: 'object', properties: { method: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE'], description: 'HTTP method to use', }, endpoint: { type: 'string', description: 'Endpoint path (e.g. "/users"). Will be appended to base URL.', }, body: { type: 'object', description: 'Optional request body for POST/PUT requests', }, headers: { type: 'object', description: 'Optional request headers', additionalProperties: { type: 'string', }, }, }, required: ['method', 'endpoint'], },
- src/index.ts:19-24 (schema)TypeScript interface defining the expected arguments structure for the 'test_endpoint' tool.interface TestEndpointArgs { method: 'GET' | 'POST' | 'PUT' | 'DELETE'; endpoint: string; body?: any; headers?: Record<string, string>; }
- src/index.ts:26-32 (helper)Type guard function to validate if provided arguments match the TestEndpointArgs interface before executing the tool.const isValidTestEndpointArgs = (args: any): args is TestEndpointArgs => { if (typeof args !== 'object' || args === null) return false; if (!['GET', 'POST', 'PUT', 'DELETE'].includes(args.method)) return false; if (typeof args.endpoint !== 'string') return false; if (args.headers !== undefined && typeof args.headers !== 'object') return false; return true; };