Skip to main content
Glama
saidsurucu

Yargı MCP

by saidsurucu

get_bedesten_document_markdown

Read-onlyIdempotent

Retrieve full text of Turkish court decisions in clean Markdown format using document IDs from Bedesten search results.

Instructions

Use this when retrieving full text of any Bedesten-supported court decision. Returns clean Markdown format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentIdYesDocument ID from Bedesten search results

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
mime_typeNoOriginal content type (İçerik Türü) (text/html or application/pdf)
documentIdYesThe document ID (Belge Kimliği) from Bedesten
source_urlYesThe source URL (Kaynak URL) of the document
markdown_contentNoThe decision content (Karar İçeriği) converted to Markdown

Implementation Reference

  • Core handler function that implements the get_bedesten_document_markdown tool logic: fetches document by ID from Bedesten API, handles base64 decoding, supports HTML and PDF mime types, converts to markdown using MarkItDown, and structures the response.
    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 schema defining the output structure of the tool response.
    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)")
  • Helper function for converting HTML content to markdown.
    def _convert_html_to_markdown(self, html_content: str) -> Optional[str]:
        """Convert HTML to Markdown using MarkItDown"""
        if not html_content:
            return None
            
        try:
            # Convert HTML string to bytes and create BytesIO stream
            html_bytes = html_content.encode('utf-8')
            html_stream = io.BytesIO(html_bytes)
            
            # Pass BytesIO stream to MarkItDown to avoid temp file creation
            md_converter = MarkItDown()
            result = md_converter.convert(html_stream)
            markdown_content = result.text_content
            
            logger.info("Successfully converted HTML to Markdown")
            return markdown_content
            
        except Exception as e:
            logger.error(f"Error converting HTML to Markdown: {e}")
            return f"Error converting HTML content: {str(e)}"
  • Helper function for converting PDF content to markdown.
    def _convert_pdf_to_markdown(self, pdf_bytes: bytes) -> Optional[str]:
        """Convert PDF to Markdown using MarkItDown"""
        if not pdf_bytes:
            return None
            
        try:
            # Create BytesIO stream from PDF bytes
            pdf_stream = io.BytesIO(pdf_bytes)
            
            # Pass BytesIO stream to MarkItDown to avoid temp file creation
            md_converter = MarkItDown()
            result = md_converter.convert(pdf_stream)
            markdown_content = result.text_content
            
            logger.info("Successfully converted PDF to Markdown")
            return markdown_content
            
        except Exception as e:
            logger.error(f"Error converting PDF to Markdown: {e}")
            return f"Error converting PDF content: {str(e)}. The document may be corrupted or in an unsupported format."
  • Input schema models used by the handler for API requests.
    class BedestenDocumentRequestData(BaseModel):
        documentId: str
    
    class BedestenDocumentRequest(BaseModel):
        data: BedestenDocumentRequestData
        applicationName: str = "UyapMevzuat"
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds valuable behavioral context beyond what annotations provide. While annotations indicate read-only and idempotent operations, the description specifies the return format ('clean Markdown format') and clarifies this is for 'full text' retrieval. This helps the agent understand the output characteristics that annotations don't cover.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and well-structured in just two sentences. The first sentence clearly states when to use the tool, and the second sentence specifies the return format. Every word serves a purpose with zero wasted text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of both annotations (readOnlyHint, idempotentHint) and an output schema, the description provides adequate context. It specifies the document source scope and output format, which complements the structured data well. However, it could be more complete by mentioning the relationship to search operations given the many sibling search tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the input schema already fully documents the single 'documentId' parameter. The description doesn't add any additional parameter semantics beyond what's in the schema, so it meets the baseline expectation without providing extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: retrieving full text of court decisions in Markdown format. It specifies the resource ('Bedesten-supported court decision') and the action ('retrieving full text'), but doesn't explicitly differentiate from sibling tools like 'get_bddk_document_markdown' or 'get_emsal_document_markdown' which likely serve similar purposes for different document sources.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides basic context ('when retrieving full text of any Bedesten-supported court decision') but doesn't offer explicit guidance on when to use this tool versus alternatives. With many sibling search tools present, the description doesn't clarify if this should be used after a search operation or as a standalone retrieval method.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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