File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ Provide:
6363``` python
6464from fastmcp import FastMCP
6565import asyncio
66- import requests
66+ import httpx
6767from typing import Any
6868
6969class APIError (Exception ):
@@ -75,14 +75,14 @@ mcp = FastMCP("server-name")
7575async def search_data (query : str ) -> str :
7676 """ Search external API and format as plain text."""
7777 try :
78- # Real API call (no caching)
79- response = requests .get(f " https://api.example.com/search?q= { query} " )
80- response.raise_for_status()
81-
82- # Format as plain text for LLM
83- data = response.json()
84- return format_search_results(data)
85- except requests.RequestException as e:
78+ async with httpx.AsyncClient() as client:
79+ response = await client .get(f " https://api.example.com/search " , params = { " q " : query})
80+ response.raise_for_status()
81+
82+ # Format as plain text for LLM
83+ data = response.json()
84+ return format_search_results(data)
85+ except httpx.RequestError as e:
8686 return f " Search failed: { str (e)} "
8787
8888def format_search_results (data : dict[str , Any]) -> str :
You can’t perform that action at this time.
0 commit comments