Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ea-open-source committed Jan 14, 2025
1 parent b6d2e6b commit 2e95eac
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 68 deletions.
14 changes: 13 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "mcp-server-aidd"
version = "0.1.14"
description = "This MCP server provides a set of tools that support AI-driven Development workflows."
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.11"
authors = [{name = "SkyDeck.ai", email = "[email protected]"}]
license = {text = "MIT"}
keywords = ["mcp", "development", "ai", "aidd", "code-analysis"]
Expand Down Expand Up @@ -32,6 +32,18 @@ packages = ["src/aidd"]
[tool.hatch.envs.default]
dependencies = [
"build",
"ruff>=0.9.1",
]

[tool.ruff]
line-length = 200
target-version = "py311"

# Enable rules
lint.select = [
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
]

[project.urls]
Expand Down
4 changes: 3 additions & 1 deletion src/aidd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from . import server
import asyncio

from . import server


def main():
"""Main entry point for the package."""
asyncio.run(server.main())
Expand Down
8 changes: 4 additions & 4 deletions src/aidd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import json
import sys
import traceback
from typing import Optional
from contextlib import AsyncExitStack
from typing import Optional

from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters
from mcp.types import TextContent, CallToolResult
from mcp.client.stdio import stdio_client
from mcp.client.stdio import StdioServerParameters, stdio_client
from mcp.types import CallToolResult, TextContent


class MCPClient:
Expand Down
6 changes: 4 additions & 2 deletions src/aidd/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
from mcp.server.models import InitializationOptions

import mcp.server.stdio
import mcp.types as types
from mcp.server import NotificationOptions, Server
import mcp.server.stdio
from mcp.server.models import InitializationOptions

from .tools import TOOL_DEFINITIONS, TOOL_HANDLERS

server = Server("aidd")
Expand Down
83 changes: 58 additions & 25 deletions src/aidd/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,69 @@
from .path_tools import (
get_allowed_directory_tool, update_allowed_directory_tool,
handle_get_allowed_directory, handle_update_allowed_directory
from .code_analysis import handle_tree_sitter_map, tree_sitter_map_tool
from .code_execution import (
execute_code_tool,
execute_shell_script_tool,
handle_execute_code,
handle_execute_shell_script,
)
from .directory_tools import (
list_directory_tool, handle_list_directory,
create_directory_tool, handle_create_directory,
directory_tree_tool, handle_directory_tree
create_directory_tool,
directory_tree_tool,
handle_create_directory,
handle_directory_tree,
handle_list_directory,
list_directory_tool,
)
from .file_tools import (
read_file_tool, read_multiple_files_tool, write_file_tool,
handle_read_file, handle_read_multiple_files, handle_write_file, edit_file_tool, handle_edit_file,
move_file_tool, handle_move_file,
search_files_tool, handle_search_files,
delete_file_tool, handle_delete_file,
get_file_info_tool, handle_get_file_info,
)
from .code_execution import (
execute_code_tool, handle_execute_code,
execute_shell_script_tool, handle_execute_shell_script
)
from .code_analysis import (
tree_sitter_map_tool, handle_tree_sitter_map
delete_file_tool,
edit_file_tool,
get_file_info_tool,
handle_delete_file,
handle_edit_file,
handle_get_file_info,
handle_move_file,
handle_read_file,
handle_read_multiple_files,
handle_search_files,
handle_write_file,
move_file_tool,
read_file_tool,
read_multiple_files_tool,
search_files_tool,
write_file_tool,
)
from .git_tools import (
git_init_tool, git_status_tool, git_diff_unstaged_tool, git_diff_staged_tool, git_diff_tool, git_commit_tool,
git_add_tool, git_reset_tool, git_log_tool, git_create_branch_tool, git_checkout_tool, git_show_tool,
handle_git_init, handle_git_status, handle_git_diff_unstaged, handle_git_diff_staged, handle_git_diff, handle_git_commit,
handle_git_add, handle_git_reset, handle_git_log, handle_git_create_branch, handle_git_checkout, handle_git_show
git_add_tool,
git_checkout_tool,
git_commit_tool,
git_create_branch_tool,
git_diff_staged_tool,
git_diff_tool,
git_diff_unstaged_tool,
git_init_tool,
git_log_tool,
git_reset_tool,
git_show_tool,
git_status_tool,
handle_git_add,
handle_git_checkout,
handle_git_commit,
handle_git_create_branch,
handle_git_diff,
handle_git_diff_staged,
handle_git_diff_unstaged,
handle_git_init,
handle_git_log,
handle_git_reset,
handle_git_show,
handle_git_status,
)
from .system_tools import (
get_system_info_tool, handle_get_system_info
from .path_tools import (
get_allowed_directory_tool,
handle_get_allowed_directory,
handle_update_allowed_directory,
update_allowed_directory_tool,
)
from .system_tools import get_system_info_tool, handle_get_system_info

# Export all tools definitions
TOOL_DEFINITIONS = [
Expand Down
4 changes: 3 additions & 1 deletion src/aidd/tools/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Dict, Any
from typing import Any, Dict

import mcp.types as types


class Tool:
"""Base class for all tools"""
name: str
Expand Down
26 changes: 14 additions & 12 deletions src/aidd/tools/code_analysis.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import json
import os
from tree_sitter import Language, Parser
import tree_sitter_python
import tree_sitter_javascript
from tree_sitter_typescript._binding import language_typescript, language_tsx
import tree_sitter_java
import subprocess
from typing import Any, Dict, List

import tree_sitter_c_sharp
import tree_sitter_cpp
import tree_sitter_ruby
import tree_sitter_go
import tree_sitter_java
import tree_sitter_javascript
import tree_sitter_kotlin
import tree_sitter_python
import tree_sitter_ruby
import tree_sitter_rust
from tree_sitter import Language, Parser
from tree_sitter_php._binding import language_php
import tree_sitter_c_sharp
import tree_sitter_kotlin
from tree_sitter_typescript._binding import language_tsx, language_typescript

from .state import state
from typing import Dict, Any, List
import subprocess
import json

# Map of file extensions to language names
LANGUAGE_MAP = {
Expand Down Expand Up @@ -679,7 +680,8 @@ def format_analysis_results(analysis_results: List[Dict[str, Any]], analyzed_fil
if errors:
sections.append("\n===ERRORS===")
for error in errors:
sections.append(f"{error['path']}: {error['error'].split('\n')[0]}") # Take only the first line of error
error_first_line = error['error'].split('\n')[0]
sections.append(f"{error['path']}: {error_first_line}")

# Add repository map
sections.append("\n===REPOSITORY STRUCTURE===")
Expand Down
6 changes: 4 additions & 2 deletions src/aidd/tools/code_execution.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import subprocess
import os
from typing import List, Dict, Any
import stat
import subprocess
from typing import Any, Dict, List

import mcp.types as types

from .state import state

# Language configurations
Expand Down
11 changes: 7 additions & 4 deletions src/aidd/tools/directory_tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
import os
from datetime import datetime
import subprocess
import json
from .state import state
from datetime import datetime

from mcp.types import TextContent

from .state import state


def list_directory_tool():
return {
"name": "list_directory",
Expand Down Expand Up @@ -219,7 +222,7 @@ async def handle_directory_tree(arguments: dict):
# Add all intermediate directories
for i in range(len(parts)):
parent = os.sep.join(parts[:i])
current = os.sep.join(parts[:i+1])
os.sep.join(parts[:i+1])
if i < len(parts) - 1: # It's a directory
directory_map.setdefault(parent, {"dirs": set(), "files": set()})["dirs"].add(parts[i])
else: # It's a file
Expand Down
12 changes: 8 additions & 4 deletions src/aidd/tools/file_tools.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import re
import difflib
import json
import os
import re
import stat
import subprocess
from datetime import datetime
from typing import List

import mcp.types as types
from datetime import datetime

from .state import state


def read_file_tool():
return {
"name": "read_file",
Expand Down Expand Up @@ -716,8 +719,9 @@ async def apply_file_edits(file_path: str, edits: List[dict], dry_run: bool = Fa
f.write(modified_content)

# Return results
return f"{'=== Failed Matches ===\n' + json.dumps(failed_matches, indent=2) + '\n\n' if failed_matches else ''}" + \
f"{'=== Diff ===\n'}{diff}"
failed_matches_text = '=== Failed Matches ===\n' + json.dumps(failed_matches, indent=2) + '\n\n' if failed_matches else ''
diff_text = f'=== Diff ===\n{diff}'
return failed_matches_text + diff_text

async def handle_edit_file(arguments: dict):
"""Handle editing a file with pattern matching and formatting."""
Expand Down
8 changes: 5 additions & 3 deletions src/aidd/tools/git_tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
from datetime import datetime
from typing import List, Dict, Any, Optional
from typing import List

import git
from mcp.types import TextContent

from .state import state


def _get_repo(repo_path: str) -> git.Repo:
"""Helper function to get git repo with validation."""
# Determine full path based on whether input is absolute or relative
Expand Down Expand Up @@ -60,7 +62,7 @@ async def handle_git_init(arguments: dict) -> List[TextContent]:

try:
os.makedirs(full_path, exist_ok=True)
repo = git.Repo.init(full_path, initial_branch=initial_branch)
git.Repo.init(full_path, initial_branch=initial_branch)
return [TextContent(
type="text",
text=f"Initialized empty Git repository in {path} with initial branch '{initial_branch}'"
Expand Down
2 changes: 2 additions & 0 deletions src/aidd/tools/path_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

from .state import state


def get_allowed_directory_tool():
return {
"name": "get_allowed_directory",
Expand Down
3 changes: 2 additions & 1 deletion src/aidd/tools/state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import json
from pathlib import Path


# Global state management
class GlobalState:
Expand Down
15 changes: 9 additions & 6 deletions src/aidd/tools/system_tools.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import platform
import psutil
import json
from typing import Dict, Any, List
import mcp.types as types
import subprocess
import platform
import re
import subprocess
from typing import Any, Dict, List

import mcp.types as types
import psutil

from .state import state


def get_system_info_tool():
return {
"name": "get_system_info",
Expand Down Expand Up @@ -43,7 +46,7 @@ def get_wifi_info() -> str:
if process.returncode == 0:
for line in process.stdout.split('\n'):
if "Current Network Information:" in line:
next_line = next((l.strip() for l in process.stdout.split('\n')[process.stdout.split('\n').index(line)+1:] if l.strip()), "")
next_line = next((line_text.strip() for line_text in process.stdout.split('\n')[process.stdout.split('\n').index(line)+1:] if line_text.strip()), "")
return next_line.rstrip(':')
elif platform.system() == "Linux":
cmd = ["nmcli", "-t", "-f", "active,ssid", "dev", "wifi"]
Expand Down
Loading

0 comments on commit 2e95eac

Please sign in to comment.