@stabgan/openrouter-mcp-multimodal 1.1.0 → 1.2.1
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.
- package/README.md +7 -16
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/tool-handlers/analyze-image.d.ts +16 -2
- package/dist/tool-handlers/analyze-image.js +105 -51
- package/dist/tool-handlers/analyze-image.js.map +1 -1
- package/dist/tool-handlers/chat-completion.js +54 -13
- package/dist/tool-handlers/chat-completion.js.map +1 -1
- package/dist/tool-handlers/multi-image-analysis.d.ts +23 -0
- package/dist/tool-handlers/multi-image-analysis.js +249 -31
- package/dist/tool-handlers/multi-image-analysis.js.map +1 -1
- package/dist/tool-handlers.js +11 -18
- package/dist/tool-handlers.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -192,22 +192,6 @@ use_mcp_tool({
|
|
|
192
192
|
});
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
### analyze_image
|
|
196
|
-
|
|
197
|
-
Analyze a single image with an optional question:
|
|
198
|
-
|
|
199
|
-
```javascript
|
|
200
|
-
use_mcp_tool({
|
|
201
|
-
server_name: "openrouter",
|
|
202
|
-
tool_name: "analyze_image",
|
|
203
|
-
arguments: {
|
|
204
|
-
image_path: "/absolute/path/to/image.jpg",
|
|
205
|
-
question: "What objects are in this image?", // Optional
|
|
206
|
-
model: "anthropic/claude-3.5-sonnet" // Optional if default is set
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
```
|
|
210
|
-
|
|
211
195
|
### multi_image_analysis
|
|
212
196
|
|
|
213
197
|
Analyze multiple images with a single prompt:
|
|
@@ -329,3 +313,10 @@ npm run build
|
|
|
329
313
|
## License
|
|
330
314
|
|
|
331
315
|
MIT License
|
|
316
|
+
|
|
317
|
+
## Version 1.2.0 Updates
|
|
318
|
+
- Simplified image analysis by consolidating all functionality into the `multi_image_analysis` tool
|
|
319
|
+
- Added automatic selection of free models with the largest context window when no model is specified
|
|
320
|
+
- Improved handling of various image formats (file://, http://, data:)
|
|
321
|
+
- Enhanced error handling and logging for better troubleshooting
|
|
322
|
+
- Removed the `analyze_image` tool to eliminate confusion and streamline the interface
|
package/dist/index.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
5
|
import { ToolHandlers } from './tool-handlers.js';
|
|
6
|
+
// Define the default model to use when none is specified
|
|
7
|
+
const DEFAULT_MODEL = 'qwen/qwen2.5-vl-32b-instruct:free';
|
|
6
8
|
class OpenRouterMultimodalServer {
|
|
7
9
|
server;
|
|
8
10
|
toolHandlers; // Using definite assignment assertion
|
|
9
11
|
constructor() {
|
|
10
|
-
//
|
|
12
|
+
// Retrieve API key and default model from environment variables
|
|
11
13
|
const apiKey = process.env.OPENROUTER_API_KEY;
|
|
12
|
-
const defaultModel = process.env.
|
|
14
|
+
const defaultModel = process.env.DEFAULT_MODEL || DEFAULT_MODEL;
|
|
13
15
|
// Check if API key is provided
|
|
14
16
|
if (!apiKey) {
|
|
15
17
|
throw new Error('OPENROUTER_API_KEY environment variable is required');
|
|
@@ -39,12 +41,9 @@ class OpenRouterMultimodalServer {
|
|
|
39
41
|
console.error('Using API key from environment variable');
|
|
40
42
|
console.error('Note: To use OpenRouter Multimodal, add the API key to your environment variables:');
|
|
41
43
|
console.error(' OPENROUTER_API_KEY=your-api-key');
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
else {
|
|
46
|
-
console.error(' No default model set. You will need to specify a model in each request.');
|
|
47
|
-
}
|
|
44
|
+
const modelDisplay = process.env.OPENROUTER_DEFAULT_MODEL || DEFAULT_MODEL;
|
|
45
|
+
console.error(` Using default model: ${modelDisplay}`);
|
|
46
|
+
console.error('Server is ready to process tool calls. Waiting for input...');
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
const server = new OpenRouterMultimodalServer();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,mCAAmC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,0BAA0B;IACtB,MAAM,CAAS;IACf,YAAY,CAAgB,CAAC,sCAAsC;IAE3E;QACE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,mCAAmC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,yDAAyD;AACzD,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAE1D,MAAM,0BAA0B;IACtB,MAAM,CAAS;IACf,YAAY,CAAgB,CAAC,sCAAsC;IAE3E;QACE,gEAAgE;QAChE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,aAAa,CAAC;QAEhE,+BAA+B;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,wBAAwB;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACtB;YACE,IAAI,EAAE,8BAA8B;YACpC,OAAO,EAAE,OAAO;SACjB,EACD;YACE,YAAY,EAAE;gBACZ,KAAK,EAAE,EAAE;aACV;SACF,CACF,CAAC;QAEF,wBAAwB;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4
|
-
image_url?: string;
|
|
3
|
+
image_path: string;
|
|
5
4
|
question?: string;
|
|
6
5
|
model?: string;
|
|
7
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Handler for analyzing a single image
|
|
9
|
+
*/
|
|
8
10
|
export declare function handleAnalyzeImage(request: {
|
|
9
11
|
params: {
|
|
10
12
|
arguments: AnalyzeImageToolRequest;
|
|
@@ -14,6 +16,12 @@ export declare function handleAnalyzeImage(request: {
|
|
|
14
16
|
type: string;
|
|
15
17
|
text: string;
|
|
16
18
|
}[];
|
|
19
|
+
metadata: {
|
|
20
|
+
model: string;
|
|
21
|
+
usage: OpenAI.Completions.CompletionUsage | undefined;
|
|
22
|
+
error_type?: undefined;
|
|
23
|
+
error_message?: undefined;
|
|
24
|
+
};
|
|
17
25
|
isError?: undefined;
|
|
18
26
|
} | {
|
|
19
27
|
content: {
|
|
@@ -21,4 +29,10 @@ export declare function handleAnalyzeImage(request: {
|
|
|
21
29
|
text: string;
|
|
22
30
|
}[];
|
|
23
31
|
isError: boolean;
|
|
32
|
+
metadata: {
|
|
33
|
+
error_type: string;
|
|
34
|
+
error_message: string;
|
|
35
|
+
model?: undefined;
|
|
36
|
+
usage?: undefined;
|
|
37
|
+
};
|
|
24
38
|
}>;
|
|
@@ -3,6 +3,9 @@ import { promises as fs } from 'fs';
|
|
|
3
3
|
import sharp from 'sharp';
|
|
4
4
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import fetch from 'node-fetch';
|
|
6
|
+
import { findSuitableFreeModel } from './multi-image-analysis.js';
|
|
7
|
+
// Default model for image analysis
|
|
8
|
+
const DEFAULT_FREE_MODEL = 'qwen/qwen2.5-vl-32b-instruct:free';
|
|
6
9
|
async function fetchImageAsBuffer(url) {
|
|
7
10
|
try {
|
|
8
11
|
// Handle data URLs
|
|
@@ -65,67 +68,110 @@ async function processImage(buffer) {
|
|
|
65
68
|
throw error;
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Converts the image at the given path to a base64 string
|
|
73
|
+
*/
|
|
74
|
+
async function imageToBase64(imagePath) {
|
|
70
75
|
try {
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!imagePath && !imageUrl) {
|
|
75
|
-
throw new McpError(ErrorCode.InvalidParams, 'Either image_path or image_url must be provided');
|
|
76
|
+
// Ensure the image path is absolute
|
|
77
|
+
if (!path.isAbsolute(imagePath)) {
|
|
78
|
+
throw new McpError(ErrorCode.InvalidParams, 'Image path must be absolute');
|
|
76
79
|
}
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// Use the provided URL directly
|
|
81
|
-
imageSource = imageUrl;
|
|
80
|
+
// Check if the file exists
|
|
81
|
+
try {
|
|
82
|
+
await fs.access(imagePath);
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new McpError(ErrorCode.InvalidParams, `File not found: ${imagePath}`);
|
|
86
|
+
}
|
|
87
|
+
// Read the file as a buffer
|
|
88
|
+
const buffer = await fs.readFile(imagePath);
|
|
89
|
+
// Determine MIME type from file extension
|
|
90
|
+
const extension = path.extname(imagePath).toLowerCase();
|
|
91
|
+
let mimeType;
|
|
92
|
+
switch (extension) {
|
|
93
|
+
case '.png':
|
|
94
|
+
mimeType = 'image/png';
|
|
95
|
+
break;
|
|
96
|
+
case '.jpg':
|
|
97
|
+
case '.jpeg':
|
|
98
|
+
mimeType = 'image/jpeg';
|
|
99
|
+
break;
|
|
100
|
+
case '.webp':
|
|
101
|
+
mimeType = 'image/webp';
|
|
102
|
+
break;
|
|
103
|
+
case '.gif':
|
|
104
|
+
mimeType = 'image/gif';
|
|
105
|
+
break;
|
|
106
|
+
case '.bmp':
|
|
107
|
+
mimeType = 'image/bmp';
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
mimeType = 'application/octet-stream';
|
|
111
|
+
}
|
|
112
|
+
// Convert buffer to base64
|
|
113
|
+
const base64 = buffer.toString('base64');
|
|
114
|
+
return { base64, mimeType };
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Error converting image to base64:', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handler for analyzing a single image
|
|
123
|
+
*/
|
|
124
|
+
export async function handleAnalyzeImage(request, openai, defaultModel) {
|
|
125
|
+
const args = request.params.arguments;
|
|
126
|
+
try {
|
|
127
|
+
// Validate inputs
|
|
128
|
+
if (!args.image_path) {
|
|
129
|
+
throw new McpError(ErrorCode.InvalidParams, 'An image path is required');
|
|
93
130
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
throw new McpError(ErrorCode.InvalidParams, 'No image source provided');
|
|
131
|
+
if (!args.question) {
|
|
132
|
+
throw new McpError(ErrorCode.InvalidParams, 'A question about the image is required');
|
|
97
133
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
console.error(`Processing image: ${args.image_path}`);
|
|
135
|
+
// Convert the image to base64
|
|
136
|
+
const { base64, mimeType } = await imageToBase64(args.image_path);
|
|
137
|
+
// Create the content array for the OpenAI API
|
|
138
|
+
const content = [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: args.question
|
|
142
|
+
},
|
|
107
143
|
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
|
|
112
|
-
text: args.question || "What's in this image?"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
type: 'image_url',
|
|
116
|
-
image_url: {
|
|
117
|
-
url: `data:image/jpeg;base64,${base64Image}`
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
]
|
|
144
|
+
type: 'image_url',
|
|
145
|
+
image_url: {
|
|
146
|
+
url: `data:${mimeType};base64,${base64}`
|
|
147
|
+
}
|
|
121
148
|
}
|
|
122
149
|
];
|
|
123
|
-
|
|
124
|
-
//
|
|
150
|
+
// Select model with priority:
|
|
151
|
+
// 1. User-specified model
|
|
152
|
+
// 2. Default model from environment
|
|
153
|
+
// 3. Default free vision model (qwen/qwen2.5-vl-32b-instruct:free)
|
|
154
|
+
let model = args.model || defaultModel || DEFAULT_FREE_MODEL;
|
|
155
|
+
// If a model is specified but not our default free model, verify it exists
|
|
156
|
+
if (model !== DEFAULT_FREE_MODEL) {
|
|
157
|
+
try {
|
|
158
|
+
await openai.models.retrieve(model);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.error(`Specified model ${model} not found, falling back to auto-selection`);
|
|
162
|
+
model = await findSuitableFreeModel(openai);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
console.error(`Making API call with model: ${model}`);
|
|
166
|
+
// Make the API call
|
|
125
167
|
const completion = await openai.chat.completions.create({
|
|
126
168
|
model,
|
|
127
|
-
messages:
|
|
169
|
+
messages: [{
|
|
170
|
+
role: 'user',
|
|
171
|
+
content
|
|
172
|
+
}]
|
|
128
173
|
});
|
|
174
|
+
// Return the analysis result
|
|
129
175
|
return {
|
|
130
176
|
content: [
|
|
131
177
|
{
|
|
@@ -133,10 +179,14 @@ export async function handleAnalyzeImage(request, openai, defaultModel) {
|
|
|
133
179
|
text: completion.choices[0].message.content || '',
|
|
134
180
|
},
|
|
135
181
|
],
|
|
182
|
+
metadata: {
|
|
183
|
+
model: completion.model,
|
|
184
|
+
usage: completion.usage
|
|
185
|
+
}
|
|
136
186
|
};
|
|
137
187
|
}
|
|
138
188
|
catch (error) {
|
|
139
|
-
console.error('Error
|
|
189
|
+
console.error('Error in image analysis:', error);
|
|
140
190
|
if (error instanceof McpError) {
|
|
141
191
|
throw error;
|
|
142
192
|
}
|
|
@@ -148,6 +198,10 @@ export async function handleAnalyzeImage(request, openai, defaultModel) {
|
|
|
148
198
|
},
|
|
149
199
|
],
|
|
150
200
|
isError: true,
|
|
201
|
+
metadata: {
|
|
202
|
+
error_type: error instanceof Error ? error.constructor.name : 'Unknown',
|
|
203
|
+
error_message: error instanceof Error ? error.message : String(error)
|
|
204
|
+
}
|
|
151
205
|
};
|
|
152
206
|
}
|
|
153
207
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze-image.js","sourceRoot":"","sources":["../../src/tool-handlers/analyze-image.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,KAAK,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"analyze-image.js","sourceRoot":"","sources":["../../src/tool-handlers/analyze-image.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,mCAAmC;AACnC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAQ/D,KAAK,UAAU,kBAAkB,CAAC,GAAW;IAC3C,IAAI,CAAC;QACH,mBAAmB;QACnB,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,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C,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;gBACvE,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aACtE;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -49,21 +49,52 @@ function truncateMessagesToFit(messages, maxTokens) {
|
|
|
49
49
|
}
|
|
50
50
|
return truncated;
|
|
51
51
|
}
|
|
52
|
+
// Find a suitable free model with the largest context window
|
|
53
|
+
async function findSuitableFreeModel(openai) {
|
|
54
|
+
try {
|
|
55
|
+
// Query available models with 'free' in their name
|
|
56
|
+
const modelsResponse = await openai.models.list();
|
|
57
|
+
if (!modelsResponse || !modelsResponse.data || modelsResponse.data.length === 0) {
|
|
58
|
+
return 'deepseek/deepseek-chat-v3-0324:free'; // Fallback to a known model
|
|
59
|
+
}
|
|
60
|
+
// Filter models with 'free' in ID
|
|
61
|
+
const freeModels = modelsResponse.data
|
|
62
|
+
.filter(model => model.id.includes('free'))
|
|
63
|
+
.map(model => {
|
|
64
|
+
// Try to extract context length from the model object
|
|
65
|
+
let contextLength = 0;
|
|
66
|
+
try {
|
|
67
|
+
const modelAny = model; // Cast to any to access non-standard properties
|
|
68
|
+
if (typeof modelAny.context_length === 'number') {
|
|
69
|
+
contextLength = modelAny.context_length;
|
|
70
|
+
}
|
|
71
|
+
else if (modelAny.context_window) {
|
|
72
|
+
contextLength = parseInt(modelAny.context_window, 10);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
console.error(`Error parsing context length for model ${model.id}:`, e);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
id: model.id,
|
|
80
|
+
contextLength: contextLength || 0
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
if (freeModels.length === 0) {
|
|
84
|
+
return 'deepseek/deepseek-chat-v3-0324:free'; // Fallback if no free models found
|
|
85
|
+
}
|
|
86
|
+
// Sort by context length and pick the one with the largest context window
|
|
87
|
+
freeModels.sort((a, b) => b.contextLength - a.contextLength);
|
|
88
|
+
console.error(`Selected free model: ${freeModels[0].id} with context length: ${freeModels[0].contextLength}`);
|
|
89
|
+
return freeModels[0].id;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error('Error finding suitable free model:', error);
|
|
93
|
+
return 'deepseek/deepseek-chat-v3-0324:free'; // Fallback to a known model
|
|
94
|
+
}
|
|
95
|
+
}
|
|
52
96
|
export async function handleChatCompletion(request, openai, defaultModel) {
|
|
53
97
|
const args = request.params.arguments;
|
|
54
|
-
// Validate model selection
|
|
55
|
-
const model = args.model || defaultModel;
|
|
56
|
-
if (!model) {
|
|
57
|
-
return {
|
|
58
|
-
content: [
|
|
59
|
-
{
|
|
60
|
-
type: 'text',
|
|
61
|
-
text: 'No model specified and no default model configured in MCP settings. Please specify a model or set OPENROUTER_DEFAULT_MODEL in the MCP configuration.',
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
isError: true,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
98
|
// Validate message array
|
|
68
99
|
if (args.messages.length === 0) {
|
|
69
100
|
return {
|
|
@@ -77,8 +108,18 @@ export async function handleChatCompletion(request, openai, defaultModel) {
|
|
|
77
108
|
};
|
|
78
109
|
}
|
|
79
110
|
try {
|
|
111
|
+
// Select model with priority:
|
|
112
|
+
// 1. User-specified model
|
|
113
|
+
// 2. Default model from environment
|
|
114
|
+
// 3. Free model with the largest context window (selected automatically)
|
|
115
|
+
let model = args.model || defaultModel;
|
|
116
|
+
if (!model) {
|
|
117
|
+
model = await findSuitableFreeModel(openai);
|
|
118
|
+
console.error(`Using auto-selected model: ${model}`);
|
|
119
|
+
}
|
|
80
120
|
// Truncate messages to fit within context window
|
|
81
121
|
const truncatedMessages = truncateMessagesToFit(args.messages, MAX_CONTEXT_TOKENS);
|
|
122
|
+
console.error(`Making API call with model: ${model}`);
|
|
82
123
|
const completion = await openai.chat.completions.create({
|
|
83
124
|
model,
|
|
84
125
|
messages: truncatedMessages,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-completion.js","sourceRoot":"","sources":["../../src/tool-handlers/chat-completion.ts"],"names":[],"mappings":"AAGA,yBAAyB;AACzB,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAQlC,wDAAwD;AACxD,SAAS,kBAAkB,CAAC,IAAY;IACtC,8CAA8C;IAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,qDAAqD;AACrD,SAAS,qBAAqB,CAC5B,QAAsC,EACtC,SAAiB;IAEjB,MAAM,SAAS,GAAiC,EAAE,CAAC;IACnD,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAE1B,iDAAiD;IACjD,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;QACnC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,iBAAiB,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAiB,CAAC,CAAC;IACzE,CAAC;IAED,wDAAwD;IACxD,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAE5B,sDAAsD;QACtD,IAAI,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;YAAE,SAAS;QAEnD,+CAA+C;QAC/C,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACxC,MAAM,aAAa,GAAG,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CA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?: string;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Find a suitable free model with vision capabilities, defaulting to Qwen
|
|
13
|
+
*/
|
|
14
|
+
export declare function findSuitableFreeModel(openai: OpenAI): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Process and analyze multiple images using OpenRouter
|
|
17
|
+
*/
|
|
11
18
|
export declare function handleMultiImageAnalysis(request: {
|
|
12
19
|
params: {
|
|
13
20
|
arguments: MultiImageAnalysisToolRequest;
|
|
@@ -17,6 +24,14 @@ export declare function handleMultiImageAnalysis(request: {
|
|
|
17
24
|
type: string;
|
|
18
25
|
text: string;
|
|
19
26
|
}[];
|
|
27
|
+
metadata: {
|
|
28
|
+
model: string;
|
|
29
|
+
usage: OpenAI.Completions.CompletionUsage | undefined;
|
|
30
|
+
successful_images: number;
|
|
31
|
+
failed_images: number;
|
|
32
|
+
error_type?: undefined;
|
|
33
|
+
error_message?: undefined;
|
|
34
|
+
};
|
|
20
35
|
isError?: undefined;
|
|
21
36
|
} | {
|
|
22
37
|
content: {
|
|
@@ -24,4 +39,12 @@ export declare function handleMultiImageAnalysis(request: {
|
|
|
24
39
|
text: string;
|
|
25
40
|
}[];
|
|
26
41
|
isError: boolean;
|
|
42
|
+
metadata: {
|
|
43
|
+
error_type: string;
|
|
44
|
+
error_message: string;
|
|
45
|
+
model?: undefined;
|
|
46
|
+
usage?: undefined;
|
|
47
|
+
successful_images?: undefined;
|
|
48
|
+
failed_images?: undefined;
|
|
49
|
+
};
|
|
27
50
|
}>;
|
|
@@ -1,65 +1,237 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import sharp from 'sharp';
|
|
3
3
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { promises as fs } from 'fs';
|
|
6
|
+
import { tmpdir } from 'os';
|
|
7
|
+
// Remove uuid import as we'll use a simple random string generator instead
|
|
8
|
+
// import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
// Default model for image analysis
|
|
10
|
+
const DEFAULT_FREE_MODEL = 'qwen/qwen2.5-vl-32b-instruct:free';
|
|
11
|
+
// Image processing constants
|
|
12
|
+
const MAX_DIMENSION = 800;
|
|
13
|
+
const JPEG_QUALITY = 80;
|
|
14
|
+
const MAX_RETRY_ATTEMPTS = 3;
|
|
15
|
+
const RETRY_DELAY = 1000; // ms
|
|
16
|
+
// Simple random ID generator to replace uuid
|
|
17
|
+
function generateRandomId() {
|
|
18
|
+
return Math.random().toString(36).substring(2, 15) +
|
|
19
|
+
Math.random().toString(36).substring(2, 15);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sleep function for retry mechanisms
|
|
23
|
+
*/
|
|
24
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
25
|
+
/**
|
|
26
|
+
* Get MIME type from file extension or data URL
|
|
27
|
+
*/
|
|
28
|
+
function getMimeType(url) {
|
|
29
|
+
if (url.startsWith('data:')) {
|
|
30
|
+
const match = url.match(/^data:([^;]+);/);
|
|
31
|
+
return match ? match[1] : 'application/octet-stream';
|
|
32
|
+
}
|
|
33
|
+
const extension = path.extname(url.split('?')[0]).toLowerCase();
|
|
34
|
+
switch (extension) {
|
|
35
|
+
case '.png': return 'image/png';
|
|
36
|
+
case '.jpg':
|
|
37
|
+
case '.jpeg': return 'image/jpeg';
|
|
38
|
+
case '.webp': return 'image/webp';
|
|
39
|
+
case '.gif': return 'image/gif';
|
|
40
|
+
case '.bmp': return 'image/bmp';
|
|
41
|
+
case '.svg': return 'image/svg+xml';
|
|
42
|
+
default: return 'application/octet-stream';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Fetch image from various sources: data URLs, file paths, or remote URLs
|
|
47
|
+
*/
|
|
4
48
|
async function fetchImageAsBuffer(url) {
|
|
5
49
|
try {
|
|
6
50
|
// Handle data URLs
|
|
7
51
|
if (url.startsWith('data:')) {
|
|
8
52
|
const matches = url.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
|
|
9
53
|
if (!matches || matches.length !== 3) {
|
|
10
|
-
throw new Error('Invalid data URL');
|
|
54
|
+
throw new Error('Invalid data URL format');
|
|
11
55
|
}
|
|
12
56
|
return Buffer.from(matches[2], 'base64');
|
|
13
57
|
}
|
|
14
|
-
// Handle file URLs
|
|
58
|
+
// Handle file URLs with file:// protocol
|
|
15
59
|
if (url.startsWith('file://')) {
|
|
16
60
|
const filePath = url.replace('file://', '');
|
|
17
|
-
|
|
18
|
-
|
|
61
|
+
try {
|
|
62
|
+
return await fs.readFile(filePath);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`Error reading file at ${filePath}:`, error);
|
|
66
|
+
throw new Error(`Failed to read file: ${filePath}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Handle absolute and relative file paths
|
|
70
|
+
if (url.startsWith('/') || url.startsWith('./') || url.startsWith('../') || /^[A-Za-z]:\\/.test(url)) {
|
|
71
|
+
try {
|
|
72
|
+
return await fs.readFile(url);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error(`Error reading file at ${url}:`, error);
|
|
76
|
+
throw new Error(`Failed to read file: ${url}`);
|
|
77
|
+
}
|
|
19
78
|
}
|
|
20
79
|
// Handle http/https URLs
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
80
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
81
|
+
for (let attempt = 0; attempt < MAX_RETRY_ATTEMPTS; attempt++) {
|
|
82
|
+
try {
|
|
83
|
+
// Use AbortController for timeout instead of timeout option
|
|
84
|
+
const controller = new AbortController();
|
|
85
|
+
const timeoutId = setTimeout(() => controller.abort(), 15000);
|
|
86
|
+
const response = await fetch(url, {
|
|
87
|
+
signal: controller.signal,
|
|
88
|
+
headers: {
|
|
89
|
+
'User-Agent': 'OpenRouter-MCP-Server/1.0'
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// Clear the timeout to prevent memory leaks
|
|
93
|
+
clearTimeout(timeoutId);
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
96
|
+
}
|
|
97
|
+
return Buffer.from(await response.arrayBuffer());
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
console.error(`Error fetching URL (attempt ${attempt + 1}/${MAX_RETRY_ATTEMPTS}): ${url}`, error);
|
|
101
|
+
if (attempt < MAX_RETRY_ATTEMPTS - 1) {
|
|
102
|
+
// Exponential backoff with jitter
|
|
103
|
+
const delay = RETRY_DELAY * Math.pow(2, attempt) * (0.5 + Math.random() * 0.5);
|
|
104
|
+
await sleep(delay);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
24
111
|
}
|
|
25
|
-
|
|
112
|
+
// If we get here, the URL format is unsupported
|
|
113
|
+
throw new Error(`Unsupported URL format: ${url}`);
|
|
26
114
|
}
|
|
27
115
|
catch (error) {
|
|
28
116
|
console.error(`Error fetching image from ${url}:`, error);
|
|
29
117
|
throw error;
|
|
30
118
|
}
|
|
119
|
+
// TypeScript requires a return statement here, but this is unreachable
|
|
120
|
+
return Buffer.from([]);
|
|
31
121
|
}
|
|
32
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Process and optimize image for API consumption
|
|
124
|
+
*/
|
|
125
|
+
async function processImage(buffer, mimeType) {
|
|
33
126
|
try {
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
127
|
+
// Create a temporary directory for processing if needed
|
|
128
|
+
const tempDir = path.join(tmpdir(), `openrouter-mcp-${generateRandomId()}`);
|
|
129
|
+
await fs.mkdir(tempDir, { recursive: true });
|
|
130
|
+
// Get image info
|
|
131
|
+
let sharpInstance = sharp(buffer);
|
|
132
|
+
const metadata = await sharpInstance.metadata();
|
|
133
|
+
// Skip processing for small images
|
|
134
|
+
if (metadata.width && metadata.height &&
|
|
135
|
+
metadata.width <= MAX_DIMENSION &&
|
|
136
|
+
metadata.height <= MAX_DIMENSION &&
|
|
137
|
+
(mimeType === 'image/jpeg' || mimeType === 'image/webp')) {
|
|
138
|
+
return buffer.toString('base64');
|
|
139
|
+
}
|
|
140
|
+
// Resize larger images
|
|
39
141
|
if (metadata.width && metadata.height) {
|
|
40
142
|
const largerDimension = Math.max(metadata.width, metadata.height);
|
|
41
143
|
if (largerDimension > MAX_DIMENSION) {
|
|
42
144
|
const resizeOptions = metadata.width > metadata.height
|
|
43
145
|
? { width: MAX_DIMENSION }
|
|
44
146
|
: { height: MAX_DIMENSION };
|
|
45
|
-
|
|
46
|
-
.resize(resizeOptions)
|
|
47
|
-
.jpeg({ quality: JPEG_QUALITY })
|
|
48
|
-
.toBuffer();
|
|
49
|
-
return resizedBuffer.toString('base64');
|
|
147
|
+
sharpInstance = sharpInstance.resize(resizeOptions);
|
|
50
148
|
}
|
|
51
149
|
}
|
|
52
|
-
//
|
|
53
|
-
const
|
|
150
|
+
// Convert to JPEG for consistency and small size
|
|
151
|
+
const processedBuffer = await sharpInstance
|
|
54
152
|
.jpeg({ quality: JPEG_QUALITY })
|
|
55
153
|
.toBuffer();
|
|
56
|
-
return
|
|
154
|
+
return processedBuffer.toString('base64');
|
|
57
155
|
}
|
|
58
156
|
catch (error) {
|
|
59
157
|
console.error('Error processing image:', error);
|
|
60
|
-
|
|
158
|
+
// If sharp processing fails, return the original buffer
|
|
159
|
+
// This is a fallback to ensure we don't completely fail on processing errors
|
|
160
|
+
console.error('Returning original image without processing');
|
|
161
|
+
return buffer.toString('base64');
|
|
61
162
|
}
|
|
62
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Find a suitable free model with vision capabilities, defaulting to Qwen
|
|
166
|
+
*/
|
|
167
|
+
export async function findSuitableFreeModel(openai) {
|
|
168
|
+
try {
|
|
169
|
+
// First try with an exact match for our preferred model
|
|
170
|
+
const preferredModel = DEFAULT_FREE_MODEL;
|
|
171
|
+
try {
|
|
172
|
+
// Check if our preferred model is available
|
|
173
|
+
const modelInfo = await openai.models.retrieve(preferredModel);
|
|
174
|
+
if (modelInfo && modelInfo.id) {
|
|
175
|
+
console.error(`Using preferred model: ${preferredModel}`);
|
|
176
|
+
return preferredModel;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error(`Preferred model ${preferredModel} not available, searching for alternatives...`);
|
|
181
|
+
}
|
|
182
|
+
// Query available models
|
|
183
|
+
const modelsResponse = await openai.models.list();
|
|
184
|
+
if (!modelsResponse?.data || modelsResponse.data.length === 0) {
|
|
185
|
+
console.error('No models found, using default fallback model');
|
|
186
|
+
return DEFAULT_FREE_MODEL;
|
|
187
|
+
}
|
|
188
|
+
// First, try to find free vision models
|
|
189
|
+
const freeVisionModels = modelsResponse.data
|
|
190
|
+
.filter(model => {
|
|
191
|
+
const modelId = model.id.toLowerCase();
|
|
192
|
+
return modelId.includes('free') &&
|
|
193
|
+
(modelId.includes('vl') || modelId.includes('vision') || modelId.includes('claude') ||
|
|
194
|
+
modelId.includes('gemini') || modelId.includes('gpt-4') || modelId.includes('qwen'));
|
|
195
|
+
})
|
|
196
|
+
.map(model => {
|
|
197
|
+
// Extract context length if available
|
|
198
|
+
let contextLength = 0;
|
|
199
|
+
try {
|
|
200
|
+
const modelAny = model;
|
|
201
|
+
if (typeof modelAny.context_length === 'number') {
|
|
202
|
+
contextLength = modelAny.context_length;
|
|
203
|
+
}
|
|
204
|
+
else if (modelAny.context_window) {
|
|
205
|
+
contextLength = parseInt(modelAny.context_window, 10);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
console.error(`Error parsing context length for model ${model.id}:`, e);
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
id: model.id,
|
|
213
|
+
contextLength: contextLength || 0
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
if (freeVisionModels.length > 0) {
|
|
217
|
+
// Sort by context length and pick the one with the largest context window
|
|
218
|
+
freeVisionModels.sort((a, b) => b.contextLength - a.contextLength);
|
|
219
|
+
const selectedModel = freeVisionModels[0].id;
|
|
220
|
+
console.error(`Selected free vision model: ${selectedModel} with context length: ${freeVisionModels[0].contextLength}`);
|
|
221
|
+
return selectedModel;
|
|
222
|
+
}
|
|
223
|
+
// If no free vision models found, fallback to our default
|
|
224
|
+
console.error('No free vision models found, using default fallback model');
|
|
225
|
+
return DEFAULT_FREE_MODEL;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
console.error('Error finding suitable model:', error);
|
|
229
|
+
return DEFAULT_FREE_MODEL;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Process and analyze multiple images using OpenRouter
|
|
234
|
+
*/
|
|
63
235
|
export async function handleMultiImageAnalysis(request, openai, defaultModel) {
|
|
64
236
|
const args = request.params.arguments;
|
|
65
237
|
try {
|
|
@@ -75,31 +247,57 @@ export async function handleMultiImageAnalysis(request, openai, defaultModel) {
|
|
|
75
247
|
type: 'text',
|
|
76
248
|
text: args.prompt
|
|
77
249
|
}];
|
|
250
|
+
// Track successful and failed images for reporting
|
|
251
|
+
const successfulImages = [];
|
|
252
|
+
const failedImages = [];
|
|
78
253
|
// Process each image
|
|
79
|
-
for (const image of args.images) {
|
|
254
|
+
for (const [index, image] of args.images.entries()) {
|
|
80
255
|
try {
|
|
256
|
+
console.error(`Processing image ${index + 1}/${args.images.length}: ${image.url.substring(0, 50)}...`);
|
|
257
|
+
// Get MIME type
|
|
258
|
+
const mimeType = getMimeType(image.url);
|
|
81
259
|
// Fetch and process the image
|
|
82
260
|
const imageBuffer = await fetchImageAsBuffer(image.url);
|
|
83
|
-
const base64Image = await processImage(imageBuffer);
|
|
261
|
+
const base64Image = await processImage(imageBuffer, mimeType);
|
|
262
|
+
// Use JPEG as the output format for consistency
|
|
263
|
+
const outputMimeType = 'image/jpeg';
|
|
84
264
|
// Add to content
|
|
85
265
|
content.push({
|
|
86
266
|
type: 'image_url',
|
|
87
267
|
image_url: {
|
|
88
|
-
url: `data
|
|
268
|
+
url: `data:${outputMimeType};base64,${base64Image}`
|
|
89
269
|
}
|
|
90
270
|
});
|
|
271
|
+
successfulImages.push(image.url);
|
|
91
272
|
}
|
|
92
273
|
catch (error) {
|
|
93
|
-
console.error(`Error processing image ${image.url}:`, error);
|
|
274
|
+
console.error(`Error processing image ${index + 1} (${image.url.substring(0, 30)}...):`, error);
|
|
275
|
+
failedImages.push({ url: image.url, error: error instanceof Error ? error.message : String(error) });
|
|
94
276
|
// Continue with other images if one fails
|
|
95
277
|
}
|
|
96
278
|
}
|
|
97
279
|
// If no images were successfully processed
|
|
98
280
|
if (content.length === 1) {
|
|
99
|
-
|
|
281
|
+
const errorDetails = failedImages.map(img => `${img.url.substring(0, 30)}...: ${img.error}`).join('; ');
|
|
282
|
+
throw new Error(`Failed to process any of the provided images. Errors: ${errorDetails}`);
|
|
283
|
+
}
|
|
284
|
+
// Select model with priority:
|
|
285
|
+
// 1. User-specified model
|
|
286
|
+
// 2. Default model from environment
|
|
287
|
+
// 3. Default free vision model (qwen/qwen2.5-vl-32b-instruct:free)
|
|
288
|
+
let model = args.model || defaultModel || DEFAULT_FREE_MODEL;
|
|
289
|
+
// If a model is specified but not our default free model, verify it exists
|
|
290
|
+
if (model !== DEFAULT_FREE_MODEL) {
|
|
291
|
+
try {
|
|
292
|
+
await openai.models.retrieve(model);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
console.error(`Specified model ${model} not found, falling back to auto-selection`);
|
|
296
|
+
model = await findSuitableFreeModel(openai);
|
|
297
|
+
}
|
|
100
298
|
}
|
|
101
|
-
|
|
102
|
-
|
|
299
|
+
console.error(`Making API call with model: ${model}`);
|
|
300
|
+
console.error(`Successfully processed ${successfulImages.length} images, ${failedImages.length} failed`);
|
|
103
301
|
// Make the API call
|
|
104
302
|
const completion = await openai.chat.completions.create({
|
|
105
303
|
model,
|
|
@@ -108,13 +306,29 @@ export async function handleMultiImageAnalysis(request, openai, defaultModel) {
|
|
|
108
306
|
content
|
|
109
307
|
}]
|
|
110
308
|
});
|
|
309
|
+
// Format the response
|
|
310
|
+
let responseText = completion.choices[0].message.content || '';
|
|
311
|
+
// Add information about failed images if any
|
|
312
|
+
if (failedImages.length > 0) {
|
|
313
|
+
const formattedErrors = args.markdown_response !== false
|
|
314
|
+
? `\n\n---\n\n**Note:** ${failedImages.length} image(s) could not be processed:\n${failedImages.map((img, i) => `- Image ${i + 1}: ${img.error}`).join('\n')}`
|
|
315
|
+
: `\n\nNote: ${failedImages.length} image(s) could not be processed: ${failedImages.map((img, i) => `Image ${i + 1}: ${img.error}`).join('; ')}`;
|
|
316
|
+
responseText += formattedErrors;
|
|
317
|
+
}
|
|
318
|
+
// Return the analysis result
|
|
111
319
|
return {
|
|
112
320
|
content: [
|
|
113
321
|
{
|
|
114
322
|
type: 'text',
|
|
115
|
-
text:
|
|
323
|
+
text: responseText,
|
|
116
324
|
},
|
|
117
325
|
],
|
|
326
|
+
metadata: {
|
|
327
|
+
model: completion.model,
|
|
328
|
+
usage: completion.usage,
|
|
329
|
+
successful_images: successfulImages.length,
|
|
330
|
+
failed_images: failedImages.length
|
|
331
|
+
}
|
|
118
332
|
};
|
|
119
333
|
}
|
|
120
334
|
catch (error) {
|
|
@@ -130,6 +344,10 @@ export async function handleMultiImageAnalysis(request, openai, defaultModel) {
|
|
|
130
344
|
},
|
|
131
345
|
],
|
|
132
346
|
isError: true,
|
|
347
|
+
metadata: {
|
|
348
|
+
error_type: error instanceof Error ? error.constructor.name : 'Unknown',
|
|
349
|
+
error_message: error instanceof Error ? error.message : String(error)
|
|
350
|
+
}
|
|
133
351
|
};
|
|
134
352
|
}
|
|
135
353
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-image-anal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AAC,0BAA0B,KAAK,CAAC,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC7D,0CAA0C;YAC5C,CAAC;QACH,CAAC;QAED,2CAA2C;QAC3C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,eAAe;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,YAAY,IAAI,6BAA6B,CAAC;QAE1E,oBAAoB;QACpB,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;YACtD,KAAK;YACL,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,OAAO;iBACR,CAAQ;SACV,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE;iBAClD;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QAEvD,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC9B,MAAM,KAAK,CAAC;QACd,CAAC;QAED,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,2BAA2B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBAC1F;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"multi-image-analysis.js","sourceRoot":"","sources":["../../src/tool-handlers/multi-image-analysis.ts"],"names":[],"mappings":"AAAA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AAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,2BAA2B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBAC1F;aACF;YACD,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE;gBACR,UAAU,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;gBACvE,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aACtE;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/tool-handlers.js
CHANGED
|
@@ -7,8 +7,8 @@ import { handleChatCompletion } from './tool-handlers/chat-completion.js';
|
|
|
7
7
|
import { handleSearchModels } from './tool-handlers/search-models.js';
|
|
8
8
|
import { handleGetModelInfo } from './tool-handlers/get-model-info.js';
|
|
9
9
|
import { handleValidateModel } from './tool-handlers/validate-model.js';
|
|
10
|
-
import { handleAnalyzeImage } from './tool-handlers/analyze-image.js';
|
|
11
10
|
import { handleMultiImageAnalysis } from './tool-handlers/multi-image-analysis.js';
|
|
11
|
+
import { handleAnalyzeImage } from './tool-handlers/analyze-image.js';
|
|
12
12
|
export class ToolHandlers {
|
|
13
13
|
server;
|
|
14
14
|
openai;
|
|
@@ -35,7 +35,7 @@ export class ToolHandlers {
|
|
|
35
35
|
tools: [
|
|
36
36
|
// Chat Completion Tool
|
|
37
37
|
{
|
|
38
|
-
name: '
|
|
38
|
+
name: 'mcp_openrouter_chat_completion',
|
|
39
39
|
description: 'Send a message to OpenRouter.ai and get a response',
|
|
40
40
|
inputSchema: {
|
|
41
41
|
type: 'object',
|
|
@@ -110,9 +110,9 @@ export class ToolHandlers {
|
|
|
110
110
|
},
|
|
111
111
|
maxContextTokens: 200000
|
|
112
112
|
},
|
|
113
|
-
// Image Analysis Tool
|
|
113
|
+
// Single Image Analysis Tool
|
|
114
114
|
{
|
|
115
|
-
name: '
|
|
115
|
+
name: 'mcp_openrouter_analyze_image',
|
|
116
116
|
description: 'Analyze an image using OpenRouter vision models',
|
|
117
117
|
inputSchema: {
|
|
118
118
|
type: 'object',
|
|
@@ -121,10 +121,6 @@ export class ToolHandlers {
|
|
|
121
121
|
type: 'string',
|
|
122
122
|
description: 'Path to the image file to analyze (must be an absolute path)',
|
|
123
123
|
},
|
|
124
|
-
image_url: {
|
|
125
|
-
type: 'string',
|
|
126
|
-
description: 'URL or data URL of the image (can be a file:// URL, http(s):// URL, or data: URI)',
|
|
127
|
-
},
|
|
128
124
|
question: {
|
|
129
125
|
type: 'string',
|
|
130
126
|
description: 'Question to ask about the image',
|
|
@@ -134,15 +130,12 @@ export class ToolHandlers {
|
|
|
134
130
|
description: 'OpenRouter model to use (e.g., "anthropic/claude-3.5-sonnet")',
|
|
135
131
|
},
|
|
136
132
|
},
|
|
137
|
-
|
|
138
|
-
{ required: ['image_path'] },
|
|
139
|
-
{ required: ['image_url'] }
|
|
140
|
-
]
|
|
133
|
+
required: ['image_path'],
|
|
141
134
|
},
|
|
142
135
|
},
|
|
143
136
|
// Multi-Image Analysis Tool
|
|
144
137
|
{
|
|
145
|
-
name: '
|
|
138
|
+
name: 'mcp_openrouter_multi_image_analysis',
|
|
146
139
|
description: 'Analyze multiple images at once with a single prompt and receive detailed responses',
|
|
147
140
|
inputSchema: {
|
|
148
141
|
type: 'object',
|
|
@@ -155,7 +148,7 @@ export class ToolHandlers {
|
|
|
155
148
|
properties: {
|
|
156
149
|
url: {
|
|
157
150
|
type: 'string',
|
|
158
|
-
description: 'URL or data URL of the image (
|
|
151
|
+
description: 'URL or data URL of the image (use file:// URL prefix for local files, http(s):// for web images, or data: for base64 encoded images)',
|
|
159
152
|
},
|
|
160
153
|
alt: {
|
|
161
154
|
type: 'string',
|
|
@@ -176,7 +169,7 @@ export class ToolHandlers {
|
|
|
176
169
|
},
|
|
177
170
|
model: {
|
|
178
171
|
type: 'string',
|
|
179
|
-
description: 'OpenRouter model to use
|
|
172
|
+
description: 'OpenRouter model to use. If not specified, the system will use a free model with vision capabilities or the default model.',
|
|
180
173
|
},
|
|
181
174
|
},
|
|
182
175
|
required: ['images', 'prompt'],
|
|
@@ -278,19 +271,19 @@ export class ToolHandlers {
|
|
|
278
271
|
}));
|
|
279
272
|
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
280
273
|
switch (request.params.name) {
|
|
281
|
-
case '
|
|
274
|
+
case 'mcp_openrouter_chat_completion':
|
|
282
275
|
return handleChatCompletion({
|
|
283
276
|
params: {
|
|
284
277
|
arguments: request.params.arguments
|
|
285
278
|
}
|
|
286
279
|
}, this.openai, this.defaultModel);
|
|
287
|
-
case '
|
|
280
|
+
case 'mcp_openrouter_analyze_image':
|
|
288
281
|
return handleAnalyzeImage({
|
|
289
282
|
params: {
|
|
290
283
|
arguments: request.params.arguments
|
|
291
284
|
}
|
|
292
285
|
}, this.openai, this.defaultModel);
|
|
293
|
-
case '
|
|
286
|
+
case 'mcp_openrouter_multi_image_analysis':
|
|
294
287
|
return handleMultiImageAnalysis({
|
|
295
288
|
params: {
|
|
296
289
|
arguments: request.params.arguments
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-handlers.js","sourceRoot":"","sources":["../src/tool-handlers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,sBAAsB,EACtB,QAAQ,GACT,MAAM,oCAAoC,CAAC;AAC5C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,uBAAuB;AACvB,OAAO,EAAE,oBAAoB,EAA6B,MAAM,oCAAoC,CAAC;AACrG,OAAO,E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,cAAc,EACxB,iBAAiB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CACvC,CAAC;YACN,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stabgan/openrouter-mcp-multimodal",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "MCP server for OpenRouter providing text chat and image analysis tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -42,9 +42,10 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@modelcontextprotocol/sdk": "^1.4.1",
|
|
45
|
-
"axios": "^1.
|
|
45
|
+
"axios": "^1.8.4",
|
|
46
|
+
"dotenv": "^16.4.7",
|
|
46
47
|
"node-fetch": "^3.3.2",
|
|
47
|
-
"openai": "^4.
|
|
48
|
+
"openai": "^4.89.1",
|
|
48
49
|
"sharp": "^0.33.3"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
@@ -57,4 +58,4 @@
|
|
|
57
58
|
"uri-js": "npm:uri-js-replace",
|
|
58
59
|
"whatwg-url": "^14.1.0"
|
|
59
60
|
}
|
|
60
|
-
}
|
|
61
|
+
}
|