Update article query logic and improve response structure

Removed the unused `smd_detail_article` decorator and expanded the response structure to include detailed article data in nested JSON. Adjusted the pagination default `pageSize` from 10 to 25 to handle larger datasets effectively.
This commit is contained in:
ThomasTaroni 2025-06-21 20:06:17 +02:00
parent d779b5bd98
commit 1554d5e4ab

View file

@ -24,7 +24,6 @@ logger = logging.getLogger(__name__)
# Initialize FastMCP server # Initialize FastMCP server
mcp = FastMCP("SMD Researcher", host="0.0.0.0", port=8000, timeout_keep_alive=720) mcp = FastMCP("SMD Researcher", host="0.0.0.0", port=8000, timeout_keep_alive=720)
@mcp.tool()
async def smd_detail_article(article_id: str) -> dict: async def smd_detail_article(article_id: str) -> dict:
""" """
Get the Details of an article found by the tool smd_research based on the article_id. Get the Details of an article found by the tool smd_research based on the article_id.
@ -85,7 +84,7 @@ async def smd_research(search_query: str = "Bundesrat", date_from: str = "2024-0
], ],
"exact": False, "exact": False,
"pagination": { "pagination": {
"pageSize": 10, "pageSize": 25,
"currentPage": 1 "currentPage": 1
}, },
"onlyResults": False "onlyResults": False
@ -98,12 +97,30 @@ async def smd_research(search_query: str = "Bundesrat", date_from: str = "2024-0
} }
response = requests.post(url, headers=headers, json=query) response = requests.post(url, headers=headers, json=query)
if response.status_code == 200: if response.status_code == 200:
return response.json() result = response.json()
# Artikel-Liste aus der `data`-Struktur der Antwort
articles = result.get("data", [])
# Verschachtelte JSON-Resultate von `smd_detail_article` sammeln
detailed_articles = []
for article in articles:
article_id = article.get("id")
if article_id:
detailed_result = smd_detail_article(article_id)
detailed_articles.append(detailed_result)
# Gesamtantwort mit kombinierter JSON-Struktur
return {
"search_result": result,
"detailed_articles": detailed_articles
}
else: else:
return { return {
"message": response.text "message": response.text
} }
def run_server(): def run_server():
"""Run the MCP server using FastMCP's built-in event loop handling.""" """Run the MCP server using FastMCP's built-in event loop handling."""