Skip to main content
Glama
ctkadvisors

GraphQL MCP Server

by ctkadvisors

languages

Query and filter language data using GraphQL to integrate and manage multilingual content in applications via the MCP server.

Instructions

GraphQL languages query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNofilter - Input type: LanguageFilterInput

Implementation Reference

  • The 'tools/list' RPC handler fetches the GraphQL schema and generates the list of available tools using getToolsFromSchema(), which dynamically includes the 'languages' tool corresponding to the 'languages' query field.
    const schema = await fetchSchema();
    const queryTools = getToolsFromSchema(schema);
    
    // Only include mutations if they are enabled
    const mutationTools = ENABLE_MUTATIONS ? getToolsFromMutationType(schema) : [];
    const allTools = [...queryTools, ...mutationTools];
    
    log(
      "info",
      `Returning ${allTools.length} tools (${queryTools.length} queries, ${mutationTools.length} mutations${!ENABLE_MUTATIONS ? ' - mutations disabled' : ''})`
    );
    
    const response: JSONRPCResponse = {
      jsonrpc: "2.0",
      id,
      result: {
        tools: allTools,
      },
    };
    console.log(JSON.stringify(response));
  • Within getToolsFromSchema(), this code block creates the MCPTool definition for each query field (including 'languages'), setting its name, description, and inputSchema derived from the field's GraphQL arguments.
    // Create a tool for this field - Truncate name to 64 characters if needed
    const truncatedName =
      fieldName.length > 64 ? fieldName.substring(0, 64) : fieldName;
    
    // Store mapping from truncated to original name if truncation occurred
    if (truncatedName !== fieldName) {
      toolNameMappings[truncatedName] = fieldName;
    }
    
    const tool: MCPTool = {
      name: truncatedName,
      description: field.description || `GraphQL ${fieldName} query`,
      inputSchema: {
        type: "object",
        properties: properties,
        required: required,
      },
    };
  • In the 'tools/call' RPC handler, tool calls are dispatched based on name; for 'languages' (not a mutation), it calls executeGraphQLTool(name, args).
    const isMutation = name.startsWith("mutation_");
    
    // Check if mutations are enabled
    if (isMutation && !ENABLE_MUTATIONS) {
      log("error", `Mutation ${name} called but mutations are disabled`);
      const response: JSONRPCResponse = {
        jsonrpc: "2.0",
        id,
        error: {
          code: -32000,
          message: "Mutations are disabled. Set ENABLE_MUTATIONS=true to enable them.",
        },
      };
      console.log(JSON.stringify(response));
      return;
  • The core handler function for query tools like 'languages'. It fetches the schema, looks up the GraphQL field by name, processes arguments, dynamically generates a GraphQL query (including selection set via analyzeFields), and executes it.
    async function executeGraphQLTool(
      name: string,
      args: Record<string, any> | undefined
    ): Promise<any> {
      try {
        // If this name is in our mapping, use the original field name
        const actualFieldName = toolNameMappings[name] || name;
    
        // Check if the tool is in the whitelist (if whitelist is enabled)
        if (WHITELISTED_QUERIES && !WHITELISTED_QUERIES.includes(actualFieldName)) {
          throw new Error(`Tool '${actualFieldName}' is not in the whitelist`);
        }
    
        // Get the schema
        const schema = await fetchSchema();
        if (!schema) {
          throw new Error("Schema not available");
        }
    
        // Get the query type
        const queryType = schema.getQueryType();
        if (!queryType) {
          throw new Error("Schema has no query type");
        }
    
        // Get the field for this tool using the resolved field name
        const fields = queryType.getFields();
        const field = fields[actualFieldName];
    
        if (!field) {
          throw new Error(`Unknown field: ${actualFieldName}`);
        }
    
        try {
          // Process input arguments
          const processedArgs = processArguments(args, field.args, schema);
    
          // Get return type and analyze it
          const returnType = getNamedType(field.type);
    
          // First determine which arguments are actually being used
          const usedArgNames: string[] = [];
          field.args.forEach((arg) => {
            if (processedArgs && processedArgs[arg.name] !== undefined) {
              usedArgNames.push(arg.name);
            }
          });
    
          // Build variables definition - only for arguments that are actually used
          const varDefs = field.args
            .filter((arg) => usedArgNames.includes(arg.name))
            .map((arg) => {
              // Need to preserve non-null and list wrappers in variable definitions
              const typeStr = arg.type.toString();
              return `$${arg.name}: ${typeStr}`;
            })
            .filter(Boolean)
            .join(", ");
    
          // Build field arguments - only for arguments that are actually used
          const fieldArgs = usedArgNames
            .map((argName) => {
              return `${argName}: $${argName}`;
            })
            .join(", ");
    
          // Build selection set based on return type
          let selectionSet = "";
    
          if (isObjectType(returnType)) {
            // For objects or lists of objects, analyze fields
            const fields = analyzeFields(returnType, schema);
            selectionSet = buildSelectionSet(fields);
          } else if (isListType(returnType)) {
            // For lists, unwrap and analyze the inner type
            const innerType = getNamedType(returnType.ofType);
            if (isObjectType(innerType)) {
              const fields = analyzeFields(innerType as GraphQLObjectType, schema);
              selectionSet = buildSelectionSet(fields);
            }
          }
    
          // Build the final query
          // Only include variable definitions if fieldArgs is used
          const shouldIncludeVarDefs = fieldArgs && fieldArgs.length > 0;
          const query = `
            query ${name}Query${shouldIncludeVarDefs ? `(${varDefs})` : ""} {
              ${name}${fieldArgs && fieldArgs.length > 0 ? `(${fieldArgs})` : ""} ${
            selectionSet ? `{\n${selectionSet}  }` : ""
          }
            }
          `;
    
          log("debug", `Generated query for ${name}:`, {
            query,
            variables: processedArgs,
          });
    
          // Execute the query
          return await executeQuery({ query, variables: processedArgs });
        } catch (error) {
          throw new Error(
            `Error executing query for ${name}: ${
              error instanceof Error ? error.message : String(error)
            }`
          );
        }
      } catch (error) {
        log(
          "error",
          `Error executing tool ${name}: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but provides almost none. 'GraphQL languages query' implies a read operation but doesn't specify what data is returned, whether there are rate limits, authentication requirements, pagination behavior, or any other operational characteristics. The description adds minimal value beyond the implied query nature.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just three words with zero wasted language. While it's under-specified, it's not verbose or poorly structured - it's front-loaded with the essential information that this is a GraphQL query for languages.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given a tool with 1 parameter (including a nested object), no annotations, no output schema, and multiple sibling tools, the description is severely incomplete. It doesn't explain what the tool returns, how it differs from similar tools, what the filter parameter actually does, or provide any operational context needed for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% (the single 'filter' parameter has a description), so the baseline is 3. The tool description doesn't add any meaningful information about parameters beyond what's already in the schema - it doesn't explain what LanguageFilterInput contains, what filtering capabilities exist, or provide examples of filter usage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'GraphQL languages query' is a tautology that essentially restates the tool name 'languages' with the addition of 'GraphQL query' - it doesn't specify what the tool actually does beyond being a query. It doesn't distinguish this from sibling tools like 'language' (singular) or explain what 'languages' refers to in this context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is absolutely no guidance about when to use this tool versus alternatives. The description provides no context about when this query should be used instead of sibling tools like 'language', 'countries', or 'continents', nor does it mention any prerequisites or constraints for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/ctkadvisors/graphql-mcp'

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