Skip to content

Commit 30cd972

Browse files
author
mrachidi
committed
formating and linting
1 parent dabf050 commit 30cd972

16 files changed

+76
-44
lines changed

mcp_simple_tool/server.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ def main(port: int, transport: str) -> int:
3434
"associated weaknesses to help engineers understand security implications."
3535
)
3636

37-
package_vuln_description: str = (
38-
"Check for known vulnerabilities in a Python package using the OSV "
39-
"(Open Source Vulnerabilities) database. Provide a package name from PyPI "
40-
"(e.g., 'requests', 'django', 'flask') and optionally a specific version. "
41-
"Returns a comprehensive security report including vulnerability details, "
42-
"affected versions, severity scores, and remediation guidance."
43-
)
4437

4538
epss_description: str = (
4639
"Get Exploit Prediction Scoring System (EPSS) scores for a CVE to assess "

mcp_simple_tool/tools/cve_lookup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ async def lookup_cve(
219219
except Exception as e:
220220
return [
221221
types.TextContent(
222-
type="text", text=f"Error: Failed to fetch CVE information: {str(e)}"
222+
type="text",
223+
text=f"Error: Failed to fetch CVE information: {str(e)}",
223224
)
224225
]

mcp_simple_tool/tools/cvss_calculator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ async def calculate_cvss_score(
239239
except Exception as e:
240240
return [
241241
types.TextContent(
242-
type="text", text=f"Error: Failed to calculate CVSS score: {str(e)}"
242+
type="text",
243+
text=f"Error: Failed to calculate CVSS score: {str(e)}",
243244
)
244245
]

mcp_simple_tool/tools/epss_lookup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ async def get_epss_score(
4141
)
4242
]
4343

44-
headers = {"User-Agent": "MCP EPSS Lookup Tool v1.0", "Accept": "application/json"}
44+
headers = {
45+
"User-Agent": "MCP EPSS Lookup Tool v1.0",
46+
"Accept": "application/json",
47+
}
4548

4649
try:
4750
timeout = httpx.Timeout(15.0, connect=10.0)
@@ -181,12 +184,14 @@ async def get_epss_score(
181184
except (ValueError, TypeError) as e:
182185
return [
183186
types.TextContent(
184-
type="text", text=f"Error: Failed to parse EPSS score data: {str(e)}"
187+
type="text",
188+
text=f"Error: Failed to parse EPSS score data: {str(e)}",
185189
)
186190
]
187191
except Exception as e:
188192
return [
189193
types.TextContent(
190-
type="text", text=f"Error: Failed to fetch EPSS information: {str(e)}"
194+
type="text",
195+
text=f"Error: Failed to fetch EPSS information: {str(e)}",
191196
)
192197
]

mcp_simple_tool/tools/exploit_availability.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ async def get_exploit_availability(
5252
async with httpx.AsyncClient(
5353
follow_redirects=True, headers=headers, timeout=timeout
5454
) as client:
55-
5655
# Check 1: NIST NVD for CVE references that might indicate exploits
5756
nvd_url = f"https://services.nvd.nist.gov/rest/json/cves/2.0?cveId={cve_id}"
5857
try:
@@ -102,7 +101,10 @@ async def get_exploit_availability(
102101
"details": [],
103102
}
104103
except Exception as e:
105-
exploit_sources["NVD_References"] = {"status": "ERROR", "error": str(e)}
104+
exploit_sources["NVD_References"] = {
105+
"status": "ERROR",
106+
"error": str(e),
107+
}
106108

107109
# Check 2: Search CVE Mitre for additional exploit references
108110
try:
@@ -131,7 +133,10 @@ async def get_exploit_availability(
131133
"keywords": [],
132134
}
133135
except Exception as e:
134-
exploit_sources["MITRE_Page"] = {"status": "ERROR", "error": str(e)}
136+
exploit_sources["MITRE_Page"] = {
137+
"status": "ERROR",
138+
"error": str(e),
139+
}
135140

136141
# Check 3: Search GitHub for potential PoCs (indirect check)
137142
try:
@@ -143,7 +148,10 @@ async def get_exploit_availability(
143148
"search_url_poc": f"https://github.com/search?q={cve_id}+poc&type=repositories",
144149
}
145150
except Exception as e:
146-
exploit_sources["GitHub_Search"] = {"status": "ERROR", "error": str(e)}
151+
exploit_sources["GitHub_Search"] = {
152+
"status": "ERROR",
153+
"error": str(e),
154+
}
147155

148156
# Check 4: ExploitDB search guidance (since they don't have a public API)
149157
exploit_sources["ExploitDB"] = {

mcp_simple_tool/tools/vex_status.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ async def get_vex_status(
6161
async with httpx.AsyncClient(
6262
follow_redirects=True, headers=headers, timeout=timeout
6363
) as client:
64-
6564
# Check 1: NVD for vendor statements and VEX-like information
6665
try:
6766
nvd_url = (
@@ -97,7 +96,6 @@ async def get_vex_status(
9796
]
9897
)
9998
):
100-
10199
# Try to determine VEX-like status from URL/tags
102100
status = "under_investigation" # Default
103101
confidence = "low"
@@ -170,7 +168,8 @@ async def get_vex_status(
170168
except Exception as e:
171169
return [
172170
types.TextContent(
173-
type="text", text=f"Error: Failed to check VEX status: {str(e)}"
171+
type="text",
172+
text=f"Error: Failed to check VEX status: {str(e)}",
174173
)
175174
]
176175

@@ -215,9 +214,11 @@ async def get_vex_status(
215214

216215
result += f"**{status_emoji} {status.replace('_', ' ').title()}:** {len(statements)} statement(s)\n"
217216
for stmt in statements[:3]: # Show first 3
218-
confidence_emoji = {"high": "🔥", "medium": "⚡", "low": "💫"}.get(
219-
stmt["confidence"], "❓"
220-
)
217+
confidence_emoji = {
218+
"high": "🔥",
219+
"medium": "⚡",
220+
"low": "💫",
221+
}.get(stmt["confidence"], "❓")
221222
result += f" • {stmt.get('vendor', 'Unknown')} {confidence_emoji}\n"
222223
result += f" URL: {stmt.get('url', 'N/A')[:80]}...\n"
223224
if len(statements) > 3:

mcp_simple_tool/tools/vulnerability_search.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ async def search_vulnerabilities(
155155
search_text = " with " + ", ".join(search_desc) if search_desc else ""
156156
return [
157157
types.TextContent(
158-
type="text", text=f"No vulnerabilities found{search_text}."
158+
type="text",
159+
text=f"No vulnerabilities found{search_text}.",
159160
)
160161
]
161162

@@ -180,7 +181,7 @@ async def search_vulnerabilities(
180181
cve = vuln_data.get("cve", {})
181182
cve_id = cve.get("id", "Unknown")
182183
published = cve.get("published", "Unknown")
183-
last_modified = cve.get("lastModified", "Unknown")
184+
cve.get("lastModified", "Unknown")
184185

185186
# Get description
186187
descriptions = cve.get("descriptions", [])
@@ -200,7 +201,11 @@ async def search_vulnerabilities(
200201
severity_emoji = "⚪"
201202

202203
# Try CVSS 3.1 first, then 3.0, then 2.0
203-
for version in ["cvssMetricV31", "cvssMetricV30", "cvssMetricV2"]:
204+
for version in [
205+
"cvssMetricV31",
206+
"cvssMetricV30",
207+
"cvssMetricV2",
208+
]:
204209
if version in metrics and metrics[version]:
205210
metric = metrics[version][0] # Take first metric
206211
cvss_data = metric.get("cvssData", {})
@@ -224,7 +229,7 @@ async def search_vulnerabilities(
224229
try:
225230
pub_date = datetime.fromisoformat(published.replace("Z", "+00:00"))
226231
pub_formatted = pub_date.strftime("%Y-%m-%d")
227-
except:
232+
except (ValueError, TypeError, AttributeError):
228233
pub_formatted = (
229234
published[:10] if len(published) >= 10 else published
230235
)
@@ -281,6 +286,7 @@ async def search_vulnerabilities(
281286
except Exception as e:
282287
return [
283288
types.TextContent(
284-
type="text", text=f"Error: Failed to search vulnerabilities: {str(e)}"
289+
type="text",
290+
text=f"Error: Failed to search vulnerabilities: {str(e)}",
285291
)
286292
]

mcp_simple_tool/tools/vulnerability_timeline.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def parse_date(date_str: str) -> Optional[datetime]:
2727
return datetime.fromisoformat(date_str.split("T")[0])
2828
else:
2929
return datetime.fromisoformat(date_str)
30-
except:
30+
except (ValueError, TypeError):
3131
# Try other common formats
3232
for fmt in ["%Y-%m-%d", "%Y/%m/%d", "%m/%d/%Y", "%d/%m/%Y"]:
3333
try:
3434
return datetime.strptime(date_str, fmt)
35-
except:
35+
except (ValueError, TypeError):
3636
continue
3737
return None
3838

@@ -75,7 +75,6 @@ async def get_vulnerability_timeline(
7575
async with httpx.AsyncClient(
7676
follow_redirects=True, headers=headers, timeout=timeout
7777
) as client:
78-
7978
# Get comprehensive CVE data from NVD
8079
nvd_url = f"https://services.nvd.nist.gov/rest/json/cves/2.0?cveId={cve_id}"
8180
try:

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ dependencies = ["anyio>=4.5", "click>=8.1.0", "httpx>=0.27", "mcp"]
2424
mcp-simple-tool = "mcp_simple_tool.server:main"
2525

2626
[project.optional-dependencies]
27-
dev = ["pyright>=1.1.378", "pytest>=8.3.3", "ruff>=0.6.9", "pytest-asyncio>=0.23.5", "black>=24.0.0"]
27+
dev = ["pyright>=1.1.378",
28+
"pytest>=8.3.3",
29+
"ruff>=0.6.9",
30+
"pytest-asyncio>=0.23.5",
31+
"black>=24.0.0",
32+
"h11==0.14.0"]
2833

2934
[build-system]
3035
requires = ["hatchling"]
@@ -40,7 +45,7 @@ venv = ".venv"
4045

4146
[tool.ruff.lint]
4247
select = ["E", "F", "I"]
43-
ignore = []
48+
ignore = ["E501"]
4449

4550
[tool.ruff]
4651
line-length = 88

tests/run_tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def run_test_script(script_name: str) -> bool:
2020
print("=" * 60)
2121

2222
result = subprocess.run(
23-
[sys.executable, os.path.join(os.path.dirname(__file__), script_name)],
23+
[
24+
sys.executable,
25+
os.path.join(os.path.dirname(__file__), script_name),
26+
],
2427
capture_output=True,
2528
text=True,
2629
timeout=30,

0 commit comments

Comments
 (0)