fix: ruff format MCP files + update required tool count to 21

This commit is contained in:
2026-03-12 01:40:46 -07:00
parent 338e2c7c88
commit 2c909f60dc
6 changed files with 75 additions and 24 deletions
@@ -16,7 +16,9 @@ Be constructive and specific in your feedback."""
# You can also create dynamic prompts that take parameters
def create_custom_analysis_prompt(file_path: str, analysis_type: str = "general") -> str:
def create_custom_analysis_prompt(
file_path: str, analysis_type: str = "general"
) -> str:
"""Create a dynamic analysis prompt for a specific file."""
analysis_types = {
+7 -2
View File
@@ -109,7 +109,10 @@ def get_directory_structure(
for entry in entries:
if entry.is_dir():
entry_data: dict[str, Any] = {"name": entry.name, "type": "directory"}
entry_data: dict[str, Any] = {
"name": entry.name,
"type": "directory",
}
# Check if we should filter this directory
if should_filter(entry):
@@ -267,7 +270,9 @@ def get_git_info(path: str) -> dict[str, str | None]:
for commit in repo.iter_commits(max_count=5):
short_hash = commit.hexsha[:7]
msg = commit.message
first_line = (msg.decode() if isinstance(msg, bytes) else str(msg)).split("\n")[0]
first_line = (
msg.decode() if isinstance(msg, bytes) else str(msg)
).split("\n")[0]
commits.append(f"{short_hash} {first_line}")
recent_commits = "\n".join(commits)
except Exception:
+53 -16
View File
@@ -362,11 +362,13 @@ class HanzoMCPServer:
if tm is not None:
tools_dict = getattr(tm, "_tools", {})
for name, tool in tools_dict.items():
tool_list.append({
"name": name,
"description": getattr(tool, "description", ""),
"inputSchema": getattr(tool, "parameters", {}),
})
tool_list.append(
{
"name": name,
"description": getattr(tool, "description", ""),
"inputSchema": getattr(tool, "parameters", {}),
}
)
except Exception:
pass
@@ -375,11 +377,13 @@ class HanzoMCPServer:
try:
tools = self.mcp.list_tools()
for t in tools:
tool_list.append({
"name": t.name,
"description": t.description or "",
"inputSchema": getattr(t, "parameters", {}),
})
tool_list.append(
{
"name": t.name,
"description": t.description or "",
"inputSchema": getattr(t, "parameters", {}),
}
)
except Exception:
pass
@@ -402,7 +406,16 @@ class HanzoMCPServer:
if method == "resources/list":
try:
resources = self.mcp.list_resources()
return {"resources": [{"uri": r.uri, "name": r.name, "mimeType": getattr(r, "mimeType", "text/plain")} for r in resources]}
return {
"resources": [
{
"uri": r.uri,
"name": r.name,
"mimeType": getattr(r, "mimeType", "text/plain"),
}
for r in resources
]
}
except Exception:
return {"resources": []}
@@ -411,15 +424,35 @@ class HanzoMCPServer:
uri = (params or {}).get("uri", "")
try:
content = await self.mcp.read_resource(uri)
return {"contents": [{"uri": uri, "mimeType": "text/plain", "text": str(content)}]}
return {
"contents": [
{"uri": uri, "mimeType": "text/plain", "text": str(content)}
]
}
except Exception as e:
return {"contents": [{"uri": uri, "mimeType": "text/plain", "text": f"Error: {e}"}]}
return {
"contents": [
{
"uri": uri,
"mimeType": "text/plain",
"text": f"Error: {e}",
}
]
}
# prompts/list
if method == "prompts/list":
try:
prompts = self.mcp.list_prompts()
return {"prompts": [{"name": p.name, "description": getattr(p, "description", "")} for p in prompts]}
return {
"prompts": [
{
"name": p.name,
"description": getattr(p, "description", ""),
}
for p in prompts
]
}
except Exception:
return {"prompts": []}
@@ -427,7 +460,9 @@ class HanzoMCPServer:
if method == "prompts/get":
name = (params or {}).get("name", "")
try:
prompt = await self.mcp.get_prompt(name, params.get("arguments", {}))
prompt = await self.mcp.get_prompt(
name, params.get("arguments", {})
)
return prompt
except Exception as e:
raise ValueError(f"Prompt error: {e}")
@@ -447,7 +482,9 @@ class HanzoMCPServer:
tools=tool_list,
call_tool=call_tool,
handle_method=handle_method,
name=self.mcp.name if hasattr(self.mcp, "name") else "hanzo-mcp",
name=self.mcp.name
if hasattr(self.mcp, "name")
else "hanzo-mcp",
)
)
if server:
@@ -82,7 +82,8 @@ class ForgivingEditHelper:
# Find end position by counting lines in needle
needle_line_count = norm_needle.count("\n") + 1
end_pos = sum(
len(line) + 1 for line in original_lines[: lines_before + needle_line_count]
len(line) + 1
for line in original_lines[: lines_before + needle_line_count]
)
matched = "\n".join(
+8 -2
View File
@@ -36,6 +36,7 @@ HEADER_SIZE = 9 # 4 (magic) + 1 (type) + 4 (length)
# ── Encode / Decode ─────────────────────────────────────────────────────
def encode(msg_type: int, payload: Any) -> bytes:
"""Encode a ZAP message: magic + type + length + JSON payload."""
data = json.dumps(payload).encode("utf-8")
@@ -62,7 +63,9 @@ def decode(buf: bytes) -> tuple[int, Any] | None:
if len(buf) < HEADER_SIZE + length:
return None
try:
payload = json.loads(buf[HEADER_SIZE : HEADER_SIZE + length].decode("utf-8"))
payload = json.loads(
buf[HEADER_SIZE : HEADER_SIZE + length].decode("utf-8")
)
return (msg_type, payload)
except (json.JSONDecodeError, UnicodeDecodeError):
return None
@@ -89,6 +92,7 @@ def decode(buf: bytes) -> tuple[int, Any] | None:
# ── Client tracking ─────────────────────────────────────────────────────
class ZapClient:
__slots__ = ("writer", "client_id", "browser", "version", "connected_at")
@@ -308,6 +312,8 @@ async def start_zap_server(
Returns:
ZapServer instance if started, None otherwise.
"""
server = ZapServer(tools=tools, call_tool=call_tool, handle_method=handle_method, name=name)
server = ZapServer(
tools=tools, call_tool=call_tool, handle_method=handle_method, name=name
)
ok = await server.start(preferred_port=preferred_port)
return server if ok else None
+2 -2
View File
@@ -306,5 +306,5 @@ class TestTotalToolCount:
), f"{pkg_name}: expected {expected_count} tools, got {actual}"
total += actual
# Required tools: 20 (1+8+1+1+1+2+1+1+1+3)
assert total == 20, f"Expected 20 required tools, got {total}"
# Required tools: 21 (1+9+1+1+1+2+1+1+1+3)
assert total == 21, f"Expected 21 required tools, got {total}"