auto_analyze_image
Analyze images to extract and interpret code, architecture, errors, or documentation using file paths or clipboard input for targeted insights.
Instructions
自动获取并分析图片(支持文件路径或剪贴板)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| focusArea | No | 分析重点区域 | code |
| imagePath | No | 图片文件路径(可选,不提供则使用剪贴板) |
Implementation Reference
- src/services/auto-image-service.ts:25-82 (handler)The primary handler function that implements the tool logic: supports image input from file path, URL, or clipboard; processes and analyzes the image using GLMService; returns structured analysis result with source info.async autoGetAndAnalyzeImage( imagePath?: string, focusArea: 'code' | 'architecture' | 'error' | 'documentation' = 'code' ): Promise<ImageAnalysisResult & { source: string }> { try { logger.info('开始自动获取图片', { imagePath, focusArea }); let source: string; let finalImagePath: string; if (imagePath) { // 检查是否为网络URL if (this.isUrl(imagePath)) { source = 'url'; finalImagePath = await this.downloadImageFromUrl(imagePath); logger.info('从网络URL下载图片', { url: imagePath, path: finalImagePath }); } else { // 如果提供了文件路径,直接使用 source = 'file'; finalImagePath = imagePath; // 验证文件是否存在 if (!(await this.fileExists(finalImagePath))) { throw new Error(`文件不存在: ${imagePath}`); } logger.info('使用提供的文件路径', { path: finalImagePath }); } } else { // 如果没有提供文件路径,尝试从剪贴板获取 source = 'clipboard'; const clipboardImage = await this.getImageFromClipboard(); if (!clipboardImage) { throw new Error('无法获取图片:没有提供文件路径且剪贴板中没有图片'); } finalImagePath = clipboardImage; logger.info('从剪贴板获取图片', { path: finalImagePath }); } // 分析图片 const result = await this.analyzeImageFile(finalImagePath, focusArea); // 如果是剪贴板或URL下载的图片,清理临时文件 if (source === 'clipboard' || source === 'url') { await this.cleanupTempFile(finalImagePath); } return { ...result, source, }; } catch (error) { logger.error('自动获取并分析图片失败', { error }); throw new Error(`自动处理图片失败: ${error instanceof Error ? error.message : '未知错误'}`); } }
- src/index.ts:43-62 (schema)Input schema definition for the 'auto_analyze_image' tool, including parameters for imagePath (optional) and focusArea.{ name: 'auto_analyze_image', description: '自动获取并分析图片(支持文件路径、网络URL或剪贴板)', inputSchema: { type: 'object', properties: { imagePath: { type: 'string', description: '图片文件路径或网络URL(可选,不提供则使用剪贴板)', }, focusArea: { type: 'string', enum: ['code', 'architecture', 'error', 'documentation'], description: '分析重点区域', default: 'code', }, }, required: [], }, },
- src/index.ts:40-65 (registration)Tool registration in the ListToolsRequestHandler, exposing the tool to MCP clients.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'auto_analyze_image', description: '自动获取并分析图片(支持文件路径、网络URL或剪贴板)', inputSchema: { type: 'object', properties: { imagePath: { type: 'string', description: '图片文件路径或网络URL(可选,不提供则使用剪贴板)', }, focusArea: { type: 'string', enum: ['code', 'architecture', 'error', 'documentation'], description: '分析重点区域', default: 'code', }, }, required: [], }, }, ], }; });
- src/index.ts:76-81 (registration)Dispatch logic in CallToolRequestHandler that routes calls to the AutoImageService handler.if (name === 'auto_analyze_image') { result = await this.autoImageService.autoGetAndAnalyzeImage( typedArgs.imagePath, typedArgs.focusArea || 'code' ); } else {
- src/types/index.ts:1-16 (schema)TypeScript interface defining the structure of the image analysis result returned by the tool.export interface ImageAnalysisResult { description?: string; content?: string; type?: string; layout?: string; issues?: string[]; details?: string; summary: string; confidence: number; metadata?: { format?: string; width?: number; height?: number; fileSize?: string; }; }