Fix PyPI regex and switch Bicep modules to /api/bicep-modules endpoint
catalog.py: Fix HTML parsing regex — pypi-server.i80.dk uses relative hrefs like href="pkg-name/" not /simple/pkg-name/. Use simpler <a> text extractor. modules.py: Replace /call-tool POST (wrong) with GET /api/bicep-modules (new REST endpoint added to DevOpsMCP). Simpler, no MCP protocol overhead.
This commit is contained in:
@@ -55,12 +55,11 @@ class BicepModuleCatalog:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _fetch_from_devops_mcp(cls) -> list[dict[str, Any]]:
|
async def _fetch_from_devops_mcp(cls) -> list[dict[str, Any]]:
|
||||||
"""Call DevOpsMCP list_bicep_modules tool via HTTP."""
|
"""Call DevOpsMCP /api/bicep-modules REST endpoint."""
|
||||||
url = f"{DEVOPS_MCP_URL}/call-tool"
|
url = f"{DEVOPS_MCP_URL}/api/bicep-modules"
|
||||||
payload = {"tool": "list_bicep_modules", "arguments": {}}
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=20)) as session:
|
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=20)) as session:
|
||||||
async with session.post(url, json=payload) as resp:
|
async with session.get(url) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
raise RuntimeError(f"DevOpsMCP returned {resp.status}")
|
raise RuntimeError(f"DevOpsMCP returned {resp.status}")
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
|
|||||||
@@ -64,16 +64,18 @@ class PypiCatalog:
|
|||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
html = await resp.text()
|
html = await resp.text()
|
||||||
|
|
||||||
# Parse simple index HTML — each <a href="/simple/pkg-name/"> pkg-name </a>
|
# Parse simple index HTML — each <a href="pkg-name/">pkg-name</a><br>
|
||||||
|
# The pypi-server.i80.dk simple index uses relative hrefs: href="pkg-name/"
|
||||||
import re
|
import re
|
||||||
for match in re.finditer(r'href="[^"]+/([^/]+)/"[^>]*>([^<]+)<', html):
|
for match in re.finditer(r'<a\s+href="[^"]*">([^<]+)</a>', html):
|
||||||
pkg_name = match.group(2).strip()
|
pkg_name = match.group(1).strip()
|
||||||
packages.append({
|
if pkg_name:
|
||||||
"name": pkg_name,
|
packages.append({
|
||||||
"label": pkg_name,
|
"name": pkg_name,
|
||||||
"detail": f"i80 package — pypi-server.i80.dk",
|
"label": pkg_name,
|
||||||
"sort_prefix": "0_i80_", # sorts before standard packages
|
"detail": "i80 package — pypi-server.i80.dk",
|
||||||
})
|
"sort_prefix": "0_i80_", # sorts before standard packages
|
||||||
|
})
|
||||||
|
|
||||||
return packages
|
return packages
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user