grok-code-mcp-server
v1.0.0
Published
MCP server for xAI's grok-code-fast-1 model - Expert coding assistant with 256K context
Maintainers
Readme
Grok Code MCP Server
Expert coding assistant powered by xAI's grok-code-fast-1 model
Features • Installation • Usage • Tools • Examples • API
🚀 Features
- 256K Context Window - Handle massive codebases and multi-file projects
- 4x Faster - Optimized for speed compared to competing models
- 1/10th Cost - Economical pricing at $0.20/1M input tokens
- Native Reasoning - Access to model's reasoning traces in real-time
- Tool Calling - Native function calling support for complex workflows
- Production Ready - Battle-tested for real-world coding tasks
📦 Installation
Option 1: Install from npm (Recommended)
npm install -g grok-code-mcp-serverOption 2: Install from GitHub
npm install -g github:yourusername/grok-code-mcp-serverOption 3: Local Development
git clone https://github.com/yourusername/grok-code-mcp-server.git
cd grok-code-mcp-server
npm install
npm run build
npm link🔧 Configuration
1. Get your API Key
Get your xAI API key from x.ai/api
2. Configure MCP
Add to your Claude Desktop or compatible MCP client configuration:
Claude Desktop (claude_desktop_config.json)
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"grok-code": {
"command": "npx",
"args": ["-y", "grok-code-mcp-server"],
"env": {
"XAI_API_KEY": "your-xai-api-key-here"
}
}
}
}Alternative: Using .mcp.json in your project
{
"mcpServers": {
"grok-code": {
"command": "npx",
"args": ["-y", "grok-code-mcp-server"],
"env": {
"XAI_API_KEY": "your-xai-api-key-here"
},
"timeout": 45000,
"autoApprove": [
"grok_generate_code",
"grok_refactor_code",
"grok_analyze_code"
]
}
}
}3. Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| XAI_API_KEY | Your xAI API key (required) | - |
| XAI_API_URL | API endpoint URL | https://api.x.ai/v1/chat/completions |
| XAI_TIMEOUT | Request timeout in ms | 30000 |
🛠️ Available Tools
grok_generate_code
Generate production-ready code with tests and documentation.
Parameters:
task(required): Description of code to generatelanguage: Programming language (typescript, python, go, etc.)framework: Framework to use (React, FastAPI, Next.js, etc.)context: Additional context or requirementsincludeTests: Generate unit tests (default: false)includeComments: Include helpful comments (default: true)style: Coding style preferences
Example:
{
"tool": "grok_generate_code",
"arguments": {
"task": "Create a React hook for managing localStorage",
"language": "typescript",
"framework": "React",
"includeTests": true
}
}grok_refactor_code
Refactor existing code for better quality and maintainability.
Parameters:
code(required): Code to refactorgoal(required): Refactoring goallanguage: Programming languagepreserveBehavior: Ensure behavior remains unchanged (default: true)targetPatterns: Design patterns to apply
grok_analyze_code
Analyze code for bugs, performance issues, and quality.
Parameters:
code(required): Code to analyzeaspects: Areas to analyze (performance, security, maintainability, bugs, style, complexity)language: Programming language
grok_review_pr
Review pull request changes with detailed feedback.
Parameters:
diff(required): Git diff to reviewcontext: PR descriptionfocusAreas: Specific areas to focus onstandards: Coding standards to check
grok_explain_code
Explain code functionality with adjustable complexity.
Parameters:
code(required): Code to explaintargetAudience: Complexity level (beginner, intermediate, expert)focusOn: Specific aspects to focus on
grok_debug_code
Debug code and identify issues with fixes.
Parameters:
code(required): Code with bugserror: Error messageexpectedBehavior: What the code should dolanguage: Programming language
grok_optimize_code
Optimize code for performance or readability.
Parameters:
code(required): Code to optimizetargetMetric: What to optimize (speed, memory, readability, all)constraints: Constraints to maintain
📚 Examples
Generate a TypeScript Function
// Using with Claude
"Can you use grok to generate a TypeScript function that validates email addresses with comprehensive tests?"
// Direct tool call
{
"tool": "grok_generate_code",
"arguments": {
"task": "Create a function to validate email addresses",
"language": "typescript",
"includeTests": true,
"includeComments": true
}
}Refactor Legacy Code
{
"tool": "grok_refactor_code",
"arguments": {
"code": "// your legacy code here",
"goal": "Convert to modern async/await pattern",
"language": "javascript",
"preserveBehavior": true
}
}Analyze Code Quality
{
"tool": "grok_analyze_code",
"arguments": {
"code": "// code to analyze",
"aspects": ["performance", "security", "maintainability"],
"language": "python"
}
}🔌 Integration with Claude
When using with Claude Desktop or Claude.ai, the tools are available directly:
Human: Can you help me create a React component for a todo list using the grok code server?