Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 2.29 KB

File metadata and controls

51 lines (34 loc) · 2.29 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

dev-mcp-server is an MCP (Model Context Protocol) server that bridges LSP (Language Server Protocol) functionality for OCaml development. It exposes ocamllsp capabilities and ocp-index tools as MCP tools, enabling AI assistants to perform code navigation and lookup operations on OCaml codebases.

Build and Run Commands

# Install dependencies (requires uv package manager)
uv sync

# Run the server (stdio transport for MCP)
uv run dev-mcp-server

# Or run directly
uv run python server.py

# Disable specific tool groups
uv run dev-mcp-server --no-lsp        # Disable ocamllsp tools
uv run dev-mcp-server --no-ocp-index  # Disable ocp-index/ocp-grep tools

# Environment variables (alternative to CLI flags)
DEV_MCP_NO_LSP=1 uv run dev-mcp-server
DEV_MCP_NO_OCP_INDEX=1 uv run dev-mcp-server

Architecture

The codebase consists of two main files:

  • server.py: FastMCP server exposing tools. Tools are conditionally registered at startup via register_lsp_tools() and register_ocp_index_tools(). Tool groups:

    • LSP-based tools: find_references, go_to_definition, go_to_type_definition, hover, type_search, get_documentation
    • ocp-index tools: ocp_index_complete, ocp_index_print, ocp_index_type, ocp_index_locate, ocp_grep
  • lsp_client.py: JSON-RPC client managing an ocamllsp subprocess. Handles LSP protocol framing, request/response correlation via threading, and file synchronization (didOpen/didClose).

Key Design Patterns

  • Lazy LSP initialization: The LspClient instance is created on first tool invocation and reused. Workspace changes trigger client restart.
  • Workspace detection: Searches parent directories for dune-project, .git, or dune-workspace markers.
  • File sync: Files are automatically opened in LSP before queries and tracked to avoid duplicate opens.
  • ocamllsp extensions: Several tools use custom ocamllsp methods (ocamllsp/hoverExtended, ocamllsp/typeSearch, ocamllsp/getDocumentation) documented in SPEC.md.

Dependencies

  • Python 3.10+
  • mcp[cli]>=1.2.0 (FastMCP framework)
  • External: ocamllsp (LSP server), optionally ocp-index and ocp-grep for identifier lookup tools