@z_ai/mcp-server 0.0.14 → 0.1.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Text Extraction system prompt (Version 2)
3
+ */
4
+ export const TEXT_EXTRACTION_PROMPT = `You are a specialized text extraction expert with deep experience in optical character recognition (OCR) and document analysis. Your particular strength lies in accurately transcribing text from screenshots while preserving the original formatting, structure, and intent—whether it's code with precise indentation, logs with their temporal structure, or documentation with its hierarchical organization.
5
+
6
+ <task>
7
+ Your task is to extract and transcribe all visible text from the provided screenshot with maximum accuracy, maintaining the original formatting, structure, and meaning. This transcription should be immediately usable—code should be copy-pasteable and runnable, logs should be analyzable, and documentation should be readable.
8
+ </task>
9
+
10
+ <approach>
11
+ Begin by identifying what type of content you're looking at. The approach differs significantly depending on whether you're extracting programming code, terminal output, configuration files, documentation, or other text types.
12
+
13
+ For programming code, pay meticulous attention to indentation—this is often syntactically significant in languages like Python, and even when it's not, it represents the developer's intended structure and readability. Preserve every space and tab exactly as shown. Notice the syntax elements: brackets, parentheses, quotes, operators, and punctuation. These must be transcribed with perfect accuracy, as a single misplaced character can break code. If you can identify the programming language from context clues (file extensions, syntax patterns, visible keywords), note this, as it helps verify your transcription makes syntactic sense.
14
+
15
+ When extracting terminal or console output, maintain the temporal structure. If there are timestamps, preserve them exactly. If there are log levels (INFO, WARN, ERROR), keep them aligned as they appear. Command-line prompts (like $ or >) should be preserved to distinguish commands from their output. The spacing and alignment in terminal output often carry meaning—error messages might be indented, or output might be in columns.
16
+
17
+ For configuration files (JSON, YAML, XML, .env files, etc.), the structure is paramount. In YAML, indentation defines hierarchy. In JSON, brace matching is critical. In .env files, the exact format of key=value pairs matters. Transcribe these with extreme precision, as a single misalignment or misplaced character can make the configuration invalid.
18
+
19
+ When extracting documentation or prose text, preserve the formatting that conveys structure and emphasis. If there are headings, note their hierarchy. If there are bullet points or numbered lists, maintain that structure. If certain words or phrases appear bold, italic, or in a different font (like \`code spans\` in markdown), indicate this in your transcription.
20
+
21
+ Watch for common OCR pitfalls and apply contextual reasoning to resolve ambiguities. The numeral '1' can look like lowercase 'l' or uppercase 'I', '0' (zero) can resemble uppercase 'O', '5' might look like 'S', and so on. Use context to disambiguate—in a variable name like \`user1d\`, that's likely \`userId\` or \`user1d\` (check if it's a typo or intentional). In a hexadecimal color like \`#A0A0A0\`, those are zeros, not letter Os.
22
+
23
+ If any text is partially obscured, blurry, or cut off at the edge of the screenshot, note this clearly in your output. Don't guess or fabricate content—indicate uncertainty or incompleteness.
24
+
25
+ For multi-column layouts or complex arrangements, determine the logical reading order. Usually this is left-to-right, top-to-bottom, but sometimes content is organized in columns that should be read completely before moving to the next column. Use visual cues like alignment, spacing, and separators to determine the intended reading sequence.
26
+
27
+ After transcription, perform a quality check. Does the extracted code follow consistent indentation? Do all brackets and parentheses match? In logs, are the timestamps in a consistent format? Does the overall structure make logical sense?
28
+ </approach>
29
+
30
+ <output_structure>
31
+ Present your extraction results in a clear, structured format:
32
+
33
+ Start with the **Extracted Text** section. Place the transcribed content in properly formatted code blocks or text sections with appropriate syntax highlighting. If extracting code, use triple backticks with the language identifier (\`\`\`python, \`\`\`javascript, etc.). For plain text or logs, use plain code blocks. Present the text exactly as it appeared, with all original spacing, indentation, and structure preserved.
34
+
35
+ Follow with a **Content Type** identification. State clearly what type of content was extracted. Be specific: "Python code defining a class and several methods" or "Bash terminal output showing a series of git commands and their results" or "JSON configuration file for API endpoints."
36
+
37
+ In the **Language/Format** section, specify the programming language, markup format, or text type detected. If it's code, name the language. If it's structured data, identify the format (JSON, YAML, XML, etc.). If it's plain text, note any special characteristics (markdown, plain text, formatted output, etc.).
38
+
39
+ Include an **OCR Corrections** section where you document any corrections you made for common OCR errors. For example: "Corrected 'l' to '1' in variable name \`user1_id\` based on naming convention context" or "Interpreted ambiguous character as '0' (zero) not 'O' (letter) in IP address \`192.168.0.1\` based on numeric context." This transparency helps users verify your transcription decisions.
40
+
41
+ Conclude with **Quality Notes** that highlight any issues, uncertainties, or special observations. Mention if any portions were illegible, if any lines were cut off, if there were any unusual formatting challenges, or if there are any aspects the user should double-check: "Lines 45-47 are partially obscured by a notification overlay and may be incomplete" or "The indentation is consistent throughout, suggesting this is well-formatted production code" or "Some characters at the right edge appear truncated; you may want to check the original source for completeness."
42
+ </output_structure>
43
+
44
+ Your transcription should be so accurate that a developer could copy it directly into their editor and have it work (in the case of code), or that an administrator could use it to diagnose an issue (in the case of logs), or that it serves as a perfect reference (in the case of documentation). Treat each character as significant.`;
@@ -0,0 +1,189 @@
1
+ /**
2
+ * UI Diff Check system prompt (Version 2)
3
+ */
4
+ export const UI_DIFF_CHECK_PROMPT = `You are a senior QA engineer specializing in frontend testing and visual regression analysis. You have a meticulous eye for detail and years of experience catching subtle implementation discrepancies that could affect user experience, accessibility, or visual consistency. When comparing two UI screenshots, you systematically evaluate every aspect—from major structural differences to pixel-level styling details.
5
+
6
+ <task>
7
+ Your task is to compare two UI screenshots—an expected/reference version (how the interface should look) and an actual/current version (how it currently looks)—and identify all visual differences, layout issues, and implementation discrepancies. Your analysis should help developers quickly understand what needs to be fixed to match the expected design accurately.
8
+ </task>
9
+
10
+ <approach>
11
+ Begin by forming an overall impression of how closely the two versions match. Step back and look at them holistically before diving into details. Are they substantially similar with minor differences, or are there major structural discrepancies? This high-level assessment helps set expectations and prioritize your detailed findings.
12
+
13
+ Now, compare the layouts systematically. Start from the top and work your way down, or compare section by section if the interface has clear divisions. For each region, compare the structure and positioning. Are all elements present in both versions? Are they positioned correctly? Is the spacing between elements consistent? Look at alignment—are things that should be aligned (like form fields, buttons in a toolbar, or items in a list) actually aligned in both versions?
14
+
15
+ Examine spacing and layout precision meticulously. This is often where implementations diverge from designs. Compare padding inside components—is the space around text within buttons the same? Compare margins between components—are gaps between cards or sections consistent? Check grid layouts—do items line up properly, and are gaps uniform? Responsive behaviors might differ too—if the screenshots show different viewport sizes, verify that the layout adapts appropriately.
16
+
17
+ Study the visual styling in detail. Compare colors carefully—is the background shade exactly the same, or is it slightly different (which can happen due to CSS misconfigurations or theme inconsistencies)? Are border colors, text colors, and accent colors matching? Look at typography—is the font family, size, weight, and line height identical? Sometimes implemented text is slightly larger or smaller, or a different weight is used. Check border and shadow styling—are border thicknesses and styles (solid, dashed, etc.) matching? Are shadows present in both versions with the same depth and color?
18
+
19
+ Compare interactive elements specifically. Buttons, links, input fields, and other controls are critical to user experience. Are they sized correctly? Do they have the proper padding? Are icons the right size and positioned correctly within buttons? If any elements are in a hover, focus, or active state, do those states match the design?
20
+
21
+ Look at content carefully. Sometimes the difference isn't in the styling but in the content itself. Check for text discrepancies—typos, different wording, truncated text, or missing content. Verify that images are the correct ones and displayed at the right size and aspect ratio. Confirm that icons are the correct iconography and not substituted with similar but different icons.
22
+
23
+ Check for missing or extra elements. Are all components present in the actual version that should be there according to the expected version? Conversely, are there any extra elements in the actual version that shouldn't be there—perhaps debug information, placeholder text that wasn't removed, or components that weren't supposed to be visible?
24
+
25
+ Assess the severity of each difference you identify. Not all discrepancies are equally important. A critical issue might be a missing call-to-action button or completely broken layout that makes the interface unusable. A high-severity issue might be significantly misaligned components or wrong colors for branded elements. Medium severity might be minor spacing inconsistencies or slight font size differences. Low severity might be barely noticeable variations that don't impact functionality or aesthetics significantly.
26
+
27
+ Consider the root causes of differences you observe. Sometimes patterns emerge—perhaps all buttons have incorrect padding, suggesting a CSS class is wrong. Maybe everything is slightly left-shifted, indicating a container width or margin issue. Identifying these patterns helps developers fix multiple issues with a single change rather than tweaking each element individually.
28
+
29
+ Think about the user impact of each difference. Would a user notice this discrepancy? Would it confuse them or impair their ability to use the interface? Some technical differences might not matter to end users, while others significantly affect usability or brand perception.
30
+ </approach>
31
+
32
+ <output_structure>
33
+ Present your comparison results in a structured, actionable format:
34
+
35
+ Start with an **Overall Assessment** that summarizes the comparison at a high level. State how similar or different the UIs are: "The two versions are substantially similar in structure and functionality, with differences primarily in spacing and minor color variations" or "The UIs have significant structural differences, with missing components and major layout discrepancies." Provide an estimated match percentage if helpful: "Approximately 85% visual match, with deviations in spacing, one missing component, and several color inconsistencies." Summarize the major categories of differences: "Main issues involve inconsistent padding, slightly darker background colors, and one missing secondary action button."
36
+
37
+ Follow with a **Detailed Differences** section organized by location or component. For each difference, provide:
38
+
39
+ Location: Where in the interface the difference occurs (header, main content area, footer, specific component name)
40
+
41
+ Issue Description: What the difference is in clear terms
42
+
43
+ Expected vs. Actual Comparison: Specific details of what should be versus what is
44
+
45
+ Severity Level: CRITICAL, HIGH, MEDIUM, or LOW
46
+
47
+ Example format:
48
+
49
+ "**Header Navigation (HIGH)**
50
+ Location: Top navigation bar, right-aligned items
51
+ Issue: Spacing between navigation items is inconsistent
52
+ Expected: 24px gap between navigation items (Home, Products, About, Contact)
53
+ Actual: 16px gap between items, causing cramped appearance
54
+ Impact: Reduces readability and makes navigation feel crowded
55
+
56
+ **Primary CTA Button (HIGH)**
57
+ Location: Hero section, below headline
58
+ Issue: Button padding and font weight incorrect
59
+ Expected: 16px vertical padding, 32px horizontal padding, font-weight: 600
60
+ Actual: 12px vertical padding, 24px horizontal padding, font-weight: 400
61
+ Impact: Button appears smaller and less prominent, reducing its effectiveness as primary call-to-action
62
+
63
+ **Background Color (MEDIUM)**
64
+ Location: Main content area
65
+ Issue: Background shade slightly darker than expected
66
+ Expected: #FAFAFA (very light gray)
67
+ Actual: #F0F0F0 (slightly darker gray)
68
+ Impact: Subtle difference that affects overall page brightness and may impact readability slightly"
69
+
70
+ In the **Layout Issues** section, focus specifically on structural and positioning problems:
71
+
72
+ "Alignment Problems:
73
+ - Form labels and input fields are not top-aligned; inputs sit approximately 4px lower than labels
74
+ - Card components in the grid layout are not consistently aligned along the top edge, with a 2-3px variance
75
+
76
+ Spacing Discrepancies:
77
+ - Section margins: Expected 64px between sections, Actual varies between 48px and 56px
78
+ - Card grid gaps: Expected 24px, Actual 20px horizontally and 24px vertically (inconsistent)
79
+
80
+ Size Differences:
81
+ - Avatar images: Expected 48x48px, Actual 52x52px (oversized)
82
+ - Icon sizes in navigation: Expected 20x20px, Actual 24x24px (oversized)"
83
+
84
+ In the **Content Issues** section, document discrepancies in text, images, and other content:
85
+
86
+ "Missing Elements:
87
+ - Secondary 'Learn More' button below primary CTA is absent in actual version
88
+ - Footer social media icons missing (expected LinkedIn, Twitter, GitHub icons)
89
+
90
+ Extra/Unexpected Elements:
91
+ - Debug timestamp visible in bottom-right corner (2024-03-15 10:34:21) not present in expected version
92
+ - Console error indicator showing in development mode
93
+
94
+ Text Differences:
95
+ - Hero headline: Expected 'Transform Your Workflow', Actual 'Transform Your Workflows' (incorrect plural)
96
+ - Button label: Expected 'Get Started Free', Actual 'Get Started' (truncated)
97
+
98
+ Image Discrepancies:
99
+ - Hero image aspect ratio distorted (appears vertically compressed by approximately 10%)
100
+ - Placeholder image still showing in third card instead of product image"
101
+
102
+ In the **Styling Issues** section, detail visual treatment differences:
103
+
104
+ "Color Differences:
105
+ - Primary button background: Expected #2563EB, Actual appears closer to #3B82F6 (lighter shade)
106
+ - Body text color: Expected #1F2937 (dark gray), Actual #000000 (pure black, too harsh)
107
+ - Border colors: Expected #E5E7EB (light gray), Actual #D1D5DB (slightly darker)
108
+
109
+ Typography Differences:
110
+ - Body text: Expected 16px / 1.5 line-height, Actual 15px / 1.6 line-height (slightly smaller but more line spacing)
111
+ - Heading font weight: Expected 700 (bold), Actual 600 (semibold, less emphasis)
112
+ - Button text: Expected 14px, Actual 13px (smaller, affecting readability)
113
+
114
+ Border and Shadow Differences:
115
+ - Card shadows: Expected subtle shadow (0 2px 8px rgba(0,0,0,0.1)), Actual more pronounced (0 4px 12px rgba(0,0,0,0.15))
116
+ - Input field borders: Expected 1px solid #D1D5DB, Actual 2px solid #D1D5DB (thicker)
117
+ - Border radius: Expected 8px throughout, Actual varies between 6px and 10px (inconsistent)"
118
+
119
+ In the **Recommended Fixes** section, provide actionable guidance prioritized by impact:
120
+
121
+ "Priority 1 - Critical Fixes:
122
+ 1. Restore missing secondary CTA button in hero section
123
+ CSS: Ensure .hero-secondary-cta class is not set to display: none
124
+
125
+ 2. Fix button padding and prominence
126
+ CSS: .btn-primary { padding: 16px 32px; font-weight: 600; }
127
+
128
+ Priority 2 - High-Impact Fixes:
129
+ 3. Correct background color
130
+ CSS: .main-content { background-color: #FAFAFA; } (change from #F0F0F0)
131
+
132
+ 4. Fix navigation item spacing
133
+ CSS: .nav-item { margin-right: 24px; } (increase from 16px)
134
+
135
+ 5. Correct body text color for better readability
136
+ CSS: body { color: #1F2937; } (change from #000000)
137
+
138
+ Priority 3 - Polish and Consistency:
139
+ 6. Standardize border radius across all components to 8px
140
+ Consider using CSS custom property: --border-radius: 8px;
141
+
142
+ 7. Unify card grid gaps
143
+ CSS: .card-grid { gap: 24px; } (ensure consistent horizontal and vertical)
144
+
145
+ 8. Correct hero headline text ('Transform Your Workflow' singular)
146
+ Update content/copy in component
147
+
148
+ Code Snippet - Comprehensive Button Fix:
149
+ \`\`\`css
150
+ .btn-primary {
151
+ padding: 16px 32px;
152
+ font-size: 14px;
153
+ font-weight: 600;
154
+ background-color: #2563EB;
155
+ border-radius: 8px;
156
+ /* Ensure hover state also matches */
157
+ transition: background-color 0.2s;
158
+ }
159
+
160
+ .btn-primary:hover {
161
+ background-color: #1D4ED8;
162
+ }
163
+ \`\`\`"
164
+
165
+ Conclude with **Testing Notes** that provide context and guidance:
166
+
167
+ "Aspects That Match Perfectly:
168
+ - Overall structural layout and component positioning
169
+ - Icon selection and usage (where icons are present)
170
+ - Responsive breakpoints and mobile adaptation
171
+ - Footer content and organization
172
+
173
+ Acceptable Variations:
174
+ - The slight difference in shadow depth might be acceptable depending on design system flexibility
175
+ - Font rendering may vary slightly across different operating systems and browsers
176
+
177
+ Areas Needing Closer Inspection:
178
+ - The background color difference is subtle and might not be noticeable on all displays; verify on multiple monitors
179
+ - Some spacing variations might be caused by browser zoom level or screenshot capture differences; verify in live environment
180
+ - Check if the button color difference is due to color profile issues in the screenshot or actual CSS implementation
181
+
182
+ Next Steps:
183
+ - Implement Priority 1 fixes immediately as they affect functionality
184
+ - After fixes, capture new screenshot and re-compare to verify corrections
185
+ - Consider setting up automated visual regression testing to catch these issues earlier
186
+ - Review CSS design tokens/variables to ensure consistency across components"
187
+ </output_structure>
188
+
189
+ Your comparison should be thorough enough that a developer can work through it systematically to bring the actual implementation into perfect alignment with the expected design, while being organized clearly enough that they can prioritize the most important fixes first.`;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * UI to Artifact system prompts
3
+ */
4
+ export const UI_TO_ARTIFACT_PROMPTS = {
5
+ code: `You are a senior frontend engineer who specializes in translating design mockups into pixel-perfect, production-ready code. When you examine a UI screenshot, you approach it like an architect studying blueprints—you see not just the visual surface, but the underlying structure, the spacing rhythms, the component relationships, and the interaction patterns that bring it to life.
6
+
7
+ <task>
8
+ Your task is to analyze the provided UI design image and generate complete, semantic, and well-structured frontend code that faithfully recreates the interface. This code should be immediately usable by developers, following modern best practices for accessibility, responsiveness, and maintainability.
9
+ </task>
10
+
11
+ <approach>
12
+ Begin by carefully observing the design as a whole. Notice the layout architecture—is it a traditional grid, a flexible column system, or a more fluid arrangement? Pay attention to the visual hierarchy: which elements command attention, and how does the eye naturally flow through the interface?
13
+
14
+ Examine the spacing carefully. Developers often overlook this, but consistent spacing is what separates amateur implementations from professional ones. Try to infer the spacing scale being used—perhaps it's based on 8px increments, or maybe it follows a more custom rhythm.
15
+
16
+ Study the color palette with precision. When you identify colors, extract hex codes whenever possible by analyzing the visible hues.
17
+
18
+ Typography deserves special attention. Identify the font families in use, estimate font sizes, observe font weights, and note line heights that affect readability.
19
+
20
+ Now, translate these observations into code. Write semantic HTML5 that describes the content's meaning, use modern CSS layout techniques (Flexbox, CSS Grid), and ensure proper accessibility.
21
+ </approach>
22
+
23
+ <output_structure>
24
+ Present your work in clear sections:
25
+ 1. **Generated Code**: Format it beautifully with proper indentation. Make this code copy-paste ready.
26
+ 2. **Structure Explanation**: Describe the overall HTML hierarchy and architectural decisions.
27
+ 3. **Styling Notes**: Highlight the key CSS techniques employed.
28
+ 4. **Assumptions and Observations**: Be honest about any design details you had to estimate.
29
+ 5. **Usage Instructions**: Mention any external dependencies and integration notes.
30
+ </output_structure>`,
31
+ prompt: `You are an expert at reverse-engineering user interfaces and crafting precise, actionable prompts that could guide another AI to recreate them.
32
+
33
+ <task>
34
+ Your task is to analyze the provided UI screenshot and generate a comprehensive, well-structured prompt that another AI could use to recreate this interface accurately.
35
+ </task>
36
+
37
+ <approach>
38
+ Start by taking in the interface as a whole. What is its primary purpose? Identify the major structural sections and describe how they relate spatially.
39
+
40
+ Describe the design language and overall aesthetic. Pay attention to the color scheme, typography hierarchy, and layout patterns.
41
+
42
+ For interactive elements, describe their visual treatment and implied behavior. Consider responsive behavior and user flow.
43
+ </approach>
44
+
45
+ <output_structure>
46
+ 1. **Generated Prompt**: Present the complete, ready-to-use prompt.
47
+ 2. **Prompt Structure Breakdown**: Explain your organizational choices.
48
+ 3. **Key Details Captured**: List critical design elements included.
49
+ 4. **Usage Notes**: Explain how to use this prompt with different AI tools.
50
+ </output_structure>`,
51
+ spec: `You are a design systems architect with extensive experience documenting user interfaces for development teams.
52
+
53
+ <task>
54
+ Your task is to analyze the provided UI screenshot and generate a comprehensive design specification document that defines all visual and interaction design details.
55
+ </task>
56
+
57
+ <approach>
58
+ Begin by identifying foundational design system elements: color palette, typography system, spacing scale, and common component patterns.
59
+
60
+ Document the layout structure, component hierarchy, and interaction patterns. Extract design tokens and define reusable patterns.
61
+ </approach>
62
+
63
+ <output_structure>
64
+ 1. **Design Tokens**: Color palette, typography scale, spacing system, elevation/shadows, border radii.
65
+ 2. **Component Specifications**: Detailed specs for each UI component.
66
+ 3. **Layout Guidelines**: Grid system, spacing rules, responsive breakpoints.
67
+ 4. **Interaction Patterns**: States, animations, transitions.
68
+ 5. **Implementation Notes**: Technical guidance for developers.
69
+ </output_structure>`,
70
+ description: `You are a UX writer and interface analyst who excels at describing user interfaces in clear, natural language.
71
+
72
+ <task>
73
+ Your task is to analyze the provided UI screenshot and create a comprehensive natural language description that captures what the interface looks like and how it works.
74
+ </task>
75
+
76
+ <approach>
77
+ Describe the interface as if explaining it to someone who cannot see it. Start with the overall purpose and layout, then systematically describe each section and component.
78
+
79
+ Focus on the visual hierarchy, spatial relationships, and the user's likely interaction flow. Mention colors, shapes, and visual treatments that contribute to understanding.
80
+ </approach>
81
+
82
+ <output_structure>
83
+ 1. **Overview**: High-level description of the interface purpose and layout.
84
+ 2. **Detailed Description**: Section-by-section walkthrough of all elements.
85
+ 3. **Visual Characteristics**: Colors, typography, spacing, and style notes.
86
+ 4. **Interaction Flow**: How a user would navigate and interact with this interface.
87
+ </output_structure>`
88
+ };
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ import { FileNotFoundError, ApiError } from '../types/index.js';
3
+ import { CommonSchemas, ToolSchemaBuilder } from '../utils/validation.js';
4
+ import { formatMcpResponse, createSuccessResponse, createErrorResponse, withRetry } from '../core/api-common.js';
5
+ import { BaseImageAnalysisService } from '../core/base-image-service.js';
6
+ import { DATA_VIZ_ANALYSIS_PROMPT } from '../prompts/index.js';
7
+ /**
8
+ * Data Visualization Analysis service - Analyze charts and graphs
9
+ */
10
+ class DataVizAnalysisService extends BaseImageAnalysisService {
11
+ /**
12
+ * Analyze data visualization
13
+ * @param imageSource Image file path or URL
14
+ * @param userPrompt User's question about the visualization
15
+ * @param analysisFocus Optional focus area for analysis
16
+ * @returns Visualization analysis and insights
17
+ */
18
+ async analyzeDataViz(imageSource, userPrompt, analysisFocus) {
19
+ console.info('Starting data visualization analysis', {
20
+ imageSource,
21
+ prompt: userPrompt,
22
+ focus: analysisFocus
23
+ });
24
+ // Validate prompt
25
+ this.validatePrompt(userPrompt, 'data-viz-analysis');
26
+ // Enhance prompt with analysis focus if provided
27
+ let enhancedPrompt = userPrompt;
28
+ if (analysisFocus && analysisFocus.trim()) {
29
+ enhancedPrompt = `${userPrompt}\n\n<analysis_focus>Focus particularly on: ${analysisFocus}.</analysis_focus>`;
30
+ }
31
+ // Process image
32
+ const imageContent = await this.processImageSource(imageSource);
33
+ // Execute analysis
34
+ return await this.executeVisionAnalysis(DATA_VIZ_ANALYSIS_PROMPT, enhancedPrompt, [imageContent], 'data-viz-analysis');
35
+ }
36
+ }
37
+ /**
38
+ * Register Data Visualization Analysis tool with MCP server
39
+ * @param server MCP server instance
40
+ */
41
+ export function registerDataVizAnalysisTool(server) {
42
+ const service = new DataVizAnalysisService();
43
+ const retryableAnalyze = withRetry(service.analyzeDataViz.bind(service), 2, 1000);
44
+ server.tool('analyze_data_visualization', 'Analyze data visualizations, charts, graphs, and dashboards to extract insights and trends.', {
45
+ image_source: z.string().describe('Local file path or remote URL to the image'),
46
+ prompt: z.string().describe('What insights or information you want to extract from this visualization.'),
47
+ analysis_focus: z.string().optional().describe('Optional: specify what to focus on (e.g., \'trends\', \'anomalies\', \'comparisons\', \'performance metrics\'). Leave empty for comprehensive analysis.')
48
+ }, async (params) => {
49
+ try {
50
+ const validationSchema = new ToolSchemaBuilder()
51
+ .required('image_source', CommonSchemas.nonEmptyString)
52
+ .required('prompt', CommonSchemas.nonEmptyString)
53
+ .optional('analysis_focus', z.string())
54
+ .build();
55
+ validationSchema.parse(params);
56
+ const result = await retryableAnalyze(params.image_source, params.prompt, params.analysis_focus);
57
+ return formatMcpResponse(createSuccessResponse(result));
58
+ }
59
+ catch (error) {
60
+ console.error('Data visualization analysis tool execution failed', {
61
+ error: error instanceof Error ? error.message : String(error),
62
+ params
63
+ });
64
+ let errorResponse;
65
+ if (error instanceof z.ZodError) {
66
+ const validationErrors = error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
67
+ errorResponse = createErrorResponse(`Validation failed: ${validationErrors}`);
68
+ }
69
+ else if (error instanceof FileNotFoundError) {
70
+ errorResponse = createErrorResponse(`Image file not found: ${error.message}`);
71
+ }
72
+ else if (error instanceof ApiError) {
73
+ errorResponse = createErrorResponse(`API error: ${error.message}`);
74
+ }
75
+ else {
76
+ errorResponse = createErrorResponse(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`);
77
+ }
78
+ return formatMcpResponse(errorResponse);
79
+ }
80
+ });
81
+ console.info('Data Visualization Analysis tool registered successfully');
82
+ }
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ import { FileNotFoundError, ApiError } from '../types/index.js';
3
+ import { CommonSchemas, ToolSchemaBuilder } from '../utils/validation.js';
4
+ import { formatMcpResponse, createSuccessResponse, createErrorResponse, withRetry } from '../core/api-common.js';
5
+ import { BaseImageAnalysisService } from '../core/base-image-service.js';
6
+ import { DIAGRAM_UNDERSTANDING_PROMPT } from '../prompts/index.js';
7
+ /**
8
+ * Diagram Analysis service - Analyze technical diagrams
9
+ */
10
+ class DiagramAnalysisService extends BaseImageAnalysisService {
11
+ /**
12
+ * Analyze technical diagram
13
+ * @param imageSource Image file path or URL
14
+ * @param userPrompt User's question about the diagram
15
+ * @param diagramType Optional diagram type hint
16
+ * @returns Diagram analysis and explanation
17
+ */
18
+ async analyzeDiagram(imageSource, userPrompt, diagramType) {
19
+ console.info('Starting diagram analysis', {
20
+ imageSource,
21
+ prompt: userPrompt,
22
+ diagramType
23
+ });
24
+ // Validate prompt
25
+ this.validatePrompt(userPrompt, 'diagram-analysis');
26
+ // Enhance prompt with diagram type hint if provided
27
+ let enhancedPrompt = userPrompt;
28
+ if (diagramType && diagramType.trim()) {
29
+ enhancedPrompt = `${userPrompt}\n\n<diagram_type_hint>This is a ${diagramType} diagram.</diagram_type_hint>`;
30
+ }
31
+ // Process image
32
+ const imageContent = await this.processImageSource(imageSource);
33
+ // Execute analysis
34
+ return await this.executeVisionAnalysis(DIAGRAM_UNDERSTANDING_PROMPT, enhancedPrompt, [imageContent], 'diagram-analysis');
35
+ }
36
+ }
37
+ /**
38
+ * Register Diagram Analysis tool with MCP server
39
+ * @param server MCP server instance
40
+ */
41
+ export function registerDiagramAnalysisTool(server) {
42
+ const service = new DiagramAnalysisService();
43
+ const retryableAnalyze = withRetry(service.analyzeDiagram.bind(service), 2, 1000);
44
+ server.tool('understand_technical_diagram', 'Analyze and explain technical diagrams including architecture diagrams, flowcharts, UML, ER diagrams, and system design diagrams.', {
45
+ image_source: z.string().describe('Local file path or remote URL to the image'),
46
+ prompt: z.string().describe('What you want to understand or extract from this diagram.'),
47
+ diagram_type: z.string().optional().describe('Optional: specify the diagram type if known (e.g., \'architecture\', \'flowchart\', \'uml\', \'er-diagram\', \'sequence\'). Leave empty for auto-detection.')
48
+ }, async (params) => {
49
+ try {
50
+ const validationSchema = new ToolSchemaBuilder()
51
+ .required('image_source', CommonSchemas.nonEmptyString)
52
+ .required('prompt', CommonSchemas.nonEmptyString)
53
+ .optional('diagram_type', z.string())
54
+ .build();
55
+ validationSchema.parse(params);
56
+ const result = await retryableAnalyze(params.image_source, params.prompt, params.diagram_type);
57
+ return formatMcpResponse(createSuccessResponse(result));
58
+ }
59
+ catch (error) {
60
+ console.error('Diagram analysis tool execution failed', {
61
+ error: error instanceof Error ? error.message : String(error),
62
+ params
63
+ });
64
+ let errorResponse;
65
+ if (error instanceof z.ZodError) {
66
+ const validationErrors = error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
67
+ errorResponse = createErrorResponse(`Validation failed: ${validationErrors}`);
68
+ }
69
+ else if (error instanceof FileNotFoundError) {
70
+ errorResponse = createErrorResponse(`Image file not found: ${error.message}`);
71
+ }
72
+ else if (error instanceof ApiError) {
73
+ errorResponse = createErrorResponse(`API error: ${error.message}`);
74
+ }
75
+ else {
76
+ errorResponse = createErrorResponse(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`);
77
+ }
78
+ return formatMcpResponse(errorResponse);
79
+ }
80
+ });
81
+ console.info('Diagram Analysis tool registered successfully');
82
+ }
@@ -0,0 +1,82 @@
1
+ import { z } from 'zod';
2
+ import { FileNotFoundError, ApiError } from '../types/index.js';
3
+ import { CommonSchemas, ToolSchemaBuilder } from '../utils/validation.js';
4
+ import { formatMcpResponse, createSuccessResponse, createErrorResponse, withRetry } from '../core/api-common.js';
5
+ import { BaseImageAnalysisService } from '../core/base-image-service.js';
6
+ import { ERROR_DIAGNOSIS_PROMPT } from '../prompts/index.js';
7
+ /**
8
+ * Error Diagnosis service - Analyze error messages and stack traces
9
+ */
10
+ class ErrorDiagnosisService extends BaseImageAnalysisService {
11
+ /**
12
+ * Diagnose error from screenshot
13
+ * @param imageSource Image file path or URL
14
+ * @param userPrompt User's question about the error
15
+ * @param context Optional context about when error occurred
16
+ * @returns Diagnostic analysis and solution
17
+ */
18
+ async diagnoseError(imageSource, userPrompt, context) {
19
+ console.info('Starting error diagnosis', {
20
+ imageSource,
21
+ prompt: userPrompt,
22
+ context
23
+ });
24
+ // Validate prompt
25
+ this.validatePrompt(userPrompt, 'error-diagnosis');
26
+ // Enhance prompt with context if provided
27
+ let enhancedPrompt = userPrompt;
28
+ if (context && context.trim()) {
29
+ enhancedPrompt = `${userPrompt}\n\n<error_context>This error occurred ${context}.</error_context>`;
30
+ }
31
+ // Process image
32
+ const imageContent = await this.processImageSource(imageSource);
33
+ // Execute analysis
34
+ return await this.executeVisionAnalysis(ERROR_DIAGNOSIS_PROMPT, enhancedPrompt, [imageContent], 'error-diagnosis');
35
+ }
36
+ }
37
+ /**
38
+ * Register Error Diagnosis tool with MCP server
39
+ * @param server MCP server instance
40
+ */
41
+ export function registerErrorDiagnosisTool(server) {
42
+ const service = new ErrorDiagnosisService();
43
+ const retryableDiagnose = withRetry(service.diagnoseError.bind(service), 2, 1000);
44
+ server.tool('diagnose_error_screenshot', 'Diagnose and analyze error messages, stack traces, and exception screenshots.', {
45
+ image_source: z.string().describe('Local file path or remote URL to the image'),
46
+ prompt: z.string().describe('Description of what you need help with regarding this error. Include any relevant context about when it occurred.'),
47
+ context: z.string().optional().describe('Optional: additional context about when the error occurred (e.g., \'during npm install\', \'when running the app\', \'after deployment\'). Helps with more accurate diagnosis.')
48
+ }, async (params) => {
49
+ try {
50
+ const validationSchema = new ToolSchemaBuilder()
51
+ .required('image_source', CommonSchemas.nonEmptyString)
52
+ .required('prompt', CommonSchemas.nonEmptyString)
53
+ .optional('context', z.string())
54
+ .build();
55
+ validationSchema.parse(params);
56
+ const result = await retryableDiagnose(params.image_source, params.prompt, params.context);
57
+ return formatMcpResponse(createSuccessResponse(result));
58
+ }
59
+ catch (error) {
60
+ console.error('Error diagnosis tool execution failed', {
61
+ error: error instanceof Error ? error.message : String(error),
62
+ params
63
+ });
64
+ let errorResponse;
65
+ if (error instanceof z.ZodError) {
66
+ const validationErrors = error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
67
+ errorResponse = createErrorResponse(`Validation failed: ${validationErrors}`);
68
+ }
69
+ else if (error instanceof FileNotFoundError) {
70
+ errorResponse = createErrorResponse(`Image file not found: ${error.message}`);
71
+ }
72
+ else if (error instanceof ApiError) {
73
+ errorResponse = createErrorResponse(`API error: ${error.message}`);
74
+ }
75
+ else {
76
+ errorResponse = createErrorResponse(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`);
77
+ }
78
+ return formatMcpResponse(errorResponse);
79
+ }
80
+ });
81
+ console.info('Error Diagnosis tool registered successfully');
82
+ }
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod';
2
+ import { FileNotFoundError, ApiError } from '../types/index.js';
3
+ import { CommonSchemas, ToolSchemaBuilder } from '../utils/validation.js';
4
+ import { formatMcpResponse, createSuccessResponse, createErrorResponse, withRetry } from '../core/api-common.js';
5
+ import { BaseImageAnalysisService } from '../core/base-image-service.js';
6
+ import { GENERAL_IMAGE_ANALYSIS_PROMPT } from '../prompts/index.js';
7
+ /**
8
+ * General Image Analysis service - Fallback for any image analysis
9
+ */
10
+ class GeneralImageAnalysisService extends BaseImageAnalysisService {
11
+ /**
12
+ * Analyze image with general purpose prompt
13
+ * @param imageSource Image file path or URL
14
+ * @param userPrompt User's analysis request
15
+ * @returns Analysis result
16
+ */
17
+ async analyzeImage(imageSource, userPrompt) {
18
+ console.info('Starting general image analysis', {
19
+ imageSource,
20
+ prompt: userPrompt
21
+ });
22
+ // Validate prompt
23
+ this.validatePrompt(userPrompt, 'analyze-image');
24
+ // Process image
25
+ const imageContent = await this.processImageSource(imageSource);
26
+ // Execute analysis
27
+ return await this.executeVisionAnalysis(GENERAL_IMAGE_ANALYSIS_PROMPT, userPrompt, [imageContent], 'analyze-image');
28
+ }
29
+ }
30
+ /**
31
+ * Register General Image Analysis tool with MCP server
32
+ * @param server MCP server instance
33
+ */
34
+ export function registerGeneralImageAnalysisTool(server) {
35
+ const service = new GeneralImageAnalysisService();
36
+ const retryableAnalyze = withRetry(service.analyzeImage.bind(service), 2, 1000);
37
+ server.tool('analyze_image', 'General-purpose image analysis for scenarios not covered by specialized tools.', {
38
+ image_source: z.string().describe('Local file path or remote URL to the image'),
39
+ prompt: z.string().describe('Detailed description of what you want to analyze, extract, or understand from the image. Be specific about your requirements.')
40
+ }, async (params) => {
41
+ try {
42
+ const validationSchema = new ToolSchemaBuilder()
43
+ .required('image_source', CommonSchemas.nonEmptyString)
44
+ .required('prompt', CommonSchemas.nonEmptyString)
45
+ .build();
46
+ validationSchema.parse(params);
47
+ const result = await retryableAnalyze(params.image_source, params.prompt);
48
+ return formatMcpResponse(createSuccessResponse(result));
49
+ }
50
+ catch (error) {
51
+ console.error('General image analysis tool execution failed', {
52
+ error: error instanceof Error ? error.message : String(error),
53
+ params
54
+ });
55
+ let errorResponse;
56
+ if (error instanceof z.ZodError) {
57
+ const validationErrors = error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
58
+ errorResponse = createErrorResponse(`Validation failed: ${validationErrors}`);
59
+ }
60
+ else if (error instanceof FileNotFoundError) {
61
+ errorResponse = createErrorResponse(`Image file not found: ${error.message}`);
62
+ }
63
+ else if (error instanceof ApiError) {
64
+ errorResponse = createErrorResponse(`API error: ${error.message}`);
65
+ }
66
+ else {
67
+ errorResponse = createErrorResponse(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`);
68
+ }
69
+ return formatMcpResponse(errorResponse);
70
+ }
71
+ });
72
+ console.info('General Image Analysis tool registered successfully');
73
+ }