From 9d8fd52e99410ccb48fc7c0e03866e5045e402f2 Mon Sep 17 00:00:00 2001 From: saidsurucu Date: Wed, 28 May 2025 20:52:27 +0300 Subject: [PATCH] optimize for dumb models --- README.md | 6 +++--- danistay_mcp_module/client.py | 16 ++++++++-------- danistay_mcp_module/models.py | 2 +- emsal_mcp_module/client.py | 18 +++++++++--------- emsal_mcp_module/models.py | 2 +- mcp_server_main.py | 26 +++++++++++++------------- yargitay_mcp_module/client.py | 16 ++++++++-------- yargitay_mcp_module/models.py | 2 +- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index df18c3f..19cbf6e 100644 --- a/README.md +++ b/README.md @@ -230,16 +230,16 @@ Bu FastMCP sunucusu aşağıdaki temel araçları sunar: * **Yargıtay Araçları:** * `search_yargitay_detailed(search_query: YargitayDetailedSearchRequest) -> CompactYargitaySearchResult`: Yargıtay kararlarını detaylı kriterlerle arar. - * `get_yargitay_document_markdown(document_id: str) -> YargitayDocumentMarkdown`: Belirli bir Yargıtay kararının metnini Markdown formatında getirir. + * `get_yargitay_document_markdown(id: str) -> YargitayDocumentMarkdown`: Belirli bir Yargıtay kararının metnini Markdown formatında getirir. * **Danıştay Araçları:** * `search_danistay_by_keyword(search_query: DanistayKeywordSearchRequest) -> CompactDanistaySearchResult`: Danıştay kararlarını anahtar kelimelerle arar. * `search_danistay_detailed(search_query: DanistayDetailedSearchRequest) -> CompactDanistaySearchResult`: Danıştay kararlarını detaylı kriterlerle arar. - * `get_danistay_document_markdown(document_id: str) -> DanistayDocumentMarkdown`: Belirli bir Danıştay kararının metnini Markdown formatında getirir. + * `get_danistay_document_markdown(id: str) -> DanistayDocumentMarkdown`: Belirli bir Danıştay kararının metnini Markdown formatında getirir. * **Emsal Karar Araçları:** * `search_emsal_detailed_decisions(search_query: EmsalSearchRequest) -> CompactEmsalSearchResult`: Emsal (UYAP) kararlarını detaylı kriterlerle arar. - * `get_emsal_document_markdown(document_id: str) -> EmsalDocumentMarkdown`: Belirli bir Emsal kararının metnini Markdown formatında getirir. + * `get_emsal_document_markdown(id: str) -> EmsalDocumentMarkdown`: Belirli bir Emsal kararının metnini Markdown formatında getirir. * **Uyuşmazlık Mahkemesi Araçları:** * `search_uyusmazlik_decisions(search_params: UyusmazlikSearchRequest) -> UyusmazlikSearchResponse`: Uyuşmazlık Mahkemesi kararlarını çeşitli form kriterleriyle arar. diff --git a/danistay_mcp_module/client.py b/danistay_mcp_module/client.py index 008a69d..0892d8d 100644 --- a/danistay_mcp_module/client.py +++ b/danistay_mcp_module/client.py @@ -143,14 +143,14 @@ class DanistayApiClient: return markdown_text - async def get_decision_document_as_markdown(self, document_id: str) -> DanistayDocumentMarkdown: + async def get_decision_document_as_markdown(self, id: str) -> DanistayDocumentMarkdown: """ Retrieves a specific Danıştay decision by ID and returns its content as Markdown. The /getDokuman endpoint for Danıştay returns direct HTML. """ - document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={document_id}" + document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}" source_url = f"{self.BASE_URL}{document_api_url}" - logger.info(f"DanistayApiClient: Fetching Danistay document for Markdown (ID: {document_id}) from {source_url}") + logger.info(f"DanistayApiClient: Fetching Danistay document for Markdown (ID: {id}) from {source_url}") try: # For direct HTML response, we might want different headers if the API is sensitive, @@ -162,10 +162,10 @@ class DanistayApiClient: html_content_from_api = response.text if not isinstance(html_content_from_api, str) or not html_content_from_api.strip(): - logger.warning(f"DanistayApiClient: Received empty or non-string HTML content for ID {document_id}.") + logger.warning(f"DanistayApiClient: Received empty or non-string HTML content for ID {id}.") # Return with None markdown_content if HTML is effectively empty return DanistayDocumentMarkdown( - document_id=document_id, + id=id, markdown_content=None, source_url=source_url ) @@ -173,16 +173,16 @@ class DanistayApiClient: markdown_content = self._convert_html_to_markdown_danistay(html_content_from_api) return DanistayDocumentMarkdown( - document_id=document_id, + id=id, markdown_content=markdown_content, source_url=source_url ) except httpx.RequestError as e: - logger.error(f"DanistayApiClient: HTTP error fetching Danistay document (ID: {document_id}): {e}") + logger.error(f"DanistayApiClient: HTTP error fetching Danistay document (ID: {id}): {e}") raise # Removed ValueError for JSON as Danistay /getDokuman returns direct HTML except Exception as e: # Catches other errors like MarkItDown issues if they propagate - logger.error(f"DanistayApiClient: General error processing Danistay document (ID: {document_id}): {e}") + logger.error(f"DanistayApiClient: General error processing Danistay document (ID: {id}): {e}") raise async def close_client_session(self): diff --git a/danistay_mcp_module/models.py b/danistay_mcp_module/models.py index c139f42..3cccef6 100644 --- a/danistay_mcp_module/models.py +++ b/danistay_mcp_module/models.py @@ -104,7 +104,7 @@ class DanistayApiResponse(BaseModel): class DanistayDocumentMarkdown(BaseModel): """Model for a Danistay decision document, containing only Markdown content.""" - document_id: str + id: str markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.") source_url: HttpUrl diff --git a/emsal_mcp_module/client.py b/emsal_mcp_module/client.py index e4b292f..8a1158b 100644 --- a/emsal_mcp_module/client.py +++ b/emsal_mcp_module/client.py @@ -133,14 +133,14 @@ class EmsalApiClient: return markdown_text - async def get_decision_document_as_markdown(self, document_id: str) -> EmsalDocumentMarkdown: + async def get_decision_document_as_markdown(self, id: str) -> EmsalDocumentMarkdown: """ Retrieves a specific Emsal decision by ID and returns its content as Markdown. Assumes Emsal /getDokuman endpoint returns JSON with HTML content in the 'data' field. """ - document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={document_id}" + document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}" source_url = f"{self.BASE_URL}{document_api_url}" - logger.info(f"EmsalApiClient: Fetching Emsal document for Markdown (ID: {document_id}) from {source_url}") + logger.info(f"EmsalApiClient: Fetching Emsal document for Markdown (ID: {id}) from {source_url}") try: response = await self.http_client.get(document_api_url) @@ -151,24 +151,24 @@ class EmsalApiClient: html_content_from_api = response_json.get("data") if not isinstance(html_content_from_api, str) or not html_content_from_api.strip(): - logger.warning(f"EmsalApiClient: Received empty or non-string HTML in 'data' field for Emsal ID {document_id}.") - return EmsalDocumentMarkdown(document_id=document_id, markdown_content=None, source_url=source_url) + logger.warning(f"EmsalApiClient: Received empty or non-string HTML in 'data' field for Emsal ID {id}.") + return EmsalDocumentMarkdown(id=id, markdown_content=None, source_url=source_url) markdown_content = self._clean_html_and_convert_to_markdown_emsal(html_content_from_api) return EmsalDocumentMarkdown( - document_id=document_id, + id=id, markdown_content=markdown_content, source_url=source_url ) except httpx.RequestError as e: - logger.error(f"EmsalApiClient: HTTP error fetching Emsal document (ID: {document_id}): {e}") + logger.error(f"EmsalApiClient: HTTP error fetching Emsal document (ID: {id}): {e}") raise except ValueError as e: - logger.error(f"EmsalApiClient: ValueError processing Emsal document response (ID: {document_id}): {e}") + logger.error(f"EmsalApiClient: ValueError processing Emsal document response (ID: {id}): {e}") raise except Exception as e: - logger.error(f"EmsalApiClient: General error processing Emsal document (ID: {document_id}): {e}") + logger.error(f"EmsalApiClient: General error processing Emsal document (ID: {id}): {e}") raise async def close_client_session(self): diff --git a/emsal_mcp_module/models.py b/emsal_mcp_module/models.py index 7cd937a..59588a8 100644 --- a/emsal_mcp_module/models.py +++ b/emsal_mcp_module/models.py @@ -92,7 +92,7 @@ class EmsalApiResponse(BaseModel): class EmsalDocumentMarkdown(BaseModel): """Model for an Emsal decision document, containing only Markdown content.""" - document_id: str + id: str markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.") source_url: HttpUrl diff --git a/mcp_server_main.py b/mcp_server_main.py index ccc1366..9942b0f 100644 --- a/mcp_server_main.py +++ b/mcp_server_main.py @@ -169,12 +169,12 @@ async def search_yargitay_detailed( raise @app.tool() -async def get_yargitay_document_markdown(document_id: str) -> YargitayDocumentMarkdown: - """Retrieves a specific Yargitay decision by its ID and returns its content as Markdown.""" - logger.info(f"Tool 'get_yargitay_document_markdown' called for ID: {document_id}") - if not document_id or not document_id.strip(): raise ValueError("Document ID must be a non-empty string.") +async def get_yargitay_document_markdown(id: str) -> YargitayDocumentMarkdown: + """Retrieves a specific Yargitay decision by its ID and returns its content as Markdown. Use id field from previous Yargıtay search results.""" + logger.info(f"Tool 'get_yargitay_document_markdown' called for ID: {id}") + if not id or not id.strip(): raise ValueError("Document ID must be a non-empty string.") try: - return await yargitay_client_instance.get_decision_document_as_markdown(document_id) + return await yargitay_client_instance.get_decision_document_as_markdown(id) except Exception as e: logger.exception(f"Error in tool 'get_yargitay_document_markdown'.") raise @@ -271,12 +271,12 @@ async def search_danistay_detailed( raise @app.tool() -async def get_danistay_document_markdown(document_id: str) -> DanistayDocumentMarkdown: +async def get_danistay_document_markdown(id: str) -> DanistayDocumentMarkdown: """Retrieves a specific Danıştay decision by ID and returns its content as Markdown.""" - logger.info(f"Tool 'get_danistay_document_markdown' called for ID: {document_id}") - if not document_id or not document_id.strip(): raise ValueError("Document ID must be a non-empty string for Danıştay.") + logger.info(f"Tool 'get_danistay_document_markdown' called for ID: {id}") + if not id or not id.strip(): raise ValueError("Document ID must be a non-empty string for Danıştay.") try: - return await danistay_client_instance.get_decision_document_as_markdown(document_id) + return await danistay_client_instance.get_decision_document_as_markdown(id) except Exception as e: logger.exception(f"Error in tool 'get_danistay_document_markdown'.") raise @@ -339,12 +339,12 @@ async def search_emsal_detailed_decisions( raise @app.tool() -async def get_emsal_document_markdown(document_id: str) -> EmsalDocumentMarkdown: +async def get_emsal_document_markdown(id: str) -> EmsalDocumentMarkdown: """Retrieves a specific Emsal decision by ID and returns its content as Markdown.""" - logger.info(f"Tool 'get_emsal_document_markdown' called for ID: {document_id}") - if not document_id or not document_id.strip(): raise ValueError("Document ID required for Emsal.") + logger.info(f"Tool 'get_emsal_document_markdown' called for ID: {id}") + if not id or not id.strip(): raise ValueError("Document ID required for Emsal.") try: - return await emsal_client_instance.get_decision_document_as_markdown(document_id) + return await emsal_client_instance.get_decision_document_as_markdown(id) except Exception as e: logger.exception(f"Error in tool 'get_emsal_document_markdown'.") raise diff --git a/yargitay_mcp_module/client.py b/yargitay_mcp_module/client.py index 88172f9..a28cbc3 100644 --- a/yargitay_mcp_module/client.py +++ b/yargitay_mcp_module/client.py @@ -130,15 +130,15 @@ class YargitayOfficialApiClient: return markdown_output - async def get_decision_document_as_markdown(self, document_id: str) -> YargitayDocumentMarkdown: + async def get_decision_document_as_markdown(self, id: str) -> YargitayDocumentMarkdown: """ Retrieves a specific Yargitay decision by its ID and returns its content as Markdown. Based on user-provided /getDokuman response structure. """ - document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={document_id}" + document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}" source_url = f"{self.BASE_URL}{document_api_url}" # The original URL of the document - logger.info(f"YargitayOfficialApiClient: Fetching document for Markdown conversion (ID: {document_id})") + logger.info(f"YargitayOfficialApiClient: Fetching document for Markdown conversion (ID: {id})") try: response = await self.http_client.get(document_api_url) @@ -149,24 +149,24 @@ class YargitayOfficialApiClient: html_content_from_api = response_json.get("data") if not isinstance(html_content_from_api, str): - logger.error(f"YargitayOfficialApiClient: 'data' field in API response is not a string or not found (ID: {document_id}).") + logger.error(f"YargitayOfficialApiClient: 'data' field in API response is not a string or not found (ID: {id}).") raise ValueError("Expected HTML content not found in API response's 'data' field.") markdown_content = self._convert_html_to_markdown(html_content_from_api) return YargitayDocumentMarkdown( - document_id=document_id, + id=id, markdown_content=markdown_content, source_url=source_url ) except httpx.RequestError as e: - logger.error(f"YargitayOfficialApiClient: HTTP error fetching document for Markdown (ID: {document_id}): {e}") + logger.error(f"YargitayOfficialApiClient: HTTP error fetching document for Markdown (ID: {id}): {e}") raise except ValueError as e: # For JSON parsing errors or missing 'data' field - logger.error(f"YargitayOfficialApiClient: Error processing document response for Markdown (ID: {document_id}): {e}") + logger.error(f"YargitayOfficialApiClient: Error processing document response for Markdown (ID: {id}): {e}") raise except Exception as e: # For other unexpected errors - logger.error(f"YargitayOfficialApiClient: General error fetching/processing document for Markdown (ID: {document_id}): {e}") + logger.error(f"YargitayOfficialApiClient: General error fetching/processing document for Markdown (ID: {id}): {e}") raise async def close_client_session(self): diff --git a/yargitay_mcp_module/models.py b/yargitay_mcp_module/models.py index 6a073f3..f24d6b2 100644 --- a/yargitay_mcp_module/models.py +++ b/yargitay_mcp_module/models.py @@ -64,7 +64,7 @@ class YargitayApiSearchResponse(BaseModel): class YargitayDocumentMarkdown(BaseModel): """Model for a Yargitay decision document, containing only Markdown content.""" - document_id: str = Field(..., description="The unique ID of the document.") + id: str = Field(..., description="The unique ID of the document.") markdown_content: Optional[str] = Field(None, description="The decision content converted to Markdown.") source_url: HttpUrl = Field(..., description="The source URL of the original document.")