introspect
Retrieve and analyze the schema of a GraphQL API to ensure accurate query construction. Use this tool to access schema details when direct resources are unavailable.
Instructions
Introspect the GraphQL schema, use this tool before doing a query to get the schema information if you do not have it available as a resource already.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| __ignore__ | No | This does not do anything |
Implementation Reference
- src/index.ts:89-112 (handler)Handler function that executes the 'introspect' tool logic by calling the helper function and returning the schema as MCP text content or error.async () => { try { const schema = await introspectEndpoint(env.ENDPOINT, env.HEADERS); return { content: [ { type: "text", text: schema, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Failed to introspect schema: ${error}`, }, ], }; } }
- src/index.ts:82-88 (schema)Zod input schema for the 'introspect' tool, using a dummy __ignore__ field to handle empty inputs.// This is a workaround to help clients that can't handle an empty object as an argument // They will often send undefined instead of an empty object which is not allowed by the schema __ignore__: z .boolean() .default(false) .describe("This does not do anything"), },
- src/index.ts:78-114 (registration)Registration of the 'introspect' MCP tool via server.tool, including name, description, schema, and handler.server.tool( "introspect", "Introspect the GraphQL schema, use this tool before doing a query to get the schema information if you do not have it available as a resource already.", { // This is a workaround to help clients that can't handle an empty object as an argument // They will often send undefined instead of an empty object which is not allowed by the schema __ignore__: z .boolean() .default(false) .describe("This does not do anything"), }, async () => { try { const schema = await introspectEndpoint(env.ENDPOINT, env.HEADERS); return { content: [ { type: "text", text: schema, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text", text: `Failed to introspect schema: ${error}`, }, ], }; } } );
- src/helpers/introspection.ts:8-33 (helper)Helper function that performs GraphQL introspection query on the endpoint and returns the schema in SDL format.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); }