Create wikidata.py
Browse files- mcp/wikidata.py +23 -0
mcp/wikidata.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# mcp/wikidata.py
|
2 |
+
"""
|
3 |
+
Minimal Wikidata entity lookup for biomedical concepts.
|
4 |
+
"""
|
5 |
+
|
6 |
+
import httpx
|
7 |
+
from typing import Dict, Optional
|
8 |
+
|
9 |
+
API = "https://www.wikidata.org/w/api.php"
|
10 |
+
|
11 |
+
async def simple_search(term: str) -> Optional[Dict]:
|
12 |
+
params = {
|
13 |
+
"action": "wbsearchentities",
|
14 |
+
"search": term,
|
15 |
+
"language": "en",
|
16 |
+
"format": "json",
|
17 |
+
"limit": 1
|
18 |
+
}
|
19 |
+
async with httpx.AsyncClient(timeout=15) as client:
|
20 |
+
r = await client.get(API, params=params)
|
21 |
+
r.raise_for_status()
|
22 |
+
data = r.json()["search"]
|
23 |
+
return data[0] if data else None
|