Skip to main content
Glama
alxark

data-filter-mcp

by alxark

register_filter

Validate and register a restricted Python filter for local file processing. Submit a function filter_item(data) to transform JSON, YAML, or TXT files into a text result.

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 standard-library modules (don't try to import them in your functions):

  • 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

  • Imports, 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

  • 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.
Behavior5/5

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

With no annotations, the description fully discloses behavioral traits: validation, restricted Python subset, preloaded modules, safety rules, expiration via TTL, and forbidden actions. This is comprehensive beyond what annotations typically provide.

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 well-organized with sections but somewhat lengthy for a tool with one parameter. However, each section adds necessary clarity for a complex tool, so it earns a 4 for being appropriately detailed without bloat.

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?

Given the tool's complexity (Python code validation, constraints, multiple input types), the description covers all essential aspects: usage order, function signature, input handling, safety rules, and return format. Complete even with output schema present.

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 100% (single param 'code'), but description adds rich semantics: explains the code must define filter_item, specifies function signature, input types, and required return type. This significantly enhances the schema.

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?

The description clearly states it validates and registers a restricted Python filter for later execution on a local file. It distinguishes from siblings by explicitly saying 'Use this tool first' and contrasts with run_filter.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: 'Use this tool first when you want to run custom filtering or transformation logic against a local document.' It implies when not to use (for execution, use run_filter) and gives alternative context.

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

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/alxark/data-filter-mcp'

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