api_get
Performs a GET request to an API endpoint by specifying the URL and optional headers, enabling direct interaction with web services through the Browser Agent MCP.
Instructions
Perform a GET request to an API endpoint
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| headers | No | Request headers | |
| url | Yes | API endpoint URL |
Implementation Reference
- src/executor.ts:512-541 (handler)Core implementation of the 'api_get' tool: performs a GET request using Playwright APIRequestContext, handles headers, fetches response data, and formats output including status and body.async function handleApiGet(client: APIRequestContext, args: any): Promise<{ toolResult: CallToolResult }> { try { const options = args.headers ? { headers: args.headers } : undefined; const response = await client.get(args.url, options); const responseData = await getResponseData(response); return { toolResult: { content: [ { type: "text", text: `GET ${args.url} - Status: ${response.status()}`, }, ...responseData ], isError: false, }, }; } catch (error) { return { toolResult: { content: [{ type: "text", text: `GET request failed: ${(error as Error).message}`, }], isError: true, }, }; } }
- src/tools.ts:131-146 (schema)Tool definition for 'api_get' including input schema specifying required 'url' and optional 'headers'.{ name: "api_get", description: "Perform a GET request to an API endpoint", inputSchema: { type: "object", properties: { url: { type: "string", description: "API endpoint URL" }, headers: { type: "object", description: "Request headers", additionalProperties: { type: "string" } } }, required: ["url"] } },
- src/executor.ts:209-210 (registration)Registration and dispatch of 'api_get' handler in the main executeToolCall switch statement.case "api_get": return await handleApiGet(apiClient!, args);
- src/executor.ts:144-161 (helper)Helper function used by api_get to parse and format API response body as text content, preferring pretty-printed JSON.async function getResponseData(response: any): Promise<TextContent[]> { const contentType = response.headers()['content-type'] || ''; let responseText: string; if (contentType.includes('application/json')) { try { const json = await response.json(); responseText = JSON.stringify(json, null, 2); } catch (e) { responseText = await response.text(); } } else { responseText = await response.text(); } return [{ type: "text", text: `Response body:\n${responseText}`, } as TextContent]; }
- src/handlers.ts:61-63 (registration)MCP server handler for listing tools, which includes the 'api_get' tool from registerTools().server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools, }));