Skip to main content

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 — local git with GitHub API fallback for shallow clones
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=".", repo=None, stat_only=False, path_filter=None, context=3)

Compare two commits or branches. Tries local git diff first; falls back to GitHub compare API when refs are missing (common in shallow clones).

from mcp_methods import git_diff

# Full diff (local git)
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)

# Shallow clone: local diff fails → auto-detects repo and uses GitHub API
diff = git_diff("v1.0", "v2.0")

# Explicit repo for API fallback
diff = git_diff("v1.0", "v2.0", repo="owner/repo")

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, and ignore crates directly (not a ripgrep subprocess). Parallel file walking with per-thread searcher reuse, mmap, SIMD literal optimization, and .gitignore support.
  • GitHub: HTTP via ureq, JSON processing via serde_json, text compaction in Rust.
  • File I/O: Path validation and traversal protection in Rust.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

mcp_methods-0.3.2-cp313-cp313-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.13Windows x86-64

mcp_methods-0.3.2-cp313-cp313-manylinux_2_39_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

mcp_methods-0.3.2-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mcp_methods-0.3.2-cp312-cp312-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.12Windows x86-64

mcp_methods-0.3.2-cp312-cp312-manylinux_2_39_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

mcp_methods-0.3.2-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mcp_methods-0.3.2-cp311-cp311-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.11Windows x86-64

mcp_methods-0.3.2-cp311-cp311-manylinux_2_39_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

mcp_methods-0.3.2-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mcp_methods-0.3.2-cp310-cp310-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.10Windows x86-64

mcp_methods-0.3.2-cp310-cp310-manylinux_2_39_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

mcp_methods-0.3.2-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file mcp_methods-0.3.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3009c25fd91b3eace3de4a9095c90b30533d37667f6678cb8147005083740763
MD5 65d22be64298ea48935302b2e75eba59
BLAKE2b-256 7b46a0fa0c65d4c4f8d08444a4bd760a11903a725819ef4433b163e288fa7991

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4ef8d1a8a5e1da9d06f48bc5731a809baa471feec7c2d90aec64fa85aba4ce60
MD5 05369cc3f7de6c79aa371a9dc64b2d1c
BLAKE2b-256 f0cddf791ee867e9e6d307bc953266dffa87f5c2f8155130133b75cf089c3e0d

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 47f7fbcd00c9b66e2d2f1d239c18fddbf40c85d2adbd9f6eb2245d32145f13d4
MD5 cc34a1b4bad9f3bd547bf03e10857dd9
BLAKE2b-256 05cd4780763abedb319d3c472f54600539816c8461e3a84d09e269b142870717

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fe0566244e53bf92332380fb6e43e2a8d90d53b5360ff02111a95d06fcb01ebe
MD5 243b88e628d077203a15c9cfeeafad7f
BLAKE2b-256 d149268def1dffe2394d3406f0efb3d60a7bd4538e70f1db707f1ce295930967

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 74bdded8a7c7e5853d58555bb1b8e2157e775cfd7dc01ee0d1f29cd8fde7a99f
MD5 b6641a38494ff411bac2640ab9b781e2
BLAKE2b-256 3efef1f07d953f94b838f8d76a41ff5b94f69fc8bd2ed8ab64a726dea8b4aeb4

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8ed337d767f3d6f4ad559bd59b5b0c74f20b98a7b368fac402a1ffeb4be5648
MD5 086f29dcf2f0414d1a08e23a59de9477
BLAKE2b-256 b7e48d1fabc4063127f5dfac3b027506f3b22968a450d9b09e130c55852e4447

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 927cd69d6c6b58d0b398e6b8504ff43c238906f0c68d1db92dd62ec07f020522
MD5 f2130af1cb2f1fed1436c9acb72aa57e
BLAKE2b-256 9747972742aab3d10c5f0bf8fdde3cef87dee2689d4509951853baafc0db6046

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 eab10dd0838e2e9b82ef50f536e2d4a705b60bda20623fb015b8814e04bf2bbb
MD5 dbd8b08baff3a5629f9c8e15428ef9bc
BLAKE2b-256 e84f39950d37997ce478e232f0faff04541ed5362000c71d53670542cb7e4aa7

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80e297a13d07b376254dd3b34aab1cbedd37c3d36a4f5021a68da2b72cbbfdc3
MD5 5b7c7a0c64b56c382d56592874291814
BLAKE2b-256 8db75764e15edd6ee1fffce4a85f079fadef63125f6391beb8d217398c3722e1

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d93b8c4ab9dd29e11c1c05cae06094645ebe4ef025ba22c54f29eb6cb2e116af
MD5 52f4407cce48baab23ab49568af55be4
BLAKE2b-256 0a8a3961c5a0158c5b94ec0853a7ab6e812bd8a04983571984f7439fd2d5daef

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6ba01dfb750bee29c675f1348014736b56a262c9490708738e69aae2326aeb49
MD5 3eb115f3477cc2a4764feee92e58342c
BLAKE2b-256 d7204163831d3c175fc018cfe659246478865b026055ec719784c6f5b2912a69

See more details on using hashes here.

File details

Details for the file mcp_methods-0.3.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 844ebe4eb16266da1dc51cfcbc0200535b3f79e785b9262fde94032e1a38c417
MD5 d136987e16bcca2894a26f4131e7e6f7
BLAKE2b-256 0d37bb50c869c1d36a86fff85d898eb63f2fce61b2ae404d4dc36dc4a4a0a31c

See more details on using hashes here.

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