Skip to content

Commit 2df7241

Browse files
bhaumanBruce Hauman
andauthored
docs: Add documentation for auto-start nREPL CLI and config options (#101)
- Update README.md CLI options to document :start-nrepl-cmd and :parse-nrepl-port - Update CONFIG.md with new configuration options for auto-starting nREPL - Add example configuration file for auto-start feature - Clarify that auto-start requires launching from project directory - Emphasize usefulness for Claude Code and other CLI-based LLM tools Co-authored-by: Bruce Hauman <[email protected]>
1 parent 03d1963 commit 2df7241

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

CONFIG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ Controls the file timestamp tracking behavior (default: `:partial-read`). This s
3939

4040
The timestamp tracking system prevents accidental overwrites when files are modified by external processes (other developers, editors, git operations, etc.).
4141

42+
### `:start-nrepl-cmd`
43+
**Optional** - A command to automatically start an nREPL server if one is not already running. Must be specified as a vector of strings. The MCP server will start this process and manage its lifecycle.
44+
45+
**Important**: This feature requires the MCP server to be launched from your project directory (where your `deps.edn` or `project.clj` is located). The nREPL server will be started in the current working directory. This makes it ideal for use with Claude Code and other command-line LLM clients where you want automatic nREPL startup - you can simply start Claude Code in your project directory and the nREPL will launch automatically.
46+
47+
**Available values:**
48+
- `["lein" "repl" ":headless"]` - Start Leiningen REPL in headless mode
49+
- `["clojure" "-M:nrepl"]` - Start Clojure with nREPL alias
50+
- `["bb" "nrepl-server"]` - Start Babashka nREPL server
51+
52+
**When to use:**
53+
- With Claude Code or other CLI-based LLM tools launched from your project directory
54+
- When you want automatic nREPL server management without separate terminal windows
55+
- In CI/CD environments where automatic startup is beneficial
56+
57+
### `:parse-nrepl-port`
58+
**Optional** - When `true` and used with `:start-nrepl-cmd`, automatically discovers the nREPL port from the command's stdout output. Defaults to `true` when `:start-nrepl-cmd` is provided. The parser recognizes common nREPL port announcement formats.
59+
60+
**Available values:**
61+
- `true` (default when `:start-nrepl-cmd` is provided) - Parse port from nREPL output
62+
- `false` - Don't parse port; requires `:port` to be explicitly provided
63+
64+
**When to use:**
65+
- `true` - When the nREPL server announces its port in stdout (most common case)
66+
- `false` - When using a fixed port configuration or when port is known in advance
67+
68+
**Note:** When `:parse-nrepl-port` is `false`, you must provide the `:port` configuration.
69+
4270
### `:emacs-notify`
4371
Boolean flag to enable Emacs integration notifications.
4472

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ For a quick start: **[Creating Your Own Custom MCP Server](doc/custom-mcp-server
933933
Using the -X invocation requires EDN values.
934934

935935
#### `:port`
936-
**Required** - The nREPL server port to connect to.
936+
**Optional** - The nREPL server port to connect to. Required unless using `:start-nrepl-cmd` with `:parse-nrepl-port` or relying on an existing `.nrepl-port` file.
937937

938938
`:port 7888`
939939

@@ -942,6 +942,18 @@ Using the -X invocation requires EDN values.
942942

943943
`:host "localhost"` or `:host "0.0.0.0"`
944944

945+
#### `:start-nrepl-cmd`
946+
**Optional** - A command to automatically start an nREPL server if one is not already running. Must be specified as a vector of strings. The MCP server will start this process and manage its lifecycle.
947+
948+
**Important**: This option requires launching `clojure-mcp` from your project directory (where your `deps.edn` or `project.clj` is located). The nREPL server will be started in the current working directory. This is particularly useful for Claude Code and other command-line LLM clients where you want automatic nREPL startup without manual process management.
949+
950+
`:start-nrepl-cmd ["lein" "repl" ":headless"]` or `:start-nrepl-cmd ["clojure" "-M:nrepl"]`
951+
952+
#### `:parse-nrepl-port`
953+
**Optional** - When `true` and used with `:start-nrepl-cmd`, automatically discovers the nREPL port from the command's stdout output. Defaults to `false`. The parser recognizes common nREPL port announcement formats.
954+
955+
`:parse-nrepl-port true`
956+
945957
#### `:config-file`
946958
**Optional** - Specify the location of a configuration file. Must be a path to an existing file.
947959

@@ -968,12 +980,25 @@ Using the -X invocation requires EDN values.
968980
# Basic usage with just port
969981
clojure -X:mcp :port 7888
970982

983+
# With automatic nREPL server startup and port discovery
984+
# Perfect for Claude Code - run this from your project directory
985+
clojure -X:mcp :start-nrepl-cmd '["lein" "repl" ":headless"]' :parse-nrepl-port true
986+
987+
# For Claude Code with Clojure projects (from project directory)
988+
clojure -X:mcp :start-nrepl-cmd '["clojure" "-M:nrepl"]' :parse-nrepl-port true
989+
990+
# Auto-start with explicit port (doesn't parse from output)
991+
clojure -X:mcp :port 7888 :start-nrepl-cmd '["clojure" "-M:nrepl"]'
992+
971993
# With custom host and project directory
972994
clojure -X:mcp :port 7888 :host '"0.0.0.0"' :project-dir '"/path/to/project"'
973995

974996
# Using a custom config file
975997
clojure -X:mcp :port 7888 :config-file '"/path/to/custom-config.edn"'
976998

999+
# Using existing .nrepl-port file (no explicit port needed)
1000+
clojure -X:mcp
1001+
9771002
# Specifying Babashka environment
9781003
clojure -X:mcp :port 7888 :nrepl-env-type :bb
9791004
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;; Example configuration for automatic nREPL server startup
2+
;; Place this in .clojure-mcp/config.edn in your project root
3+
;;
4+
;; IMPORTANT: This feature requires launching clojure-mcp from your project directory
5+
;; Perfect for Claude Code and other CLI-based LLM tools where you want automatic
6+
;; nREPL startup without managing separate processes
7+
8+
{;; Automatically start an nREPL server when MCP server starts
9+
;; Must be a vector of strings representing the command and arguments
10+
:start-nrepl-cmd ["clojure" "-M:nrepl"]
11+
12+
;; Parse the port from nREPL output (default: true when :start-nrepl-cmd is provided)
13+
;; Set to false if you want to use a fixed port specified below
14+
:parse-nrepl-port true
15+
16+
;; Port is optional when :parse-nrepl-port is true
17+
;; Required when :parse-nrepl-port is false
18+
;; :port 7888
19+
20+
;; Other common configurations
21+
:allowed-directories ["." "src" "test" "resources"]
22+
:write-file-guard :partial-read
23+
:cljfmt true
24+
:bash-over-nrepl true}
25+
26+
;; Alternative configurations:
27+
28+
;; For Leiningen projects (great for Claude Code):
29+
;; {:start-nrepl-cmd ["lein" "repl" ":headless"]
30+
;; :parse-nrepl-port true}
31+
32+
;; For Babashka:
33+
;; {:start-nrepl-cmd ["bb" "nrepl-server"]
34+
;; :parse-nrepl-port true}
35+
36+
;; With fixed port (no port parsing):
37+
;; {:start-nrepl-cmd ["clojure" "-M:nrepl"]
38+
;; :parse-nrepl-port false
39+
;; :port 7888}
40+
41+
;; Claude Code usage:
42+
;; 1. Place this config in your-project/.clojure-mcp/config.edn
43+
;; 2. Open Claude Code in your project directory
44+
;; 3. The nREPL will start automatically when Claude Code connects

0 commit comments

Comments
 (0)