Skip to main content
Glama
mgraczyk

JSON Query MCP

by mgraczyk

json_query_search_values

Search large JSON files for specific values without knowing their exact paths. Input a search term and file path to retrieve matching results, limited to a specified number.

Instructions

Search for values in a JSON file. Use when you do not know the path to a value in a large JSON file, but have some idea what the value is.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesAbsolute path to the JSON file.
limitNoMaximum number of results to return (default: 5)
queryYesSearch term for finding matching values

Implementation Reference

  • Core handler logic for the tool: recursively traverses JSON, collects string/number values with paths, computes similarity to query, returns top matches.
    static async searchValues(query: string, jsonFile: string, limit = 5): Promise<SearchResult[]> {
      const data = await this.readJsonFile(jsonFile);
      const valuePaths: { path: string; value: unknown }[] = [];
    
      const collectValues = (obj: unknown, path = '$'): void => {
        if (obj && typeof obj === 'object') {
          if (Array.isArray(obj)) {
            obj.forEach((item, index) => {
              const newPath = `${path}[${index.toString()}]`;
              if (typeof item === 'string' || typeof item === 'number') {
                valuePaths.push({ path: newPath, value: item });
              }
              collectValues(item, newPath);
            });
          } else {
            Object.entries(obj).forEach(([key, value]) => {
              const newPath = path === '$' ? `$.${key}` : `${path}.${key}`;
              if (typeof value === 'string' || typeof value === 'number') {
                valuePaths.push({ path: newPath, value });
              }
              collectValues(value, newPath);
            });
          }
        }
      };
    
      collectValues(data);
    
      const stringQuery = String(query).toLowerCase();
      const matches = valuePaths
        .filter((item) => typeof item.value === 'string' || typeof item.value === 'number')
        .map((item) => ({
          path: item.path,
          similarity: stringSimilarity.compareTwoStrings(
            stringQuery,
            String(item.value).toLowerCase(),
          ),
          value: item.value,
        }));
    
      return matches.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
    }
  • src/server.ts:99-132 (registration)
    Registers the tool 'json_query_search_values' with description, Zod input schema, and wrapper handler that calls JsonUtils.searchValues.
    server.tool(
      'json_query_search_values',
      'Search for values in a JSON file. Use when you do not know the path to a value in a large JSON file, but have some idea what the value is.',
      {
        file_path: z.string().describe(PATH_ARG_DESCRIPTION),
        query: z.string().min(1).describe('Search term for finding matching values'),
        limit: z
          .number()
          .int()
          .min(1)
          .max(100)
          .optional()
          .default(5)
          .describe('Maximum number of results to return (default: 5)'),
      },
      async ({ file_path, query, limit }) => {
        try {
          const resolvedPath = path.resolve(file_path);
    
          const results = await JsonUtils.searchValues(query, resolvedPath, limit);
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(results, null, 2),
              },
            ],
          };
        } catch (error) {
          return getErrorResponse(error);
        }
      },
    );
  • Zod schema defining the input parameters for the tool: file_path (string), query (string), limit (number, optional default 5).
    {
      file_path: z.string().describe(PATH_ARG_DESCRIPTION),
      query: z.string().min(1).describe('Search term for finding matching values'),
      limit: z
        .number()
        .int()
        .min(1)
        .max(100)
        .optional()
        .default(5)
        .describe('Maximum number of results to return (default: 5)'),
    },
  • TypeScript interface defining the output structure for search results: path, similarity score, optional value.
    export interface SearchResult {
      path: string;
      similarity: number;
      value?: unknown;
    }
  • Helper method to read and parse JSON file from disk, used by searchValues.
    private static async readJsonFile(filePath: string): Promise<unknown> {
      try {
        const content = await fs.readFile(filePath, 'utf-8');
        return JSON.parse(content);
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to read or parse JSON file: ${error}`);
        } else {
          throw new Error('Failed to read or parse JSON file');
        }
      }
    }
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 of behavioral disclosure. It mentions searching in 'a large JSON file' and returning results based on a query, but it lacks details on how the search works (e.g., case-sensitivity, partial matches), what the output format is, or any performance considerations like rate limits. This leaves significant gaps for an agent to understand the tool's behavior fully.

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 sentences that are front-loaded and efficient. The first sentence states the purpose, and the second provides usage guidelines, with no wasted words. It's appropriately sized for the tool's complexity and easy for an agent to parse.

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

Completeness3/5

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

Given the tool has no annotations and no output schema, the description is incomplete. It covers the basic purpose and usage but lacks details on behavioral traits, output format, and error handling. For a search tool with three parameters, this leaves the agent with insufficient context to use it effectively beyond the basics.

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?

The input schema has 100% description coverage, so the schema already documents all parameters (file_path, limit, query) well. The description adds minimal value by implying the query is for 'matching values' and the file is 'large,' but it doesn't provide additional syntax or format details beyond what the schema offers. This meets the baseline for high schema coverage.

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: 'Search for values in a JSON file.' It specifies the verb 'search' and resource 'values in a JSON file,' and distinguishes it from siblings by noting it's for when 'you do not know the path to a value.' However, it doesn't explicitly name the sibling tools or detail how they differ in functionality, keeping it from a perfect score.

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

Usage Guidelines4/5

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

The description provides clear context on when to use this tool: 'Use when you do not know the path to a value in a large JSON file, but have some idea what the value is.' This gives a specific scenario and implies alternatives (like path-based queries), but it doesn't explicitly name the sibling tools or state when not to use it, which prevents a score of 5.

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