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
grep_files Ripgrep-powered file search with parallel walking, early termination, context lines, and multiple output modes
grep 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
grep_lines Search through text lines with context window merging
grep_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 grep_files, read_file, git_issue, ElementCache

# File search — returns formatted string ready for LLM consumption
results = grep_files(
    ["/path/to/project"],
    r"def \w+",
    type_filter="py",
    max_results=50,
)

# Safe file reading with allowed directory enforcement
content = read_file("src/main.py", ["/path/to/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.5-cp313-cp313-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.13Windows x86-64

mcp_methods-0.2.5-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.5-cp313-cp313-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

mcp_methods-0.2.5-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.5-cp312-cp312-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

mcp_methods-0.2.5-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.5-cp311-cp311-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

mcp_methods-0.2.5-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.5-cp310-cp310-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 97fdcdd87594f79edbfef3937f7c672698bfa04dd7ed313fc625da8c150217c5
MD5 fd45e61435590fff1ce6e5ef7e3fa0aa
BLAKE2b-256 10838b5a587e8f4219940f001ee9fd89a94374df062b712637c57708141bb309

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 e9bedbdb73f983e927595cc6ff3ba796f27d4a0982178478068419a6154428af
MD5 4ffa7aed28e024ff51c345956872ef25
BLAKE2b-256 c9459d1f36a8191ae56ec2cb4e267fb6722523700ad387e29795eb2edf073311

See more details on using hashes here.

File details

Details for the file mcp_methods-0.2.5-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dda088fc755cccf0a6ea4204befcb83128664aea5fc4e0ae363fa725c909819a
MD5 000b0419bb6d94fccb709d9821eb064a
BLAKE2b-256 2ab2af781bb300cc64d6ea877e0f43bdad4def92e8172eda221af59c5212cfeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ecd63da692e6a8e066b8f1c6b8ac9b65352523aff92cb68a91868ec1e8b39c17
MD5 de5be73039a58fab93001248034eab53
BLAKE2b-256 3ed3a0850a754652964ca85fc44e249cbd2bc4c8d49b4eb51dc9b8aa9533b4c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 7faaf0f69d4f5f5ad20ed8645c313048578d0b17be7bf0ff636d1634d40e717d
MD5 771d1f68532b58343a1651b84b6800e9
BLAKE2b-256 1391bf4efaa9b0de58c8984f2fdefdbf428dbc7c4ed981374b1947a4fa668635

See more details on using hashes here.

File details

Details for the file mcp_methods-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d386e6aa964f62a16c6c6c42394b4fdd1449bb110907aa33904bee586b28861e
MD5 4261ed858f6e104732eb8684a4d94ce0
BLAKE2b-256 d53b8668c2ac753277597915b435fd247a799c8001ee95040711e73b114b93c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5664ff3bc99f75d4c1321f4c94bec48b77aadebac59fd7005b40046051b64d1d
MD5 a5a17867af2aa134a86521a8694cbbcd
BLAKE2b-256 de79d36b917ebae638ba3930ed9ec7370e5fdc154d2df32aa560571149a3c14f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 0b6458a96b899ef421b687e5904c523b7cdc26655e0556cafbbee4b052e0f8f8
MD5 9363a3c7df7dbc6bebc3f3c57857adf6
BLAKE2b-256 54785728208309cd9167d3063064a422021a64c8a6dc3bb8571ee69259a8ffcc

See more details on using hashes here.

File details

Details for the file mcp_methods-0.2.5-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e58fcef8a959620b2f720e2450e804aa6965e5dffeec62b6700753b38bcbf46e
MD5 b77f87f247a39499f47a5a69b89d9c04
BLAKE2b-256 54f6d98e5077150732014bbb659cb6df18cb24c64887458d4d3b34a40b72abb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 805b60dd44b7ce29aa32e7bf33aa06d0f256c68105e941bc1004adff4db44047
MD5 c7620e4c085a4e95fa6c79cc6f0b9ac3
BLAKE2b-256 24b52471264cc1be706e749e4b4a3ffe24f596317221d75afb54c8aa674b7f85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 12c5a2a7c006570784ec58d94d3d8520ab4d7136e014c2a5bddb653c703313e2
MD5 1ebe0d16cf525852d911471907e7d8e5
BLAKE2b-256 2c2f8e34499d78e0d47d3ae691a6cd23fdc466f070c250ca5f212d997a908450

See more details on using hashes here.

File details

Details for the file mcp_methods-0.2.5-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mcp_methods-0.2.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 10f94ead28f400f9707dc18ee28b23acf7d74655c2336597816f6c9fe61d0e44
MD5 36bbca27b210764c7abb6d46666a8f0b
BLAKE2b-256 89c4577d24d6d24da597c9d37a2338dbb2b1782b152d64459329dcdb0cfcfcd6

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