Skip to main content
Glama

get_bedesten_document_markdown

Extract legal decision documents from Bedesten API in Markdown format by providing the document ID, enabling structured access to Turkish court rulings and legal data.

Instructions

Get legal decision document from Bedesten API in Markdown format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentIdYesDocument ID from Bedesten search results

Implementation Reference

  • MCP tool handler: Receives documentId parameter, validates it, and delegates to BedestenApiClient instance to fetch and return the document as markdown. This is the entry point for the tool.
    async def get_bedesten_document_markdown( documentId: str = Field(..., description="Document ID from Bedesten search results") ) -> BedestenDocumentMarkdown: """Get legal decision document as Markdown from Bedesten API.""" logger.info(f"Tool 'get_bedesten_document_markdown' called for ID: {documentId}") if not documentId or not documentId.strip(): raise ValueError("Document ID must be a non-empty string.") try: return await bedesten_client_instance.get_document_as_markdown(documentId) except Exception as e: logger.exception("Error in tool 'get_kyb_bedesten_document_markdown'") raise
  • BedestenApiClient.get_document_as_markdown: Fetches the document via API POST to /emsal-karar/getDocumentContent, decodes base64 content (HTML or PDF), converts to markdown using MarkItDown, handles errors, returns BedestenDocumentMarkdown.
    async def get_document_as_markdown(self, document_id: str) -> BedestenDocumentMarkdown: """ Get document content and convert to markdown. Handles both HTML (text/html) and PDF (application/pdf) content types. """ logger.info(f"BedestenApiClient: Fetching document for markdown conversion (ID: {document_id})") try: # Prepare request doc_request = BedestenDocumentRequest( data=BedestenDocumentRequestData(documentId=document_id) ) # Get document response = await self.http_client.post( self.DOCUMENT_ENDPOINT, json=doc_request.model_dump() ) response.raise_for_status() response_json = response.json() doc_response = BedestenDocumentResponse(**response_json) # Add null safety checks for document data if not hasattr(doc_response, 'data') or doc_response.data is None: raise ValueError("Document response does not contain data") if not hasattr(doc_response.data, 'content') or doc_response.data.content is None: raise ValueError("Document data does not contain content") if not hasattr(doc_response.data, 'mimeType') or doc_response.data.mimeType is None: raise ValueError("Document data does not contain mimeType") # Decode base64 content with error handling try: content_bytes = base64.b64decode(doc_response.data.content) except Exception as e: raise ValueError(f"Failed to decode base64 content: {str(e)}") mime_type = doc_response.data.mimeType logger.info(f"BedestenApiClient: Document mime type: {mime_type}") # Convert to markdown based on mime type if mime_type == "text/html": html_content = content_bytes.decode('utf-8') markdown_content = self._convert_html_to_markdown(html_content) elif mime_type == "application/pdf": markdown_content = self._convert_pdf_to_markdown(content_bytes) else: logger.warning(f"Unsupported mime type: {mime_type}") markdown_content = f"Unsupported content type: {mime_type}. Unable to convert to markdown." return BedestenDocumentMarkdown( documentId=document_id, markdown_content=markdown_content, source_url=f"{self.BASE_URL}/document/{document_id}", mime_type=mime_type ) except httpx.RequestError as e: logger.error(f"BedestenApiClient: HTTP error fetching document {document_id}: {e}") raise except Exception as e: logger.error(f"BedestenApiClient: Error processing document {document_id}: {e}") raise
  • Pydantic output schema/model for the tool response: BedestenDocumentMarkdown defining documentId, markdown_content, source_url, mime_type.
    class BedestenDocumentMarkdown(BaseModel): documentId: str = Field(..., description="The document ID (Belge Kimliği) from Bedesten") markdown_content: Optional[str] = Field(None, description="The decision content (Karar İçeriği) converted to Markdown") source_url: str = Field(..., description="The source URL (Kaynak URL) of the document") mime_type: Optional[str] = Field(None, description="Original content type (İçerik Türü) (text/html or application/pdf)")
  • @app.tool decorator registers the get_bedesten_document_markdown function as an MCP tool with description and annotations.
    @app.tool( description="Get legal decision document from Bedesten API in Markdown format", annotations={ "readOnlyHint": True, "idempotentHint": True } )
  • BedestenApiClient.close_client_session: Closes the httpx.AsyncClient session (cleanup).
    async def close_client_session(self): """Close HTTP client session""" await self.http_client.aclose() logger.info("BedestenApiClient: HTTP client session closed.")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saidsurucu/yargi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server