Skip to main content
Glama
mgraczyk

JSON Query MCP

by mgraczyk

json_query_jsonpath

Extract specific data from large JSON files by evaluating JSONPath expressions. Ideal for precise querying and retrieving values within complex JSON structures.

Instructions

Query a JSON file using JSONPath. Use to get values precisely from large JSON files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesAbsolute path to the JSON file.
jsonpathYesJSONPath expression to evaluate

Implementation Reference

  • src/server.ts:35-60 (registration)
    Registers the 'json_query_jsonpath' tool using McpServer.tool, including description, input schema with Zod, and inline async handler.
    server.tool(
      'json_query_jsonpath',
      'Query a JSON file using JSONPath. Use to get values precisely from large JSON files.',
      {
        file_path: z.string().describe(PATH_ARG_DESCRIPTION),
        jsonpath: z.string().min(1).describe('JSONPath expression to evaluate'),
      },
      async ({ file_path, jsonpath }) => {
        try {
          const resolvedPath = path.resolve(file_path);
    
          const results = await JsonUtils.queryByJsonPath(jsonpath, resolvedPath);
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(results, null, 2),
              },
            ],
          };
        } catch (error) {
          return getErrorResponse(error);
        }
      },
    );
  • The tool handler function that resolves the file path, delegates to JsonUtils.queryByJsonPath, formats the result as MCP content, and handles errors.
    async ({ file_path, jsonpath }) => {
      try {
        const resolvedPath = path.resolve(file_path);
    
        const results = await JsonUtils.queryByJsonPath(jsonpath, resolvedPath);
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(results, null, 2),
            },
          ],
        };
      } catch (error) {
        return getErrorResponse(error);
      }
    },
  • Core helper method that reads the JSON file, applies JSONPath query using jsonpath-plus library, and returns array of path-value results.
    static async queryByJsonPath(path: string, jsonFile: string): Promise<JsonPathResult[]> {
      const data = await this.readJsonFile(jsonFile);
    
      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
      const results = JSONPath({
        path,
        json: data as object,
        resultType: 'all',
      }) as { path: string; value: unknown }[];
    
      return results.map((result) => ({
        path: result.path,
        value: result.value,
      }));
    }
  • Zod schema defining input parameters: file_path (string) and jsonpath (non-empty string).
      file_path: z.string().describe(PATH_ARG_DESCRIPTION),
      jsonpath: z.string().min(1).describe('JSONPath expression to evaluate'),
    },
  • TypeScript interface defining the output structure for JSONPath query results.
    export interface JsonPathResult {
      path: string;
      value: unknown;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the tool 'gets values' (read operation) and works on 'large JSON files,' but lacks details on error handling (e.g., invalid paths, file not found), performance considerations, or output format. For a tool with no annotations, this leaves significant behavioral gaps.

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 two concise sentences with zero waste. It's front-loaded with the core purpose and follows with a usage hint. Every word earns its place, making it easy to parse quickly.

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 no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., matched values, errors), how results are structured, or any limitations (e.g., JSONPath support level). For a query tool with two parameters, this leaves too much unspecified for reliable 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%, so the schema already documents both parameters (file_path, jsonpath) adequately. The description adds no additional parameter semantics beyond what's in the schema (e.g., no examples of JSONPath expressions or file path constraints). Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Query a JSON file using JSONPath' specifies the verb (query) and resource (JSON file). It distinguishes from siblings by mentioning 'JSONPath' (vs. search_keys/search_values) but doesn't explicitly contrast them. The purpose is specific and actionable.

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

Usage Guidelines3/5

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

The description provides some usage context: 'Use to get values precisely from large JSON files' implies when to use it (for precise extraction from large files). However, it doesn't explicitly state when to choose this tool over siblings (json_query_search_keys, json_query_search_values) or any exclusions. The guidance is implied rather than explicit.

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/mgraczyk/json-query-mcp'

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