Skip to main content
Glama
server.py1.34 kB
from mcp.server.fastmcp import FastMCP import json import os from .ocr import recognize_text, recognize_text_with_layout # Initialize FastMCP server mcp = FastMCP("macos-ocr") @mcp.tool() def read_image_text(image_path: str) -> str: """ Read text from an image using macOS native OCR. Args: image_path: Absolute path to the local image file. """ if not os.path.exists(image_path): raise FileNotFoundError(f"Image file not found: {image_path}") try: return recognize_text(image_path) except Exception as e: return f"Error processing image: {str(e)}" @mcp.tool() def read_image_layout(image_path: str) -> str: """ Read text with layout information (bounding boxes) from an image. Returns a JSON string containing a list of text blocks with their content, confidence, and normalized bounding boxes. Args: image_path: Absolute path to the local image file. """ if not os.path.exists(image_path): raise FileNotFoundError(f"Image file not found: {image_path}") try: data = recognize_text_with_layout(image_path) return json.dumps(data, ensure_ascii=False) except Exception as e: return json.dumps({"error": str(e)}) def main(): mcp.run() if __name__ == "__main__": main()

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/wenjiazhu/macos-ocr-mcp'

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