@joeytheman/gemini-mcp-tool 1.3.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/LICENSE +26 -0
- package/README.md +239 -0
- package/dist/__tests__/ask-gemini.test.d.ts +2 -0
- package/dist/__tests__/ask-gemini.test.d.ts.map +1 -0
- package/dist/__tests__/ask-gemini.test.js +165 -0
- package/dist/__tests__/ask-gemini.test.js.map +1 -0
- package/dist/__tests__/server.test.d.ts +2 -0
- package/dist/__tests__/server.test.d.ts.map +1 -0
- package/dist/__tests__/server.test.js +72 -0
- package/dist/__tests__/server.test.js.map +1 -0
- package/dist/__tests__/tools.test.d.ts +2 -0
- package/dist/__tests__/tools.test.d.ts.map +1 -0
- package/dist/__tests__/tools.test.js +131 -0
- package/dist/__tests__/tools.test.js.map +1 -0
- package/dist/__tests__/utils/changeModeChunker.test.d.ts +2 -0
- package/dist/__tests__/utils/changeModeChunker.test.d.ts.map +1 -0
- package/dist/__tests__/utils/changeModeChunker.test.js +137 -0
- package/dist/__tests__/utils/changeModeChunker.test.js.map +1 -0
- package/dist/__tests__/utils/changeModeParser.test.d.ts +2 -0
- package/dist/__tests__/utils/changeModeParser.test.d.ts.map +1 -0
- package/dist/__tests__/utils/changeModeParser.test.js +254 -0
- package/dist/__tests__/utils/changeModeParser.test.js.map +1 -0
- package/dist/__tests__/utils/changeModeTranslator.test.d.ts +2 -0
- package/dist/__tests__/utils/changeModeTranslator.test.d.ts.map +1 -0
- package/dist/__tests__/utils/changeModeTranslator.test.js +112 -0
- package/dist/__tests__/utils/changeModeTranslator.test.js.map +1 -0
- package/dist/__tests__/utils/chunkCache.test.d.ts +2 -0
- package/dist/__tests__/utils/chunkCache.test.d.ts.map +1 -0
- package/dist/__tests__/utils/chunkCache.test.js +140 -0
- package/dist/__tests__/utils/chunkCache.test.js.map +1 -0
- package/dist/__tests__/utils/commandExecutor.test.d.ts +2 -0
- package/dist/__tests__/utils/commandExecutor.test.d.ts.map +1 -0
- package/dist/__tests__/utils/commandExecutor.test.js +139 -0
- package/dist/__tests__/utils/commandExecutor.test.js.map +1 -0
- package/dist/__tests__/utils/geminiExecutor.test.d.ts +2 -0
- package/dist/__tests__/utils/geminiExecutor.test.d.ts.map +1 -0
- package/dist/__tests__/utils/geminiExecutor.test.js +337 -0
- package/dist/__tests__/utils/geminiExecutor.test.js.map +1 -0
- package/dist/__tests__/utils/responseCache.test.d.ts +2 -0
- package/dist/__tests__/utils/responseCache.test.d.ts.map +1 -0
- package/dist/__tests__/utils/responseCache.test.js +98 -0
- package/dist/__tests__/utils/responseCache.test.js.map +1 -0
- package/dist/__tests__/utils/test-helpers.d.ts +17 -0
- package/dist/__tests__/utils/test-helpers.d.ts.map +1 -0
- package/dist/__tests__/utils/test-helpers.js +50 -0
- package/dist/__tests__/utils/test-helpers.js.map +1 -0
- package/dist/constants.d.ts +96 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +89 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +186 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/ask-gemini.tool.d.ts +3 -0
- package/dist/tools/ask-gemini.tool.d.ts.map +1 -0
- package/dist/tools/ask-gemini.tool.js +65 -0
- package/dist/tools/ask-gemini.tool.js.map +1 -0
- package/dist/tools/brainstorm.tool.d.ts +3 -0
- package/dist/tools/brainstorm.tool.d.ts.map +1 -0
- package/dist/tools/brainstorm.tool.js +147 -0
- package/dist/tools/brainstorm.tool.js.map +1 -0
- package/dist/tools/fetch-chunk.tool.d.ts +3 -0
- package/dist/tools/fetch-chunk.tool.d.ts.map +1 -0
- package/dist/tools/fetch-chunk.tool.js +67 -0
- package/dist/tools/fetch-chunk.tool.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +43 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +81 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/simple-tools.d.ts +4 -0
- package/dist/tools/simple-tools.d.ts.map +1 -0
- package/dist/tools/simple-tools.js +42 -0
- package/dist/tools/simple-tools.js.map +1 -0
- package/dist/tools/test-tool.example.d.ts +13 -0
- package/dist/tools/test-tool.example.d.ts.map +1 -0
- package/dist/tools/test-tool.example.js +32 -0
- package/dist/tools/test-tool.example.js.map +1 -0
- package/dist/tools/timeout-test.tool.d.ts +3 -0
- package/dist/tools/timeout-test.tool.d.ts.map +1 -0
- package/dist/tools/timeout-test.tool.js +36 -0
- package/dist/tools/timeout-test.tool.js.map +1 -0
- package/dist/utils/changeModeChunker.d.ts +11 -0
- package/dist/utils/changeModeChunker.d.ts.map +1 -0
- package/dist/utils/changeModeChunker.js +89 -0
- package/dist/utils/changeModeChunker.js.map +1 -0
- package/dist/utils/changeModeParser.d.ts +15 -0
- package/dist/utils/changeModeParser.d.ts.map +1 -0
- package/dist/utils/changeModeParser.js +67 -0
- package/dist/utils/changeModeParser.js.map +1 -0
- package/dist/utils/changeModeTranslator.d.ts +8 -0
- package/dist/utils/changeModeTranslator.d.ts.map +1 -0
- package/dist/utils/changeModeTranslator.js +70 -0
- package/dist/utils/changeModeTranslator.js.map +1 -0
- package/dist/utils/chunkCache.d.ts +22 -0
- package/dist/utils/chunkCache.d.ts.map +1 -0
- package/dist/utils/chunkCache.js +161 -0
- package/dist/utils/chunkCache.js.map +1 -0
- package/dist/utils/commandExecutor.d.ts +2 -0
- package/dist/utils/commandExecutor.d.ts.map +1 -0
- package/dist/utils/commandExecutor.js +79 -0
- package/dist/utils/commandExecutor.js.map +1 -0
- package/dist/utils/geminiExecutor.d.ts +17 -0
- package/dist/utils/geminiExecutor.d.ts.map +1 -0
- package/dist/utils/geminiExecutor.js +238 -0
- package/dist/utils/geminiExecutor.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +42 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/responseCache.d.ts +33 -0
- package/dist/utils/responseCache.d.ts.map +1 -0
- package/dist/utils/responseCache.js +87 -0
- package/dist/utils/responseCache.js.map +1 -0
- package/dist/utils/timeoutManager.d.ts +2 -0
- package/dist/utils/timeoutManager.d.ts.map +1 -0
- package/dist/utils/timeoutManager.js +2 -0
- package/dist/utils/timeoutManager.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,YAAY,CAAC;AAGpC,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC;AAGX,eAAO,MAAM,eAAe;;;;;;;;;CAUlB,CAAC;AAGX,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAGX,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;CAuBX,CAAC;AAIX,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCN,CAAC;AAIX,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAGzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CACjE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Logging
|
|
2
|
+
export const LOG_PREFIX = "[GMCPT]";
|
|
3
|
+
// Error messages
|
|
4
|
+
export const ERROR_MESSAGES = {
|
|
5
|
+
QUOTA_EXCEEDED: "RESOURCE_EXHAUSTED",
|
|
6
|
+
QUOTA_EXCEEDED_SHORT: "⚠️ Gemini Pro daily quota exceeded. Please retry with model: 'gemini-3-flash-preview'",
|
|
7
|
+
TOOL_NOT_FOUND: "not found in registry",
|
|
8
|
+
NO_PROMPT_PROVIDED: "Please provide a prompt for analysis. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions",
|
|
9
|
+
};
|
|
10
|
+
// Status messages
|
|
11
|
+
export const STATUS_MESSAGES = {
|
|
12
|
+
QUOTA_SWITCHING: "🚫 Gemini Pro quota exceeded, switching to Flash model...",
|
|
13
|
+
FLASH_RETRY: "⚡ Retrying with Gemini Flash...",
|
|
14
|
+
FLASH_SUCCESS: "✅ Flash model completed successfully",
|
|
15
|
+
SANDBOX_EXECUTING: "🔒 Executing Gemini CLI command in sandbox mode...",
|
|
16
|
+
GEMINI_RESPONSE: "Gemini response:",
|
|
17
|
+
// Timeout prevention messages
|
|
18
|
+
PROCESSING_START: "🔍 Starting analysis (may take 5-15 minutes for large codebases)",
|
|
19
|
+
PROCESSING_CONTINUE: "⏳ Still processing... Gemini is working on your request",
|
|
20
|
+
PROCESSING_COMPLETE: "✅ Analysis completed successfully",
|
|
21
|
+
};
|
|
22
|
+
// Models
|
|
23
|
+
export const MODELS = {
|
|
24
|
+
PRO: "gemini-3.1-pro-preview",
|
|
25
|
+
FLASH: "gemini-3-flash-preview",
|
|
26
|
+
};
|
|
27
|
+
// MCP Protocol Constants
|
|
28
|
+
export const PROTOCOL = {
|
|
29
|
+
// Message roles
|
|
30
|
+
ROLES: {
|
|
31
|
+
USER: "user",
|
|
32
|
+
ASSISTANT: "assistant",
|
|
33
|
+
},
|
|
34
|
+
// Content types
|
|
35
|
+
CONTENT_TYPES: {
|
|
36
|
+
TEXT: "text",
|
|
37
|
+
},
|
|
38
|
+
// Status codes
|
|
39
|
+
STATUS: {
|
|
40
|
+
SUCCESS: "success",
|
|
41
|
+
ERROR: "error",
|
|
42
|
+
FAILED: "failed",
|
|
43
|
+
REPORT: "report",
|
|
44
|
+
},
|
|
45
|
+
// Notification methods
|
|
46
|
+
NOTIFICATIONS: {
|
|
47
|
+
PROGRESS: "notifications/progress",
|
|
48
|
+
},
|
|
49
|
+
// Timeout prevention
|
|
50
|
+
KEEPALIVE_INTERVAL: 25000, // 25 seconds
|
|
51
|
+
};
|
|
52
|
+
// CLI Constants
|
|
53
|
+
export const CLI = {
|
|
54
|
+
// Command names
|
|
55
|
+
COMMANDS: {
|
|
56
|
+
GEMINI: "gemini",
|
|
57
|
+
ECHO: "echo",
|
|
58
|
+
},
|
|
59
|
+
// Command flags
|
|
60
|
+
FLAGS: {
|
|
61
|
+
MODEL: "-m",
|
|
62
|
+
SANDBOX: "-s",
|
|
63
|
+
PROMPT: "-p",
|
|
64
|
+
HELP: "-help",
|
|
65
|
+
// Phase 1: Critical flags
|
|
66
|
+
YOLO: "-y",
|
|
67
|
+
APPROVAL_MODE: "--approval-mode",
|
|
68
|
+
OUTPUT_FORMAT: "-o",
|
|
69
|
+
INCLUDE_DIRECTORIES: "--include-directories",
|
|
70
|
+
DEBUG: "-d",
|
|
71
|
+
// Phase 2: Enhanced features
|
|
72
|
+
PROMPT_INTERACTIVE: "-i",
|
|
73
|
+
EXTENSIONS: "-e",
|
|
74
|
+
RESUME: "-r",
|
|
75
|
+
},
|
|
76
|
+
// Default values
|
|
77
|
+
DEFAULTS: {
|
|
78
|
+
MODEL: "default", // Fallback model used when no specific model is provided
|
|
79
|
+
BOOLEAN_TRUE: "true",
|
|
80
|
+
BOOLEAN_FALSE: "false",
|
|
81
|
+
APPROVAL_MODE_DEFAULT: "default",
|
|
82
|
+
APPROVAL_MODE_AUTO_EDIT: "auto_edit",
|
|
83
|
+
APPROVAL_MODE_YOLO: "yolo",
|
|
84
|
+
OUTPUT_FORMAT_TEXT: "text",
|
|
85
|
+
OUTPUT_FORMAT_JSON: "json",
|
|
86
|
+
OUTPUT_FORMAT_STREAM_JSON: "stream-json",
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,UAAU;AACV,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AAEpC,iBAAiB;AACjB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,cAAc,EAAE,oBAAoB;IACpC,oBAAoB,EAAE,uFAAuF;IAC7G,cAAc,EAAE,uBAAuB;IACvC,kBAAkB,EAAE,6IAA6I;CACzJ,CAAC;AAEX,kBAAkB;AAClB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,eAAe,EAAE,2DAA2D;IAC5E,WAAW,EAAE,iCAAiC;IAC9C,aAAa,EAAE,sCAAsC;IACrD,iBAAiB,EAAE,oDAAoD;IACvE,eAAe,EAAE,kBAA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SAAS,EAAE,yDAAyD;QAC3E,YAAY,EAAE,MAAM;QACpB,aAAa,EAAE,OAAO;QACtB,qBAAqB,EAAE,SAAS;QAChC,uBAAuB,EAAE,WAAW;QACpC,kBAAkB,EAAE,MAAM;QAC1B,kBAAkB,EAAE,MAAM;QAC1B,kBAAkB,EAAE,MAAM;QAC1B,yBAAyB,EAAE,aAAa;KACzC;CACO,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { Logger } from "./utils/logger.js";
|
|
6
|
+
import { PROTOCOL } from "./constants.js";
|
|
7
|
+
import { getToolDefinitions, getPromptDefinitions, executeTool, toolExists, getPromptMessage } from "./tools/index.js";
|
|
8
|
+
const server = new Server({
|
|
9
|
+
name: "gemini-cli-mcp",
|
|
10
|
+
version: "1.1.4",
|
|
11
|
+
}, {
|
|
12
|
+
capabilities: {
|
|
13
|
+
tools: {},
|
|
14
|
+
prompts: {},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
let isProcessing = false;
|
|
18
|
+
let currentOperationName = "";
|
|
19
|
+
let latestOutput = "";
|
|
20
|
+
async function sendNotification(method, params) {
|
|
21
|
+
try {
|
|
22
|
+
await server.notification({ method, params });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
Logger.error("notification failed: ", error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @param progressToken The progress token provided by the client
|
|
30
|
+
* @param progress The current progress value
|
|
31
|
+
* @param total Optional total value
|
|
32
|
+
* @param message Optional status message
|
|
33
|
+
*/
|
|
34
|
+
async function sendProgressNotification(progressToken, progress, total, message) {
|
|
35
|
+
if (!progressToken)
|
|
36
|
+
return; // Only send if client requested progress
|
|
37
|
+
try {
|
|
38
|
+
const params = {
|
|
39
|
+
progressToken,
|
|
40
|
+
progress
|
|
41
|
+
};
|
|
42
|
+
if (total !== undefined)
|
|
43
|
+
params.total = total; // future cache progress
|
|
44
|
+
if (message)
|
|
45
|
+
params.message = message;
|
|
46
|
+
await server.notification({
|
|
47
|
+
method: PROTOCOL.NOTIFICATIONS.PROGRESS,
|
|
48
|
+
params
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
Logger.error("Failed to send progress notification:", error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function startProgressUpdates(operationName, progressToken) {
|
|
56
|
+
isProcessing = true;
|
|
57
|
+
currentOperationName = operationName;
|
|
58
|
+
latestOutput = ""; // Reset latest output
|
|
59
|
+
const progressMessages = [
|
|
60
|
+
`🧠 ${operationName} - Gemini is analyzing your request...`,
|
|
61
|
+
`📊 ${operationName} - Processing files and generating insights...`,
|
|
62
|
+
`✨ ${operationName} - Creating structured response for your review...`,
|
|
63
|
+
`⏱️ ${operationName} - Large analysis in progress (this is normal for big requests)...`,
|
|
64
|
+
`🔍 ${operationName} - Still working... Gemini takes time for quality results...`,
|
|
65
|
+
];
|
|
66
|
+
let messageIndex = 0;
|
|
67
|
+
let progress = 0;
|
|
68
|
+
// Send immediate acknowledgment if progress requested
|
|
69
|
+
if (progressToken) {
|
|
70
|
+
sendProgressNotification(progressToken, 0, undefined, // No total - indeterminate progress
|
|
71
|
+
`🔍 Starting ${operationName}`);
|
|
72
|
+
}
|
|
73
|
+
// Keep client alive with periodic updates
|
|
74
|
+
const progressInterval = setInterval(async () => {
|
|
75
|
+
if (isProcessing && progressToken) {
|
|
76
|
+
// Simply increment progress value
|
|
77
|
+
progress += 1;
|
|
78
|
+
// Include latest output if available
|
|
79
|
+
const baseMessage = progressMessages[messageIndex % progressMessages.length];
|
|
80
|
+
const outputPreview = latestOutput.slice(-150).trim(); // Last 150 chars
|
|
81
|
+
const message = outputPreview
|
|
82
|
+
? `${baseMessage}\n📝 Output: ...${outputPreview}`
|
|
83
|
+
: baseMessage;
|
|
84
|
+
await sendProgressNotification(progressToken, progress, undefined, // No total - indeterminate progress
|
|
85
|
+
message);
|
|
86
|
+
messageIndex++;
|
|
87
|
+
}
|
|
88
|
+
else if (!isProcessing) {
|
|
89
|
+
clearInterval(progressInterval);
|
|
90
|
+
}
|
|
91
|
+
}, PROTOCOL.KEEPALIVE_INTERVAL); // Every 25 seconds
|
|
92
|
+
return { interval: progressInterval, progressToken };
|
|
93
|
+
}
|
|
94
|
+
function stopProgressUpdates(progressData, success = true) {
|
|
95
|
+
const operationName = currentOperationName; // Store before clearing
|
|
96
|
+
isProcessing = false;
|
|
97
|
+
currentOperationName = "";
|
|
98
|
+
clearInterval(progressData.interval);
|
|
99
|
+
// Send final progress notification if client requested progress
|
|
100
|
+
if (progressData.progressToken) {
|
|
101
|
+
sendProgressNotification(progressData.progressToken, 100, 100, success ? `✅ ${operationName} completed successfully` : `❌ ${operationName} failed`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// tools/list
|
|
105
|
+
server.setRequestHandler(ListToolsRequestSchema, async (request) => {
|
|
106
|
+
return { tools: getToolDefinitions() };
|
|
107
|
+
});
|
|
108
|
+
// tools/get
|
|
109
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
110
|
+
const toolName = request.params.name;
|
|
111
|
+
if (toolExists(toolName)) {
|
|
112
|
+
// Check if client requested progress updates
|
|
113
|
+
const progressToken = request.params._meta?.progressToken;
|
|
114
|
+
// Start progress updates if client requested them
|
|
115
|
+
const progressData = startProgressUpdates(toolName, progressToken);
|
|
116
|
+
try {
|
|
117
|
+
// Get prompt and other parameters from arguments with proper typing
|
|
118
|
+
const args = request.params.arguments || {};
|
|
119
|
+
Logger.toolInvocation(toolName, request.params.arguments);
|
|
120
|
+
// Execute the tool using the unified registry with progress callback
|
|
121
|
+
const result = await executeTool(toolName, args, (newOutput) => {
|
|
122
|
+
latestOutput = newOutput;
|
|
123
|
+
});
|
|
124
|
+
// Stop progress updates
|
|
125
|
+
stopProgressUpdates(progressData, true);
|
|
126
|
+
return {
|
|
127
|
+
content: [
|
|
128
|
+
{
|
|
129
|
+
type: "text",
|
|
130
|
+
text: result,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
isError: false,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
// Stop progress updates on error
|
|
138
|
+
stopProgressUpdates(progressData, false);
|
|
139
|
+
Logger.error(`Error in tool '${toolName}':`, error);
|
|
140
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
141
|
+
return {
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: "text",
|
|
145
|
+
text: `Error executing ${toolName}: ${errorMessage}`,
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
isError: true,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
// prompts/list
|
|
157
|
+
server.setRequestHandler(ListPromptsRequestSchema, async (request) => {
|
|
158
|
+
return { prompts: getPromptDefinitions() };
|
|
159
|
+
});
|
|
160
|
+
// prompts/get
|
|
161
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
162
|
+
const promptName = request.params.name;
|
|
163
|
+
const args = request.params.arguments || {};
|
|
164
|
+
const promptMessage = getPromptMessage(promptName, args);
|
|
165
|
+
if (!promptMessage) {
|
|
166
|
+
throw new Error(`Unknown prompt: ${promptName}`);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
messages: [{
|
|
170
|
+
role: "user",
|
|
171
|
+
content: {
|
|
172
|
+
type: "text",
|
|
173
|
+
text: promptMessage
|
|
174
|
+
}
|
|
175
|
+
}]
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
// Start the server
|
|
179
|
+
async function main() {
|
|
180
|
+
Logger.debug("init gemini-mcp-tool");
|
|
181
|
+
const transport = new StdioServerTransport();
|
|
182
|
+
await server.connect(transport);
|
|
183
|
+
Logger.debug("gemini-mcp-tool listening on stdio");
|
|
184
|
+
}
|
|
185
|
+
main().catch((error) => { Logger.error("Fatal error:", error); process.exit(1); });
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GASvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAiB,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;IACE,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,OAAO;CACjB,EAAC;IACA,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;KACZ;CACF,CACF,CAAC;AAEF,IAAI,YAAY,GAAG,KAAK,CAAC;AAAC,IAAI,oBAAoB,GAAG,EAAE,CA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M,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAEzD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,CAAC;gBACT,IAAI,EAAE,MAAe;gBACrB,OAAO,EAAE;oBACP,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,aAAa;iBACpB;aACF,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAAC,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9E,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACrD,CAAC;AAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,GAAE,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-gemini.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ask-gemini.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA6B5C,eAAO,MAAM,aAAa,EAAE,WA0D3B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { executeGeminiCLI, processChangeModeOutput } from '../utils/geminiExecutor.js';
|
|
3
|
+
import { ERROR_MESSAGES, STATUS_MESSAGES } from '../constants.js';
|
|
4
|
+
const askGeminiArgsSchema = z.object({
|
|
5
|
+
prompt: z.string().min(1).describe("Analysis request. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions"),
|
|
6
|
+
model: z.string().optional().describe("Optional model to use (e.g., 'gemini-3-flash-preview'). If not specified, uses the default model (gemini-3.1-pro-preview)."),
|
|
7
|
+
sandbox: z.boolean().default(false).describe("Use sandbox mode (-s flag) to safely test code changes, execute scripts, or run potentially risky operations in an isolated environment"),
|
|
8
|
+
changeMode: z.boolean().default(false).describe("Enable structured change mode - formats prompts to prevent tool errors and returns structured edit suggestions that Claude can apply directly"),
|
|
9
|
+
chunkIndex: z.union([z.number(), z.string()]).optional().describe("Which chunk to return (1-based)"),
|
|
10
|
+
chunkCacheKey: z.string().optional().describe("Optional cache key for continuation"),
|
|
11
|
+
workingDirectory: z.string().optional().describe("Working directory to run Gemini from. Use drive root (e.g., 'C:/' or 'D:/') to access files on that drive."),
|
|
12
|
+
// Phase 1: Critical flags
|
|
13
|
+
yolo: z.boolean().default(false).describe("Auto-accept all actions (YOLO mode). Automatically approves all confirmations without prompting. Use with caution in automated workflows."),
|
|
14
|
+
approvalMode: z.enum(["default", "auto_edit", "yolo"]).optional().describe("Set approval mode: 'default' (prompt for approval), 'auto_edit' (auto-approve edit tools only), 'yolo' (auto-approve all tools). Overrides yolo flag if both are set."),
|
|
15
|
+
outputFormat: z.enum(["text", "json", "stream-json"]).optional().describe("Output format: 'text' (default human-readable), 'json' (structured JSON), 'stream-json' (streaming JSON for real-time processing)"),
|
|
16
|
+
includeDirectories: z.union([z.string(), z.array(z.string())]).optional().describe("Additional directories to include in workspace (comma-separated string or array). Example: 'src,tests' or ['src', 'tests']"),
|
|
17
|
+
debug: z.boolean().default(false).describe("Enable debug mode for verbose logging and troubleshooting"),
|
|
18
|
+
// Phase 2: Enhanced features (for future implementation)
|
|
19
|
+
promptInteractive: z.string().optional().describe("Execute the provided prompt and continue in interactive mode"),
|
|
20
|
+
extensions: z.union([z.string(), z.array(z.string())]).optional().describe("Specific extensions to use (comma-separated or array). If not provided, all extensions are used."),
|
|
21
|
+
resume: z.string().optional().describe("Resume a previous session. Use 'latest' for most recent or session index number"),
|
|
22
|
+
});
|
|
23
|
+
export const askGeminiTool = {
|
|
24
|
+
name: "ask-gemini",
|
|
25
|
+
description: "Ask Google Gemini with full CLI support: model selection [-m], sandbox [-s], YOLO mode [-y], approval modes, output formats, and more",
|
|
26
|
+
zodSchema: askGeminiArgsSchema,
|
|
27
|
+
prompt: {
|
|
28
|
+
description: "Execute Gemini CLI with advanced options. Supports file analysis (@syntax), YOLO mode, different approval levels, output formats (text/json), debug mode, and structured change mode for edit suggestions.",
|
|
29
|
+
},
|
|
30
|
+
category: 'gemini',
|
|
31
|
+
annotations: {
|
|
32
|
+
title: "Ask Gemini",
|
|
33
|
+
readOnlyHint: true,
|
|
34
|
+
openWorldHint: true,
|
|
35
|
+
},
|
|
36
|
+
execute: async (args, onProgress) => {
|
|
37
|
+
const { prompt, model, sandbox, changeMode, chunkIndex, chunkCacheKey, workingDirectory, yolo, approvalMode, outputFormat, includeDirectories, debug, promptInteractive, extensions, resume } = args;
|
|
38
|
+
if (!prompt?.trim()) {
|
|
39
|
+
throw new Error(ERROR_MESSAGES.NO_PROMPT_PROVIDED);
|
|
40
|
+
}
|
|
41
|
+
if (changeMode && chunkIndex && chunkCacheKey) {
|
|
42
|
+
return processChangeModeOutput('', // empty for cache...
|
|
43
|
+
chunkIndex, chunkCacheKey, prompt);
|
|
44
|
+
}
|
|
45
|
+
const result = await executeGeminiCLI(prompt, {
|
|
46
|
+
model: model,
|
|
47
|
+
sandbox: !!sandbox,
|
|
48
|
+
changeMode: !!changeMode,
|
|
49
|
+
yolo: !!yolo,
|
|
50
|
+
approvalMode: approvalMode,
|
|
51
|
+
outputFormat: outputFormat,
|
|
52
|
+
includeDirectories: includeDirectories,
|
|
53
|
+
debug: !!debug,
|
|
54
|
+
promptInteractive: promptInteractive,
|
|
55
|
+
extensions: extensions,
|
|
56
|
+
resume: resume,
|
|
57
|
+
cwd: workingDirectory,
|
|
58
|
+
}, onProgress);
|
|
59
|
+
if (changeMode) {
|
|
60
|
+
return processChangeModeOutput(result, args.chunkIndex, undefined, prompt);
|
|
61
|
+
}
|
|
62
|
+
return `${STATUS_MESSAGES.GEMINI_RESPONSE}\n${result}`; // changeMode false
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=ask-gemini.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-gemini.tool.js","sourceRoot":"","sources":["../../src/tools/ask-gemini.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACvF,OAAO,EACL,cAAc,EACd,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,yHAAyH,CAAC;IAC7J,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4HAA4H,CAAC;IACnK,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,yIAAyI,CAAC;IACvL,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,+IAA+I,CAAC;IAChM,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IACpG,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,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E,iBAAuC;YAC1D,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,MAA4B;YACpC,GAAG,EAAE,gBAAsC;SAC5C,EACD,UAAU,CACX,CAAC;QAEF,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,uBAAuB,CAC5B,MAAM,EACN,IAAI,CAAC,UAAgC,EACrC,SAAS,EACT,MAAgB,CACjB,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,eAAe,CAAC,eAAe,KAAK,MAAM,EAAE,CAAC,CAAC,mBAAmB;IAC7E,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brainstorm.tool.d.ts","sourceRoot":"","sources":["../../src/tools/brainstorm.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAgI5C,eAAO,MAAM,cAAc,EAAE,WAyD5B,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Logger } from '../utils/logger.js';
|
|
3
|
+
import { executeGeminiCLI } from '../utils/geminiExecutor.js';
|
|
4
|
+
function buildBrainstormPrompt(config) {
|
|
5
|
+
const { prompt, methodology, domain, constraints, existingContext, ideaCount, includeAnalysis } = config;
|
|
6
|
+
// Select methodology framework
|
|
7
|
+
let frameworkInstructions = getMethodologyInstructions(methodology, domain);
|
|
8
|
+
let enhancedPrompt = `# BRAINSTORMING SESSION
|
|
9
|
+
|
|
10
|
+
## Core Challenge
|
|
11
|
+
${prompt}
|
|
12
|
+
|
|
13
|
+
## Methodology Framework
|
|
14
|
+
${frameworkInstructions}
|
|
15
|
+
|
|
16
|
+
## Context Engineering
|
|
17
|
+
*Use the following context to inform your reasoning:*
|
|
18
|
+
${domain ? `**Domain Focus:** ${domain} - Apply domain-specific knowledge, terminology, and best practices.` : ''}
|
|
19
|
+
${constraints ? `**Constraints & Boundaries:** ${constraints}` : ''}
|
|
20
|
+
${existingContext ? `**Background Context:** ${existingContext}` : ''}
|
|
21
|
+
|
|
22
|
+
## Output Requirements
|
|
23
|
+
- Generate ${ideaCount} distinct, creative ideas
|
|
24
|
+
- Each idea should be unique and non-obvious
|
|
25
|
+
- Focus on actionable, implementable concepts
|
|
26
|
+
- Use clear, descriptive naming
|
|
27
|
+
- Provide brief explanations for each idea
|
|
28
|
+
|
|
29
|
+
${includeAnalysis ? `
|
|
30
|
+
## Analysis Framework
|
|
31
|
+
For each idea, provide:
|
|
32
|
+
- **Feasibility:** Implementation difficulty (1-5 scale)
|
|
33
|
+
- **Impact:** Potential value/benefit (1-5 scale)
|
|
34
|
+
- **Innovation:** Uniqueness/creativity (1-5 scale)
|
|
35
|
+
- **Quick Assessment:** One-sentence evaluation
|
|
36
|
+
` : ''}
|
|
37
|
+
|
|
38
|
+
## Format
|
|
39
|
+
Present ideas in a structured format:
|
|
40
|
+
|
|
41
|
+
### Idea [N]: [Creative Name]
|
|
42
|
+
**Description:** [2-3 sentence explanation]
|
|
43
|
+
${includeAnalysis ? '**Feasibility:** [1-5] | **Impact:** [1-5] | **Innovation:** [1-5]\n**Assessment:** [Brief evaluation]' : ''}
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
**Before finalizing, review the list: remove near-duplicates and ensure each idea satisfies the constraints.**
|
|
48
|
+
|
|
49
|
+
Begin brainstorming session:`;
|
|
50
|
+
return enhancedPrompt;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns methodology-specific instructions for structured brainstorming
|
|
54
|
+
*/
|
|
55
|
+
function getMethodologyInstructions(methodology, domain) {
|
|
56
|
+
const methodologies = {
|
|
57
|
+
'divergent': `**Divergent Thinking Approach:**
|
|
58
|
+
- Generate maximum quantity of ideas without self-censoring
|
|
59
|
+
- Build on wild or seemingly impractical ideas
|
|
60
|
+
- Combine unrelated concepts for unexpected solutions
|
|
61
|
+
- Use "Yes, and..." thinking to expand each concept
|
|
62
|
+
- Postpone evaluation until all ideas are generated`,
|
|
63
|
+
'convergent': `**Convergent Thinking Approach:**
|
|
64
|
+
- Focus on refining and improving existing concepts
|
|
65
|
+
- Synthesize related ideas into stronger solutions
|
|
66
|
+
- Apply critical evaluation criteria
|
|
67
|
+
- Prioritize based on feasibility and impact
|
|
68
|
+
- Develop implementation pathways for top ideas`,
|
|
69
|
+
'scamper': `**SCAMPER Creative Triggers:**
|
|
70
|
+
- **Substitute:** What can be substituted or replaced?
|
|
71
|
+
- **Combine:** What can be combined or merged?
|
|
72
|
+
- **Adapt:** What can be adapted from other domains?
|
|
73
|
+
- **Modify:** What can be magnified, minimized, or altered?
|
|
74
|
+
- **Put to other use:** How else can this be used?
|
|
75
|
+
- **Eliminate:** What can be removed or simplified?
|
|
76
|
+
- **Reverse:** What can be rearranged or reversed?`,
|
|
77
|
+
'design-thinking': `**Human-Centered Design Thinking:**
|
|
78
|
+
- **Empathize:** Consider user needs, pain points, and contexts
|
|
79
|
+
- **Define:** Frame problems from user perspective
|
|
80
|
+
- **Ideate:** Generate user-focused solutions
|
|
81
|
+
- **Consider Journey:** Think through complete user experience
|
|
82
|
+
- **Prototype Mindset:** Focus on testable, iterative concepts`,
|
|
83
|
+
'lateral': `**Lateral Thinking Approach:**
|
|
84
|
+
- Make unexpected connections between unrelated fields
|
|
85
|
+
- Challenge fundamental assumptions
|
|
86
|
+
- Use random word association to trigger new directions
|
|
87
|
+
- Apply metaphors and analogies from other domains
|
|
88
|
+
- Reverse conventional thinking patterns`,
|
|
89
|
+
'auto': `**AI-Optimized Approach:**
|
|
90
|
+
${domain ? `Given the ${domain} domain, I'll apply the most effective combination of:` : 'I\'ll intelligently combine multiple methodologies:'}
|
|
91
|
+
- Divergent exploration with domain-specific knowledge
|
|
92
|
+
- SCAMPER triggers and lateral thinking
|
|
93
|
+
- Human-centered perspective for practical value`
|
|
94
|
+
};
|
|
95
|
+
return methodologies[methodology] || methodologies['auto'];
|
|
96
|
+
}
|
|
97
|
+
const brainstormArgsSchema = z.object({
|
|
98
|
+
prompt: z.string().min(1).describe("Primary brainstorming challenge or question to explore"),
|
|
99
|
+
model: z.string().optional().describe("Optional model to use (e.g., 'gemini-3-flash-preview'). If not specified, uses the default model (gemini-3.1-pro-preview)."),
|
|
100
|
+
methodology: z.enum(['divergent', 'convergent', 'scamper', 'design-thinking', 'lateral', 'auto']).default('auto').describe("Brainstorming framework: 'divergent' (generate many ideas), 'convergent' (refine existing), 'scamper' (systematic triggers), 'design-thinking' (human-centered), 'lateral' (unexpected connections), 'auto' (AI selects best)"),
|
|
101
|
+
domain: z.string().optional().describe("Domain context for specialized brainstorming (e.g., 'software', 'business', 'creative', 'research', 'product', 'marketing')"),
|
|
102
|
+
constraints: z.string().optional().describe("Known limitations, requirements, or boundaries (budget, time, technical, legal, etc.)"),
|
|
103
|
+
existingContext: z.string().optional().describe("Background information, previous attempts, or current state to build upon"),
|
|
104
|
+
ideaCount: z.number().int().positive().default(12).describe("Target number of ideas to generate (default: 10-15)"),
|
|
105
|
+
includeAnalysis: z.boolean().default(true).describe("Include feasibility, impact, and implementation analysis for generated ideas"),
|
|
106
|
+
workingDirectory: z.string().optional().describe("Working directory to run Gemini from."),
|
|
107
|
+
});
|
|
108
|
+
export const brainstormTool = {
|
|
109
|
+
name: "brainstorm",
|
|
110
|
+
description: "Generate novel ideas with dynamic context gathering. --> Creative frameworks (SCAMPER, Design Thinking, etc.), domain context integration, idea clustering, feasibility analysis, and iterative refinement.",
|
|
111
|
+
zodSchema: brainstormArgsSchema,
|
|
112
|
+
prompt: {
|
|
113
|
+
description: "Generate structured brainstorming prompt with methodology-driven ideation, domain context integration, and analytical evaluation framework",
|
|
114
|
+
},
|
|
115
|
+
category: 'gemini',
|
|
116
|
+
annotations: {
|
|
117
|
+
title: "Brainstorm",
|
|
118
|
+
readOnlyHint: true,
|
|
119
|
+
openWorldHint: true,
|
|
120
|
+
},
|
|
121
|
+
execute: async (args, onProgress) => {
|
|
122
|
+
const { prompt, model, methodology = 'auto', domain, constraints, existingContext, ideaCount = 12, includeAnalysis = true, workingDirectory } = args;
|
|
123
|
+
if (!prompt?.trim()) {
|
|
124
|
+
throw new Error("You must provide a valid brainstorming challenge or question to explore");
|
|
125
|
+
}
|
|
126
|
+
let enhancedPrompt = buildBrainstormPrompt({
|
|
127
|
+
prompt: prompt.trim(),
|
|
128
|
+
methodology: methodology,
|
|
129
|
+
domain: domain,
|
|
130
|
+
constraints: constraints,
|
|
131
|
+
existingContext: existingContext,
|
|
132
|
+
ideaCount: ideaCount,
|
|
133
|
+
includeAnalysis: includeAnalysis
|
|
134
|
+
});
|
|
135
|
+
Logger.debug(`Brainstorm: Using methodology '${methodology}' for domain '${domain || 'general'}'`);
|
|
136
|
+
// Report progress to user
|
|
137
|
+
onProgress?.(`Generating ${ideaCount} ideas via ${methodology} methodology...`);
|
|
138
|
+
// Execute with Gemini
|
|
139
|
+
return await executeGeminiCLI(enhancedPrompt, {
|
|
140
|
+
model: model,
|
|
141
|
+
sandbox: false,
|
|
142
|
+
changeMode: false,
|
|
143
|
+
cwd: workingDirectory,
|
|
144
|
+
}, onProgress);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=brainstorm.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brainstorm.tool.js","sourceRoot":"","sources":["../../src/tools/brainstorm.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,SAAS,qBAAqB,CAAC,MAQ9B;IACC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAEzG,+BAA+B;IAC/B,IAAI,qBAAqB,GAAG,0BAA0B,CAAC,WAAW,EAAE,MA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AW,GAAG,MAAM,EACpB,MAAM,EACN,WAAW,EACX,eAAe,EACf,SAAS,GAAG,EAAE,EACd,eAAe,GAAG,IAAI,EACtB,gBAAgB,EACjB,GAAG,IAAI,CAAC;QAET,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;QAC7F,CAAC;QAED,IAAI,cAAc,GAAG,qBAAqB,CAAC;YACzC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAY;YAC/B,WAAW,EAAE,WAAqB;YAClC,MAAM,EAAE,MAA4B;YACpC,WAAW,EAAE,WAAiC;YAC9C,eAAe,EAAE,eAAqC;YACtD,SAAS,EAAE,SAAmB;YAC9B,eAAe,EAAE,eAA0B;SAC5C,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,kCAAkC,WAAW,iBAAiB,MAAM,IAAI,SAAS,GAAG,CAAC,CAAC;QAEnG,0BAA0B;QAC1B,UAAU,EAAE,CAAC,cAAc,SAAS,cAAc,WAAW,iBAAiB,CAAC,CAAC;QAEhF,sBAAsB;QACtB,OAAO,MAAM,gBAAgB,CAC3B,cAAc,EACd;YACE,KAAK,EAAE,KAA2B;YAClC,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,KAAK;YACjB,GAAG,EAAE,gBAAsC;SAC5C,EACD,UAAU,CACX,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-chunk.tool.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-chunk.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,eAAO,MAAM,cAAc,EAAE,WAyE5B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getChunks } from '../utils/chunkCache.js';
|
|
3
|
+
import { formatChangeModeResponse, summarizeChangeModeEdits } from '../utils/changeModeTranslator.js';
|
|
4
|
+
import { Logger } from '../utils/logger.js';
|
|
5
|
+
const inputSchema = z.object({
|
|
6
|
+
cacheKey: z.string().describe("The cache key provided in the initial changeMode response"),
|
|
7
|
+
chunkIndex: z.number().min(1).describe("Which chunk to retrieve (1-based index)")
|
|
8
|
+
});
|
|
9
|
+
export const fetchChunkTool = {
|
|
10
|
+
name: 'fetch-chunk',
|
|
11
|
+
description: 'Retrieves cached chunks from a changeMode response. Use this to get subsequent chunks after receiving a partial changeMode response.',
|
|
12
|
+
zodSchema: inputSchema,
|
|
13
|
+
prompt: {
|
|
14
|
+
description: 'Fetch the next chunk of a response',
|
|
15
|
+
arguments: [
|
|
16
|
+
{
|
|
17
|
+
name: 'prompt',
|
|
18
|
+
description: 'fetch-chunk cacheKey=<key> chunkIndex=<number>',
|
|
19
|
+
required: true
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
category: 'utility',
|
|
24
|
+
annotations: {
|
|
25
|
+
title: "Fetch Chunk",
|
|
26
|
+
readOnlyHint: true,
|
|
27
|
+
idempotentHint: true,
|
|
28
|
+
},
|
|
29
|
+
execute: async (args, onProgress) => {
|
|
30
|
+
const { cacheKey, chunkIndex } = args;
|
|
31
|
+
Logger.toolInvocation('fetch-chunk', args);
|
|
32
|
+
Logger.debug(`Fetching chunk ${chunkIndex} with cache key: ${cacheKey}`);
|
|
33
|
+
// Retrieve cached chunks
|
|
34
|
+
const chunks = getChunks(cacheKey);
|
|
35
|
+
if (!chunks) {
|
|
36
|
+
return `❌ Cache miss: No chunks found for cache key "${cacheKey}".
|
|
37
|
+
|
|
38
|
+
Possible reasons:
|
|
39
|
+
1. The cache key is incorrect, Have you ran ask-gemini with changeMode enabled?
|
|
40
|
+
2. The cache has expired (10 minute TTL)
|
|
41
|
+
3. The MCP server was restarted and the file-based cache was cleared
|
|
42
|
+
|
|
43
|
+
Please re-run the original changeMode request to regenerate the chunks.`;
|
|
44
|
+
}
|
|
45
|
+
// Validate chunk index
|
|
46
|
+
if (chunkIndex < 1 || chunkIndex > chunks.length) {
|
|
47
|
+
return `❌ Invalid chunk index: ${chunkIndex}
|
|
48
|
+
|
|
49
|
+
Available chunks: 1 to ${chunks.length}
|
|
50
|
+
You requested: ${chunkIndex}
|
|
51
|
+
|
|
52
|
+
Please use a valid chunk index.`;
|
|
53
|
+
}
|
|
54
|
+
// Get the requested chunk
|
|
55
|
+
const chunk = chunks[chunkIndex - 1];
|
|
56
|
+
// Format the response
|
|
57
|
+
let result = formatChangeModeResponse(chunk.edits, { current: chunkIndex, total: chunks.length, cacheKey });
|
|
58
|
+
// Add summary for first chunk
|
|
59
|
+
if (chunkIndex === 1 && chunks.length > 1) {
|
|
60
|
+
const allEdits = chunks.flatMap(c => c.edits);
|
|
61
|
+
result = summarizeChangeModeEdits(allEdits, true) + '\n\n' + result;
|
|
62
|
+
}
|
|
63
|
+
Logger.debug(`Returning chunk ${chunkIndex} of ${chunks.length} with ${chunk.edits.length} edits`);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=fetch-chunk.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-chunk.tool.js","sourceRoot":"","sources":["../../src/tools/fetch-chunk.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACtG,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2DAA2D,CAAC;IAC1F,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,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