#!/bin/bash # Script to configure OCaml LSP MCP server for Claude in a subdirectory set -e # Check if a directory argument was provided if [ "$#" -ne 1 ]; then echo "Usage: $0 " echo "Example: $0 /path/to/ocaml/project" exit 1 fi WORKSPACE_DIR="$1" # Convert to absolute path if relative if [[ "$WORKSPACE_DIR" != /* ]]; then WORKSPACE_DIR="$(cd "$WORKSPACE_DIR" && pwd)" fi # Check if workspace directory exists if [ ! -d "$WORKSPACE_DIR" ]; then echo "Error: Directory '$WORKSPACE_DIR' does not exist" exit 1 fi # Find ocamllsp dynamically OCAMLLSP="" # Try using which command directly OCAMLLSP=$(which ocamllsp 2>/dev/null || true) # If not found, try with opam exec if [ -z "$OCAMLLSP" ]; then OCAMLLSP=$(opam exec -- which ocamllsp 2>/dev/null || true) fi # If still not found, check current opam switch if [ -z "$OCAMLLSP" ] && [ -n "$OPAM_SWITCH_PREFIX" ]; then if [ -f "$OPAM_SWITCH_PREFIX/bin/ocamllsp" ]; then OCAMLLSP="$OPAM_SWITCH_PREFIX/bin/ocamllsp" fi fi if [ -z "$OCAMLLSP" ] || [ ! -f "$OCAMLLSP" ]; then echo "Error: Could not find ocamllsp" echo "Please ensure ocamllsp is installed: opam install ocaml-lsp-server" exit 1 fi # Find mcp-language-server MCP_SERVER="/Users/avsm/go/bin/mcp-language-server" if [ ! -f "$MCP_SERVER" ]; then echo "Error: mcp-language-server not found at $MCP_SERVER" echo "Please ensure mcp-language-server is installed" exit 1 fi echo "Configuring OCaml LSP MCP for workspace: $WORKSPACE_DIR" echo "Using ocamllsp: $OCAMLLSP" echo "Using mcp-language-server: $MCP_SERVER" # Execute the Claude MCP configuration command claude mcp add ocamllsp "$MCP_SERVER" -- -workspace "$WORKSPACE_DIR" -lsp "$OCAMLLSP" if [ $? -eq 0 ]; then echo "Successfully configured OCaml LSP MCP for $WORKSPACE_DIR" else echo "Failed to configure OCaml LSP MCP" exit 1 fi