Mistral Codestral MCP server

Integrates with Mistral's code-related APIs to enable code completion, bug fixing, and test generation across multiple programming languages.
Back to servers
Setup instructions
Provider
Brian W. Smith
Release date
Jan 19, 2025
Language
TypeScript
Stats
2 stars

This MCP server implementation provides a robust solution for code completion, bug fixing, and test generation using Mistral's Codestral API. It supports multiple programming languages and includes features like rate limiting, error handling, and resource access for code files.

Installation

To get started with the Mistral Codestral MCP Server:

  • Clone the repository
  • Install dependencies:
    npm install
    
  • Copy the example environment file and add your Mistral API key:
    cp .env.example .env
    
  • Build the project:
    npm run build
    

Usage

Starting the Server

Launch the server with:

npm start

Configuration

Open the .env file and add your Mistral API key:

MISTRAL_API_KEY=your_api_key_here

Available Tools

Code Completion

Process code for various tasks including completion, bug fixing, or test generation.

Parameters:

  • code (string, required): The code to process
  • language (string, optional): Programming language
  • task (string, required): One of:
    • "complete": For code completion
    • "fix": For bug fixing
    • "test": For test generation
    • "fim": For Fill-in-the-Middle completion

API Details

The server supports two main Mistral models:

  • codestral-latest: Default model for code-related tasks
  • codestral-mamba-latest: Alternative model with Mamba architecture

Key features include:

  • Automatic rate limiting (100ms minimum between requests)
  • 30-second timeout for API calls
  • Comprehensive error handling for API responses
  • Response validation using Zod schemas
  • Automatic extraction of code blocks from responses
  • Debug logging for API interactions

Error Handling

The server implements robust error handling including:

  • Properly formatted API errors
  • Rate limiting implementation
  • Input validation using Zod schemas
  • Specific error messages for common issues like:
    • Authentication failures
    • Rate limit exceeded
    • Server errors
    • Invalid input validation

Resource Access

The server provides access to code files through the file://code resource URI, enabling integration with workspace files.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mistral-codestral" '{"command":"npx","args":["-y","mcp-mistral-codestral"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mistral-codestral": {
            "command": "npx",
            "args": [
                "-y",
                "mcp-mistral-codestral"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mistral-codestral": {
            "command": "npx",
            "args": [
                "-y",
                "mcp-mistral-codestral"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later