Skip to main content
Glama
introspection.ts875 B
import { buildClientSchema, getIntrospectionQuery, printSchema } from "graphql"; import { readFile } from "node:fs/promises"; /** * Introspect a GraphQL endpoint and return the schema as the GraphQL SDL * @param endpoint - The endpoint to introspect * @returns The schema */ export async function introspectEndpoint( endpoint: string, headers?: Record<string, string>, ) { const response = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json", ...headers, }, body: JSON.stringify({ query: getIntrospectionQuery(), }), }); if (!response.ok) { throw new Error(`GraphQL request failed: ${response.statusText}`); } const responseJson = (await response.json()) as any; // Transform to a schema object const schema = buildClientSchema(responseJson.data); // Print the schema SDL return printSchema(schema); }

Implementation Reference

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/FabrWill/gql-mcp'

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