introspect-schema
Analyze GraphQL schemas to retrieve type definitions, directives, and descriptions. Filter results to focus on specific types for targeted schema exploration.
Instructions
Introspect the GraphQL schema. Optionally filter to specific types.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| typeNames | No | A list of specific type names to filter the introspection. | |
| descriptions | No | ||
| directives | No |
Implementation Reference
- src/index.ts:94-121 (handler)The main asynchronous handler function implementing the 'introspect-schema' tool. It handles optional typeNames filtering by calling introspectTypes, otherwise fetches the full schema using endpoint configuration or local/URL schema, and returns the schema as text content or error.const introspectSchemaHandler = async ({ typeNames, descriptions = true, directives = true }: any) => { if (typeNames === null) { typeNames = undefined; } try { if (typeNames && typeNames.length > 0) { const filtered = await introspectTypes(env.ENDPOINT, env.HEADERS, typeNames); return { content: [{ type: "text", text: filtered }] }; } else { let schema; if (env.SCHEMA) { if (env.SCHEMA.startsWith("http://") || env.SCHEMA.startsWith("https://")) { schema = await introspectSchemaFromUrl(env.SCHEMA); } else { schema = await introspectLocalSchema(env.SCHEMA); } } else { schema = await introspectEndpoint(env.ENDPOINT, env.HEADERS); } return { content: [{ type: "text", text: schema }] }; } } catch (error) { return { isError: true, content: [{ type: "text", text: `Introspection failed: ${error}` }], }; } };
- src/index.ts:127-131 (schema)Zod input schema for the 'introspect-schema' tool parameters: typeNames (optional array of strings), descriptions and directives (optional booleans defaulting to true).{ typeNames: z.array(z.string()).optional().describe("A list of specific type names to filter the introspection."), descriptions: z.boolean().optional().default(true), directives: z.boolean().optional().default(true), },
- src/index.ts:124-133 (registration)MCP server.tool registration for the 'introspect-schema' tool, including name, description, input schema, and handler binding.server.tool( "introspect-schema", "Introspect the GraphQL schema. Optionally filter to specific types.", { typeNames: z.array(z.string()).optional().describe("A list of specific type names to filter the introspection."), descriptions: z.boolean().optional().default(true), directives: z.boolean().optional().default(true), }, introspectSchemaHandler );
- src/index.ts:122-122 (registration)Internal toolHandlers Map registration for HTTP transport handling.toolHandlers.set("introspect-schema", introspectSchemaHandler);
- src/helpers/introspection.ts:21-46 (helper)Helper function to introspect a remote GraphQL endpoint using getIntrospectionQuery and return the schema SDL.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(); // Transform to a schema object const schema = buildClientSchema((responseJson as any).data); // Print the schema SDL return printSchema(schema); }