Skip to content

Commit 43a40d5

Browse files
python health mcp tool (#41406)
* initial commit * add health tool to joint mcp server * remove separate health mcp server * formatting * fix whitespace * doc
1 parent f336e8f commit 43a40d5

File tree

6 files changed

+582
-483
lines changed

6 files changed

+582
-483
lines changed

.github/copilot-instructions.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,42 @@ tox -e pylint --c <path_to_tox.ini> --root .
223223
**REQUIREMENTS:**
224224
- Use Python 3.9 compatible environment
225225
- Follow official fixing guidelines
226-
- Use tox mcp tool for running MyPy
226+
- Use tox mcp tool for running MyPy
227+
228+
---
229+
230+
## Python SDK Health tool
231+
232+
- Use the azure-sdk-python-mcp mcp tool to lookup a library's health status.
233+
- Always include the date of last update based on the Last Refresh date.
234+
- Explanation of statuses can be found here: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/repo_health_status.md
235+
- Release blocking checks are MyPy, Pylint, Sphinx, and Tests - CI. These checks should all PASS. If not PASS, mention that the library is blocked for release.
236+
- If links are available in the table, make the statuses (e.g. PASS, WARNING, etc) you report linked. Avoid telling the user to check the links in the report themselves.
237+
- Don't share information like SDK Owned
238+
239+
### Example
240+
241+
As of <Last Refresh date>, here is the health status for azure-ai-projects:
242+
243+
Overall Status: ⚠️ NEEDS_ACTION
244+
245+
✅ Passing Checks:
246+
247+
Pyright: PASS
248+
Sphinx: PASS
249+
Type Checked Samples: ENABLED
250+
SLA Questions and Bugs: 0
251+
252+
⚠️ Areas Needing Attention:
253+
254+
Pylint: WARNING
255+
Tests - Live: ❓ UNKNOWN
256+
Tests - Samples: ❌ DISABLED
257+
Customer-reported issues: 🔴 5 open issues
258+
259+
❌ Release blocking
260+
261+
Mypy: FAIL
262+
Tests - CI: FAIL
263+
264+
This library is failing two release blocking checks - Mypy and Tests - CI. The library needs attention primarily due to Pylint warnings, disabled sample tests, and open customer-reported issues.

.vscode/mcp.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"run",
99
"main.py"
1010
],
11-
},
11+
}
1212
}
13-
}
13+
}

doc/dev/ai/typespec_generation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,12 @@ Copilot will guide you through these steps. It will inform you of expected durat
136136
* **Your action:** Copy the PR URL and use the `azure-rest-api-specs` agent as instructed.
137137

138138
By following this guide and interacting effectively with Copilot, you can significantly accelerate the SDK generation process while ensuring adherence to Azure SDK standards.
139+
140+
141+
### Checking the health status of a library
142+
143+
To get a quick glance of a library's health and whether it can pass CI checks to release the package, you can ask VS Code Copilot to check its health status. For example, while in `Agent` mode, you can say:
144+
145+
`What is the health status of azure-ai-projects?`
146+
147+
This will report the library's status from [aka.ms/azsdk/python/health](https://www.aka.ms/azsdk/python/health) and help identify any blockers for release.

tools/mcp/azure-sdk-python-mcp/main.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from mcp.server.fastmcp import FastMCP
2-
import subprocess
3-
from typing import Dict, List, Optional, Any
41
import logging
52
import sys
63
import os
74
import re
5+
import csv
6+
import subprocess
7+
from io import StringIO
8+
from typing import Dict, List, Optional, Any
9+
10+
import httpx
811
from github import Github
12+
from mcp.server.fastmcp import FastMCP
913

1014
# Create FastMCP instance
1115
mcp = FastMCP("azure-sdk-python-mcp")
@@ -242,6 +246,51 @@ def init_local_tool(tsp_config_path: str, repo_path:str) -> Dict[str, Any]:
242246
"code": 1
243247
}
244248

249+
250+
@mcp.tool("check_library_health")
251+
def check_library_health(library_name: str) -> Dict[str, Any]:
252+
"""Checks the health status of a client library.
253+
254+
:param str library_name: The name of the library to check.
255+
:returns: A dictionary containing the result of the command.
256+
"""
257+
258+
url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/python-sdk-health-report/scripts/repo_health_status_report/health_report.csv"
259+
response = httpx.get(url)
260+
261+
try:
262+
response.raise_for_status()
263+
264+
csv_data = StringIO(response.text)
265+
reader = csv.reader(csv_data)
266+
267+
headers = next(reader)
268+
column_headers = headers[1:]
269+
270+
result = {}
271+
for row in reader:
272+
if row:
273+
key = row[0]
274+
values_dict = {header: value for header, value in zip(column_headers, row[1:])}
275+
result[key] = values_dict
276+
277+
except httpx.HTTPError as e:
278+
logger.error(f"Error downloading health report: {e}")
279+
return {
280+
"success": False,
281+
"stderr": f"Failed to fetch health report for {library_name}. Status code: {response.status_code}",
282+
"stdout": "",
283+
"code": response.status_code
284+
}
285+
286+
return {
287+
"success": True,
288+
"stdout": result[library_name] if library_name in result else f"No health data found for {library_name}",
289+
"stderr": "",
290+
"code": response.status_code
291+
}
292+
293+
245294
# Run the MCP server
246295
if __name__ == "__main__":
247-
mcp.run(transport='stdio')
296+
mcp.run(transport='stdio')

tools/mcp/azure-sdk-python-mcp/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dependencies = [
1313
"pygithub>=2.6.1",
1414
"pylint>=3.3.7",
1515
"tox>=4.26.0",
16+
"httpx>=0.24.0",
1617
]

0 commit comments

Comments
 (0)