Skip to main content

Local MCP server for running restricted Python text filters over files

Project description

data-filter-mcp

Local MCP server that registers restricted Python filters and runs them against local json, yaml, and txt files.

What it does

  • register_filter accepts Python source code with exactly one top-level function: def filter_item(data):
  • run_filter loads a local file, passes the loaded document into filter_item(data), and returns the text from result_text
  • Registered filters live only in memory and expire automatically based on server TTL settings

What filter code may use

Filter bodies are AST-validated against a whitelist. In addition to a curated set of builtins (len, sorted, max, min, range, enumerate, zip, sum, any, all, conversions, etc.) and safe string/dict/list methods, filters may also use:

  • lambda expressions — typically as key= arguments, e.g. sorted(data, key=lambda item: item.get("score")). Lambda bodies are validated by the same rules as the rest of the filter.
  • jsonjson.loads, json.dumps.
  • yamlyaml.safe_load, yaml.safe_dump. The unsafe yaml.load / yaml.dump are intentionally not exposed.
  • rere.match, re.search, re.fullmatch, re.findall, re.sub, re.subn, re.compile, re.escape, plus Match / Pattern methods (group, groups, groupdict, start, end, span).

Note: re.compile runs against patterns supplied by filter code, so a pathological pattern can stall the server (ReDoS). Treat filter source as trusted-but-restricted.

Run with uvx

After publishing to PyPI, start the server with:

uvx data-filter-mcp --filter-ttl-seconds 3600 --cleanup-interval-seconds 60

Show the available CLI flags with:

uvx data-filter-mcp --help

Restricting file access with --workdir

By default the server can read any file on the local filesystem. Use one or more --workdir flags to restrict file reads to specific directories:

uvx data-filter-mcp \
  --filter-ttl-seconds 3600 \
  --cleanup-interval-seconds 60 \
  --workdir /Users/me/project \
  --workdir /tmp/data

Rules:

  • Each --workdir value must be an absolute path to an existing directory.
  • run_filter will only accept files located inside the allowed directories.
  • If no --workdir flags are provided, no restrictions are applied (backward compatible).

Example MCP client configuration:

{
  "mcpServers": {
    "data-filter": {
      "command": "uvx",
      "args": [
        "data-filter-mcp",
        "--filter-ttl-seconds",
        "3600",
        "--cleanup-interval-seconds",
        "60",
        "--workdir",
        "/Users/me/project",
        "--workdir",
        "/tmp/data"
      ]
    }
  }
}

Run locally

python server.py --filter-ttl-seconds 3600 --cleanup-interval-seconds 60
python -m data_filter_mcp.server --filter-ttl-seconds 3600 --cleanup-interval-seconds 60
.venv/bin/data-filter-mcp --filter-ttl-seconds 3600 --cleanup-interval-seconds 60

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

data_filter_mcp-0.2.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

data_filter_mcp-0.2.1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file data_filter_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: data_filter_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for data_filter_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f52430c1355e9882f87dfc8f2a3cbf0b9c3988fe8c42319612ade4dfe4d9425b
MD5 9e7be3380614bb3fd927cc6ce59d0a01
BLAKE2b-256 517bb1ba04ccbe29ec61eb4c0e00b479a7090a0537ac06363f42c8171b8e9265

See more details on using hashes here.

Provenance

The following attestation bundles were made for data_filter_mcp-0.2.1.tar.gz:

Publisher: release.yml on alxark/data-filter-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file data_filter_mcp-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for data_filter_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe6254624bcfbfc5107a3301cdaa4b231c1baf7336255d27b93a9197ae495967
MD5 f943b167b371bb6497eb0ba20bd30335
BLAKE2b-256 ba3af19e8acecee8aee97d10c366911c8a1bdf7b2402d9b3d7eb4f0d555603f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for data_filter_mcp-0.2.1-py3-none-any.whl:

Publisher: release.yml on alxark/data-filter-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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