get_bddk_document_markdown
Convert BDDK decision documents into Markdown format by providing the document ID and optional page number, simplifying access to legal texts for analysis and processing.
Instructions
Get BDDK decision document as Markdown
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | BDDK document ID (e.g., '310') | |
| page_number | No | Page number |
Implementation Reference
- mcp_server_main.py:1820-1864 (registration)MCP tool registration (@app.tool) and thin handler wrapper that invokes BddkApiClient.get_document_markdown and formats response@app.tool( description="Get BDDK decision document as Markdown", annotations={ "readOnlyHint": True, "openWorldHint": False, "idempotentHint": True } ) async def get_bddk_document_markdown( document_id: str = Field(..., description="BDDK document ID (e.g., '310')"), page_number: int = Field(1, ge=1, description="Page number") ) -> dict: """Retrieve BDDK decision document in Markdown format.""" logger.info(f"BDDK document retrieval tool called for ID: {document_id}, page: {page_number}") if not document_id or not document_id.strip(): return { "document_id": document_id, "markdown_content": "", "page_number": page_number, "total_pages": 0, "error": "Document ID is required" } try: result = await bddk_client_instance.get_document_markdown(document_id, page_number) logger.info(f"BDDK document retrieved successfully. Page {result.page_number}/{result.total_pages}") return { "document_id": result.document_id, "markdown_content": result.markdown_content, "page_number": result.page_number, "total_pages": result.total_pages } except Exception as e: logger.exception(f"Error retrieving BDDK document: {e}") return { "document_id": document_id, "markdown_content": "", "page_number": page_number, "total_pages": 0, "error": str(e) }
- bddk_mcp_module/client.py:162-247 (handler)Core handler logic in BddkApiClient.get_document_markdown: fetches document from multiple URL patterns, converts PDF/HTML to paginated Markdown using MarkItDownasync def get_document_markdown( self, document_id: str, page_number: int = 1 ) -> BddkDocumentMarkdown: """ Retrieve a BDDK document and convert it to Markdown format. Args: document_id: BDDK document ID (e.g., '310') page_number: Page number for paginated content (1-indexed) Returns: BddkDocumentMarkdown with paginated content """ try: # Try different URL patterns for BDDK documents potential_urls = [ f"https://www.bddk.org.tr/Mevzuat/DokumanGetir/{document_id}", f"https://www.bddk.org.tr/Mevzuat/Liste/{document_id}", f"https://www.bddk.org.tr/KurumHakkinda/EkGetir/13?ekId={document_id}", f"https://www.bddk.org.tr/KurumHakkinda/EkGetir/5?ekId={document_id}" ] document_url = None response = None # Try each URL pattern until one works for url in potential_urls: try: logger.info(f"Trying BDDK document URL: {url}") response = await self.http_client.get( url, follow_redirects=True ) response.raise_for_status() document_url = url break except httpx.HTTPStatusError: continue if not response or not document_url: raise Exception(f"Could not find document with ID {document_id}") logger.info(f"Successfully fetched BDDK document from: {document_url}") # Determine content type content_type = response.headers.get("content-type", "").lower() # Convert to Markdown based on content type if "pdf" in content_type: # Handle PDF documents pdf_stream = io.BytesIO(response.content) result = self.markitdown.convert_stream(pdf_stream, file_extension=".pdf") markdown_content = result.text_content else: # Handle HTML documents html_stream = io.BytesIO(response.content) result = self.markitdown.convert_stream(html_stream, file_extension=".html") markdown_content = result.text_content # Clean up the markdown content markdown_content = markdown_content.strip() # Calculate pagination total_length = len(markdown_content) total_pages = math.ceil(total_length / self.DOCUMENT_MARKDOWN_CHUNK_SIZE) # Extract the requested page start_idx = (page_number - 1) * self.DOCUMENT_MARKDOWN_CHUNK_SIZE end_idx = start_idx + self.DOCUMENT_MARKDOWN_CHUNK_SIZE page_content = markdown_content[start_idx:end_idx] return BddkDocumentMarkdown( document_id=document_id, markdown_content=page_content, page_number=page_number, total_pages=total_pages ) except httpx.HTTPStatusError as e: logger.error(f"HTTP error fetching BDDK document {document_id}: {e}") raise Exception(f"Failed to fetch BDDK document: {str(e)}") except Exception as e: logger.error(f"Error processing BDDK document {document_id}: {e}") raise Exception(f"Failed to process BDDK document: {str(e)}")
- bddk_mcp_module/models.py:34-43 (schema)Pydantic schema/model for BddkDocumentMarkdown response defining structure and validationclass BddkDocumentMarkdown(BaseModel): """ BDDK decision document converted to Markdown format. Supports paginated content for long documents (5000 chars per page). """ document_id: str = Field(..., description="BDDK document ID") markdown_content: str = Field("", description="Document content in Markdown") page_number: int = Field(1, description="Current page number") total_pages: int = Field(1, description="Total number of pages")
- mcp_server_main.py:363-363 (helper)Global singleton instance of BddkApiClient used by the tool handlerbddk_client_instance = BddkApiClient()
- mcp_server_main.py:330-336 (helper)Imports for BddkApiClient class and BddkDocumentMarkdown model used in tool implementationfrom bddk_mcp_module.client import BddkApiClient from bddk_mcp_module.models import ( BddkSearchRequest, BddkSearchResult, BddkDocumentMarkdown )