@rlabs-inc/gemini-mcp 0.6.2 → 0.7.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.
- package/README.md +46 -43
- package/dist/cli/commands/config.d.ts +8 -0
- package/dist/cli/commands/config.js +147 -0
- package/dist/cli/commands/image.d.ts +7 -0
- package/dist/cli/commands/image.js +133 -0
- package/dist/cli/commands/query.d.ts +7 -0
- package/dist/cli/commands/query.js +94 -0
- package/dist/cli/commands/research.d.ts +7 -0
- package/dist/cli/commands/research.js +147 -0
- package/dist/cli/commands/search.d.ts +7 -0
- package/dist/cli/commands/search.js +152 -0
- package/dist/cli/commands/speak.d.ts +7 -0
- package/dist/cli/commands/speak.js +168 -0
- package/dist/cli/commands/tokens.d.ts +8 -0
- package/dist/cli/commands/tokens.js +105 -0
- package/dist/cli/commands/video.d.ts +7 -0
- package/dist/cli/commands/video.js +154 -0
- package/dist/cli/config.d.ts +23 -0
- package/dist/cli/config.js +89 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +180 -0
- package/dist/cli/ui/box.d.ts +20 -0
- package/dist/cli/ui/box.js +112 -0
- package/dist/cli/ui/colors.d.ts +46 -0
- package/dist/cli/ui/colors.js +106 -0
- package/dist/cli/ui/index.d.ts +21 -0
- package/dist/cli/ui/index.js +42 -0
- package/dist/cli/ui/progress.d.ts +37 -0
- package/dist/cli/ui/progress.js +125 -0
- package/dist/cli/ui/spinner.d.ts +42 -0
- package/dist/cli/ui/spinner.js +96 -0
- package/dist/cli/ui/theme.d.ts +48 -0
- package/dist/cli/ui/theme.js +200 -0
- package/dist/gemini-client.d.ts +1 -0
- package/dist/gemini-client.js +35 -8
- package/dist/index.d.ts +6 -3
- package/dist/index.js +26 -218
- package/dist/server.d.ts +7 -0
- package/dist/server.js +221 -0
- package/dist/tools/deep-research.js +9 -2
- package/package.json +9 -3
package/dist/server.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server for Gemini
|
|
3
|
+
*
|
|
4
|
+
* Provides Gemini models as MCP tools for Claude Code integration.
|
|
5
|
+
* This is the original MCP server functionality, now modularized.
|
|
6
|
+
*/
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
+
import { parseArgs } from 'node:util';
|
|
10
|
+
// Import tools
|
|
11
|
+
import { registerQueryTool } from './tools/query.js';
|
|
12
|
+
import { registerBrainstormTool } from './tools/brainstorm.js';
|
|
13
|
+
import { registerAnalyzeTool } from './tools/analyze.js';
|
|
14
|
+
import { registerSummarizeTool } from './tools/summarize.js';
|
|
15
|
+
import { registerImageGenTool } from './tools/image-gen.js';
|
|
16
|
+
import { registerImageEditTool } from './tools/image-edit.js';
|
|
17
|
+
import { registerVideoGenTool } from './tools/video-gen.js';
|
|
18
|
+
import { registerCodeExecTool } from './tools/code-exec.js';
|
|
19
|
+
import { registerSearchTool } from './tools/search.js';
|
|
20
|
+
import { registerStructuredTool } from './tools/structured.js';
|
|
21
|
+
import { registerYouTubeTool } from './tools/youtube.js';
|
|
22
|
+
import { registerDocumentTool } from './tools/document.js';
|
|
23
|
+
import { registerUrlContextTool } from './tools/url-context.js';
|
|
24
|
+
import { registerCacheTool } from './tools/cache.js';
|
|
25
|
+
import { registerSpeechTool } from './tools/speech.js';
|
|
26
|
+
import { registerTokenCountTool } from './tools/token-count.js';
|
|
27
|
+
import { registerDeepResearchTool } from './tools/deep-research.js';
|
|
28
|
+
// Import Gemini client and logger
|
|
29
|
+
import { initGeminiClient } from './gemini-client.js';
|
|
30
|
+
import { setupLogger, logger } from './utils/logger.js';
|
|
31
|
+
export async function startMcpServer(argv) {
|
|
32
|
+
// Parse command line arguments
|
|
33
|
+
const { values } = parseArgs({
|
|
34
|
+
args: argv,
|
|
35
|
+
options: {
|
|
36
|
+
verbose: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
short: 'v',
|
|
39
|
+
default: false,
|
|
40
|
+
},
|
|
41
|
+
quiet: {
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
short: 'q',
|
|
44
|
+
default: false,
|
|
45
|
+
},
|
|
46
|
+
help: {
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
short: 'h',
|
|
49
|
+
default: false,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
allowPositionals: true,
|
|
53
|
+
});
|
|
54
|
+
// Show help if requested
|
|
55
|
+
if (values.help) {
|
|
56
|
+
console.log(`
|
|
57
|
+
MCP Server Gemini - Integrates Google's Gemini models with Claude Code
|
|
58
|
+
|
|
59
|
+
Usage:
|
|
60
|
+
gemini-mcp [options]
|
|
61
|
+
gemini serve [options]
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
-v, --verbose Enable verbose logging (shows all prompts and responses)
|
|
65
|
+
-q, --quiet Run in quiet mode (minimal logging)
|
|
66
|
+
-h, --help Show this help message
|
|
67
|
+
|
|
68
|
+
Environment Variables:
|
|
69
|
+
GEMINI_API_KEY (required) Your Google Gemini API key
|
|
70
|
+
VERBOSE (optional) Set to "true" to enable verbose logging
|
|
71
|
+
QUIET (optional) Set to "true" to enable quiet mode
|
|
72
|
+
GEMINI_MODEL (optional) Default Gemini model to use
|
|
73
|
+
GEMINI_PRO_MODEL (optional) Specify Pro model variant
|
|
74
|
+
GEMINI_FLASH_MODEL (optional) Specify Flash model variant
|
|
75
|
+
|
|
76
|
+
For CLI mode, run: gemini --help
|
|
77
|
+
`);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
// Configure logging mode based on command line args or environment variables
|
|
81
|
+
let logLevel = 'normal';
|
|
82
|
+
if (values.verbose || process.env.VERBOSE === 'true') {
|
|
83
|
+
logLevel = 'verbose';
|
|
84
|
+
}
|
|
85
|
+
else if (values.quiet || process.env.QUIET === 'true') {
|
|
86
|
+
logLevel = 'quiet';
|
|
87
|
+
}
|
|
88
|
+
setupLogger(logLevel);
|
|
89
|
+
// Check for required API key
|
|
90
|
+
if (!process.env.GEMINI_API_KEY) {
|
|
91
|
+
logger.error('Error: GEMINI_API_KEY environment variable is required');
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
// Get model name from environment or use default
|
|
95
|
+
const defaultModel = 'gemini-3-pro-preview';
|
|
96
|
+
const geminiModel = process.env.GEMINI_MODEL || defaultModel;
|
|
97
|
+
// Log model configuration for debugging
|
|
98
|
+
logger.debug(`Model configuration:
|
|
99
|
+
- GEMINI_MODEL: ${process.env.GEMINI_MODEL || '(not set, using default)'}
|
|
100
|
+
- GEMINI_PRO_MODEL: ${process.env.GEMINI_PRO_MODEL || '(not set, using default)'}
|
|
101
|
+
- GEMINI_FLASH_MODEL: ${process.env.GEMINI_FLASH_MODEL || '(not set, using default)'}`);
|
|
102
|
+
logger.info(`Starting MCP Gemini Server with model: ${geminiModel}`);
|
|
103
|
+
logger.info(`Logging mode: ${logLevel}`);
|
|
104
|
+
// Handle unexpected stdio errors
|
|
105
|
+
process.stdin.on('error', (err) => {
|
|
106
|
+
logger.error('STDIN error:', err);
|
|
107
|
+
});
|
|
108
|
+
process.stdout.on('error', (err) => {
|
|
109
|
+
logger.error('STDOUT error:', err);
|
|
110
|
+
});
|
|
111
|
+
try {
|
|
112
|
+
// Initialize Gemini client
|
|
113
|
+
await initGeminiClient();
|
|
114
|
+
// Create MCP server
|
|
115
|
+
const server = new McpServer({
|
|
116
|
+
name: 'Gemini',
|
|
117
|
+
version: '0.7.0',
|
|
118
|
+
});
|
|
119
|
+
// Register tools
|
|
120
|
+
registerQueryTool(server);
|
|
121
|
+
registerBrainstormTool(server);
|
|
122
|
+
registerAnalyzeTool(server);
|
|
123
|
+
registerSummarizeTool(server);
|
|
124
|
+
registerImageGenTool(server);
|
|
125
|
+
registerImageEditTool(server);
|
|
126
|
+
registerVideoGenTool(server);
|
|
127
|
+
registerCodeExecTool(server);
|
|
128
|
+
registerSearchTool(server);
|
|
129
|
+
registerStructuredTool(server);
|
|
130
|
+
registerYouTubeTool(server);
|
|
131
|
+
registerDocumentTool(server);
|
|
132
|
+
registerUrlContextTool(server);
|
|
133
|
+
registerCacheTool(server);
|
|
134
|
+
registerSpeechTool(server);
|
|
135
|
+
registerTokenCountTool(server);
|
|
136
|
+
registerDeepResearchTool(server);
|
|
137
|
+
// Start server with stdio transport
|
|
138
|
+
const transport = new StdioServerTransport();
|
|
139
|
+
// Set up error handling for transport
|
|
140
|
+
transport.onclose = () => {
|
|
141
|
+
logger.warn('MCP transport connection closed');
|
|
142
|
+
logger.debug('Connection closed event triggered');
|
|
143
|
+
// Attempt to recover connection with backoff strategy
|
|
144
|
+
let reconnectAttempts = 0;
|
|
145
|
+
const maxReconnectAttempts = 5;
|
|
146
|
+
const attemptReconnect = () => {
|
|
147
|
+
if (reconnectAttempts >= maxReconnectAttempts) {
|
|
148
|
+
logger.error(`Failed to reconnect after ${maxReconnectAttempts} attempts`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
reconnectAttempts++;
|
|
152
|
+
const delay = Math.min(1000 * Math.pow(1.5, reconnectAttempts - 1), 10000);
|
|
153
|
+
logger.info(`Attempting to reconnect (${reconnectAttempts}/${maxReconnectAttempts}) after ${delay}ms...`);
|
|
154
|
+
setTimeout(() => {
|
|
155
|
+
try {
|
|
156
|
+
if (process.stdin.destroyed || process.stdout.destroyed) {
|
|
157
|
+
logger.error('Cannot reconnect: stdin or stdout is destroyed');
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
server
|
|
161
|
+
.connect(transport)
|
|
162
|
+
.then(() => {
|
|
163
|
+
logger.info('Successfully reconnected to MCP transport');
|
|
164
|
+
reconnectAttempts = 0;
|
|
165
|
+
})
|
|
166
|
+
.catch((e) => {
|
|
167
|
+
logger.error('Reconnection failed:', e);
|
|
168
|
+
attemptReconnect();
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
logger.error('Error during reconnection attempt:', e);
|
|
173
|
+
attemptReconnect();
|
|
174
|
+
}
|
|
175
|
+
}, delay);
|
|
176
|
+
};
|
|
177
|
+
attemptReconnect();
|
|
178
|
+
};
|
|
179
|
+
transport.onerror = (error) => {
|
|
180
|
+
logger.error('MCP transport error:', error);
|
|
181
|
+
if (error instanceof Error) {
|
|
182
|
+
logger.debug(`Error name: ${error.name}, message: ${error.message}`);
|
|
183
|
+
logger.debug(`Stack trace: ${error.stack}`);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
// Connect to transport
|
|
187
|
+
try {
|
|
188
|
+
logger.debug(`Process details - PID: ${process.pid}, Node version: ${process.version}`);
|
|
189
|
+
logger.debug(`Environment variables: API_KEY=${process.env.GEMINI_API_KEY ? 'SET' : 'NOT_SET'}, VERBOSE=${process.env.VERBOSE || 'not set'}`);
|
|
190
|
+
logger.debug(`Process stdin/stdout state - isTTY: ${process.stdin.isTTY}, ${process.stdout.isTTY}`);
|
|
191
|
+
await server.connect(transport);
|
|
192
|
+
logger.info('MCP Gemini Server running');
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
logger.error('Failed to connect MCP server transport:', err);
|
|
196
|
+
if (err instanceof Error) {
|
|
197
|
+
logger.debug(`Error stack: ${err.stack}`);
|
|
198
|
+
logger.debug(`Error details: name=${err.name}, message=${err.message}`);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
logger.debug(`Non-Error object thrown: ${JSON.stringify(err)}`);
|
|
202
|
+
}
|
|
203
|
+
logger.warn('Server will attempt to continue running despite connection error');
|
|
204
|
+
}
|
|
205
|
+
// Handle process termination
|
|
206
|
+
process.on('SIGINT', async () => {
|
|
207
|
+
logger.info('Shutting down MCP Gemini Server');
|
|
208
|
+
await server.close();
|
|
209
|
+
process.exit(0);
|
|
210
|
+
});
|
|
211
|
+
process.on('SIGTERM', async () => {
|
|
212
|
+
logger.info('Shutting down MCP Gemini Server');
|
|
213
|
+
await server.close();
|
|
214
|
+
process.exit(0);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
logger.error('Failed to start MCP Gemini Server:', error);
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -51,7 +51,7 @@ export function registerDeepResearchTool(server) {
|
|
|
51
51
|
**What happens now:**
|
|
52
52
|
1. The Deep Research Agent is autonomously planning its research approach
|
|
53
53
|
2. It will search the web, read sources, and synthesize findings
|
|
54
|
-
3. This typically takes
|
|
54
|
+
3. This typically takes 5-20 minutes (max 60 min for complex queries)
|
|
55
55
|
|
|
56
56
|
**To check progress:**
|
|
57
57
|
Use \`gemini-check-research\` with the Research ID above.
|
|
@@ -111,6 +111,10 @@ The Interactions API required for Deep Research may not be available yet in your
|
|
|
111
111
|
? outputs[outputs.length - 1].text || 'No text output'
|
|
112
112
|
: 'Research completed but no output found';
|
|
113
113
|
logger.info(`Research completed: ${researchId}`);
|
|
114
|
+
// Build the saved path info if available
|
|
115
|
+
const savedPathInfo = result.savedPath
|
|
116
|
+
? `| **Full Response** | \`${result.savedPath}\` |`
|
|
117
|
+
: '';
|
|
114
118
|
return {
|
|
115
119
|
content: [
|
|
116
120
|
{
|
|
@@ -122,6 +126,9 @@ The Interactions API required for Deep Research may not be available yet in your
|
|
|
122
126
|
| **Research ID** | \`${researchId}\` |
|
|
123
127
|
| **Status** | ✅ Completed |
|
|
124
128
|
| **Duration** | ${elapsedMinutes}m ${elapsedSeconds}s |
|
|
129
|
+
${savedPathInfo}
|
|
130
|
+
|
|
131
|
+
> **Note:** The full response (including citations, images, and all metadata) has been saved to the file above.
|
|
125
132
|
|
|
126
133
|
---
|
|
127
134
|
|
|
@@ -170,7 +177,7 @@ The research task encountered an error. You can try:
|
|
|
170
177
|
| **Elapsed** | ${elapsedMinutes}m ${elapsedSeconds}s |
|
|
171
178
|
| **Query** | ${operationInfo?.prompt.substring(0, 50) || 'Unknown'}... |
|
|
172
179
|
|
|
173
|
-
The agent is still working. Deep research typically takes
|
|
180
|
+
The agent is still working. Deep research typically takes 5-20 minutes (max 60 min for complex queries).
|
|
174
181
|
|
|
175
182
|
Check again in 30-60 seconds using \`gemini-check-research\`.`,
|
|
176
183
|
},
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rlabs-inc/gemini-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"mcpName": "io.github.rlabs-inc/gemini-mcp",
|
|
5
|
+
"description": "MCP server for Gemini 3 integration with Claude Code - 30+ AI tools including image/video generation, deep research, code execution, and beautiful CLI",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
|
-
"gemini-mcp": "dist/index.js"
|
|
9
|
+
"gemini-mcp": "dist/index.js",
|
|
10
|
+
"gemini": "dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/RLabs-Inc/gemini-mcp.git"
|
|
9
15
|
},
|
|
10
16
|
"scripts": {
|
|
11
17
|
"build": "bun run tsc && chmod 755 dist/index.js",
|