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_filteraccepts Python source code with exactly one top-level function:def filter_item(data):run_filterloads a local file, passes the loaded document intofilter_item(data), and returns the text fromresult_textconvert_fileloads a local file, passes it intofilter_item(data), and writes the returned text to another local file- 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 a curated set of standard-library modules. Modules are exposed by their canonical names (math, datetime, hashlib, etc.). Filesystem, process, network, and unsafe serialization modules (os, pathlib, shutil, subprocess, socket, urllib, pickle, etc.) are intentionally not available.
lambdaexpressions — typically askey=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.json—json.loads,json.dumps.yaml—yaml.safe_load,yaml.safe_dump. The unsafeyaml.load/yaml.dumpare intentionally not exposed.re—re.match,re.search,re.fullmatch,re.findall,re.sub,re.subn,re.compile,re.escape, plusMatch/Patternmethods (group,groups,groupdict,start,end,span).math— numeric helpers such asmath.ceil,math.floor,math.sqrt,math.log,math.exp,math.pow,math.factorial,math.gcd,math.lcm,math.isfinite,math.isclose.statistics— aggregates such asstatistics.mean,statistics.median,statistics.stdev,statistics.variance,statistics.quantiles.datetime—datetime.datetime.fromisoformat,datetime.datetime.now,datetime.timedelta,datetime.timezone.utc, and instance methods such asisoformat,strftime,timestamp,weekday,total_seconds. General instance attribute reads such asdt.yearanddt.monthare not supported by the current policy.decimal—decimal.Decimal(...),quantize,normalize,to_eng_string,to_integral_value.collections—collections.Counter,collections.defaultdict,collections.OrderedDict,collections.deque, plus methods such asmost_common,elements,popleft,appendleft,rotate.itertools—chain,chain.from_iterable,islice,takewhile,dropwhile,groupby,starmap,accumulate,combinations,permutations,product,filterfalse.functools—reduce,partial,cmp_to_key,wraps. Caching decorators such aslru_cacheandcacheare intentionally not exposed because they can retain process-local state across filter calls.operator—itemgetter,methodcaller, and arithmetic/comparison helpers such asadd,mul,lt,eq,gt.attrgetteris intentionally not exposed.textwrap—fill,wrap,shorten,indent,dedent.html—html.escape,html.unescape.base64—b64encode,b64decode,urlsafe_b64encode,urlsafe_b64decode,b32encode,b32decode,b16encode,b16decode.hashlib—hashlib.sha256,hashlib.sha1,hashlib.md5,hashlib.blake2b,hashlib.new, plus hash object methods such ashexdigest,digest,update.ipaddress—ip_address,ip_network,ip_interface,IPv4Network,IPv6Network, plus methods such assupernet,subnets,hosts,overlaps,subnet_of,supernet_of. General instance attribute reads such asaddr.is_privateandaddr.compressedare not supported by the current policy.unicodedata—category,name,lookup,numeric,digit,decimal,bidirectional,combining,mirrored.difflib—get_close_matches,ndiff,unified_diff,context_diff,SequenceMatcher.
Note: re.compile runs against patterns supplied by filter code, so a pathological pattern can stall the server (ReDoS). Some helpers such as difflib.SequenceMatcher can also be CPU-heavy on large inputs. 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
--workdirvalue must be an absolute path to an existing directory. run_filterwill only accept files located inside the allowed directories.- If no
--workdirflags are provided, no restrictions are applied (backward compatible). convert_filealways requires at least one--workdirbecause it writes to disk.convert_filerequires the destination path to be inside an allowed workdir.convert_filecreates missing destination parent directories automatically.convert_filerefuses to replace an existing destination file unlessoverwriteistrue.
Writing transformed files with convert_file
Use convert_file when the filtered output should be persisted instead of returned
inline to the model. The tool accepts:
filter_id— an identifier returned byregister_filtersource_file_path— absolute path to the json/yaml/txt file to loaddestination_file_path— absolute path where the returned text should be savedfile_type— optional source file type override (json,yaml, ortxt)overwrite— optional boolean, defaultfalse
Example flow:
def filter_item(data):
return "\n".join(data["items"])
Then call convert_file with a source such as /tmp/data/items.json and a
destination such as /tmp/data/out/items.txt. The result is written as UTF-8
text. The returned metadata includes the resolved source and destination paths,
the effective source file type, bytes_written, and whether an existing file was
overwritten.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file data_filter_mcp-0.2.5.tar.gz.
File metadata
- Download URL: data_filter_mcp-0.2.5.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84f51a7d42a38c3123e77ecc7bfca7a310a21a9a4a532be08b0ea776346e1e78
|
|
| MD5 |
c1fb3794f0e0fd5bcd4135fc0abb8b0f
|
|
| BLAKE2b-256 |
0958d4f33d10dfaa7cf402046206c91e207ce06b8fb09e9199dd0b2e5b417b81
|
Provenance
The following attestation bundles were made for data_filter_mcp-0.2.5.tar.gz:
Publisher:
release.yml on alxark/data-filter-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
data_filter_mcp-0.2.5.tar.gz -
Subject digest:
84f51a7d42a38c3123e77ecc7bfca7a310a21a9a4a532be08b0ea776346e1e78 - Sigstore transparency entry: 1809312567
- Sigstore integration time:
-
Permalink:
alxark/data-filter-mcp@901c10b4fbcbb3c00f14d2ab42c2bbcfc9ce576f -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/alxark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@901c10b4fbcbb3c00f14d2ab42c2bbcfc9ce576f -
Trigger Event:
push
-
Statement type:
File details
Details for the file data_filter_mcp-0.2.5-py3-none-any.whl.
File metadata
- Download URL: data_filter_mcp-0.2.5-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b1b6a9bb2c3a49c6b6e57714bf82441d81f3f3adc90885e1dc9af658987605c
|
|
| MD5 |
00db747a7a2fa10aeda33fd59817dee7
|
|
| BLAKE2b-256 |
df00d59da3a93092b28a405c93b8556e91f828467419445f8eef7698e458aac6
|
Provenance
The following attestation bundles were made for data_filter_mcp-0.2.5-py3-none-any.whl:
Publisher:
release.yml on alxark/data-filter-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
data_filter_mcp-0.2.5-py3-none-any.whl -
Subject digest:
4b1b6a9bb2c3a49c6b6e57714bf82441d81f3f3adc90885e1dc9af658987605c - Sigstore transparency entry: 1809312599
- Sigstore integration time:
-
Permalink:
alxark/data-filter-mcp@901c10b4fbcbb3c00f14d2ab42c2bbcfc9ce576f -
Branch / Tag:
refs/tags/v0.2.5 - Owner: https://github.com/alxark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@901c10b4fbcbb3c00f14d2ab42c2bbcfc9ce576f -
Trigger Event:
push
-
Statement type: