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.
Installing the OCaml MCP server is straightforward using OPAM:
opam install ocaml-mcp-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
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
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
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
The server currently implements:
Some features still in progress include OAuth 2.1 authentication, request cancellation, and WebSocket/SSE transport options.
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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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