Building OCaml MCP - what features would you want?

Hi everyone,

I’m experimenting with OCaml MCP, an implementation of the Model Context Protocol that enables AI coding assistants to better understand and work with OCaml projects.

I’ve had a lot of success with coding agents in OCaml, and I’m convinced they could get significantly more productive with deep integration with the language/tooling. OCaml MCP is a first iteration on that idea.

Seeking community input

I’m planning the roadmap for a first release (in the coming weeks) and would love to hear what features you’d find most useful. Some ideas:

  • Search packages and documentation on OCaml.org
  • Search for code examples à la Sherlocode
  • Integration with test frameworks like Alcotest
  • Explore semantic project structure (library + module dependencies)
  • Something else entirely? Moonshot ideas?

Here are some features that are already implemented or work-in-progress:

  • Dune RPC integration (build status, building targets)
  • File operations with OCaml-aware features (format, return diagnostic)
  • OCaml expression evaluation in project context
  • And other WIP features like running tests, get module signature, project structure

Thanks for any thoughts or ideas!


PS: I’ve been thinking quite a lot about agentic coding in OCaml recently, beyond this MCP server. If you’re interested in that space, I’d love to talk!

6 Likes

Seeing as you also just announced Raven, were you able to leverage agents effectively there?

in ahrefs we have some wrappers on top of merlin exposed in mcp. One example is to be able to get the type of a value at a specific position.

edit: I see that you have it in

3 Likes

this would probably deserve to be a project on its own. dune-deps and ocamldep/codept are nice starting point, but they could definitely do with more power.

1 Like

What excellent timing, Thibaut! @sadiq @jonludlam @ryang and I just wrote up our recent experiments in this direction as well; draft here: https://www.cl.cam.ac.uk/~avsm2/2025-ocaml-ai-draft1.pdf. Our intention with this is to just add people working in this space into this and keep it as updated as possible (probably a fool’s errand given the pace of developments), but do ping me if you’d like to join the Overleaf and add notes in.

Our own experiments started off aimed at open models that we plausibly could use alongside teaching OCaml (taught in the first year undergraduate course here at Cambridge). But since then, frontier models like Claude’s have been storming away in terms of capabilities so we’ve been using those too.

I hacked up an OCaml MCP implementation a few months ago that @mseri has been using, but I can retire that in favour of yours. In addition to the MCP tools you suggest above, we’ve been building a package embedding of the entire opam ecosystem so that you can search for relevant packages from within the assistant.

E.g. for an ocaml-jmap implementation I tried to code entirely from scratch from the RFCs, the agent (Claude Code) could scan the embeddings and come up with the following recommendations (screenshotted to avoid pasting LLM-generated text into this forum):

I’ve not yet played with fine-grained use of MCP for types. Is your ocaml-mcp-server ready to try out? It seems to hang in Claude Code in stdio mode for me after a quick attempt, but I’ll debug further…

3 Likes

I’ve also been playing quite a bit with AI assistants recently.

I agree it actually works quite well for generating OCaml code. Modules, abstractions, and type-safety really help guide the model and keep things consistent. The main issue I had was the poor memory of these tools: often they forget that they already implemented a function a few hours ago, and they start again something similar, again and again.

To avoid that, I wrote (with some help) a small tool to remove dead-code—which I find even more useful for generated code than for “real” projects: prune. It’s quite handy, and adding an MCP interface would be really nice.

More generally, any tool that can help to detect code duplication smells or enforce some linting rules would be super useful. I started to write a few pre-hook scripts for working on AI-assisted projects—at some point, I’ll probably open-source them.

5 Likes

With great success! I’ve pushed the CLAUDE.md file on GitHub if anyone’s interested: raven/CLAUDE.md at main · raven-ml/raven · GitHub

Love the idea! I’d definitely be playing with that, thanks for sharing!

2 Likes

Was curious to try it out on my medium-large code base, but the opam install command in the readme doesn’t work. Do you have a sense of when you would actually put something on the opam repo?

Thanks, I’ll reach out!

I noticed that too, this should be fixed after Stdio servers are too strict · Issue #3 · tmattio/ocaml-mcp · GitHub.
Generally, the MCP libraries should be good to experiment with (apart from the above issue), but the OCaml MCP server is too early stage to get any real benefit - my goal with the post was to collect some ideas/feature request as I work towards a first usable version.

I’m hoping to get an initial release in the 2-3 weeks.

1 Like

So after finally getting the web to look nice and optimized for human consumption, we’re now looking to go back to the simple text browsers of yore so AI can browse it for us? :wink:

2 Likes