test_runs_getHttpResponses
Retrieve HTTP response data from LoadRunner Cloud performance tests to analyze server behavior and identify issues during test execution.
Instructions
Get HTTP responses for a test run from LoadRunner Cloud.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| runId | Yes | The ID of the test run. |
Implementation Reference
- The main execution function that handles the tool logic: authenticates, constructs the API URL, fetches HTTP responses from LoadRunner Cloud for the given runId, and parses the JSON response.const executeFunction = async ({ runId }) => { const baseUrl = process.env.LRC_BASE_URL; const tenantId = process.env.LRC_TENANT_ID; const token = await getAuthToken(); try { // Construct the URL with query parameters const url = new URL(`${baseUrl}/test-runs/${runId}/http-responses`); url.searchParams.append('TENANTID', tenantId); // Set up headers for the request const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }; // Perform the fetch request const response = await fetch(url.toString(), { method: 'GET', headers }); // Check if the response was successful if (!response.ok) { const text = await response.text(); try { const errorData = JSON.parse(text); throw new Error(JSON.stringify(errorData)); } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON error response:', text); throw new Error(text); } } // Parse and return the response data const text = await response.text(); try { const data = JSON.parse(text); return data; } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON success response:', text); return { error: 'Received non-JSON response from API', raw: text }; } } catch (error) { console.error('Error retrieving HTTP responses:', error); return { error: 'An error occurred while retrieving HTTP responses.' }; } };
- The tool's JSON Schema definition, including name, description, input parameters (runId: string, required), used for validation and listing.type: 'function', function: { name: 'test_runs_getHttpResponses', description: 'Get HTTP responses for a test run from LoadRunner Cloud.', parameters: { type: 'object', properties: { runId: { type: 'string', description: 'The ID of the test run.' } }, required: ['runId'] } } }
- lib/tools.js:7-16 (registration)Discovers and loads the apiTool objects from all tool files listed in toolPaths, including this tool, making them available for the MCP server.export async function discoverTools() { const toolPromises = toolPaths.map(async (file) => { const module = await import(`../tools/${file}`); return { ...module.apiTool, path: file, }; }); return Promise.all(toolPromises); }
- tools/paths.js:1-11 (registration)Central list of all tool file paths relative to tools/, explicitly including the path to this tool's implementation file for discovery.export const toolPaths = [ 'loadrunner-cloud/load-runner-cloud-api/projects-get-projects.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-active-test-runs.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-test-run-transactions.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-test-run-summary.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-http-responses.js', 'loadrunner-cloud/load-runner-cloud-api/test-runs-get-test-run-recent.js', 'loadrunner-cloud/load-runner-cloud-api/projects-get-load-tests.js', 'loadrunner-cloud/load-runner-cloud-api/projects-get-load-test-scripts.js', 'loadrunner-cloud/load-runner-cloud-api/projects-get-load-test-runs.js' ];
- Supporting helper function getAuthToken() used by the handler for authentication. (Note: excerpt shows usage; full helper file provides the auth logic.)/** * Function to get an auth token from LoadRunner Cloud. * * @returns {Promise<string|Object>} - The access token or an error message object. */ const getAuthToken = async () => { const baseUrl = process.env.LRC_BASE_URL; const tenantId = process.env.LRC_TENANT_ID; const clientId = process.env.LRC_CLIENT_ID; const clientSecret = process.env.LRC_CLIENT_SECRET; try { const url = new URL(`${baseUrl}/auth-client`); url.searchParams.append('TENANTID', tenantId); const headers = { 'Content-Type': 'application/json', 'accept': 'application/json' }; const body = JSON.stringify({ client_id: clientId, client_secret: clientSecret }); const response = await fetch(url.toString(), { method: 'POST', headers, body }); if (!response.ok) { const text = await response.text(); try { const errorData = JSON.parse(text); throw new Error(JSON.stringify(errorData)); } catch (jsonErr) { // Not JSON, log the raw text console.error('Non-JSON error response:', text); throw new Error(text); } } const data = await response.json(); // Adjust according to actual API response structure return data.access_token || data.token || data; } catch (error) { console.error('Error retrieving auth token:', error); return { error: 'An error occurred while retrieving auth token.' }; } }; export { getAuthToken };