Skip to main content
Glama
GongRzhe

JSON MCP Server

filter

Filter JSON data by applying conditions to specific JSONPath expressions. Retrieve targeted data from a JSON source URL based on defined criteria, enabling precise data extraction for analysis or manipulation.

Instructions

Filter JSON data using conditions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conditionYesFilter condition (e.g. @.price < 10)
jsonPathYesBase JSONPath expression
urlYesURL of the JSON data source

Implementation Reference

  • Handler logic for the 'filter' tool within the CallToolRequestSchema handler. Fetches JSON from URL, extracts base data using jsonPath, and applies filtering based on condition string using inline comparison logic for >, <, >=, <=, ==, != operators.
    const { url, jsonPath, condition } = FilterArgumentsSchema.parse(args);
    const jsonData = await fetchData(url);
    
    // Get base data using jsonPath
    let baseData = JSONPath.value(jsonData, jsonPath);
    if (!Array.isArray(baseData)) {
        baseData = [baseData];
    }
    
    // Apply filter condition
    const result = baseData.filter((item: Record<string, any>) => {
        try {
            // Handle common comparison operators
            if (condition.includes(' > ')) {
                const [field, value] = condition.split(' > ').map(s => s.trim());
                const fieldName = field.replace('@.', '');
                return Number(item[fieldName]) > Number(value);
            }
            if (condition.includes(' < ')) {
                const [field, value] = condition.split(' < ').map(s => s.trim());
                const fieldName = field.replace('@.', '');
                return Number(item[fieldName]) < Number(value);
            }
            if (condition.includes(' >= ')) {
                const [field, value] = condition.split(' >= ').map(s => s.trim());
                const fieldName = field.replace('@.', '');
                return Number(item[fieldName]) >= Number(value);
            }
            if (condition.includes(' <= ')) {
                const [field, value] = condition.split(' <= ').map(s => s.trim());
                const fieldName = field.replace('@.', '');
                return Number(item[fieldName]) <= Number(value);
            }
            if (condition.includes(' == ')) {
                const [field, value] = condition.split(' == ').map(s => s.trim());
                const fieldName = field.replace('@.', '');
                const compareValue = value.startsWith('"') || value.startsWith("'") 
                    ? value.slice(1, -1) 
                    : Number(value);
                return item[fieldName] == compareValue;
            }
            if (condition.includes(' != ')) {
                const [field, value] = condition.split(' != ').map(s => s.trim());
                const fieldName = field.replace('@.', '');
                const compareValue = value.startsWith('"') || value.startsWith("'") 
                    ? value.slice(1, -1) 
                    : Number(value);
                return item[fieldName] != compareValue;
            }
            
            return false;
        } catch {
            return false;
        }
    });
    
    return {
        content: [{ 
            type: "text", 
            text: JSON.stringify(result, null, 2)
        }]
    };
  • Zod validation schema for filter tool arguments: url (string URL), jsonPath (string), condition (string). Used to parse inputs in the handler.
    const FilterArgumentsSchema = z.object({
        url: z.string().url(),
        jsonPath: z.string(),
        condition: z.string(),
    });
  • src/index.ts:424-444 (registration)
    Tool registration in ListToolsRequestSchema handler. Defines 'filter' tool with name, description, and inputSchema matching the Zod schema.
        name: "filter",
        description: "Filter JSON data using conditions",
        inputSchema: {
            type: "object",
            properties: {
                url: {
                    type: "string",
                    description: "URL of the JSON data source",
                },
                jsonPath: {
                    type: "string",
                    description: "Base JSONPath expression",
                },
                condition: {
                    type: "string",
                    description: "Filter condition (e.g. @.price < 10)",
                }
            },
            required: ["url", "jsonPath", "condition"],
        },
    }
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. While 'Filter' implies a read-only operation, the description doesn't clarify whether this tool fetches data from a URL, processes it locally, or has any side effects like caching. It also omits details about error handling, performance, or output format, leaving significant gaps in understanding the tool's behavior.

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

Conciseness4/5

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

The description is a single, efficient sentence with no wasted words, making it appropriately concise. However, it lacks front-loading of critical information—it doesn't immediately clarify the tool's scope or differentiate it from siblings, which slightly reduces its effectiveness despite the brevity.

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 the complexity of a tool that filters JSON data from a URL with three required parameters and no output schema, the description is incomplete. It fails to explain the output format, error conditions, or how the filtering integrates with the data source. Without annotations or an output schema, the agent lacks sufficient context to use the tool effectively.

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%, meaning the input schema already documents all three parameters with descriptions. The tool description adds no additional meaning beyond what the schema provides, such as explaining how parameters interact or providing usage examples. However, since the schema is comprehensive, the baseline score of 3 is appropriate.

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

Purpose3/5

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

The description 'Filter JSON data using conditions' states the tool's purpose with a clear verb ('Filter') and resource ('JSON data'), but it's vague about scope and doesn't distinguish from its sibling 'query'. It doesn't specify what kind of filtering or what the output looks like, leaving the agent uncertain about the exact operation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus its sibling 'query', nor does it mention any prerequisites or alternative scenarios. Without any context about when this tool is appropriate, the agent must guess based on the tool name alone.

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/GongRzhe/JSON-MCP-Server'

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