largefile 0.1.7__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {largefile-0.1.7 → largefile-0.2.0}/.github/workflows/release.yml +33 -14
- {largefile-0.1.7 → largefile-0.2.0}/PKG-INFO +2 -2
- {largefile-0.1.7 → largefile-0.2.0}/pyproject.toml +3 -2
- {largefile-0.1.7 → largefile-0.2.0}/src/config.py +2 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/editor.py +17 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/file_access.py +9 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/main.py +2 -4
- largefile-0.2.0/src/server.py +348 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/tools.py +64 -82
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_directory_workflows.py +6 -3
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_documentation_workflows.py +6 -6
- largefile-0.2.0/tests/integration/test_mcp_server.py +75 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_search_directory_workflows.py +10 -8
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_editor.py +69 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_file_access.py +25 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_revert_edit.py +12 -22
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_search_engine.py +10 -12
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_tools.py +26 -45
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_tools_list_directory.py +21 -23
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_tools_search_directory.py +22 -26
- {largefile-0.1.7 → largefile-0.2.0}/uv.lock +77 -2
- largefile-0.1.7/src/mcp_schemas.py +0 -375
- largefile-0.1.7/src/server.py +0 -25
- largefile-0.1.7/tests/integration/test_mcp_server.py +0 -24
- {largefile-0.1.7 → largefile-0.2.0}/.gitattributes +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/.github/workflows/ci.yml +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/.gitignore +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/.python-version +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/README.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/codecov.yml +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/3rd-party/python-mcp-sdk.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/3rd-party/research-llm-file-editing-apis.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/3rd-party/tree-sitter.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/API.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/CONTRIBUTING.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/configuration.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/design.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/docs/examples.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/scripts/.gitignore +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/scripts/pre-push +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/__init__.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/data_models.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/exceptions.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/search_engine.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/tree_parser.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/src/utils.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/__init__.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_codebase_workflows.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_editor_operations.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_file_strategies.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_performance_strategies.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/integration/test_real_world_examples.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/LICENSES.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/README.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/csharp/aspnet-controller.cs +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/go/docker-daemon.go +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/java/spring-application.java +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/javascript/lodash-utility.js +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/markdown/anthropic-readme.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/markdown/fastapi-docs.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/markdown/nodejs-readme.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/markdown/openai-readme.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/markdown/pytorch-readme.md +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/php/laravel-model.php +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/python/django-models.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/rust/serde-derive.rs +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/text/rfc-specification.txt +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/text/shakespeare-complete.txt +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/test_data/typescript/vscode-extension.ts +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/__init__.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_backup_management.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_tree_parser.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/unit/test_tree_parser_verification.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/utils/__init__.py +0 -0
- {largefile-0.1.7 → largefile-0.2.0}/tests/utils/env_override.py +0 -0
|
@@ -66,12 +66,12 @@ jobs:
|
|
|
66
66
|
run: |
|
|
67
67
|
TAG_VERSION=${GITHUB_REF#refs/tags/v}
|
|
68
68
|
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
|
|
71
71
|
echo "Error: Tag version ($TAG_VERSION) does not match pyproject.toml version ($PYPROJECT_VERSION)"
|
|
72
72
|
exit 1
|
|
73
73
|
fi
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
echo "Version validation passed: $TAG_VERSION"
|
|
76
76
|
|
|
77
77
|
- name: Install dependencies
|
|
@@ -83,6 +83,12 @@ jobs:
|
|
|
83
83
|
- name: Build package
|
|
84
84
|
run: uv build
|
|
85
85
|
|
|
86
|
+
- name: Upload build artifacts
|
|
87
|
+
uses: actions/upload-artifact@v4
|
|
88
|
+
with:
|
|
89
|
+
name: dist
|
|
90
|
+
path: dist/
|
|
91
|
+
|
|
86
92
|
- name: Create GitHub Release
|
|
87
93
|
uses: softprops/action-gh-release@v2
|
|
88
94
|
with:
|
|
@@ -97,22 +103,35 @@ jobs:
|
|
|
97
103
|
url: https://pypi.org/project/largefile/
|
|
98
104
|
|
|
99
105
|
steps:
|
|
100
|
-
- name:
|
|
101
|
-
|
|
106
|
+
- name: Check if version exists on PyPI
|
|
107
|
+
id: pypi_check
|
|
108
|
+
run: |
|
|
109
|
+
VERSION=${GITHUB_REF#refs/tags/v}
|
|
110
|
+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --retry 3 "https://pypi.org/pypi/largefile/${VERSION}/json")
|
|
111
|
+
if [ "$STATUS" = "200" ]; then
|
|
112
|
+
echo "Version $VERSION already exists on PyPI, skipping publish"
|
|
113
|
+
echo "exists=true" >> "$GITHUB_OUTPUT"
|
|
114
|
+
elif [ "$STATUS" = "404" ]; then
|
|
115
|
+
echo "Version $VERSION not found on PyPI, will publish"
|
|
116
|
+
echo "exists=false" >> "$GITHUB_OUTPUT"
|
|
117
|
+
else
|
|
118
|
+
echo "::warning::Unexpected status $STATUS from PyPI for version $VERSION, attempting publish anyway"
|
|
119
|
+
echo "exists=false" >> "$GITHUB_OUTPUT"
|
|
120
|
+
fi
|
|
102
121
|
|
|
103
|
-
- name:
|
|
104
|
-
|
|
122
|
+
- name: Download build artifacts
|
|
123
|
+
if: steps.pypi_check.outputs.exists == 'false'
|
|
124
|
+
uses: actions/download-artifact@v4
|
|
105
125
|
with:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
- name: Set up Python
|
|
110
|
-
run: uv python install 3.11
|
|
126
|
+
name: dist
|
|
127
|
+
path: dist/
|
|
111
128
|
|
|
112
|
-
- name:
|
|
113
|
-
|
|
129
|
+
- name: Install uv
|
|
130
|
+
if: steps.pypi_check.outputs.exists == 'false'
|
|
131
|
+
uses: astral-sh/setup-uv@v6
|
|
114
132
|
|
|
115
133
|
- name: Publish to PyPI
|
|
116
|
-
|
|
134
|
+
if: steps.pypi_check.outputs.exists == 'false'
|
|
135
|
+
run: uv publish dist/*
|
|
117
136
|
env:
|
|
118
137
|
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: largefile
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: MCP server for AI assistants to navigate, search, and edit large codebases, logs, and data files with semantic code analysis
|
|
5
5
|
Project-URL: Homepage, https://github.com/peteretelej/largefile
|
|
6
6
|
Project-URL: Repository, https://github.com/peteretelej/largefile.git
|
|
@@ -23,7 +23,7 @@ Classifier: Typing :: Typed
|
|
|
23
23
|
Requires-Python: >=3.10
|
|
24
24
|
Requires-Dist: chardet>=5.0.0
|
|
25
25
|
Requires-Dist: click>=8.2.1
|
|
26
|
-
Requires-Dist: mcp
|
|
26
|
+
Requires-Dist: mcp<2.0.0,>=1.7.0
|
|
27
27
|
Requires-Dist: rapidfuzz>=3.0.0
|
|
28
28
|
Requires-Dist: tree-sitter-go>=0.21.0
|
|
29
29
|
Requires-Dist: tree-sitter-java>=0.21.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "largefile"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "MCP server for AI assistants to navigate, search, and edit large codebases, logs, and data files with semantic code analysis"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -27,7 +27,7 @@ classifiers = [
|
|
|
27
27
|
dependencies = [
|
|
28
28
|
"chardet>=5.0.0",
|
|
29
29
|
"click>=8.2.1",
|
|
30
|
-
"mcp>=1.
|
|
30
|
+
"mcp>=1.7.0,<2.0.0",
|
|
31
31
|
"rapidfuzz>=3.0.0",
|
|
32
32
|
"tree-sitter>=0.21.0",
|
|
33
33
|
"tree-sitter-python>=0.21.0",
|
|
@@ -56,6 +56,7 @@ packages = ["src"]
|
|
|
56
56
|
|
|
57
57
|
[dependency-groups]
|
|
58
58
|
dev = [
|
|
59
|
+
"mcp[cli]",
|
|
59
60
|
"mypy>=1.16.1",
|
|
60
61
|
"pytest>=8.4.1",
|
|
61
62
|
"pytest-asyncio>=1.0.0",
|
|
@@ -28,6 +28,8 @@ class Config:
|
|
|
28
28
|
max_backups: int = int(os.getenv("LARGEFILE_MAX_BACKUPS", "10"))
|
|
29
29
|
max_batch_changes: int = int(os.getenv("LARGEFILE_MAX_BATCH_CHANGES", "50"))
|
|
30
30
|
|
|
31
|
+
log_level: str = os.getenv("LARGEFILE_LOG_LEVEL", "WARNING").upper()
|
|
32
|
+
|
|
31
33
|
enable_tree_sitter: bool = (
|
|
32
34
|
os.getenv("LARGEFILE_ENABLE_TREE_SITTER", "true").lower() == "true"
|
|
33
35
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Search/replace engine with fuzzy matching and atomic operations."""
|
|
2
2
|
|
|
3
3
|
import difflib
|
|
4
|
+
import logging
|
|
4
5
|
import os
|
|
5
6
|
|
|
6
7
|
from .config import config
|
|
@@ -9,6 +10,8 @@ from .exceptions import EditError
|
|
|
9
10
|
from .file_access import normalize_path, read_file_content, write_file_content
|
|
10
11
|
from .search_engine import find_similar_patterns
|
|
11
12
|
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
12
15
|
|
|
13
16
|
def generate_diff_preview(original: str, modified: str, search_text: str) -> str:
|
|
14
17
|
"""Generate a diff preview showing before/after changes."""
|
|
@@ -456,6 +459,20 @@ def batch_edit_content(
|
|
|
456
459
|
# Generate unified diff preview
|
|
457
460
|
preview_text = generate_diff_preview(original_content, modified_content, "batch")
|
|
458
461
|
|
|
462
|
+
# All-or-nothing: if any change failed, do not write to disk
|
|
463
|
+
if changes_failed > 0 and not preview:
|
|
464
|
+
return EditResult(
|
|
465
|
+
success=False,
|
|
466
|
+
preview=preview_text,
|
|
467
|
+
changes_made=0,
|
|
468
|
+
line_number=0,
|
|
469
|
+
similarity_used=0.0,
|
|
470
|
+
match_type="batch",
|
|
471
|
+
changes_applied=changes_applied,
|
|
472
|
+
changes_failed=changes_failed,
|
|
473
|
+
results=change_results,
|
|
474
|
+
)
|
|
475
|
+
|
|
459
476
|
result = EditResult(
|
|
460
477
|
success=changes_applied > 0,
|
|
461
478
|
preview=preview_text,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import hashlib
|
|
2
|
+
import logging
|
|
2
3
|
import mmap
|
|
3
4
|
import os
|
|
4
5
|
import time
|
|
@@ -11,6 +12,8 @@ from .config import config
|
|
|
11
12
|
from .data_models import BackupInfo
|
|
12
13
|
from .exceptions import FileAccessError
|
|
13
14
|
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
14
17
|
|
|
15
18
|
def normalize_path(file_path: str) -> str:
|
|
16
19
|
"""Convert to absolute canonical path with home directory expansion."""
|
|
@@ -559,6 +562,12 @@ def write_file_content(file_path: str, content: str) -> None:
|
|
|
559
562
|
os.unlink(canonical_path)
|
|
560
563
|
|
|
561
564
|
os.rename(temp_path, canonical_path)
|
|
565
|
+
except PermissionError as e:
|
|
566
|
+
if os.path.exists(temp_path):
|
|
567
|
+
os.unlink(temp_path)
|
|
568
|
+
raise FileAccessError(
|
|
569
|
+
f"Permission denied (file may be read-only): {file_path}"
|
|
570
|
+
) from e
|
|
562
571
|
except Exception as e:
|
|
563
572
|
if os.path.exists(temp_path):
|
|
564
573
|
os.unlink(temp_path)
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"""MCP server implementation using FastMCP."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
from typing import Annotated, Any
|
|
6
|
+
|
|
7
|
+
from mcp.server.fastmcp import FastMCP
|
|
8
|
+
from mcp.types import ToolAnnotations
|
|
9
|
+
from pydantic import Field
|
|
10
|
+
|
|
11
|
+
from . import tools
|
|
12
|
+
from .config import config
|
|
13
|
+
|
|
14
|
+
logging.basicConfig(
|
|
15
|
+
stream=sys.stderr,
|
|
16
|
+
level=logging.WARNING,
|
|
17
|
+
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
|
18
|
+
)
|
|
19
|
+
logging.getLogger().setLevel(getattr(logging, config.log_level, logging.WARNING))
|
|
20
|
+
|
|
21
|
+
mcp = FastMCP("largefile")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@mcp.tool(
|
|
25
|
+
annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False),
|
|
26
|
+
structured_output=False,
|
|
27
|
+
)
|
|
28
|
+
def get_overview(
|
|
29
|
+
absolute_file_path: Annotated[
|
|
30
|
+
str,
|
|
31
|
+
Field(
|
|
32
|
+
description="Absolute path to target file (e.g., /path/to/large_module.py)"
|
|
33
|
+
),
|
|
34
|
+
],
|
|
35
|
+
) -> dict:
|
|
36
|
+
"""Get file structure, size, and semantic outline for large files (code, logs, data).
|
|
37
|
+
|
|
38
|
+
Use FIRST when working with any file over 1000 lines or when you need to
|
|
39
|
+
understand file structure. Returns: line count, byte size, binary detection,
|
|
40
|
+
long line stats, section headings, and suggested search patterns. For code
|
|
41
|
+
files, uses Tree-sitter to extract functions, classes, and structure. Does
|
|
42
|
+
NOT return file content - use read_content or search_content for that.
|
|
43
|
+
"""
|
|
44
|
+
return tools.get_overview(absolute_file_path) # type: ignore[no-any-return]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@mcp.tool(
|
|
48
|
+
annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False),
|
|
49
|
+
structured_output=False,
|
|
50
|
+
)
|
|
51
|
+
def search_content(
|
|
52
|
+
absolute_file_path: Annotated[
|
|
53
|
+
str, Field(description="Absolute path to target file")
|
|
54
|
+
],
|
|
55
|
+
pattern: Annotated[
|
|
56
|
+
str,
|
|
57
|
+
Field(
|
|
58
|
+
description="Text pattern to find (e.g., 'class User', 'ERROR', or regex like r'\\d{3}-\\d{4}')"
|
|
59
|
+
),
|
|
60
|
+
],
|
|
61
|
+
max_results: Annotated[
|
|
62
|
+
int, Field(description="Maximum results to return (1-100)", ge=1, le=100)
|
|
63
|
+
] = 20,
|
|
64
|
+
context_lines: Annotated[
|
|
65
|
+
int, Field(description="Lines of context before/after each match")
|
|
66
|
+
] = 2,
|
|
67
|
+
fuzzy: Annotated[
|
|
68
|
+
bool,
|
|
69
|
+
Field(
|
|
70
|
+
description="Enable fuzzy matching to handle typos and whitespace differences (default: true)"
|
|
71
|
+
),
|
|
72
|
+
] = True,
|
|
73
|
+
regex: Annotated[
|
|
74
|
+
bool,
|
|
75
|
+
Field(
|
|
76
|
+
description="Enable regex pattern matching (e.g., r'error.*timeout'). Disables fuzzy matching."
|
|
77
|
+
),
|
|
78
|
+
] = False,
|
|
79
|
+
case_sensitive: Annotated[
|
|
80
|
+
bool,
|
|
81
|
+
Field(
|
|
82
|
+
description="Match exact case when true (default: false for case-insensitive)"
|
|
83
|
+
),
|
|
84
|
+
] = False,
|
|
85
|
+
invert: Annotated[
|
|
86
|
+
bool,
|
|
87
|
+
Field(description="Return lines that do NOT match the pattern (like grep -v)"),
|
|
88
|
+
] = False,
|
|
89
|
+
count_only: Annotated[
|
|
90
|
+
bool,
|
|
91
|
+
Field(
|
|
92
|
+
description="Return only the match count, not content. Efficient for large files."
|
|
93
|
+
),
|
|
94
|
+
] = False,
|
|
95
|
+
) -> dict:
|
|
96
|
+
"""Search large files for text patterns without loading entire content into memory.
|
|
97
|
+
|
|
98
|
+
Use when finding functions, classes, errors, log entries, or counting
|
|
99
|
+
occurrences. Supports: fuzzy matching (handles typos/whitespace), regex
|
|
100
|
+
patterns, case-insensitive search, inverted matching (like grep -v), and
|
|
101
|
+
count-only mode. Returns ranked matches with line numbers and context
|
|
102
|
+
(lines truncated to 500 chars). When count_only=True, returns
|
|
103
|
+
{count, pattern, fuzzy_enabled, regex_enabled, case_sensitive, inverted}
|
|
104
|
+
instead of the full results structure.
|
|
105
|
+
"""
|
|
106
|
+
return tools.search_content( # type: ignore[no-any-return]
|
|
107
|
+
absolute_file_path,
|
|
108
|
+
pattern,
|
|
109
|
+
max_results=max_results,
|
|
110
|
+
context_lines=context_lines,
|
|
111
|
+
fuzzy=fuzzy,
|
|
112
|
+
regex=regex,
|
|
113
|
+
case_sensitive=case_sensitive,
|
|
114
|
+
invert=invert,
|
|
115
|
+
count_only=count_only,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@mcp.tool(
|
|
120
|
+
annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False),
|
|
121
|
+
structured_output=False,
|
|
122
|
+
)
|
|
123
|
+
def read_content(
|
|
124
|
+
absolute_file_path: Annotated[
|
|
125
|
+
str, Field(description="Absolute path to target file")
|
|
126
|
+
],
|
|
127
|
+
offset: Annotated[
|
|
128
|
+
int,
|
|
129
|
+
Field(
|
|
130
|
+
description="Starting line number, 1-indexed (default: 1). Ignored in tail/head modes.",
|
|
131
|
+
ge=1,
|
|
132
|
+
),
|
|
133
|
+
] = 1,
|
|
134
|
+
limit: Annotated[
|
|
135
|
+
int,
|
|
136
|
+
Field(
|
|
137
|
+
description="Lines to return (default 100). Reduce for files with long lines (check get_overview)."
|
|
138
|
+
),
|
|
139
|
+
] = 100,
|
|
140
|
+
pattern: Annotated[
|
|
141
|
+
str | None,
|
|
142
|
+
Field(
|
|
143
|
+
description="Pattern to position read (finds match, then reads around it). Overrides offset."
|
|
144
|
+
),
|
|
145
|
+
] = None,
|
|
146
|
+
mode: Annotated[
|
|
147
|
+
str,
|
|
148
|
+
Field(
|
|
149
|
+
description="Reading mode: 'lines' (by range), 'semantic' (tree-sitter chunks), 'tail' (last N), 'head' (first N)"
|
|
150
|
+
),
|
|
151
|
+
] = "lines",
|
|
152
|
+
) -> dict:
|
|
153
|
+
"""Read specific portions of large files efficiently.
|
|
154
|
+
|
|
155
|
+
Use after search_content locates content, or directly with tail/head modes
|
|
156
|
+
for logs. Modes: 'lines' (read by offset/limit), 'semantic' (complete
|
|
157
|
+
functions/classes via Tree-sitter), 'tail' (last N lines - ideal for logs),
|
|
158
|
+
'head' (first N lines). Does NOT search - use search_content first to find
|
|
159
|
+
line numbers, then read_content to examine. For files over 500MB, tail/head
|
|
160
|
+
modes are most efficient.
|
|
161
|
+
"""
|
|
162
|
+
return tools.read_content( # type: ignore[no-any-return]
|
|
163
|
+
absolute_file_path,
|
|
164
|
+
offset=offset,
|
|
165
|
+
limit=limit,
|
|
166
|
+
pattern=pattern,
|
|
167
|
+
mode=mode,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@mcp.tool(
|
|
172
|
+
annotations=ToolAnnotations(readOnlyHint=False, destructiveHint=True),
|
|
173
|
+
structured_output=False,
|
|
174
|
+
)
|
|
175
|
+
def edit_content(
|
|
176
|
+
absolute_file_path: Annotated[
|
|
177
|
+
str, Field(description="Absolute path to target file")
|
|
178
|
+
],
|
|
179
|
+
changes: Annotated[
|
|
180
|
+
list[dict[str, Any]],
|
|
181
|
+
Field(
|
|
182
|
+
description="Array of {search, replace, fuzzy?} objects. Applied in order."
|
|
183
|
+
),
|
|
184
|
+
],
|
|
185
|
+
fuzzy: Annotated[
|
|
186
|
+
bool,
|
|
187
|
+
Field(description="Enable fuzzy matching for all changes (default: true)"),
|
|
188
|
+
] = True,
|
|
189
|
+
preview: Annotated[
|
|
190
|
+
bool,
|
|
191
|
+
Field(
|
|
192
|
+
description="Show diff preview without applying changes. Always preview first!"
|
|
193
|
+
),
|
|
194
|
+
] = True,
|
|
195
|
+
) -> dict:
|
|
196
|
+
"""Edit large files using search/replace with fuzzy matching.
|
|
197
|
+
|
|
198
|
+
Use instead of line-based editing to avoid LLM line number errors. Fuzzy
|
|
199
|
+
matching handles whitespace and formatting differences automatically.
|
|
200
|
+
Preview mode (default) shows diff without applying. Creates automatic
|
|
201
|
+
backup before changes - use revert_edit to undo. Does NOT support regex
|
|
202
|
+
in replacement - patterns must be literal text (use fuzzy=true for
|
|
203
|
+
flexibility).
|
|
204
|
+
"""
|
|
205
|
+
return tools.edit_content( # type: ignore[no-any-return]
|
|
206
|
+
absolute_file_path,
|
|
207
|
+
changes=changes,
|
|
208
|
+
fuzzy=fuzzy,
|
|
209
|
+
preview=preview,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@mcp.tool(
|
|
214
|
+
annotations=ToolAnnotations(readOnlyHint=False, destructiveHint=True),
|
|
215
|
+
structured_output=False,
|
|
216
|
+
)
|
|
217
|
+
def revert_edit(
|
|
218
|
+
absolute_file_path: Annotated[
|
|
219
|
+
str, Field(description="Absolute path to the file to revert")
|
|
220
|
+
],
|
|
221
|
+
backup_id: Annotated[
|
|
222
|
+
str | None,
|
|
223
|
+
Field(description="Backup ID from response. Omit to use most recent."),
|
|
224
|
+
] = None,
|
|
225
|
+
) -> dict:
|
|
226
|
+
"""Restore a file to a previous state from automatic backups.
|
|
227
|
+
|
|
228
|
+
Use when edit_content made unwanted changes. Backups are created
|
|
229
|
+
automatically before each edit. Current state is saved as new backup
|
|
230
|
+
before reverting (so revert is reversible). Without backup_id, reverts to
|
|
231
|
+
most recent backup. Returns list of available backups with timestamps.
|
|
232
|
+
"""
|
|
233
|
+
return tools.revert_edit( # type: ignore[no-any-return]
|
|
234
|
+
absolute_file_path,
|
|
235
|
+
backup_id=backup_id,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@mcp.tool(
|
|
240
|
+
annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False),
|
|
241
|
+
structured_output=False,
|
|
242
|
+
)
|
|
243
|
+
def list_directory(
|
|
244
|
+
absolute_dir_path: Annotated[
|
|
245
|
+
str, Field(description="The absolute path to the directory to list.")
|
|
246
|
+
],
|
|
247
|
+
max_depth: Annotated[
|
|
248
|
+
int,
|
|
249
|
+
Field(
|
|
250
|
+
description="How many levels deep to recurse (default: 1 = direct children only)."
|
|
251
|
+
),
|
|
252
|
+
] = 1,
|
|
253
|
+
max_entries: Annotated[
|
|
254
|
+
int | None,
|
|
255
|
+
Field(
|
|
256
|
+
description="Maximum total entries to return. Defaults to server config (200).",
|
|
257
|
+
ge=1,
|
|
258
|
+
),
|
|
259
|
+
] = None,
|
|
260
|
+
include_hidden: Annotated[
|
|
261
|
+
bool,
|
|
262
|
+
Field(description="Include entries starting with '.' (default: false)."),
|
|
263
|
+
] = False,
|
|
264
|
+
) -> dict:
|
|
265
|
+
"""List the contents of a directory.
|
|
266
|
+
|
|
267
|
+
Each entry has a type field: 'dir' for directories, 'file' for files.
|
|
268
|
+
Use max_depth > 1 to recurse into subdirectories. Automatically ignores
|
|
269
|
+
__pycache__, node_modules, and .git. Returns entry type, size in bytes,
|
|
270
|
+
and child count for directories.
|
|
271
|
+
"""
|
|
272
|
+
return tools.list_directory( # type: ignore[no-any-return]
|
|
273
|
+
absolute_dir_path,
|
|
274
|
+
max_depth=max_depth,
|
|
275
|
+
max_entries=max_entries,
|
|
276
|
+
include_hidden=include_hidden,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
@mcp.tool(
|
|
281
|
+
annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False),
|
|
282
|
+
structured_output=False,
|
|
283
|
+
)
|
|
284
|
+
def search_directory(
|
|
285
|
+
absolute_dir_path: Annotated[
|
|
286
|
+
str, Field(description="The absolute path to the directory to search.")
|
|
287
|
+
],
|
|
288
|
+
pattern: Annotated[str, Field(description="Text pattern to search for.")],
|
|
289
|
+
include_pattern: Annotated[
|
|
290
|
+
str,
|
|
291
|
+
Field(
|
|
292
|
+
description="fnmatch glob matched against file names (default: '*'). Examples: '*.py', '*.md', '*.ts'."
|
|
293
|
+
),
|
|
294
|
+
] = "*",
|
|
295
|
+
max_results: Annotated[
|
|
296
|
+
int | None,
|
|
297
|
+
Field(
|
|
298
|
+
description="Total match cap across all files. Defaults to server config (100).",
|
|
299
|
+
ge=1,
|
|
300
|
+
le=100,
|
|
301
|
+
),
|
|
302
|
+
] = None,
|
|
303
|
+
context_lines: Annotated[
|
|
304
|
+
int,
|
|
305
|
+
Field(description="Lines of context before/after each match (default: 2)."),
|
|
306
|
+
] = 2,
|
|
307
|
+
fuzzy: Annotated[
|
|
308
|
+
bool,
|
|
309
|
+
Field(
|
|
310
|
+
description="Enable fuzzy matching (default: false, expensive for many files)."
|
|
311
|
+
),
|
|
312
|
+
] = False,
|
|
313
|
+
regex: Annotated[
|
|
314
|
+
bool,
|
|
315
|
+
Field(description="Enable Python regex matching (default: false)."),
|
|
316
|
+
] = False,
|
|
317
|
+
case_sensitive: Annotated[
|
|
318
|
+
bool,
|
|
319
|
+
Field(description="Case-sensitive search (default: false)."),
|
|
320
|
+
] = False,
|
|
321
|
+
invert: Annotated[
|
|
322
|
+
bool,
|
|
323
|
+
Field(description="Return non-matching lines, like grep -v (default: false)."),
|
|
324
|
+
] = False,
|
|
325
|
+
include_hidden: Annotated[
|
|
326
|
+
bool,
|
|
327
|
+
Field(description="Include dot-files and dot-dirs (default: false)."),
|
|
328
|
+
] = False,
|
|
329
|
+
) -> dict:
|
|
330
|
+
"""Search for a text pattern across all files in a directory.
|
|
331
|
+
|
|
332
|
+
Returns results grouped by file with line numbers and context. Use
|
|
333
|
+
include_pattern to filter by file extension (e.g. '*.py'). Automatically
|
|
334
|
+
ignores __pycache__, node_modules, and .git. Prefer fuzzy=False (default)
|
|
335
|
+
for multi-file search performance.
|
|
336
|
+
"""
|
|
337
|
+
return tools.search_directory( # type: ignore[no-any-return]
|
|
338
|
+
absolute_dir_path,
|
|
339
|
+
pattern,
|
|
340
|
+
include_pattern=include_pattern,
|
|
341
|
+
max_results=max_results,
|
|
342
|
+
context_lines=context_lines,
|
|
343
|
+
fuzzy=fuzzy,
|
|
344
|
+
regex=regex,
|
|
345
|
+
case_sensitive=case_sensitive,
|
|
346
|
+
invert=invert,
|
|
347
|
+
include_hidden=include_hidden,
|
|
348
|
+
)
|