Skip to main content
Glama

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
NameRequiredDescriptionDefault
headersNoRequest headers
urlYesAPI endpoint URL

Implementation Reference

  • 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,
          },
        };
      }
    }
  • 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"]
      }
    },
  • Registration and dispatch of 'api_get' handler in the main executeToolCall switch statement.
    case "api_get":
      return await handleApiGet(apiClient!, args);
  • 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,
    }));
Install Server

Other Tools

Related Tools

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/imprvhub/mcp-browser-agent'

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