|
1 | | -import { z } from 'zod' |
2 | 1 | import * as LZString from 'lz-string' |
| 2 | +import { z } from 'zod' |
3 | 3 |
|
4 | 4 | import type { GraphQLMCP } from '../graphql.app' |
5 | 5 |
|
@@ -72,13 +72,13 @@ const graphQLErrorSchema = z.object({ |
72 | 72 | timestamp: z.string(), |
73 | 73 | ray_id: z.string(), |
74 | 74 | }), |
75 | | -}); |
76 | | - |
| 75 | +}) |
| 76 | + |
77 | 77 | // Define the overall GraphQL response schema |
78 | 78 | const graphQLResponseSchema = z.object({ |
79 | 79 | data: z.union([z.record(z.unknown()), z.null()]), |
80 | 80 | errors: z.union([z.array(graphQLErrorSchema), z.null()]), |
81 | | -}); |
| 81 | +}) |
82 | 82 |
|
83 | 83 | /** |
84 | 84 | * Fetches the high-level overview of the GraphQL schema |
@@ -1009,7 +1009,9 @@ export function registerGraphQLTools(agent: GraphQLMCP) { |
1009 | 1009 |
|
1010 | 1010 | // Generate GraphQL API Explorer link for this query |
1011 | 1011 | const compressedQuery = LZString.compressToEncodedURIComponent(query) |
1012 | | - const compressedVariables = LZString.compressToEncodedURIComponent(JSON.stringify(variables)) |
| 1012 | + const compressedVariables = LZString.compressToEncodedURIComponent( |
| 1013 | + JSON.stringify(variables) |
| 1014 | + ) |
1013 | 1015 | const explorerUrl = `https://graphql.cloudflare.com/explorer?query=${compressedQuery}&variables=${compressedVariables}` |
1014 | 1016 |
|
1015 | 1017 | // Check if the response is too large (MCP server will fail if > 1MB) |
@@ -1075,32 +1077,34 @@ export function registerGraphQLTools(agent: GraphQLMCP) { |
1075 | 1077 | async (params) => { |
1076 | 1078 | try { |
1077 | 1079 | const { query, variables = {} } = params |
1078 | | - |
| 1080 | + |
1079 | 1081 | // Compress the query and variables using lz-string |
1080 | 1082 | const compressedQuery = LZString.compressToEncodedURIComponent(query) |
1081 | | - const compressedVariables = LZString.compressToEncodedURIComponent(JSON.stringify(variables)) |
1082 | | - |
| 1083 | + const compressedVariables = LZString.compressToEncodedURIComponent( |
| 1084 | + JSON.stringify(variables) |
| 1085 | + ) |
| 1086 | + |
1083 | 1087 | // Generate the GraphQL API Explorer URL |
1084 | 1088 | const explorerUrl = `https://graphql.cloudflare.com/explorer?query=${compressedQuery}&variables=${compressedVariables}` |
1085 | | - |
| 1089 | + |
1086 | 1090 | return { |
1087 | 1091 | content: [ |
1088 | 1092 | { |
1089 | 1093 | type: 'text', |
1090 | | - text: `**[Open in GraphQL Explorer](${explorerUrl})**\n\nYou can click the link above to open the Cloudflare GraphQL API Explorer with your query pre-populated.\n\n**Query:**\n\`\`\`graphql\n${query}\n\`\`\`\n\n${Object.keys(variables).length > 0 ? `**Variables:**\n\`\`\`json\n${JSON.stringify(variables, null, 2)}\n\`\`\`\n` : ''}` |
1091 | | - } |
1092 | | - ] |
| 1094 | + text: `**[Open in GraphQL Explorer](${explorerUrl})**\n\nYou can click the link above to open the Cloudflare GraphQL API Explorer with your query pre-populated.\n\n**Query:**\n\`\`\`graphql\n${query}\n\`\`\`\n\n${Object.keys(variables).length > 0 ? `**Variables:**\n\`\`\`json\n${JSON.stringify(variables, null, 2)}\n\`\`\`\n` : ''}`, |
| 1095 | + }, |
| 1096 | + ], |
1093 | 1097 | } |
1094 | 1098 | } catch (error) { |
1095 | 1099 | return { |
1096 | 1100 | content: [ |
1097 | 1101 | { |
1098 | 1102 | type: 'text', |
1099 | 1103 | text: JSON.stringify({ |
1100 | | - error: `Error generating GraphQL API Explorer link: ${error instanceof Error ? error.message : String(error)}` |
1101 | | - }) |
1102 | | - } |
1103 | | - ] |
| 1104 | + error: `Error generating GraphQL API Explorer link: ${error instanceof Error ? error.message : String(error)}`, |
| 1105 | + }), |
| 1106 | + }, |
| 1107 | + ], |
1104 | 1108 | } |
1105 | 1109 | } |
1106 | 1110 | } |
|
0 commit comments