PubMed Article Search
Usage
import asyncio
import json
from contextlib import AsyncExitStack
from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession
class ToolUniverseClient:
def __init__(self, server_url: str, api_key: str):
self.server_url = server_url
self.api_key = api_key
self.session = None
async def connect(self):
try:
self.transport = streamablehttp_client(url=self.server_url, headers={"SCP-HUB-API-KEY": self.api_key})
self._stack = AsyncExitStack()
await self._stack.__aenter__()
self.read, self.write, self.get_session_id = await self._stack.enter_async_context(self.transport)
self.session_ctx = ClientSession(self.read, self.write)
self.session = await self._stack.enter_async_context(self.session_ctx)
await self.session.initialize()
return True
except Exception as e:
return False
async def disconnect(self):
"""Disconnect from server"""
try:
if hasattr(self, '_stack'):
await self._stack.aclose()
print("✓ already disconnect")
except Exception as e:
print(f"✗ disconnect error: {e}")
def parse_result(self, result):
try:
if hasattr(result, 'content') and result.content:
content = result.content[0]
if hasattr(content, 'text'):
return json.loads(content.text)
return str(result)
except Exception as e:
return {"error": f"parse error: {e}", "raw": str(result)}
## Initialize and use
client = ToolUniverseClient("https://scp.intern-ai.org.cn/api/v1/mcp/36/ToolUniverse", "<your-api-key>")
await client.connect()
result = await client.session.call_tool("PubMed_search_articles", arguments={"query": "protein", "limit": 10})
result_data = client.parse_result(result)
for i, article in enumerate(result_data, 1):
print(f"{i}. {article['title']}")
print(f" Authors: {', '.join(article['authors'][:3])}")
print(f" Journal: {article['journal']} ({article['year']})")
print(f" DOI: {article['doi']}")
print(f" URL: {article['url']}\n")
await client.disconnect()
Tool: PubMed_search_articles
- Args:
query (str) - Search query, limit (int) - Max results
- Returns: List of articles with title, abstract, authors, journal, year, DOI, URL
Use Cases
- Literature review, citation discovery, research background, clinical studies
1---2name: pubmed-article-search3description: Search PubMed database for scientific articles and publications to retrieve biomedical literature.4license: MIT license5---6
7# PubMed Article Search
8
9## Usage
10
11```python
12import asyncio
13import json
14from contextlib import AsyncExitStack
15from mcp.client.streamable_http import streamablehttp_client
16from mcp import ClientSession
17
18class ToolUniverseClient:
19 def __init__(self, server_url: str, api_key: str):
20 self.server_url = server_url
21 self.api_key = api_key
22 self.session = None
23
24 async def connect(self):
25 try:
26 self.transport = streamablehttp_client(url=self.server_url, headers={"SCP-HUB-API-KEY": self.api_key})
27 self._stack = AsyncExitStack()
28 await self._stack.__aenter__()
29 self.read, self.write, self.get_session_id = await self._stack.enter_async_context(self.transport)
30 self.session_ctx = ClientSession(self.read, self.write)
31 self.session = await self._stack.enter_async_context(self.session_ctx)
32 await self.session.initialize()
33 return True
34 except Exception as e:
35 return False
36
37 async def disconnect(self):
38 """Disconnect from server"""
39 try:
40 if hasattr(self, '_stack'):
41 await self._stack.aclose()
42 print("✓ already disconnect")
43 except Exception as e:
44 print(f"✗ disconnect error: {e}")
45 def parse_result(self, result):
46 try:
47 if hasattr(result, 'content') and result.content:
48 content = result.content[0]
49 if hasattr(content, 'text'):
50 return json.loads(content.text)
51 return str(result)
52 except Exception as e:
53 return {"error": f"parse error: {e}", "raw": str(result)}
54
55## Initialize and use
56client = ToolUniverseClient("https://scp.intern-ai.org.cn/api/v1/mcp/36/ToolUniverse", "<your-api-key>")
57await client.connect()
58
59result = await client.session.call_tool("PubMed_search_articles", arguments={"query": "protein", "limit": 10})
60result_data = client.parse_result(result)
61
62for i, article in enumerate(result_data, 1):
63 print(f"{i}. {article['title']}")
64 print(f" Authors: {', '.join(article['authors'][:3])}")
65 print(f" Journal: {article['journal']} ({article['year']})")
66 print(f" DOI: {article['doi']}")
67 print(f" URL: {article['url']}\n")
68
69await client.disconnect()
70```
71
72### Tool: `PubMed_search_articles`
73- Args: `query` (str) - Search query, `limit` (int) - Max results
74- Returns: List of articles with title, abstract, authors, journal, year, DOI, URL
75
76### Use Cases
77- Literature review, citation discovery, research background, clinical studies