-
Notifications
You must be signed in to change notification settings - Fork 106
feat: add MCP client support with /mcp command #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add MCP client support with /mcp command #20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Model Context Protocol (MCP) client support to groq-code-cli, enabling integration with external MCP servers to extend the tool capabilities available to the AI assistant.
Key Changes:
- Implements MCP client manager with connection pooling and timeout handling
- Adds
/mcpslash command with subcommands for server management (add, remove, connect, disconnect, list, tools) - Integrates MCP tools into the existing tool execution framework with required user approval
- Persists MCP server configurations in
.groq/mcp.json
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/mcp/types.ts |
Defines TypeScript interfaces for MCP server configurations, tools, and results |
src/mcp/client.ts |
Implements singleton MCPClientManager for managing server connections and tool execution |
src/commands/definitions/mcp.ts |
Implements /mcp command handler with argument parsing and subcommand routing |
src/commands/base.ts |
Adds optional commandString field to CommandContext for accessing full command text |
src/commands/index.ts |
Registers mcp command and passes commandString to handlers |
src/core/agent.ts |
Integrates MCP tools into agent's tool execution flow with approval requirements |
src/tools/tool-schemas.ts |
Extracts ToolSchema interface to separate file and references new environment tool |
src/tools/schema-types.ts |
Defines shared ToolSchema interface for reuse across codebase |
package.json |
Adds @modelcontextprotocol/sdk ^1.0.0 dependency |
package-lock.json |
Locks MCP SDK and transitive dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/tools/tool-schemas.ts
Outdated
| }; | ||
| }; | ||
| } | ||
| import { GET_ENV_INFO_SCHEMA } from './environment-schemas.js'; |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import references a non-existent file 'environment-schemas.js'. The file 'src/tools/environment-schemas.ts' doesn't exist in the repository, which will cause a runtime error when this code is executed. Either the file needs to be created with the GET_ENV_INFO_SCHEMA export, or this import and the references to GET_ENV_INFO_SCHEMA should be removed.
| import { GET_ENV_INFO_SCHEMA } from './environment-schemas.js'; |
src/commands/index.ts
Outdated
| import { initCommand } from './definitions/init.js'; | ||
| import { reasoningCommand } from './definitions/reasoning.js'; | ||
| import { statsCommand } from './definitions/stats.js'; | ||
| import { contextCommand } from './definitions/context.js'; |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import references a non-existent file 'context.js'. The file 'src/commands/definitions/context.ts' doesn't exist in the repository, which will cause a runtime error. Either the file needs to be created or this import should be removed.
src/tools/tool-schemas.ts
Outdated
| 'create_tasks', | ||
| 'update_tasks' | ||
| 'update_tasks', | ||
| 'get_env_info' |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected at the end of this line. This should be removed to maintain code quality and consistency.
| 'get_env_info' | |
| 'get_env_info' |
src/mcp/client.ts
Outdated
| const timeoutPromise = new Promise<never>((_, reject) => { | ||
| setTimeout(() => reject(new Error(`Connection timeout after ${CONNECTION_TIMEOUT / 1000}s`)), CONNECTION_TIMEOUT); | ||
| }); |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setTimeout is not cleared when the Promise.race resolves with the connectPromise. This creates a potential memory leak as the timeout timer continues running even after the connection succeeds. Consider storing the timeout ID and clearing it after the race completes using clearTimeout.
src/tools/tool-schemas.ts
Outdated
| UPDATE_TASKS_SCHEMA, | ||
| EXECUTE_COMMAND_SCHEMA | ||
| EXECUTE_COMMAND_SCHEMA, | ||
| GET_ENV_INFO_SCHEMA |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GET_ENV_INFO_SCHEMA constant is referenced here but is imported from a non-existent file. This will cause a runtime error. This reference should be removed until the GET_ENV_INFO_SCHEMA is properly defined.
src/tools/tool-schemas.ts
Outdated
| 'create_tasks', | ||
| 'update_tasks' | ||
| 'update_tasks', | ||
| 'get_env_info' |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'get_env_info' tool is listed as a safe tool, but the corresponding GET_ENV_INFO_SCHEMA is imported from a non-existent file. This entry should be removed until the schema is properly defined.
src/commands/index.ts
Outdated
| initCommand, | ||
| reasoningCommand, | ||
| statsCommand, | ||
| contextCommand, |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contextCommand is being registered but is imported from a non-existent file. This will cause a runtime error. This registration should be removed until the context command is properly defined.
src/mcp/client.ts
Outdated
| const listTimeoutPromise = new Promise<never>((_, reject) => { | ||
| setTimeout(() => reject(new Error('Timeout listing tools')), CONNECTION_TIMEOUT); | ||
| }); |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setTimeout is not cleared when the Promise.race resolves with the listToolsPromise. This creates a potential memory leak as the timeout timer continues running even after the tools are listed successfully. Consider storing the timeout ID and clearing it after the race completes using clearTimeout.
src/mcp/client.ts
Outdated
| const timeoutPromise = new Promise<never>((_, reject) => { | ||
| setTimeout( | ||
| () => reject(new Error(`Tool execution timeout after ${TOOL_EXECUTION_TIMEOUT / 1000}s`)), | ||
| TOOL_EXECUTION_TIMEOUT | ||
| ); | ||
| }); |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setTimeout is not cleared when the Promise.race resolves with the executePromise. This creates a potential memory leak as the timeout timer continues running even after the tool executes successfully. Consider storing the timeout ID and clearing it after the race completes using clearTimeout.
src/mcp/client.ts
Outdated
| const timeoutPromise = new Promise<never>((_, reject) => { | ||
| setTimeout(() => reject(new Error('Health check timeout')), 5000); | ||
| }); |
Copilot
AI
Jan 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setTimeout is not cleared when the Promise.race resolves with the healthCheckPromise. This creates a potential memory leak as the timeout timer continues running even after the health check succeeds. Consider storing the timeout ID and clearing it after the race completes using clearTimeout.
Add Model Context Protocol (MCP) client support allowing groq-code-cli to connect to external MCP servers and use their tools alongside built-in tools. New features: - /mcp list - Show configured and connected MCP servers - /mcp add <name> <type> <command|url> - Add stdio or SSE server - /mcp remove <name> - Remove server configuration - /mcp connect [name] - Connect to configured servers - /mcp disconnect [name] - Disconnect from servers - /mcp tools [server] - List available tools from connected servers Implementation details: - MCPManager singleton handles connections, config persistence, and tool execution - Config stored in .groq/mcp.json - MCP tools integrated into agent with 'mcp_<server>_<tool>' naming convention - MCP tools require user approval (external execution) Edge case handling: - Connection timeout (30s) and tool execution timeout (2min) - spawn ENOENT detection with helpful PATH error messages - Invalid URL validation for SSE transport - Server health checks and dead connection cleanup - Graceful disconnect and resource cleanup
c2b49a0 to
63f9990
Compare
Addressed Copilot Review CommentsAll issues raised by Copilot's automated review have been fixed in the force-pushed commit Fixed Issues
The
|
Summary
Adds Model Context Protocol (MCP) client support, allowing groq-code-cli to connect to external MCP servers and use their tools alongside built-in tools.
New Features
/mcpSlash Command/mcp list/mcp add <name> <type> <command|url>/mcp remove <name>/mcp connect [name]/mcp disconnect [name]/mcp tools [server]Example Usage
Implementation Details
src/mcp/client.ts) - Handles connections, config persistence, and tool execution.groq/mcp.jsonmcp_<server>_<tool>(e.g.,mcp_fs_read_file)Edge Case Handling
spawn ENOENTdetection with helpful PATH error messagesFiles Changed
src/mcp/types.tssrc/mcp/client.tssrc/commands/definitions/mcp.ts/mcpslash command handlersrc/commands/base.tscommandStringto command contextsrc/commands/index.tssrc/core/agent.tssrc/tools/schema-types.tssrc/tools/tool-schemas.tspackage.json@modelcontextprotocol/sdkdependencyTesting
@modelcontextprotocol/server-filesystemread_filetool)