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, and dir summaries
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
git_issue Fetch GitHub issues/PRs with smart compaction (collapses code blocks, filters bots, truncates)
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

Usage in an MCP server

from mcp_methods import list_dir, ripgrep, ripgrep_files, read_file, git_issue, ElementCache

PROJECT = "/path/to/project"

# list_dir() — tree-formatted directory listing
tree = list_dir(PROJECT, depth=2, glob="*.py", relative_to=PROJECT)

# ripgrep() — Claude Code Grep-compatible interface
# Returns all matches by default (head_limit=None means no cap)
results = ripgrep(r"def \w+", path=PROJECT, type="py")

# ripgrep_files() — full interface with multi-dir, max_results, transform
results = ripgrep_files(
    [PROJECT],
    r"def \w+",
    type_filter="py",
    relative_to=PROJECT,  # project-relative paths in output
    max_results=500,      # early termination at engine level
)

# Safe file reading with allowed directory enforcement
content = read_file("src/main.py", [PROJECT])

# GitHub issue with compaction for context windows
cache = ElementCache()
issue = cache.fetch_issue("owner/repo", 123)
# Drill into collapsed elements
element = cache.retrieve("owner/repo", 123, "cb_1")

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.2.11-cp313-cp313-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.13Windows x86-64

mcp_methods-0.2.11-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.2.11-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

mcp_methods-0.2.11-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.2.11-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

mcp_methods-0.2.11-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.2.11-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

mcp_methods-0.2.11-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.2.11-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.2.11-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 625d7e9ab9314ab64466ec2b8a5a3674cd9769a57b8f463b8461108422fc528a
MD5 d2bbd9e944eb1f1b92e532f4e204d9d9
BLAKE2b-256 137f40f5a656539fad020eabbdc95ade80fa25ee89c5b9ed88ddc7baeb055d28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 aa3ca47bf8849692c4b82856237355cb50a46888bc7400893af8736c4c912339
MD5 5d2f34a718b3a55861312890d1b5f56f
BLAKE2b-256 8b36c01585ced2b9f31d1af3a45189e4c6b44d4ca5bcedb5ca80e20c091eca2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c61c538c62b2f25cd9739fe66ec103d7c3ec98f00a0c4292be2d29921202b50a
MD5 b239b5638ee5cc11233dc6e03b494f7a
BLAKE2b-256 1bd09ec9bba96eed2c22a6ba82db94bb316fdee4460af31c1ef3442c01ac453f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1566f511cd442fc9e082f6fb7197cf669c11e5caaf05305ceac2dbc2046343a3
MD5 e22dcaf9145d15f057bc5d9bfd906791
BLAKE2b-256 b7cc2c33e3e176aa8d57022d5b80b57c659591c443530d9e99d340ec86bbdeb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 7f605d5b658d6bdd88ccceea4772fcd575d1120a33689ed728bd8832c2b1d355
MD5 fe6538aac841c28efdc4ef24cce4c4c3
BLAKE2b-256 30b324555dac2fa1335554ad77a37610decf76301f3f4e73852afa083a203811

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e997c60feb1f880eea5ddaa893d233f17407eeb69ea8b733e84ec86e1df86940
MD5 fd00e521dc1d04d518d979a48d7ff10e
BLAKE2b-256 c8ca1e829b545acfc69c155ca7bae86e739985f29e3e3e8ced440e06e68ab836

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 615210e21e6d3b26b3e693a835284194e84f5ca36f8bf592044b97bc951a9b0d
MD5 a867cecdd575c5e563ce2d3dd4e515c8
BLAKE2b-256 7850d4122ad0249693b6b1c820e92a06a934a82b9c8636aa4c6c9e131d5ab2c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 c317c05008a0552e9041ba799abee8e0d7b23168be35eb6913fac219d031c6a5
MD5 0c670c94c529cdc8a1457392b9314dcf
BLAKE2b-256 98c290781ab74aac79e1a599804f0eafbf842bf3b6b0bad6cba2b43386021619

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b9889eba1e1ef6f006cc59e596d788b6b54c6b155c6e1349b9da16c8f7268ee
MD5 b4b662ae31a5cf55910608fdb0d2cc47
BLAKE2b-256 b277d032ed4c9a75e23ed6d76148abeb3489c2453934fcf0cc4c4becd80a89a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d896491d7de4caa676a491cc7c42c202693b1f109dd0c0d48f751df121625add
MD5 566a41339242c9ef3cf3a9c26b0dc30d
BLAKE2b-256 df922c7c8ebbd047d964c87e1c4b418d9c0dc6fa9acb7fda1952352fcdf906ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1383b422eecc7a48c39f6316af1c519364c50f07831a862489ff87ef64835287
MD5 bfff8813972a8c01cd6815dd8d79df0f
BLAKE2b-256 7e4c62fdfbf47221a9301afb26350ba1ff3f4a5aba413ecc3f135b9cd57c97e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cd7cb39e140be9263c251229dfcd1735c46e95e622bfc271c489e879adaf699
MD5 539112d8b8e1e4eb0a2595df7a008e55
BLAKE2b-256 92089904ddda1d3926d9308ca205f8be4d2fc70a57de4aa6e80eb0c42afb6614

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