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.
This commit is contained in:
parent
60c441c817
commit
bf695bef09
2 changed files with 31 additions and 72 deletions
|
@ -14,10 +14,6 @@ from mcp.server.fastmcp import FastMCP
|
||||||
# Load environment variables
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
from utils import (
|
|
||||||
create_research_prompt
|
|
||||||
)
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='[%(asctime)s][%(levelname)s] - %(message)s',
|
format='[%(asctime)s][%(levelname)s] - %(message)s',
|
||||||
|
@ -55,17 +51,46 @@ async def smd_detail_article(article_id: str) -> dict:
|
||||||
}
|
}
|
||||||
|
|
||||||
@mcp.tool()
|
@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.
|
Execute a deep search on a given query using SMD Researcher.
|
||||||
Use this tool when you need research on a topic.
|
Use this tool when you need research on a topic.
|
||||||
|
|
||||||
Args:
|
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:
|
Returns:
|
||||||
String containing research status, ID, and the actual research context
|
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"
|
url = "https://api.swissdox.ch/api/documents/search"
|
||||||
headers = {
|
headers = {
|
||||||
"authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}",
|
"authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}",
|
||||||
|
@ -79,23 +104,6 @@ async def smd_research(query: dict) -> dict:
|
||||||
"message": response.text
|
"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():
|
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."""
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue