Clojure MCP Light 标志

Clojure MCP Light

社区
bhauman

Simple Clojure tooling for AI coding assistants

发布者bhauman
代码仓库clojure-mcp-light
语言Clojure
复刻数
25
星标数
197
可用工具
0
传输类型stdio
许可协议EPL-2.0
链接
  • 将工具接入 AI 工作流

    Clojure MCP Light 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 197 个 Star 和 25 个 Fork。

clojure-mcp-light

This is not an MCP.

Simple CLI tools for LLM coding assistants working with Clojure.

TL;DR: Three CLI tools for Clojure development with LLM coding assistants:

The Problem

LLMs produce delimiter errors when editing Clojure code - mismatched parentheses, brackets, and braces. This leads to the "Paren Edit Death Loop" where the AI repeatedly fails to fix delimiter errors, wasting tokens and blocking progress.

Secondary problem: LLM coding assistants need to connect to a stateful Clojure REPL for evaluation.

These tools solve both problems.

Quick Reference

ToolUse Case
clj-nrepl-evalREPL evaluation from any LLM
clj-paren-repair-claude-hookClaude Code (or any LLM that supports Claude hooks)
clj-paren-repairGemini CLI, Codex CLI, any LLM with shell

Quick Install

Install hook tool:

bash
bbin install https://github.com/bhauman/clojure-mcp-light.git --tag v0.2.2

Note: The hook will not work unless configured in ~/.claude/settings.json - see configuration section below.

Install nREPL eval tool:

bash
bbin install https://github.com/bhauman/clojure-mcp-light.git --tag v0.2.2 --as clj-nrepl-eval --main-opts '["-m" "clojure-mcp-light.nrepl-eval"]'

Install on-demand repair tool:

bash
bbin install https://github.com/bhauman/clojure-mcp-light.git --tag v0.2.2 --as clj-paren-repair --main-opts '["-m" "clojure-mcp-light.paren-repair"]'

See individual tool sections below for important configuration and usage details.

Requirements

  • Babashka - Fast Clojure scripting (includes cljfmt)
    • Note: Version 1.12.212 or later is required when working with Codex and other tools that sandbox bash execution
  • bbin - Babashka package manager

Optional:


clj-nrepl-eval LLM nREPL connection without an MCP

nREPL client for evaluating Clojure code from the command line.

This provides coding assistants access to REPL eval via shell calls. It is specifically designed for LLM interaction and allows the LLM to discover and manage its REPL sessions without needing to configure an MCP server.

How it helps

  • Lets LLMs evaluate code in a running REPL
  • Maintains persistent sessions per target
  • Auto-discovers nREPL ports
  • Auto-repairs delimiters before evaluation
  • Helpful output that guides LLMs

Installation

Installation is in two steps, installing the command line tool and then telling the coding assistants about clj-nrepl-eval.

bash
bbin install https://github.com/bhauman/clojure-mcp-light.git --tag v0.2.2 --as clj-nrepl-eval --main-opts '["-m" "clojure-mcp-light.nrepl-eval"]'

Or from local checkout:

bash
bbin install . --as clj-nrepl-eval --main-opts '["-m" "clojure-mcp-light.nrepl-eval"]'

Verify that it is installed and working by starting a nREPL and then doing a test eval.

bash
# this missing paren is there to demonstrate that delimiters are repaired automatically
clj-nrepl-eval -p 7888 "(+ 1 2 3" 
# => 6

Telling the LLM about clj-nrepl-eval

Choose one or more of these approaches. Each has trade-offs:

ApproachAvailabilityWhen info is usedBest for
Custom instructionsAll LLM clientsAlways in contextSimplest, most effective
Slash commandsMost coding assistantsWhen you invoke itOn-demand awareness
SkillsClaude Code onlyLLM pulls when neededAutomatic, context-aware

Each can be installed locally (per-project) or globally (all projects).

Custom instructions

The simplest and perhaps most effective approach. Works with all LLM coding assistants.

Add to your custom instructions file:

  • Global: ~/.claude/CLAUDE.md, ~/.gemini/GEMINI.md, ~/.codex/AGENTS.md
  • Local: ./CLAUDE.md, ./GEMINI.md, ./AGENTS.md in project root
markdown
# Clojure REPL Evaluation

The command `clj-nrepl-eval` is installed on your path for evaluating Clojure code via nREPL.

**Discover nREPL servers:**

`clj-nrepl-eval --discover-ports`

**Evaluate code:**

`clj-nrepl-eval -p <port> "<clojure-code>"`

With timeout (milliseconds)

`clj-nrepl-eval -p <port> --timeout 5000 "<clojure-code>"`

The REPL session persists between evaluations - namespaces and state are maintained.
Always use `:reload` when requiring namespaces to pick up changes.

Slash commands

Lets you interject REPL awareness into the conversation when you need it. Available in most coding assistants (installation varies by client).

  • /start-nrepl - Starts an nREPL server in the background and reports the port
  • /clojure-nrepl - Provides detailed usage info for clj-nrepl-eval

Claude Code - uses .md files in commands/ directory:

bash
# Global: ~/.claude/commands/
# Local: .claude/commands/
mkdir -p ~/.claude/commands
cp commands/*.md ~/.claude/commands/

Gemini CLI - uses .toml files (docs):

bash
# Global: ~/.gemini/commands/
# Local: .gemini/commands/

Codex CLI - uses .md files (docs):

bash
# Global: ~/.codex/prompts/

Skills

Allows the LLM to pull in REPL information when it's actually needed. Currently Claude Code only.

bash
# Global (all projects)
mkdir -p ~/.claude/skills
cp -r skills/clojure-eval ~/.claude/skills/

# Local (this project only)
mkdir -p .claude/skills
cp -r skills/clojure-eval .claude/skills/

Usage Tips

Easiest strategy: Start nREPL before your coding session

Start an nREPL before asking the LLM to use one. This way it can simply discover the port of the server in the current project with --discover-ports. Minimal ceremony to start interacting with the REPL.

Advanced: Have the LLM start and manage your nREPL sessions

Claude and other LLMs are perfectly capable of starting your nREPL server in the background and reading the port from the output. They can also kill the server if it gets hung on a bad eval.

Customize to your workflow

Once you start working with clj-nrepl-eval inside a coding assistant, it will quickly become clear how to adjust the above prompts to fit your specific projects and workflow.


clj-paren-repair-claude-hook

Claude Code Hooks let you run shell commands before or after Claude's tool calls. This hook intercepts Write/Edit operations and automatically fixes delimiter errors before they hit the filesystem.

In my usage these Hooks have fixed 100% of the errors detected.

Note: This binary already works with Codex, which shares Claude Code's hook wire format — see Use with Codex below. As other LLM clients add hook support they'll be covered too; for example, when Gemini CLI adds hooks it can use the same approach.

Why hooks instead of MCP tools?

With MCP-based editing tools, you lose Claude Code's native UI integration — tool calls are poorly formatted and difficult to read. Hooks let Claude Code operate normally with its native Edit/Write tools, preserving the clean diff UI you're used to, while transparently fixing delimiter errors behind the scenes.

How it helps

  • Fixes errors transparently before they're written to disk
  • Uses zero tokens - happens outside LLM invocation
  • Preserves Claude Code's native diff UI and tool integration
  • Install once globally, works on all Clojure file edits

Installation

bash
bbin install https://github.com/bhauman/clojure-mcp-light.git --tag v0.2.2

Or from local checkout:

bash
bbin install .

Configuration

Add to ~/.claude/settings.json:

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "clj-paren-repair-claude-hook --cljfmt"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "clj-paren-repair-claude-hook --cljfmt"
          }
        ]
      }
    ],
    "SessionEnd": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "clj-paren-repair-claude-hook --cljfmt"
          }
        ]
      }
    ]
  }
}

Options

  • --cljfmt - Enable automatic code formatting with cljfmt
  • --stats - Enable statistics tracking (logs to ~/.clojure-mcp-light/stats.log)
  • --log-level LEVEL - Set log level (trace, debug, info, warn, error)
  • --log-file PATH - Path to log file (default: ./.clojure-mcp-light-hooks.log)
  • -h, --help - Show help message

How It Works

  • PreToolUse hooks run before Write/Edit operations, fixing content before it's written
  • PostToolUse hooks run after Edit operations, fixing any issues introduced
  • SessionEnd hook cleans up temporary files when Claude Code sessions end

Write operations: If delimiter errors are detected, the content is fixed via parinfer before writing. If unfixable, the write is blocked.

Edit operations: A backup is created before the edit. After the edit, if delimiter errors exist, they're fixed automatically. If unfixable, the file is restored from backup.

Use with Codex (apply_patch)

Codex supports the same hook wire format as Claude Code, so the same clj-paren-repair-claude-hook binary works there too — no separate tool to install. The one difference: Codex makes all file edits through a single apply_patch tool (a patch document) rather than Write/Edit. The hook understands apply_patch and repairs every Clojure file a patch touches.

Add to ~/.codex/hooks.json (global) or <repo>/.codex/hooks.json (per project):

json
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": ".*",
        "hooks": [
          { "type": "command", "command": "clj-paren-repair-claude-hook --cljfmt" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "^apply_patch$",
        "hooks": [
          { "type": "command", "command": "clj-paren-repair-claude-hook --cljfmt" }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "^apply_patch$",
        "hooks": [
          { "type": "command", "command": "clj-paren-repair-claude-hook --cljfmt" }
        ]
      }
    ]
  }
}

What each hook does:

  • PreToolUse apply_patch backs up the files the patch will touch.
  • PostToolUse apply_patch repairs delimiter errors in the patched files. If a file can't be fixed it's restored from the backup and Codex is told why. On a successful repair Codex is notified that the file changed on disk (re-read before further edits) — apply_patch matches on context lines, so a silent change can desync the next patch.
  • SessionStart sweeps clojure-mcp-light temp dirs idle for 3+ days. Codex has no SessionEnd event, so cleanup runs at session start instead.

Codex-specific notes:

  • Trust the hooks. Codex requires you to review and trust command hooks before they run — use /hooks in the TUI. Trust is keyed to the file's hash, so editing hooks.json requires re-trusting.
  • Hooks run only in the interactive TUI, not under codex exec.
  • SessionStart fires when the session is configured — i.e. after your first message, not at bare launch.
  • The ^apply_patch$ matcher scopes the hook to file edits. (.* also works but then the hook runs on every tool call, including shell commands.)

Statistics Tracking

Statistics tracking helps validate that these tools are working well. At some point Clojurists may not need them—either because models stop producing delimiter errors, or because assistants include parinfer internally. Tracking helps us know when that day comes.

Add --stats to track delimiter events:

bash
clj-paren-repair-claude-hook --cljfmt --stats

Stats are written to ~/.clojure-mcp-light/stats.log as EDN:

clojure
{:event-type :delimiter-error, :hook-event "PreToolUse", :timestamp "2025-11-09T14:23:45.123Z", :file-path "/path/to/file.clj"}
{:event-type :delimiter-fixed, :hook-event "PreToolUse", :timestamp "2025-11-09T14:23:45.234Z", :file-path "/path/to/file.clj"}

Use the included stats summary script:

bash
./scripts/stats-summary.bb

Sample output:

clojure-mcp-light Utility Validation
============================================================

Delimiter Repair Metrics
========================
  Total Writes/Edits:           829
  Clean Code (no errors):       794  ( 95.8% of total)
  Errors Detected:               35  (  4.2% of total)
  Successfully Fixed:            35  (100.0% of errors)
  Failed to Fix:                  0  (  0.0% of errors)
  Parse Errors:                   0  (  0.0% of fix attempts)

Logging

Enable logging for debugging:

bash
# Debug level
clj-paren-repair-claude-hook --log-level debug --cljfmt

# Trace level (maximum verbosity)
clj-paren-repair-claude-hook --log-level trace --log-file ~/hook-debug.log

Verify Installation

bash
echo '{"hook_event_name":"PreToolUse","tool_name":"Write","tool_input":{"file_path":"test.clj","content":"(def x 1)"}}' | clj-paren-repair-claude-hook

Verify hooks are running in Claude Code:

After Claude Code edits a Clojure file, expand the tool output to see hook messages. In the terminal, press ctrl-r (or click the edit) and look for these messages surrounding the diff:

⎿ PreToolUse:Edit hook succeeded:
  ... edit diff ...
⎿ PostToolUse:Edit hook succeeded:

If you don't see these messages, check that your ~/.claude/settings.json hook configuration is correct.

Test delimiter repair:

Prompt Claude Code to intentionally write malformed Clojure (e.g., missing closing paren) to verify the hook fixes it automatically.

Pro tip

Combine with clj-paren-repair for complete coverage - hooks handle Edit/Write tools, but LLMs can also edit via Bash (sed, awk). Having both tools catches all cases.


clj-paren-repair

A shell command for LLM coding assistants that don't support hooks (like Gemini CLI and Codex CLI). When the LLM encounters a delimiter error, it calls this tool to fix it instead of trying to repair it manually.

The key insight: When we observe an AI in the "Paren Edit Death Loop"—repeatedly failing to fix delimiter errors—we're witnessing a desperate search for a solution. clj-paren-repair provides an escape route that short-circuits this behavior.

Why this works: Modern SOTA models produce very accurate edits with only small delimiter discrepancies. The errors are minor enough that parinfer can reliably fix them. This simple solution works surprisingly well.

Hooks vs clj-paren-repair: Hooks are the clear winner when available—they use zero tokens and happen without LLM invocation. However, clj-paren-repair works universally with any LLM that has shell access. When Gemini CLI gets hooks support, we should use them. Until then, clj-paren-repair is sufficient.

Using both together: Even with hooks configured, having clj-paren-repair available provides complete coverage. Hooks handle Edit/Write tools, but LLMs can also edit files via Bash (sed, awk, etc.). Having both tools catches all cases.

How it helps

  • Provides escape route from "Paren Edit Death Loop"
  • LLM calls it when it encounters delimiter errors
  • Works with any LLM that has shell access
  • Automatically formats files with cljfmt

Installation

bash
bbin install https://github.com/bhauman/clojure-mcp-light.git --tag v0.2.2 --as clj-paren-repair --main-opts '["-m" "clojure-mcp-light.paren-repair"]'

Or from local checkout:

bash
bbin install . --as clj-paren-repair --main-opts '["-m" "clojure-mcp-light.paren-repair"]'

Usage

bash
clj-paren-repair path/to/file.clj
clj-paren-repair src/core.clj src/util.clj test/core_test.clj
clj-paren-repair --help

Setup: Custom Instructions

Add to your global or local custom instructions file (GEMINI.md, AGENTS.md, CLAUDE.md etc.):

markdown
# Clojure Parenthesis Repair

The command `clj-paren-repair` is installed on your path.

Examples:
`clj-paren-repair <files>`
`clj-paren-repair path/to/file1.clj path/to/file2.clj path/to/file3.clj`

**IMPORTANT:** Do NOT try to manually repair parenthesis errors.
If you encounter unbalanced delimiters, run `clj-paren-repair` on the file
instead of attempting to fix them yourself. If the tool doesn't work,
report to the user that they need to fix the delimiter error manually.

The tool automatically formats files with cljfmt when it processes them.

Using Multiple Tools Together

Best practice for Claude Code users:

  1. Configure hooks for automatic fixing (zero tokens)
  2. Also have clj-paren-repair available for Bash-based edits
  3. Use clj-nrepl-eval for REPL evaluation

For other LLM clients (Gemini CLI, Codex, etc.):

  1. Install clj-paren-repair and add custom instructions
  2. Use clj-nrepl-eval for REPL evaluation

What These Tools Solve (and Don't)

Problem A: Bad delimiters in output - SOLVED

These tools fix mismatched/missing parentheses in edit results.

Problem B: old_string matching failures - NOT SOLVED

Sometimes LLMs struggle to produce an old_string that exactly matches the file content, causing edit failures. This is less common with newer models.

For full solution to Problem B: ClojureMCP sexp-editing tools.


Why Not Just Use ClojureMCP?

ClojureMCP provides comprehensive Clojure tooling, but:

  • ClojureMCP tools aren't native to the client - no diff UI, no integrated output formatting
  • ClojureMCP duplicates/conflicts with tools the client already has
  • These CLI tools work with the client's native tools instead of replacing them

You can use both together. Configure ClojureMCP to expose only :clojure_eval if desired:

clojure
;; .clojure-mcp/config.edn
{:enable-tools [:clojure_eval]
 :enable-prompts []
 :enable-resources []}

You can also use ClojureMCP's prompts, resources, and agents functionality to create a suite of tools that work across LLM clients.


Contributing

Contributions and ideas are welcome! Feel free to:

  • Open issues with suggestions or bug reports
  • Submit PRs with improvements
  • Share your experiments and what works (or doesn't work)

License

Eclipse Public License - v 2.0 (EPL-2.0)

See LICENSE.md for the full license text.

将 Clojure MCP Light MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Clojure MCP Light 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Clojure MCP Light 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Clojure MCP Light MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "clojure-mcp-light": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Clojure MCP Light MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Clojure MCP Light MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Clojure MCP Light 帮我完成这项任务吗?
Clojure MCP Light
当然。我已阅读。
以下是我使用 Clojure MCP Light 得到的结果。

常见问题

Clojure MCP Light MCP 服务器有什么用途?

Clojure MCP Light 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Clojure MCP Light MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Clojure MCP Light,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Clojure MCP Light MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Clojure MCP Light 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Clojure MCP Light MCP 连接到 TypingMind?

Clojure MCP Light 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Clojure MCP Light MCP 在 TypingMind 中提供哪些工具?

Clojure MCP Light 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Clojure MCP Light MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Clojure MCP Light 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇