Skip to main content
Glama
penguinszp001

mcp-server-demo

analyze_image_with_openai

Upload an image file and provide a prompt to analyze its contents using OpenAI's vision model.

Instructions

Analyze an image file with an OpenAI vision-capable model.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
promptYes
modelNogpt-4.1-mini

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:233-234 (registration)
    Tool registration via @mcp.tool() decorator on the analyze_image_with_openai function
    @mcp.tool()
    def analyze_image_with_openai(path: str, prompt: str, model: str = "gpt-4.1-mini") -> str:
  • Main handler: reads an image file, encodes it as base64, sends it to OpenAI's vision model via responses API, and returns the model's text output
    def analyze_image_with_openai(path: str, prompt: str, model: str = "gpt-4.1-mini") -> str:
        """Analyze an image file with an OpenAI vision-capable model."""
        api_key = os.getenv("OPENAI_API_KEY")
        if not api_key:
            raise ValueError("OPENAI_API_KEY is not configured.")
    
        target = _resolve_file_ops_path(path)
        if not target.is_file():
            raise ValueError(f"File does not exist: {target}")
    
        mime_type, _ = mimetypes.guess_type(str(target))
        if not mime_type or not mime_type.startswith("image/"):
            raise ValueError(f"File is not an image: {target}")
    
        image_bytes = target.read_bytes()
        image_b64 = base64.b64encode(image_bytes).decode("ascii")
        data_url = f"data:{mime_type};base64,{image_b64}"
    
        client = OpenAI(api_key=api_key)
        response = client.responses.create(
            model=model,
            input=[
                {
                    "role": "user",
                    "content": [
                        {"type": "input_text", "text": prompt},
                        {"type": "input_image", "image_url": data_url},
                    ],
                }
            ],
        )
        return response.output_text
  • Function signature defines the input schema: path (str), prompt (str), model (str, default 'gpt-4.1-mini')
    def analyze_image_with_openai(path: str, prompt: str, model: str = "gpt-4.1-mini") -> str:
  • _resolve_file_ops_path helper is used to resolve and validate the image path within the allowed root directory
    def _resolve_file_ops_path(path: str | None = None) -> Path:
        if not FILE_OPS_ROOT:
            raise ValueError("MCP_FILE_OPS_ROOT is not configured in .env.")
    
        root = Path(FILE_OPS_ROOT).expanduser().resolve()
        root.mkdir(parents=True, exist_ok=True)
    
        target = root if path is None else (root / path).resolve()
        if target != root and root not in target.parents:
            raise ValueError("Path escapes the configured MCP_FILE_OPS_ROOT.")
        return target
  • Reference to the tool in the inspect_file handler, telling users to use analyze_image_with_openai for image analysis
    elif mime_type.startswith("image/"):
        result["image_note"] = "Use analyze_image_with_openai for model vision interpretation."
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 only states the high-level action without disclosing any behavioral traits (e.g., file size limits, authentication needs, side effects). The existence of an output schema is not mentioned.

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 extremely concise at one sentence, but it is under-specified. While it avoids fluff, it sacrifices necessary detail, making it minimally adequate.

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 tool has 3 parameters with no descriptions and no annotations, the description is insufficient. It does not cover parameter semantics, output, or usage context, leaving significant gaps for an agent.

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

Parameters1/5

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

Schema description coverage is 0%, and the description adds no meaning to the parameters 'path', 'prompt', or 'model'. It does not explain their purpose, format, or constraints, leaving the agent to rely solely on parameter names.

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 analyzes an image file with an OpenAI vision-capable model, specifying the verb and resource. However, it does not differentiate from sibling tools like inspect_file, which may have overlapping functionality.

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?

The description provides no guidance on when to use this tool versus alternatives. It lacks context about prerequisites, suitable scenarios, or when not to use it.

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/penguinszp001/mcp-server-demo'

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