Skip to main content
Glama
alxark

data-filter-mcp

by alxark

register_filter

Validate and register a restricted Python filter for later execution on local JSON, YAML, or TXT files, enabling safe custom data filtering and transformation.

Instructions

Validate and register a restricted Python filter for later execution on a local file.

Use this tool first when you want to run custom filtering or transformation logic against a local document. The submitted source code must define exactly one top-level function with this exact signature:

def filter_item(data):

The server loads the target file before execution and passes the loaded document into filter_item(data).

Input document types:

  • JSON files -> parsed JSON value such as dict, list, string, number, boolean, or null

  • YAML files -> parsed YAML value such as dict, list, string, number, boolean, or null

  • TXT files -> list of text lines

The function must return a text result (str). The returned text may contain any format you want, such as plain text, YAML, CSV-like text, or a custom report.

Preloaded modules (no imports needed; redundant import statements for these modules are accepted, including aliases):

  • json, yaml, re

  • math, statistics, datetime, decimal

  • collections, itertools, functools, operator

  • textwrap, html, base64, hashlib, ipaddress, unicodedata, difflib

Safety rules:

  • The code is validated against a restricted Python subset

  • next() (including a default value), assert statements, and catching AssertionError are supported

  • Imports of other modules and all from-imports are rejected

  • Network access, dynamic execution, and unsafe attribute access are rejected

  • Registered filters are stored in memory only and expire automatically after a server-side TTL

Forbidden:

  • Using non-standard libraries or modules

  • Accessing the filesystem, network, or environment variables

  • Defining multiple top-level functions, classes, or module-level code other than redundant imports

  • Using dynamic features like eval, exec, or import

Args: code: Python source code that defines exactly one function named filter_item(data).

Returns: A structured object containing the new filter identifier, expiration timestamp, TTL in seconds, and validation policy version.

Raises: ValueError: If the code is invalid, unsafe, or does not match the required function signature.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPython source code that defines exactly one top-level function named filter_item(data). The function receives the loaded document and must return a text result.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
filter_idYesUnique filter identifier to pass into run_filter.
expires_atYesUTC timestamp in ISO 8601 format when the filter expires.
ttl_secondsYesServer-side lifetime of the registered filter in seconds.
policy_versionYesValidation policy version used for the submitted filter code.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so thoroughly: in-memory-only storage with a server-side TTL, the exact validation policy, forbidden operations, the accepted preloaded module list, and the ValueError failure mode. Nothing material about behavior is left undisclosed.

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?

Front-loaded with purpose and usage before the long structural rules, and every block (input types, modules, safety, forbidden) is scannable. It is longer than strictly necessary — the redundant-import allowance is restated in the Forbidden section — but the length is justified by a constrained DSL.

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

Completeness5/5

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

For a tool that accepts arbitrary restricted code, the description covers signature, input contract, allowed stdlib surface, safety rules, TTL lifetime, and error semantics. An output schema exists, yet the description also summarizes the return object, leaving no gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 100%, yet the description still adds real meaning: the exact required signature 'def filter_item(data)', what the argument receives for JSON/YAML/TXT inputs, and the required str return type. This is well beyond what the schema records.

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

Purpose5/5

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

States a specific verb pair and resource ('Validate and register a restricted Python filter') plus the downstream purpose ('for later execution on a local file'). An agent can distinguish this from run_filter purely from the description.

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?

Explicitly says 'Use this tool first when you want to run custom filtering or transformation logic against a local document', which clearly implies the ordering relative to run_filter. It never names run_filter directly, so the routing is inferred rather than stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools