From bf695bef092e16a72d8ef0f55d2287b39905115a Mon Sep 17 00:00:00 2001 From: ThomasTaroni Date: Sat, 21 Jun 2025 19:14:11 +0200 Subject: [PATCH] Refactor SMD utilities and streamline research query usage Remove unnecessary SMD utilities and shift query creation logic directly into `smd_research` for simplicity. This eliminates duplicate functionality and reduces reliance on external utility files, consolidating responsibilities within server implementation. --- src/phoenix_technologies/smd/server.py | 54 +++++++++++++++----------- src/phoenix_technologies/smd/utils.py | 49 ----------------------- 2 files changed, 31 insertions(+), 72 deletions(-) delete mode 100644 src/phoenix_technologies/smd/utils.py diff --git a/src/phoenix_technologies/smd/server.py b/src/phoenix_technologies/smd/server.py index 24de685..f6639f9 100644 --- a/src/phoenix_technologies/smd/server.py +++ b/src/phoenix_technologies/smd/server.py @@ -14,10 +14,6 @@ from mcp.server.fastmcp import FastMCP # Load environment variables load_dotenv() -from utils import ( - create_research_prompt -) - logging.basicConfig( level=logging.INFO, format='[%(asctime)s][%(levelname)s] - %(message)s', @@ -55,17 +51,46 @@ async def smd_detail_article(article_id: str) -> dict: } @mcp.tool() -async def smd_research(query: dict) -> dict: +async def smd_research(search_query: str = "Bundesrat", date_from: str = "2024-05-30T22:00:00.000Z", date_to: str = "2025-05-31T21:59:59.999Z") -> dict: """ Execute a deep search on a given query using SMD Researcher. Use this tool when you need research on a topic. Args: - query: The research query or topic + search_query: The SMD search query, there are Logical Operators available (AND, OR, NOT) and for a excact match use "+" before the word. For excluding use "-" before the word. For queries with multiple words use quotes. + date_from: The date to start research from, in the format YYYY-MM-DDTHH:MM:SS.SSSZ + date_to: The date to end research at, in the format YYYY-MM-DDTHH:MM:SS.SSSZ Returns: String containing research status, ID, and the actual research context """ + + query = { + "sort": { + "field": "score", + "direction": "desc" + }, + "filters": [ + { + "field": "datetime", + "value": [ + date_from, + date_to + ] + }, + { + "field": "query_text", + "value": [search_query] + } + ], + "exact": False, + "pagination": { + "pageSize": 10, + "currentPage": 1 + }, + "onlyResults": True + } + url = "https://api.swissdox.ch/api/documents/search" headers = { "authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}", @@ -79,23 +104,6 @@ async def smd_research(query: dict) -> dict: "message": response.text } - -@mcp.prompt() -def research_query(search_query: str = "Bundesrat", date_from: str = "2024-05-30T22:00:00.000Z", date_to: str = "2025-05-31T21:59:59.999Z") -> dict: - """ - Create a research query prompt for SMD Researcher. - - Args: - search_query: The SMD search query, there are Logical Operators available (AND, OR, NOT) and for a excact match use "+" before the word. For excluding use "-" before the word. For queries with multiple words use quotes. - date_from: The date to start research from, in the format YYYY-MM-DDTHH:MM:SS.SSSZ - date_to: The date to end research at, in the format YYYY-MM-DDTHH:MM:SS.SSSZ - - Returns: - A formatted prompt for research - """ - return create_research_prompt(search_query,date_from,date_to) - - def run_server(): """Run the MCP server using FastMCP's built-in event loop handling.""" diff --git a/src/phoenix_technologies/smd/utils.py b/src/phoenix_technologies/smd/utils.py deleted file mode 100644 index 7c84f68..0000000 --- a/src/phoenix_technologies/smd/utils.py +++ /dev/null @@ -1,49 +0,0 @@ -""" -SMD Researcher MCP Server Utilities - -This module provides utility functions and helpers for the SMD Researcher MCP Server. -""" - -import sys -from loguru import logger - -# Configure logging for console only (no file logging) -logger.configure(handlers=[{"sink": sys.stderr, "level": "INFO"}]) - -def create_research_prompt(search_query: str = "Bundesrat", date_from: str = "2024-05-30T22:00:00.000Z", date_to: str = "2025-05-31T21:59:59.999Z") -> dict: - """ - Create a research query prompt for SMD Researcher. - - Args: - search_query: The SMD search query, there are Logical Operators available (AND, OR, NOT) and for a excact match use "+" before the word. For excluding use "-" before the word. For queries with multiple words use quotes. - date_from: The date to start research from, in the format YYYY-MM-DDTHH:MM:SS.SSSZ - date_to: The date to end research at, in the format YYYY-MM-DDTHH:MM:SS.SSSZ - - Returns: - A formatted prompt for research as a Python dictionary. - """ - return { - "sort": { - "field": "score", - "direction": "desc" - }, - "filters": [ - { - "field": "datetime", - "value": [ - date_from, - date_to - ] - }, - { - "field": "query_text", - "value": [search_query] - } - ], - "exact": False, - "pagination": { - "pageSize": 10, - "currentPage": 1 - }, - "onlyResults": True - }