@vibe-kit/grok-cli
Version:
An open-source AI agent that brings the power of Grok directly into your terminal.
317 lines • 12.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllGrokTools = exports.addMCPToolsToGrokTools = exports.convertMCPToolToGrokTool = exports.initializeMCPServers = exports.getMCPManager = exports.GROK_TOOLS = void 0;
const client_1 = require("../mcp/client");
const config_1 = require("../mcp/config");
exports.GROK_TOOLS = [
{
type: "function",
function: {
name: "view_file",
description: "View contents of a file or list directory contents",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "Path to file or directory to view",
},
start_line: {
type: "number",
description: "Starting line number for partial file view (optional)",
},
end_line: {
type: "number",
description: "Ending line number for partial file view (optional)",
},
},
required: ["path"],
},
},
},
{
type: "function",
function: {
name: "create_file",
description: "Create a new file with specified content",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "Path where the file should be created",
},
content: {
type: "string",
description: "Content to write to the file",
},
},
required: ["path", "content"],
},
},
},
{
type: "function",
function: {
name: "str_replace_editor",
description: "Replace specific text in a file",
parameters: {
type: "object",
properties: {
path: {
type: "string",
description: "Path to the file to edit",
},
old_str: {
type: "string",
description: "Text to replace (must match exactly, or will use fuzzy matching for multi-line strings)",
},
new_str: {
type: "string",
description: "Text to replace with",
},
replace_all: {
type: "boolean",
description: "Replace all occurrences (default: false, only replaces first occurrence)",
},
},
required: ["path", "old_str", "new_str"],
},
},
},
{
type: "function",
function: {
name: "bash",
description: "Execute a bash command",
parameters: {
type: "object",
properties: {
command: {
type: "string",
description: "The bash command to execute",
},
},
required: ["command"],
},
},
},
{
type: "function",
function: {
name: "search",
description: "Unified search tool for finding text content or files (similar to Cursor's search)",
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "Text to search for or file name/path pattern",
},
search_type: {
type: "string",
enum: ["text", "files", "both"],
description: "Type of search: 'text' for content search, 'files' for file names, 'both' for both (default: 'both')",
},
include_pattern: {
type: "string",
description: "Glob pattern for files to include (e.g. '*.ts', '*.js')",
},
exclude_pattern: {
type: "string",
description: "Glob pattern for files to exclude (e.g. '*.log', 'node_modules')",
},
case_sensitive: {
type: "boolean",
description: "Whether search should be case sensitive (default: false)",
},
whole_word: {
type: "boolean",
description: "Whether to match whole words only (default: false)",
},
regex: {
type: "boolean",
description: "Whether query is a regex pattern (default: false)",
},
max_results: {
type: "number",
description: "Maximum number of results to return (default: 50)",
},
file_types: {
type: "array",
items: { type: "string" },
description: "File types to search (e.g. ['js', 'ts', 'py'])",
},
include_hidden: {
type: "boolean",
description: "Whether to include hidden files (default: false)",
},
},
required: ["query"],
},
},
},
{
type: "function",
function: {
name: "create_todo_list",
description: "Create a new todo list for planning and tracking tasks",
parameters: {
type: "object",
properties: {
todos: {
type: "array",
description: "Array of todo items",
items: {
type: "object",
properties: {
id: {
type: "string",
description: "Unique identifier for the todo item",
},
content: {
type: "string",
description: "Description of the todo item",
},
status: {
type: "string",
enum: ["pending", "in_progress", "completed"],
description: "Current status of the todo item",
},
priority: {
type: "string",
enum: ["high", "medium", "low"],
description: "Priority level of the todo item",
},
},
required: ["id", "content", "status", "priority"],
},
},
},
required: ["todos"],
},
},
},
{
type: "function",
function: {
name: "update_todo_list",
description: "Update existing todos in the todo list",
parameters: {
type: "object",
properties: {
updates: {
type: "array",
description: "Array of todo updates",
items: {
type: "object",
properties: {
id: {
type: "string",
description: "ID of the todo item to update",
},
status: {
type: "string",
enum: ["pending", "in_progress", "completed"],
description: "New status for the todo item",
},
content: {
type: "string",
description: "New content for the todo item",
},
priority: {
type: "string",
enum: ["high", "medium", "low"],
description: "New priority for the todo item",
},
},
required: ["id"],
},
},
},
required: ["updates"],
},
},
},
];
// Global MCP manager instance
let mcpManager = null;
function getMCPManager() {
if (!mcpManager) {
mcpManager = new client_1.MCPManager();
}
return mcpManager;
}
exports.getMCPManager = getMCPManager;
async function initializeMCPServers() {
const manager = getMCPManager();
const config = (0, config_1.loadMCPConfig)();
// Store original stderr.write
const originalStderrWrite = process.stderr.write;
// Temporarily suppress stderr to hide verbose MCP connection logs
process.stderr.write = function (chunk, encoding, callback) {
// Filter out mcp-remote verbose logs
const chunkStr = chunk.toString();
if (chunkStr.includes('[') && (chunkStr.includes('Using existing client port') ||
chunkStr.includes('Connecting to remote server') ||
chunkStr.includes('Using transport strategy') ||
chunkStr.includes('Connected to remote server') ||
chunkStr.includes('Local STDIO server running') ||
chunkStr.includes('Proxy established successfully') ||
chunkStr.includes('Local→Remote') ||
chunkStr.includes('Remote→Local'))) {
// Suppress these verbose logs
if (callback)
callback();
return true;
}
// Allow other stderr output
return originalStderrWrite.call(this, chunk, encoding, callback);
};
try {
for (const serverConfig of config.servers) {
try {
await manager.addServer(serverConfig);
}
catch (error) {
console.warn(`Failed to initialize MCP server ${serverConfig.name}:`, error);
}
}
}
finally {
// Restore original stderr.write
process.stderr.write = originalStderrWrite;
}
}
exports.initializeMCPServers = initializeMCPServers;
function convertMCPToolToGrokTool(mcpTool) {
return {
type: "function",
function: {
name: mcpTool.name,
description: mcpTool.description,
parameters: mcpTool.inputSchema || {
type: "object",
properties: {},
required: []
}
}
};
}
exports.convertMCPToolToGrokTool = convertMCPToolToGrokTool;
function addMCPToolsToGrokTools(baseTools) {
if (!mcpManager) {
return baseTools;
}
const mcpTools = mcpManager.getTools();
const grokMCPTools = mcpTools.map(convertMCPToolToGrokTool);
return [...baseTools, ...grokMCPTools];
}
exports.addMCPToolsToGrokTools = addMCPToolsToGrokTools;
async function getAllGrokTools() {
const manager = getMCPManager();
await manager.ensureServersInitialized();
return addMCPToolsToGrokTools(exports.GROK_TOOLS);
}
exports.getAllGrokTools = getAllGrokTools;
//# sourceMappingURL=tools.js.map