UNPKG

dataforseo-mcp-server

Version:

CLI and MCP server for DataForSEO API — browse documentation and make authenticated API requests

34 lines • 1.31 kB
import { API_BASE_URL } from "../../config/index.js"; import { getUserAgent } from "../version.js"; import { buildAuthHeader, getCredentials, } from "./auth.js"; import { resolveOutboundUserAgent } from "./user-agent.js"; export async function makeApiRequest(options) { const authorization = options.authHeader ?? buildAuthHeader(options.credentials ?? getCredentials()); const url = options.path.startsWith("http") ? options.path : `${API_BASE_URL}${options.path.startsWith("/") ? "" : "/"}${options.path}`; const headers = { Authorization: authorization, "User-Agent": resolveOutboundUserAgent(getUserAgent()), }; const method = options.method.toUpperCase(); const init = { method, headers }; if (options.body && method !== "GET" && method !== "HEAD") { headers["Content-Type"] = "application/json"; init.body = options.body; } const response = await fetch(url, init); const body = await response.text(); const responseHeaders = {}; response.headers.forEach((value, key) => { responseHeaders[key] = value; }); return { status: response.status, statusText: response.statusText, headers: responseHeaders, body, }; } //# sourceMappingURL=client.js.map