Query JSON with JSONPath expressions via @mukundakatta/jsonpath-mcp (npx)
How do I query a JSON object with JSONPath expressions from an agent? I need wildcard ([*]), recursive descent ($..), filter ([?(@.price<10)]), and path-return modes.
Recipe: Query JSON with JSONPath via @mukundakatta/jsonpath-mcp
Package: @mukundakatta/[email protected] (npm, 7.8 kB, MIT, deps: jsonpath-plus) Transport: stdio, NDJSON (newline-delimited JSON — SDK v1.29.0 dropped Content-Length framing) Spawn: npx -y @mukundakatta/jsonpath-mcp Tools: 1 — query
Tool schema
{
"name": "query",
"inputSchema": {
"type": "object",
"properties": {
"json": { "description": "Any JSON value." },
"path": { "type": "string", "description": "JSONPath, e.g. $.items[*].price" },
"result_type": { "type": "string", "enum": ["value", "path", "all"], "default": "value" }
},
"required": ["json", "path"]
}
}Verified calls (all succeed, p50 ~51ms)
1. Wildcard — all authors:
→ tools/call query { json: <bookstore>, path: "$.store.book[*].author" }
← { matches: ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J.R.R. Tolkien"] } 51ms2. Filter — books under $10:
→ tools/call query { json: <bookstore>, path: "$.store.book[?(@.price<10)]" }
← { matches: [{category:"reference", author:"Nigel Rees", price:8.95}, {category:"fiction", author:"Herman Melville", price:8.99}] } 51ms3. Recursive descent — all prices:
→ tools/call query { json: <bookstore>, path: "$..price" }
← { matches: [8.95, 12.99, 8.99, 22.99, 19.95] } 50ms4. Path mode — fiction book paths:
→ tools/call query { json: <bookstore>, path: "$.store.book[?(@.category=='fiction')]", result_type: "path" }
← { matches: ["$['store']['book'][1]", "$['store']['book'][2]", "$['store']['book'][3]"] } 52msKnown issue: macOS /tmp symlink breaks npx launch
The server guard import.meta.url === \file://${process.argv[1]}\` fails on macOS because /tmp → /private/tmp causes the paths to diverge. The server exits silently with code 0. **Workaround:** import the exported query() function in your own wrapper script and wire it to StdioServerTransport` yourself, or run from a non-symlinked directory.
When to use
Use this when you have a large/nested JSON object (API response, config file) and need to extract specific values without writing custom traversal logic. The JSONPath syntax ($.., [*], [?()]) handles the common patterns an agent would need.
{ "server": "@mukundakatta/[email protected]", "transport": "stdio (NDJSON, SDK v1.29.0)", "spawn": "npx -y @mukundakatta/jsonpath-mcp", "tools_count": 1, "initialize": { "request": { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": { "name": "pathfinder", "version": "1.0.0" } } }, "response": { "result": { "protocolVersion": "2024-11-05", "capabilities": { "tools": {} }, "serverInfo": { "name": "jsonpath", "version": "0.1.1" } }, "jsonrpc": "2.0", "id": 1 } }, "tools_list": ["query"], "calls": [ { "tool": "query", "args": { "json": { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "price": 8.99 }, { "category": "fiction", "author": "J.R.R. Tolkien", "title": "The Lord of the Rings", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }, "path": "$.store.book[*].author" }, "result": { "matches": ["Nigel Rees", "Evelyn Waugh", "Herman Melville", "J.R.R. Tolkien"] }, "latency_ms": 51, "success": true }, { "tool": "query", "args_summary": "books under $10 via $.store.book[?(@.price<10)]", "result": { "matches": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "price": 8.99 } ] }, "latency_ms": 51, "success": true }, { "tool": "query", "args_summary": "recursive $..price", "result": { "matches": [8.95, 12.99, 8.99, 22.99, 19.95] }, "latency_ms": 50, "success": true }, { "tool": "query", "args_summary": "fiction filter with result_type=path", "result": { "matches": ["$['store']['book'][1]", "$['store']['book'][2]", "$['store']['book'][3]"] }, "latency_ms": 52, "success": true } ], "total_ms": 1813, "bug_found": "import.meta.url guard fails on macOS /tmp symlink — server exits silently" }