Skip to main content
Glama
stabgan

OpenRouter MCP Multimodal Server

by stabgan

analyze_image

Analyze images by answering questions about visual content using AI vision models to extract information and insights.

Instructions

Analyze an image using a vision model

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_pathYesFile path, URL, or data URL
questionNoQuestion about the image
modelNo

Implementation Reference

  • The handler function `handleAnalyzeImage` which processes the image analysis request by preparing the image and sending it to the OpenRouter/OpenAI API.
    export async function handleAnalyzeImage(
      request: { params: { arguments: AnalyzeImageToolRequest } },
      openai: OpenAI,
      defaultModel?: string,
    ) {
      const { image_path, question, model } = request.params.arguments;
    
      if (!image_path) {
        return { content: [{ type: 'text', text: 'image_path is required.' }], isError: true };
      }
    
      try {
        const imageUrl = await prepareImageUrl(image_path);
    
        const completion = await openai.chat.completions.create({
          model: model || defaultModel || DEFAULT_MODEL,
          messages: [
            {
              role: 'user',
              content: [
                { type: 'text', text: question || "What's in this image?" },
                { type: 'image_url', image_url: { url: imageUrl } },
              ],
            },
          ] as ChatCompletionMessageParam[],
        });
    
        return { content: [{ type: 'text', text: completion.choices[0].message.content || '' }] };
      } catch (error: unknown) {
        const msg = error instanceof Error ? error.message : String(error);
        return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
      }
    }
  • The `AnalyzeImageToolRequest` interface defining the expected input structure for the `analyze_image` tool.
    export interface AnalyzeImageToolRequest {
      image_path: string;
      question?: string;
      model?: string;
    }
  • Registration of the `analyze_image` tool in the `ListToolsRequestSchema` handler.
    {
      name: 'analyze_image',
      description: 'Analyze an image using a vision model',
      inputSchema: {
        type: 'object',
        properties: {
          image_path: { type: 'string', description: 'File path, URL, or data URL' },
          question: { type: 'string', description: 'Question about the image' },
          model: { type: 'string' },
        },
        required: ['image_path'],
      },
    },
  • The `CallToolRequestSchema` handler routing the `analyze_image` request to the implementation function.
    case 'analyze_image':
      return handleAnalyzeImage(
        wrapToolArgs(args as AnalyzeImageToolRequest | undefined),
        this.openai,
        this.defaultModel,
      );

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/stabgan/openrouter-mcp-multimodal'

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