Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions codemcp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
from .common import normalize_file_path
from .git_query import get_current_commit_hash
from .tools.chmod import chmod
from .tools.edit_file import edit_file_content
from .tools.glob import glob_files
from .tools.grep import grep_files
from .tools.edit_file import edit_file
from .tools.glob import glob
from .tools.grep import grep
from .tools.init_project import init_project
from .tools.ls import ls_directory
from .tools.mv import mv_file
from .tools.read_file import read_file_content
from .tools.rm import rm_file
from .tools.ls import ls
from .tools.mv import mv
from .tools.read_file import read_file
from .tools.rm import rm
from .tools.run_command import run_command
from .tools.think import think
from .tools.write_file import write_file_content
from .tools.write_file import write_file

# Initialize FastMCP server
mcp = FastMCP("codemcp")
Expand Down Expand Up @@ -182,7 +182,7 @@ async def codemcp(
if path is None:
raise ValueError("path is required for ReadFile subtool")

result = await read_file_content(path, offset, limit, chat_id, commit_hash)
result = await read_file(path, offset, limit, chat_id, commit_hash)
return result

if subtool == "WriteFile":
Expand All @@ -193,9 +193,7 @@ async def codemcp(
if chat_id is None:
raise ValueError("chat_id is required for WriteFile subtool")

result = await write_file_content(
path, content, description, chat_id, commit_hash
)
result = await write_file(path, content, description, chat_id, commit_hash)
return result

if subtool == "EditFile":
Expand All @@ -216,16 +214,14 @@ async def codemcp(
# Accept either new_string or new_str (prefer new_string if both are provided)
new_content = new_string or new_str

result = await edit_file_content(
path, old_content, new_content, None, description, chat_id, commit_hash
)
result = await edit_file(path, old_content, new_content, None, description, chat_id, commit_hash)
return result

if subtool == "LS":
if path is None:
raise ValueError("path is required for LS subtool")

result = await ls_directory(path, chat_id, commit_hash)
result = await ls(path, chat_id, commit_hash)
return result

if subtool == "InitProject":
Expand Down Expand Up @@ -267,9 +263,7 @@ async def codemcp(
raise ValueError("path is required for Grep subtool")

try:
result_string = await grep_files(
pattern, path, include, chat_id, commit_hash
)
result_string = await grep(pattern, path, include, chat_id, commit_hash)
return result_string
except Exception as e:
logging.error(f"Error in Grep subtool: {e}", exc_info=True)
Expand All @@ -282,9 +276,7 @@ async def codemcp(
raise ValueError("path is required for Glob subtool")

try:
result_string = await glob_files(
pattern, path, limit, offset, chat_id, commit_hash
)
result_string = await glob(pattern, path, limit, offset, chat_id, commit_hash)
return result_string
except Exception as e:
logging.error(f"Error in Glob subtool: {e}", exc_info=True)
Expand All @@ -298,7 +290,7 @@ async def codemcp(
if chat_id is None:
raise ValueError("chat_id is required for RM subtool")

result = await rm_file(path, description, chat_id, commit_hash)
result = await rm(path, description, chat_id, commit_hash)
return result

if subtool == "MV":
Expand All @@ -315,9 +307,7 @@ async def codemcp(
if chat_id is None:
raise ValueError("chat_id is required for MV subtool")

result = await mv_file(
source_path, target_path, description, chat_id, commit_hash
)
result = await mv(source_path, target_path, description, chat_id, commit_hash)
return result

if subtool == "Think":
Expand Down
8 changes: 4 additions & 4 deletions codemcp/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from .git_diff import git_diff
from .git_log import git_log
from .git_show import git_show
from .mv import mv_file
from .rm import rm_file
from .mv import mv
from .rm import rm

__all__ = [
"chmod",
"git_blame",
"git_diff",
"git_log",
"git_show",
"mv_file",
"rm_file",
"mv",
"rm",
]
10 changes: 5 additions & 5 deletions codemcp/tools/edit_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
logger = logging.getLogger(__name__)

__all__ = [
"edit_file_content",
"edit_file",
"find_similar_file",
"apply_edit_pure",
]
Expand Down Expand Up @@ -744,8 +744,8 @@ def debug_string_comparison(
return not content_same


async def edit_file_content(
file_path: str,
async def edit_file(
path: str,
old_string: str | None = None,
new_string: str | None = None,
read_file_timestamps: dict[str, float] | None = None,
Expand All @@ -761,7 +761,7 @@ async def edit_file_content(
whitespace on otherwise empty lines.

Args:
file_path: The absolute path to the file to edit
path: The absolute path to the file to edit
old_string: The text to replace (use empty string for new file creation)
new_string: The new text to replace old_string with
read_file_timestamps: Dictionary mapping file paths to timestamps when they were last read
Expand All @@ -785,7 +785,7 @@ async def edit_file_content(
chat_id = "" if chat_id is None else chat_id

# Normalize the file path
full_file_path = normalize_file_path(file_path)
full_file_path = normalize_file_path(path)

# Normalize string inputs to ensure consistent newlines
old_string = old_string.replace("\r\n", "\n")
Expand Down
Loading