Skip to content

Commit fef5e77

Browse files
bhaumanBruce Hauman
andauthored
Config validation (#104)
* Add Malli-based configuration validation - Add metosin/malli dependency for data-driven schema validation - Create comprehensive config schemas in clojure-mcp.config.schema - Support all configuration options including models, agents, resources, prompts - Provide automatic spell-checking for typos in configuration keys - Include human-readable error messages with documentation references - Add comprehensive test suite for validation scenarios - Support environment variable references [:env "VAR_NAME"] - Validate nested structures like thinking config, agent config, etc. - Use closed map schema to detect unknown/misspelled keys * integrating configuration validation * update schema for models * update agent config schema * updating agent docs * some more schema touch ups * enhancing schemas * small fix for tests * improving validation * cleaning up validation and getting ready for merging * fix ci test * minor tweaks --------- Co-authored-by: Bruce Hauman <bhauman@gmail.com>
1 parent 6228850 commit fef5e77

File tree

11 files changed

+712
-487
lines changed

11 files changed

+712
-487
lines changed

deps.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
;; for prompt templating
99
pogonos/pogonos {:mvn/version "0.2.1"}
1010

11+
;; for configuration validation
12+
metosin/malli {:mvn/version "0.19.1"}
13+
1114
;; Clojure source manipulation
1215
rewrite-clj/rewrite-clj {:mvn/version "1.1.47"}
1316
dev.weavejester/cljfmt {:mvn/version "0.13.1"}

doc/configuring-agents.md

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ The agent tool builder dynamically creates MCP tools from agent configurations d
1616
**Agents have NO tools by default.** You must explicitly specify which tools an agent can use via `:enable-tools`. This is a safety feature to prevent unintended access to powerful capabilities.
1717

1818
Agents can now access ALL available tools, including:
19-
- Read-only tools (grep, read-file, etc.)
20-
- **File editing tools** (file-write, clojure-edit, etc.)
21-
- **Code execution tools** (clojure-eval, bash)
22-
- Agent tools (dispatch-agent, architect)
19+
- Read-only tools (grep, read_file, etc.)
20+
- **File editing tools** (file_write, clojure_edit, etc.)
21+
- **Code execution tools** (clojure_eval, bash)
22+
- Agent tools (dispatch_agent, architect)
2323

2424
Always consider the security implications when granting tool access.
2525

@@ -33,7 +33,7 @@ Add an `:agents` key to your `.clojure-mcp/config.edn`:
3333
:description "A custom agent for specific tasks"
3434
:system-message "You are a helpful assistant specialized in..."
3535
:context true
36-
:enable-tools [:read-file :grep] ; Must explicitly list tools
36+
:enable-tools [:read_file :grep] ; Must explicitly list tools
3737
:disable-tools nil}]}
3838
```
3939

@@ -65,6 +65,9 @@ Each agent configuration supports the following keys:
6565
- **`:memory-size`** - Controls conversation memory behavior:
6666
- `nil`, `false`, or `< 10` - **Stateless** (default): Clears memory on each chat
6767
- `>= 10` - **Persistent**: Accumulates messages up to limit, then resets completely
68+
- **`:track-file-changes`** - Whether to track and show file diffs (default: `true`)
69+
- `true` - Shows diffs of file modifications made by the agent
70+
- `false` - Disables file change tracking
6871

6972
## Available Tools for Agents
7073

@@ -74,33 +77,33 @@ Agents can potentially access all MCP tools:
7477
| Tool ID | Description |
7578
|---------|-------------|
7679
| `:LS` | Directory tree view |
77-
| `:read-file` | Read file contents with pattern matching |
80+
| `:read_file` | Read file contents with pattern matching |
7881
| `:grep` | Search file contents |
79-
| `:glob-files` | Find files by pattern |
82+
| `:glob_files` | Find files by pattern |
8083
| `:think` | Reasoning tool |
81-
| `:clojure-inspect-project` | Project structure analysis |
84+
| `:clojure_inspect_project` | Project structure analysis |
8285

8386
### Evaluation Tools
8487
| Tool ID | Description |
8588
|---------|-------------|
86-
| `:clojure-eval` | Execute Clojure code in REPL |
89+
| `:clojure_eval` | Execute Clojure code in REPL |
8790
| `:bash` | Execute shell commands |
8891

8992
### File Editing Tools
9093
| Tool ID | Description |
9194
|---------|-------------|
92-
| `:file-write` | Create or overwrite files |
93-
| `:file-edit` | Edit files by text replacement |
94-
| `:clojure-edit` | Structure-aware Clojure editing |
95-
| `:clojure-edit-replace-sexp` | S-expression replacement |
95+
| `:file_write` | Create or overwrite files |
96+
| `:file_edit` | Edit files by text replacement |
97+
| `:clojure_edit` | Structure-aware Clojure editing |
98+
| `:clojure_edit_replace_sexp` | S-expression replacement |
9699

97100
### Agent Tools
98101
| Tool ID | Description |
99102
|---------|-------------|
100-
| `:dispatch-agent` | Launch sub-agents |
103+
| `:dispatch_agent` | Launch sub-agents |
101104
| `:architect` | Technical planning assistant |
102-
| `:scratch-pad` | Persistent data storage |
103-
| `:code-critique` | Code review feedback |
105+
| `:scratch_pad` | Persistent data storage |
106+
| `:code_critique` | Code review feedback |
104107

105108
## Tool Access Patterns
106109

@@ -120,7 +123,7 @@ Agents can potentially access all MCP tools:
120123
:name "research_agent"
121124
:description "Can read but not modify"
122125
:system-message "You research and analyze code"
123-
:enable-tools [:read-file :grep :glob-files :clojure-inspect-project]}
126+
:enable-tools [:read_file :grep :glob_files :clojure_inspect_project]}
124127
```
125128

126129
### Write Access
@@ -129,7 +132,7 @@ Agents can potentially access all MCP tools:
129132
:name "code_writer"
130133
:description "Can create and modify files"
131134
:system-message "You write and refactor code. Always test before writing."
132-
:enable-tools [:read-file :grep :clojure-eval :file-write :clojure-edit]}
135+
:enable-tools [:read_file :grep :clojure_eval :file_write :clojure_edit]}
133136
```
134137

135138
### Full Access
@@ -139,7 +142,7 @@ Agents can potentially access all MCP tools:
139142
:description "Access to all tools - use with caution"
140143
:system-message "You have full system access. Confirm destructive operations."
141144
:enable-tools [:all]
142-
:disable-tools [:dispatch-agent] ; Can still exclude specific tools
145+
:disable-tools [:dispatch_agent] ; Can still exclude specific tools
143146
}
144147
```
145148

@@ -184,7 +187,7 @@ Here's a comprehensive configuration with agents of varying capability levels:
184187
:model :anthropic/fast
185188
:context true
186189
:memory-size false ; Explicitly stateless
187-
:enable-tools [:grep :glob-files :read-file :clojure-inspect-project]
190+
:enable-tools [:grep :glob_files :read_file :clojure_inspect_project]
188191
:disable-tools nil}
189192

190193
;; Documentation specialist - stateless
@@ -195,7 +198,7 @@ Here's a comprehensive configuration with agents of varying capability levels:
195198
and focus on practical usage."
196199
:context ["README.md" "doc/"]
197200
:memory-size nil ; Stateless (same as omitting)
198-
:enable-tools [:read-file :glob-files]}
201+
:enable-tools [:read_file :glob_files]}
199202

200203
;; Test runner - can execute but not modify
201204
{:id :test-runner
@@ -205,8 +208,8 @@ Here's a comprehensive configuration with agents of varying capability levels:
205208
but cannot modify files."
206209
:context ["test/"]
207210
:memory-size 5 ; < 10 = stateless
208-
:enable-tools [:read-file :grep :glob-files :clojure-eval :bash]
209-
:disable-tools [:file-write :file-edit :clojure-edit]}
211+
:enable-tools [:read_file :grep :glob_files :clojure_eval :bash]
212+
:disable-tools [:file_write :file_edit :clojure_edit]}
210213

211214
;; Code writer - persistent memory for multi-step refactoring
212215
{:id :code-writer
@@ -218,10 +221,10 @@ Here's a comprehensive configuration with agents of varying capability levels:
218221
:model :openai/smart
219222
:context true
220223
:memory-size 50 ; Persistent - remembers recent edits
221-
:enable-tools [:read-file :grep :glob-files
222-
:clojure-eval :bash
223-
:file-write :file-edit
224-
:clojure-edit :clojure-edit-replace-sexp]}
224+
:enable-tools [:read_file :grep :glob_files
225+
:clojure_eval :bash
226+
:file_write :file_edit
227+
:clojure_edit :clojure_edit_replace_sexp]}
225228

226229
;; Full access agent with large memory
227230
{:id :admin-agent
@@ -480,11 +483,11 @@ Examples:
480483
{:enable-tools nil} ; or omit entirely
481484

482485
;; Specific tools only
483-
{:enable-tools [:read-file :grep]}
486+
{:enable-tools [:read_file :grep]}
484487

485488
;; All tools except some
486489
{:enable-tools [:all]
487-
:disable-tools [:bash :file-write]}
490+
:disable-tools [:bash :file_write]}
488491
```
489492

490493
## Caching and Performance
@@ -507,7 +510,7 @@ Examples:
507510
### No Tools Available
508511
- Remember: agents have no tools by default
509512
- Explicitly list tools in `:enable-tools`
510-
- Check tool IDs match exactly (e.g., `:read-file` not `:read_file`)
513+
- Check tool IDs match exactly (use underscores: `:read_file` not `:read-file`)
511514

512515
### Model Not Found
513516
- Verify model is defined in `:models` configuration
@@ -517,7 +520,7 @@ Examples:
517520
### Tools Not Working
518521
- Verify tool IDs in `:enable-tools` match available tools
519522
- Check that tools aren't disabled in `:disable-tools`
520-
- Ensure the agent has the necessary tool combination (e.g., needs `:read-file` before `:clojure-edit`)
523+
- Ensure the agent has the necessary tool combination (e.g., needs `:read_file` before `:clojure_edit`)
521524

522525
### Memory Issues
523526
- **Agent doesn't remember previous conversation**: Check if `:memory-size` is `>= 10` for persistent memory
@@ -541,7 +544,7 @@ If you have existing agent configurations:
541544
### Migration Steps
542545
1. Review existing agent configs
543546
2. Add explicit `:enable-tools` lists
544-
3. For read-only agents, add: `:enable-tools [:read-file :grep :glob-files ...]`
547+
3. For read-only agents, add: `:enable-tools [:read_file :grep :glob_files ...]`
545548
4. Test thoroughly before deploying
546549

547550
## Integration with MCP Server

resources/clojure-mcp/agents/clojure_edit_agent.edn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ The agent will read the file, identify the locations to change based on context,
5959
6060
Remember: Prefer structural editing tools over text-based editing for reliability and to maintain proper Clojure syntax."
6161
:context false
62-
:include-mentioned-files true
6362
:enable-tools :all
6463
:disable-tools [:scratch_pad]
6564
:track-file-changes true}

resources/configs/example-agents.edn

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@
1414
:system-message "You are a research specialist focused on finding code patterns, examples, and understanding project structure. Be thorough in your analysis and provide specific file locations and code snippets."
1515
:model :anthropic/claude-3-5-sonnet-20241022 ; Optional: specific model
1616
:context true ; Use default project context (PROJECT_SUMMARY.md and code index)
17-
:enable-tools [:grep :glob-files :read-file :clojure-inspect-project] ; Must specify tools explicitly
17+
:enable-tools [:grep :glob_files :read_file :clojure_inspect_project] ; Must specify tools explicitly
1818
:disable-tools nil}
1919

2020
{:id :refactor-assistant
2121
:name "refactor_assistant"
2222
:description "Agent specialized in analyzing code for refactoring opportunities"
2323
:system-message "You are a refactoring specialist. Analyze code for patterns that could be improved, suggest better abstractions, and identify duplicate code. Focus on readability and maintainability."
2424
:context ["PROJECT_SUMMARY.md" "doc/LLM_CODE_STYLE.md"] ; Specific files for context
25-
:enable-tools [:read-file :grep :glob-files]
25+
:enable-tools [:read_file :grep :glob_files]
2626
:disable-tools [:bash]}
2727

2828
{:id :test-explorer
2929
:name "test_explorer"
3030
:description "Agent for exploring and understanding test files"
3131
:system-message "You are a test exploration specialist. Help understand test structure, find relevant tests, and explain test patterns. Be concise and focus on test-specific insights."
3232
:context false ; No default context
33-
:enable-tools [:read-file :glob-files :grep]
34-
:disable-tools [:bash :clojure-inspect-project]}
33+
:enable-tools [:read_file :glob_files :grep]
34+
:disable-tools [:bash :clojure_inspect_project]}
3535

3636
{:id :doc-reader
3737
:name "doc_reader"
3838
:description "Agent optimized for reading and summarizing documentation"
3939
:system-message "You are a documentation specialist. Read and summarize documentation clearly and concisely. Focus on key concepts and practical usage."
4040
;; model not specified - will use default
4141
:context ["README.md" "doc/"] ; Documentation-focused context
42-
:enable-tools [:read-file :glob-files]
42+
:enable-tools [:read_file :glob_files]
4343
:disable-tools [:grep :bash]}
4444

4545
{:id :code-writer
@@ -48,8 +48,8 @@
4848
:system-message "You are a code writing assistant. You can create new files, edit existing ones, and refactor code. Always test code in the REPL before writing to files."
4949
:context true
5050
;; Can evaluate code and write files
51-
:enable-tools [:clojure-eval :file-write :file-edit :clojure-edit
52-
:clojure-edit-replace-sexp :read-file :grep :glob-files]
51+
:enable-tools [:clojure_eval :file_write :file_edit :clojure_edit
52+
:clojure_edit_replace_sexp :read_file :grep :glob_files]
5353
:disable-tools nil}
5454

5555
{:id :full-access-agent
@@ -59,7 +59,7 @@
5959
:context true
6060
;; Special keyword :all enables all tools
6161
:enable-tools [:all] ; Gives access to every available tool
62-
:disable-tools [:dispatch-agent]}] ; But still can disable specific ones
62+
:disable-tools [:dispatch_agent]}] ; But still can disable specific ones
6363

6464
;; Optional: Define custom models for agents to use
6565
:models {:anthropic/claude-3-5-sonnet-20241022

src/clojure_mcp/agent/langchain/model.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns clojure-mcp.agent.langchain.model
22
(:require
33
[clojure.string :as string]
4-
[clojure-mcp.agent.langchain.model-spec :as spec]
4+
[clojure-mcp.config.schema :as schema]
55
[clojure-mcp.config :as config]
66
[clojure.tools.logging :as log])
77
(:import
@@ -403,8 +403,8 @@
403403
(as-> cfg (ensure-api-key cfg (:provider cfg))))]
404404
;; Validate if requested
405405
(when validate?
406-
(spec/validate-model-key model-key)
407-
(spec/validate-config-for-provider config))
406+
(schema/validate-model-key model-key)
407+
(schema/validate-config-for-provider config))
408408
(create-builder config))))
409409

410410
(defn create-builder-from-config
@@ -427,7 +427,7 @@
427427
(ensure-api-key final-provider))]
428428
;; Validate if requested
429429
(when validate?
430-
(spec/validate-config-for-provider final-config))
430+
(schema/validate-config-for-provider final-config))
431431
(create-builder final-config))))
432432

433433
(defn build-model
@@ -511,8 +511,8 @@
511511
final-config (ensure-api-key config-with-provider provider)]
512512
;; Validate if requested
513513
(when validate?
514-
(spec/validate-model-key model-key)
515-
(spec/validate-config-for-provider final-config))
514+
(schema/validate-model-key model-key)
515+
(schema/validate-config-for-provider final-config))
516516
;; Create builder
517517
(create-builder final-config))))
518518

0 commit comments

Comments
 (0)