OCaml Development Tools MCP server

Integrates with OCaml's Dune build system and Merlin code intelligence to provide real-time build status monitoring and module signature extraction for OCaml development projects.
Back to servers
Setup instructions
Provider
Thibaut Mattio
Release date
Jun 27, 2025
Stats
46 stars

OCaml MCP server is a powerful tool that integrates AI assistants with your OCaml projects through the Model Context Protocol (MCP). It provides seamless connections to OCaml development tools like Dune, Merlin, and more, allowing AI assistants to interact meaningfully with your codebase.

Installation

Installing the OCaml MCP server is straightforward using OPAM:

opam install ocaml-mcp-server

Usage

Starting the Server

You can run the OCaml MCP server in two primary ways:

Using standard input/output (stdio):

ocaml-mcp-server

As an HTTP server on a specific port:

ocaml-mcp-server --socket 8080

Features

Dune Build System Integration

The server provides comprehensive integration with the Dune build system:

  • Build Status Monitoring: Get real-time build status with detailed error reporting

    # Command handled internally by the server
    dune/build-status
    
  • Target-Specific Building: Build specific targets with streaming output

    # Command handled internally by the server
    dune/build-target
    
  • Test Execution: Run and get detailed results from tests

    # Command handled internally by the server
    dune/run-tests
    

OCaml Code Analysis

The server provides powerful code analysis capabilities:

  • Module Signature Retrieval: Get module signatures from compiled artifacts

    # Command handled internally by the server
    ocaml/module-signature
    
  • Definition Finding: Jump to symbol definitions

    # Command handled internally by the server
    ocaml/find-definition
    
  • Reference Finding: Locate all usages of a symbol

    # Command handled internally by the server
    ocaml/find-references
    
  • Type Information: Get type information at cursor position

    # Command handled internally by the server
    ocaml/type-at-pos
    
  • Project Structure Analysis: Analyze your project layout and dependencies

    # Command handled internally by the server
    ocaml/project-structure
    
  • Expression Evaluation: Evaluate OCaml expressions in the context of your project

    # Command handled internally by the server
    ocaml/eval
    

File System Tools with OCaml Enhancements

The server extends file system operations with OCaml-specific features:

  • Enhanced File Reading: Read files with automatic Merlin diagnostics for OCaml code

    # Command handled internally by the server
    fs/read
    
  • Smart File Writing: Write files with automatic OCaml formatting

    # Command handled internally by the server
    fs/write
    
  • Syntax-Aware Editing: Edit files while preserving OCaml syntax validity

    # Command handled internally by the server
    fs/edit
    

Implementation Status

The server currently implements:

  • Core protocol types and JSON-RPC messaging
  • Client/server request-response patterns
  • Notification handling
  • Multiple transport layers (stdio, socket, memory, HTTP)
  • Server-to-client request handling
  • Dynamic JSON schema generation from OCaml types
  • OCaml development tools integration
  • Full compliance with MCP 2025-06-18 specification

Some features still in progress include OAuth 2.1 authentication, request cancellation, and WebSocket/SSE transport options.

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 "ocaml-mcp-server" '{"command":"ocaml-mcp-server","args":["--socket","8080"]}'

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": {
        "ocaml-mcp-server": {
            "command": "ocaml-mcp-server",
            "args": [
                "--socket",
                "8080"
            ]
        }
    }
}

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": {
        "ocaml-mcp-server": {
            "command": "ocaml-mcp-server",
            "args": [
                "--socket",
                "8080"
            ]
        }
    }
}

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