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
2 changes: 0 additions & 2 deletions codemcp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import logging
import os
import sys
from pathlib import Path
from typing import Optional

import click
from mcp.server.fastmcp import FastMCP
Expand Down
15 changes: 1 addition & 14 deletions codemcp/tools/chmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import os
import stat
import time
from typing import Any, Literal

from ..common import normalize_file_path
Expand Down Expand Up @@ -44,10 +43,8 @@ async def chmod(
signal: Optional abort signal to terminate the subprocess
Returns:
A dictionary with execution stats and chmod output
A dictionary with chmod output
"""
start_time = time.time()

if not path:
raise ValueError("File path must be provided")

Expand Down Expand Up @@ -76,14 +73,12 @@ async def chmod(
message = f"File '{path}' is already executable"
return {
"output": message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": message,
}
elif mode == "a-x" and not is_executable:
message = f"File '{path}' is already non-executable"
return {
"output": message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": message,
}

Expand Down Expand Up @@ -118,19 +113,12 @@ async def chmod(
logging.warning(f"Failed to commit chmod changes: {commit_message}")
return {
"output": f"{action_msg}, but failed to commit changes: {commit_message}",
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": f"{action_msg}, but failed to commit changes: {commit_message}",
}

# Calculate execution time
execution_time = int(
(time.time() - start_time) * 1000
) # Convert to milliseconds

# Prepare output
output = {
"output": f"{action_msg} and committed changes",
"durationMs": execution_time,
}

# Add formatted result for assistant
Expand All @@ -142,7 +130,6 @@ async def chmod(
error_message = f"Error executing chmod: {e!s}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

Expand Down
12 changes: 1 addition & 11 deletions codemcp/tools/git_blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import shlex
import time
from typing import Any

from ..common import normalize_file_path
Expand Down Expand Up @@ -46,9 +45,8 @@ async def git_blame(
signal: Optional abort signal to terminate the subprocess
Returns:
A dictionary with execution stats and git blame output
A dictionary with git blame output
"""
start_time = time.time()

if path is None:
raise ValueError("Path must be provided for git blame")
Expand Down Expand Up @@ -88,19 +86,12 @@ async def git_blame(
error_message = f"Error: {result.stderr}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

# Calculate execution time
execution_time = int(
(time.time() - start_time) * 1000
) # Convert to milliseconds

# Prepare output
output = {
"output": result.stdout,
"durationMs": execution_time,
}

# Add formatted result for assistant
Expand All @@ -112,7 +103,6 @@ async def git_blame(
error_message = f"Error executing git blame: {e!s}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

Expand Down
12 changes: 1 addition & 11 deletions codemcp/tools/git_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import shlex
import time
from typing import Any

from ..common import normalize_file_path
Expand Down Expand Up @@ -47,9 +46,8 @@ async def git_diff(
signal: Optional abort signal to terminate the subprocess
Returns:
A dictionary with execution stats and git diff output
A dictionary with git diff output
"""
start_time = time.time()

if path is None:
raise ValueError("Path must be provided for git diff")
Expand Down Expand Up @@ -89,19 +87,12 @@ async def git_diff(
error_message = f"Error: {result.stderr}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

# Calculate execution time
execution_time = int(
(time.time() - start_time) * 1000
) # Convert to milliseconds

# Prepare output
output = {
"output": result.stdout,
"durationMs": execution_time,
}

# Add formatted result for assistant
Expand All @@ -113,7 +104,6 @@ async def git_diff(
error_message = f"Error executing git diff: {e!s}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

Expand Down
12 changes: 1 addition & 11 deletions codemcp/tools/git_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import shlex
import time
from typing import Any

from ..common import normalize_file_path
Expand Down Expand Up @@ -46,9 +45,8 @@ async def git_log(
signal: Optional abort signal to terminate the subprocess
Returns:
A dictionary with execution stats and git log output
A dictionary with git log output
"""
start_time = time.time()

if path is None:
raise ValueError("Path must be provided for git log")
Expand Down Expand Up @@ -88,19 +86,12 @@ async def git_log(
error_message = f"Error: {result.stderr}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

# Calculate execution time
execution_time = int(
(time.time() - start_time) * 1000
) # Convert to milliseconds

# Prepare output
output = {
"output": result.stdout,
"durationMs": execution_time,
}

# Add formatted result for assistant
Expand All @@ -112,7 +103,6 @@ async def git_log(
error_message = f"Error executing git log: {e!s}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

Expand Down
12 changes: 1 addition & 11 deletions codemcp/tools/git_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import shlex
import time
from typing import Any

from ..common import normalize_file_path
Expand Down Expand Up @@ -48,9 +47,8 @@ async def git_show(
signal: Optional abort signal to terminate the subprocess
Returns:
A dictionary with execution stats and git show output
A dictionary with git show output
"""
start_time = time.time()

if path is None:
raise ValueError("Path must be provided for git show")
Expand Down Expand Up @@ -90,19 +88,12 @@ async def git_show(
error_message = f"Error: {result.stderr}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

# Calculate execution time
execution_time = int(
(time.time() - start_time) * 1000
) # Convert to milliseconds

# Prepare output
output = {
"output": result.stdout,
"durationMs": execution_time,
}

# Add formatted result for assistant
Expand All @@ -114,7 +105,6 @@ async def git_show(
error_message = f"Error executing git show: {e!s}"
return {
"output": error_message,
"durationMs": int((time.time() - start_time) * 1000),
"resultForAssistant": error_message,
}

Expand Down
9 changes: 1 addition & 8 deletions codemcp/tools/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import logging
import os
import time
from pathlib import Path
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -169,10 +168,8 @@ async def glob_files(
signal: Optional abort signal to terminate the operation
Returns:
A dictionary with execution stats and matched files
A dictionary with matched files
"""
start_time = time.time()

# Use current working directory if path is not provided
if path is None:
path = os.getcwd()
Expand All @@ -186,16 +183,12 @@ async def glob_files(
# Execute glob
result = await glob(pattern, path, options, signal)

# Calculate execution time
execution_time = int((time.time() - start_time) * 1000) # Convert to milliseconds

# Get matching files
files = result.get("files", [])

# Prepare output
output = {
"filenames": files,
"durationMs": execution_time,
"numFiles": len(files),
"truncated": result.get("truncated", False),
}
Expand Down
10 changes: 1 addition & 9 deletions codemcp/tools/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import os
import subprocess
import time
from typing import Any

from ..common import normalize_file_path
Expand Down Expand Up @@ -173,10 +172,9 @@ async def grep_files(
signal: Optional abort signal to terminate the subprocess
Returns:
A dictionary with execution stats and matched files
A dictionary with matched files
"""
start_time = time.time()

# Execute git grep asynchronously
matches = await git_grep(pattern, path, include, signal)
Expand Down Expand Up @@ -215,15 +213,9 @@ async def grep_files(
)
matches.sort()

# Calculate execution time
execution_time = int(
(time.time() - start_time) * 1000,
) # Convert to milliseconds

# Prepare output
output = {
"filenames": matches[:MAX_RESULTS],
"durationMs": execution_time,
"numFiles": len(matches),
}

Expand Down
Loading