Reusable utility methods for MCP servers
Project description
mcp-methods
Shared Rust-powered utilities for MCP servers. Pip-installable library that provides fast file search, GitHub integration, and text processing — the common building blocks needed when writing MCP tool servers.
Install
pip install mcp-methods
For development (requires Rust toolchain + maturin):
pip install -e ".[dev]"
What's included
| Function | Purpose |
|---|---|
list_dir |
Tree-formatted directory listing with depth control, glob filtering, .gitignore support, dir summaries, and annotation callback |
ripgrep_files |
Ripgrep-powered file search with parallel walking, early termination, context lines, and multiple output modes |
ripgrep |
Drop-in replacement for the Claude Code Grep tool interface |
read_file |
Safe file reading with path traversal protection and line range support |
github_discussions |
Fetch a single issue/PR with smart compaction, or list issues/PRs with filters |
git_diff |
Compare two commits/branches — full diff or stat-only summary |
git_api |
GitHub REST API wrapper with token auth |
ElementCache |
Drill-down cache for collapsed elements in GitHub discussions |
ripgrep_lines |
Search through text lines with context window merging |
ripgrep_json_fields |
Extract fields from JSON text |
compact_discussion / compact_text / collapse_code_blocks |
Text compaction utilities |
extract_github_refs |
Parse GitHub issue/PR references from text |
detect_git_repo / validate_repo |
Git repository detection and validation |
Python API
list_dir(path, *, depth=1, glob=None, dirs_only=False, relative_to=None, respect_gitignore=True, skip_dirs=None, include_size=False, annotate=None)
Tree-formatted directory listing.
from mcp_methods import list_dir
# Basic tree
tree = list_dir("/project/src", depth=2, glob="*.py", relative_to="/project")
# With annotation callback (e.g. loc from knowledge graph)
def get_loc(rel_path):
node = graph.get_file(rel_path)
return f"({node.loc} loc)" if node else None
tree = list_dir("/project/src", depth=2, annotate=get_loc)
# src/
# ├── main.py (144 loc)
# ├── utils.py (28 loc)
# └── models/
# ├── user.py (89 loc)
# └── post.py (112 loc)
ripgrep(pattern, *, path=".", glob="*", type=None, output_mode="files_with_matches", max_results=None, offset=0, ...)
Claude Code Grep-compatible interface.
from mcp_methods import ripgrep
results = ripgrep(r"def \w+", path="/project", type="py", max_results=50)
ripgrep_files(source_dirs, pattern, *, glob="*", type_filter=None, output_mode="content", max_results=None, offset=0, match_limit=None, relative_to=None, ...)
Full interface with multi-directory search. max_results limits output entries, match_limit caps the search engine for early termination.
from mcp_methods import ripgrep_files
results = ripgrep_files(
["/project"],
r"def \w+",
type_filter="py",
relative_to="/project",
match_limit=500,
max_results=100,
)
github_discussions(*, repo=None, number=None, kind="all", state="open", sort="created", limit=20, labels=None, expand=None)
Fetch a single discussion or list discussions.
from mcp_methods import github_discussions, ElementCache
# List open issues
issues = github_discussions(repo="owner/repo", kind="issue", state="open")
# List pull requests
prs = github_discussions(repo="owner/repo", kind="pr", limit=10)
# Fetch a single issue/PR with smart compaction
issue = github_discussions(repo="owner/repo", number=123)
# With caching for drill-down into collapsed elements
cache = ElementCache()
issue = cache.fetch_discussion("owner/repo", 123)
element = cache.retrieve("owner/repo", 123, "cb_1")
git_diff(base, head, *, repo_path=".", stat_only=False, path_filter=None, context=3)
Compare two commits or branches.
from mcp_methods import git_diff
# Full diff
diff = git_diff("main", "feature-branch")
# Stat summary only
stat = git_diff("main", "feature-branch", stat_only=True)
# Filter to specific files
diff = git_diff("v1.0", "v2.0", path_filter="*.py", context=5)
read_file(path, allowed_dirs, *, offset=0, limit=0, max_chars=0, transform=None)
Safe file reading with path traversal protection.
from mcp_methods import read_file
content = read_file("src/main.py", ["/project"])
Architecture
All heavy lifting is in Rust (PyO3/maturin), compiled to a native Python extension:
- grep: Uses
grep-regex,grep-searcher, andignorecrates directly (not a ripgrep subprocess). Parallel file walking with per-thread searcher reuse, mmap, SIMD literal optimization, and.gitignoresupport. - GitHub: HTTP via
ureq, JSON processing viaserde_json, text compaction in Rust. - File I/O: Path validation and traversal protection in Rust.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 mcp_methods-0.3.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61496acabfc2e968090aa755d0532b5591be3fc28617386ceb4c7b3bb58e60a5
|
|
| MD5 |
abf3377326f24a00076274386fe6c857
|
|
| BLAKE2b-256 |
db2838515ecc55a1287c867616449d1dff5922426646c6e4c60e3bab2a7602dc
|
File details
Details for the file mcp_methods-0.3.1-cp313-cp313-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp313-cp313-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6686041ecf3b68553ab6498ce4b302911fe08c1bfbde73d92dc0572bca16b7f
|
|
| MD5 |
0cff180f8dcf65a7715b137df8b8769c
|
|
| BLAKE2b-256 |
9ce3c38e1f9521c98ae9cc5627f6330d4fc83194cc3ba2a451e93dca25b1be94
|
File details
Details for the file mcp_methods-0.3.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e6e44bcc48dd055db0dd3d04d6ff7c8552db2d97a3da0fa80f1161ea2c5d2e0
|
|
| MD5 |
69451639a4bfed58053108cff629bcbd
|
|
| BLAKE2b-256 |
da49586d6b4686ce598874e2f1d1a7cc09a756e3e4e77d00f7dc06c751b7abb4
|
File details
Details for the file mcp_methods-0.3.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72ea7b7b3d26d439ba77d7cf9f2587257a8c4c22d4412da9b55671712075a190
|
|
| MD5 |
6b9d73afd6b0cb70fb0104c6f0e445d7
|
|
| BLAKE2b-256 |
c09cccac419f7993127d616dc3ebc9ec3a0e64346c8df188e1c41d851b27d97e
|
File details
Details for the file mcp_methods-0.3.1-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d66c243f5714745ebc4984d877307223fc0688768c96ee3210a3e922487711b
|
|
| MD5 |
133d01e0c9c4022ccf44182227b4c599
|
|
| BLAKE2b-256 |
fd206453c36ba36361e4c3d2758d8c3f03741c3acd64657f86a33a2d508c7b24
|
File details
Details for the file mcp_methods-0.3.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44502b34464f7f0e19fc312543030e40d3cf402236fc07e7c9c6fdc038e4c54e
|
|
| MD5 |
ae367d92cc863d8c7582af8955a7047a
|
|
| BLAKE2b-256 |
1586a1b8d40398ec5c832248f3ec66a17a7d3b8ee87f5d997d48bf0725a09996
|
File details
Details for the file mcp_methods-0.3.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf507f7ad257f4278d82b78c35b8193f4069b9b598e947df9cc1072278a65e5a
|
|
| MD5 |
1665ec626a4477b9e6198b33af6c9124
|
|
| BLAKE2b-256 |
67785acbfbe5f3b35357818c17b1b9a011ef8f721fab62ada99163a298d391b9
|
File details
Details for the file mcp_methods-0.3.1-cp311-cp311-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp311-cp311-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db4c8c06b9ce362e38dcf910f23ba359456f8ccdb5f1563bc2c7b063b94f8ed0
|
|
| MD5 |
cad7f6f58a5ae849cde8547e2bc5dae3
|
|
| BLAKE2b-256 |
4586c934cbc9f47db4ca93e9b9224473641a442fcf6a8d0fb84625bb891e8146
|
File details
Details for the file mcp_methods-0.3.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed54e4d8fbccf2f2506337c2df805ef259e48226824662afefadb02ba997c39a
|
|
| MD5 |
3904ff7c0e383b253765cf9d52525e4d
|
|
| BLAKE2b-256 |
0f8fe60d833879cfb84f42a2cf7064285e9ab46e1c4ea363fcfde77453bd2b29
|
File details
Details for the file mcp_methods-0.3.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e22c6760918149fc5ac5b6a31826200f19c72e4ec4c90f65ca9844ae15e9a714
|
|
| MD5 |
f07d6d04073965be8a3fb8466e22aa09
|
|
| BLAKE2b-256 |
a52f7022c887746905bbc93306181595f613ea5d0a8b85a3aadfebbf0c9c5136
|
File details
Details for the file mcp_methods-0.3.1-cp310-cp310-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp310-cp310-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81d308e2f7b5e178a288d15850fa424a64a66c9c70c5d74ef009dfe27eb8d91e
|
|
| MD5 |
bf73daf388f8c9b4775644903b774711
|
|
| BLAKE2b-256 |
35e9c3f6a7de24ea2445b505033be0e5443acece167c5ce412c389a6f12bd83a
|
File details
Details for the file mcp_methods-0.3.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: mcp_methods-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
375be643a5dbec5b50917245caa23d40ff1310e997a2a4323cd4051384538d74
|
|
| MD5 |
1ef1c80a77092f48581f2962523e68c2
|
|
| BLAKE2b-256 |
e9fbc59198a0167738b4ff76adf95542f83f31e04c0a2c3be5013707b2fb2870
|