Skip to main content

An MCP server for fetching and extracting JSON data using JSONPath

Project description

Fetch JSONPath MCP

A Model Context Protocol (MCP) server that provides tools for fetching and extracting JSON data from URLs using JSONPath patterns.

🎯 Why Use This?

Reduce LLM Token Usage & Hallucination - Instead of fetching entire JSON responses and wasting tokens, extract only the data you need.

Traditional Fetch vs JSONPath Extract

❌ Traditional fetch (wasteful):

// API returns 2000+ tokens
{
  "data": [
    {
      "id": 1,
      "name": "Alice",
      "email": "alice@example.com", 
      "avatar": "https://...",
      "profile": {
        "bio": "Long bio text...",
        "settings": {...},
        "preferences": {...},
        "metadata": {...}
      },
      "posts": [...],
      "followers": [...],
      "created_at": "2023-01-01",
      "updated_at": "2024-01-01"
    },
    // ... 50 more users
  ],
  "pagination": {...},
  "meta": {...}
}

✅ JSONPath extract (efficient):

// Only 10 tokens - exactly what you need!
["Alice", "Bob", "Charlie"]

Using pattern: data[*].name saves 99% tokens and eliminates model hallucination from irrelevant data.

Quick Start

1. Install Dependencies

uv sync

2. Start Demo Server (Optional)

# Install demo server dependencies
uv add fastapi uvicorn

# Start demo server on port 8080
uv run demo-server

3. Run MCP Server

uv run fetch-jsonpath-mcp

Available Tools

get-json

Extract JSON data using JSONPath patterns.

{
  "name": "get-json",
  "arguments": {
    "url": "http://localhost:8080",
    "pattern": "foo[*].baz"
  }
}

Returns: [1, 2]

get-text

Get raw text content from any URL.

{
  "name": "get-text",
  "arguments": {
    "url": "http://localhost:8080"
  }
}

batch-get-json

Process multiple URLs with different JSONPath patterns.

{
  "name": "batch-get-json",
  "arguments": {
    "requests": [
      {"url": "http://localhost:8080", "pattern": "foo[*].baz"},
      {"url": "http://localhost:8080", "pattern": "bar.items[*]"}
    ]
  }
}

batch-get-text

Get text content from multiple URLs.

{
  "name": "batch-get-text",
  "arguments": {
    "urls": ["http://localhost:8080", "http://localhost:8080"]
  }
}

Demo Server Data

The demo server at http://localhost:8080 returns:

{
  "foo": [{"baz": 1, "qux": "a"}, {"baz": 2, "qux": "b"}],
  "bar": {
    "items": [10, 20, 30], 
    "config": {"enabled": true, "name": "example"}
  },
  "metadata": {"version": "1.0.0"}
}

JSONPath Examples

This project uses jsonpath-ng for JSONPath implementation.

Pattern Result Description
foo[*].baz [1, 2] Get all baz values
bar.items[*] [10, 20, 30] Get all items
metadata.version ["1.0.0"] Get version

For complete JSONPath syntax reference, see the jsonpath-ng documentation.

🚀 Performance Benefits

  • Token Efficiency: Extract only needed data, not entire JSON responses
  • Faster Processing: Smaller payloads = faster LLM responses
  • Reduced Hallucination: Less irrelevant data = more accurate outputs
  • Cost Savings: Fewer tokens = lower API costs
  • Better Focus: Clean data helps models stay on task

Configuration

Set environment variables:

export JSONRPC_MCP_TIMEOUT=30
export JSONRPC_MCP_HEADERS='{"Authorization": "Bearer token"}'
export JSONRPC_MCP_PROXY="http://proxy.example.com:8080"

Development

# Run tests
pytest

# Check code quality
ruff check --fix

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fetch_jsonpath_mcp-1.0.0.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fetch_jsonpath_mcp-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file fetch_jsonpath_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: fetch_jsonpath_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for fetch_jsonpath_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d0fbe07c37dc10be341672b8e368fc5b8941f4246608516042cc250e6053c4d3
MD5 7b4ac2c63e2710efa064abe2f7dc011a
BLAKE2b-256 3be7af62ddafd2d6eaadf3cef7d80c2c79899ebd8ef29d41c990bc3112063dd1

See more details on using hashes here.

File details

Details for the file fetch_jsonpath_mcp-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fetch_jsonpath_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83e7edd2b601893d76e7fc90b73eb4b53b08f1b050601a8bd4595493cf147d5e
MD5 0aca4366a5efc688db54b40bed6c56a2
BLAKE2b-256 0b11d9fc5bf3245448c43485efaa44cd492714f4e0ea7746366354ddb8e3c628

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page