Skip to main content
Glama
snussik
by snussik

process_url_file

Extract text and tables from documents at URLs into structured markdown and HTML formats using optimized OCR processing.

Instructions

Process a file from a URL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argumentsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool registration and handler function for "process_url_file". Validates input arguments and calls the underlying ocr_processor logic.
    @app.tool("process_url_file")
    async def process_url_file(arguments: Dict[str, Any]) -> List[TextContent]:
        """Process a file from a URL."""
        url = arguments.get("url")
        file_type = arguments.get("file_type")
    
        if not url:
            raise McpError(ErrorData(code=INVALID_PARAMS, message="url is required"))
        if not file_type:
            raise McpError(ErrorData(code=INVALID_PARAMS, message="file_type is required"))
    
        if file_type not in ["image", "pdf"]:
            raise McpError(
                ErrorData(
                    code=INVALID_PARAMS, message="file_type must be either 'image' or 'pdf'"
                )
            )
    
        try:
            result = await ocr_processor.process_url_file(
                url=url,
                file_type=file_type,
                table_format=arguments.get("table_format"),
                extract_header=arguments.get("extract_header", False),
                extract_footer=arguments.get("extract_footer", False),
                include_images=arguments.get("include_images", False),
            )
    
            return [
                TextContent(
                    type="text", text=json.dumps(result, indent=2, ensure_ascii=False)
                )
            ]
        except Exception as e:
            raise McpError(
                ErrorData(code=INTERNAL_ERROR, message=f"Error processing URL: {str(e)}")
            )
  • The core implementation of the OCR processing for files provided via URL using the Mistral SDK.
    async def process_url_file(
        self,
        url: str,
        file_type: str,
        table_format: Optional[str] = None,
        extract_header: bool = False,
        extract_footer: bool = False,
        include_images: bool = False,
    ) -> Dict[str, Any]:
        """Process a file from a URL using Mistral's OCR capabilities.
    
        Args:
            url: URL of the file to process
            file_type: Type of file: 'image' or 'pdf'
            table_format: Table formatting option (null, markdown, html)
            extract_header: Extract document headers
            extract_footer: Extract document footers
            include_images: Include base64 images in output
    
        Returns:
            Dictionary with result and metadata
        """
        if file_type not in ["image", "pdf"]:
            raise ValueError("file_type must be either 'image' or 'pdf'")
    
        # Get client from pool
        client_pool = await self._ensure_client_pool()
        client = await client_pool.get_client()
    
        try:
            # Build OCR parameters
            ocr_params = {
                "model": self.config.model,
                "document": {
                    "type": "image_url" if file_type == "image" else "document_url",
                    f"{'image' if file_type == 'image' else 'document'}_url": url,
                },
            }
    
            # Add optional parameters (use defaults from config if not specified)
            final_table_format = table_format or self.config.default_table_format
            final_extract_header = extract_header or self.config.default_extract_header
            final_extract_footer = extract_footer or self.config.default_extract_footer
            final_include_images = include_images or self.config.default_include_images
    
            if final_table_format and final_table_format != "null":
                ocr_params["table_format"] = final_table_format
            if final_extract_header:
                ocr_params["extract_header"] = True
            if final_extract_footer:
                ocr_params["extract_footer"] = True
            if final_include_images:
                ocr_params["include_image_base64"] = True
    
            # Process the document
            response = await asyncio.to_thread(client.ocr.process, **ocr_params)
    
            # Convert response to JSON
            result = json.loads(self._process_response(response))
    
            # Extract filename from URL
            parsed_url = urlparse(url)
            source_name = Path(parsed_url.path).stem or "url_document"
    
            # Save result to output directory
            result_path = self._save_result(result, source_name)
    
            # Add metadata to result
            result["_metadata"] = {
                "source_url": url,
                "output_file": str(result_path),
Behavior2/5

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

No annotations are provided, so the description carries full burden. It discloses nothing about side effects, idempotency, supported file formats, size limits, authentication requirements, or what the output schema contains. The term 'process' is behaviorally opaque.

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

Conciseness3/5

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

The description is a single short sentence, which prevents redundancy. However, it is under-specified for the complexity involved—five words cannot adequately describe a tool with nested objects and an output schema.

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

Completeness2/5

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

Given the existence of an output schema and a complex nested parameter (arguments with additionalProperties), the description is insufficient. The opaque parameter bag requires documentation that is absent from both schema and description.

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

Parameters2/5

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

Schema coverage is 0% and the description fails to compensate. While it mentions 'from a URL,' the actual parameter is an opaque 'arguments' object with no documented structure. The description doesn't clarify what keys (e.g., 'url', 'headers') should be included in the arguments object.

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

Purpose3/5

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

The description uses the vague verb 'process' but does specify the resource (file) and distinguishes from siblings by mentioning 'from a URL' (contrasting with process_local_file and process_batch_local_files). However, it fails to specify what processing actually occurs (download, parse, validate, etc.).

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus process_local_file or process_batch_local_files. While 'URL' in the name/description implies remote files versus local, it doesn't state prerequisites (e.g., publicly accessible URLs) or when local processing is preferred.

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/snussik/mcp_mistral_ocr_opt'

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