@jayarrowz/mcp-arsr 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -125
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,125 +1,161 @@
|
|
|
1
|
-
# ARSR MCP Server
|
|
2
|
-
|
|
3
|
-
**Adaptive Retrieval-Augmented Self-Refinement** — a closed-loop MCP server that lets LLMs iteratively verify and correct their own claims using uncertainty-guided retrieval.
|
|
4
|
-
|
|
5
|
-
## What it does
|
|
6
|
-
|
|
7
|
-
Unlike one-shot RAG (retrieve → generate), ARSR runs a refinement loop:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
Generate draft → Decompose claims → Score uncertainty
|
|
11
|
-
↑ ↓
|
|
12
|
-
Decide stop ← Revise with evidence ← Retrieve for low-confidence claims
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
The key insight: **retrieval is guided by uncertainty**. Only claims the model is unsure about trigger evidence fetching, and the queries are adversarial — designed to *disprove* the claim, not just confirm it.
|
|
16
|
-
|
|
17
|
-
## Architecture
|
|
18
|
-
|
|
19
|
-
The server exposes 6 MCP tools. The outer LLM (Claude, GPT, etc.) orchestrates the loop by calling them in sequence:
|
|
20
|
-
|
|
21
|
-
| # | Tool | Purpose |
|
|
22
|
-
|---|------|---------|
|
|
23
|
-
| 1 | `arsr_draft_response` | Generate initial candidate answer (returns `is_refusal` flag) |
|
|
24
|
-
| 2 | `arsr_decompose_claims` | Split into atomic verifiable claims |
|
|
25
|
-
| 3 | `arsr_score_uncertainty` | Estimate confidence via semantic entropy |
|
|
26
|
-
| 4 | `arsr_retrieve_evidence` | Web search for low-confidence claims |
|
|
27
|
-
| 5 | `arsr_revise_response` | Rewrite draft with evidence |
|
|
28
|
-
| 6 | `arsr_should_continue` | Decide: iterate or finalize |
|
|
29
|
-
|
|
30
|
-
**Inner LLM**: Tools 1-5 use Claude Haiku internally for intelligence (query generation, claim extraction, evidence evaluation). This keeps costs low while the outer model handles orchestration.
|
|
31
|
-
|
|
32
|
-
**Refusal detection**: `arsr_draft_response` returns a structured `is_refusal` flag (classified by the inner LLM) indicating whether the draft is a non-answer. When `is_refusal` is true, downstream tools (`decompose`, `revise`) pivot to extracting claims from the original query and building an answer from retrieved evidence instead of trying to refine a refusal.
|
|
33
|
-
|
|
34
|
-
**Web Search**: `arsr_retrieve_evidence` uses the Anthropic API's built-in web search tool — no external search API keys needed.
|
|
35
|
-
|
|
36
|
-
## Setup
|
|
37
|
-
|
|
38
|
-
### Prerequisites
|
|
39
|
-
|
|
40
|
-
- Node.js 18+
|
|
41
|
-
- An Anthropic API key
|
|
42
|
-
|
|
43
|
-
### Install & Build
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
cd arsr-mcp-server
|
|
47
|
-
npm install
|
|
48
|
-
npm run build
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Environment
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Run
|
|
58
|
-
|
|
59
|
-
**stdio mode** (for Claude Desktop, Cursor, etc.):
|
|
60
|
-
```bash
|
|
61
|
-
npm start
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
**HTTP mode** (for remote access):
|
|
65
|
-
```bash
|
|
66
|
-
TRANSPORT=http PORT=3001 npm start
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Claude Desktop Configuration
|
|
70
|
-
|
|
71
|
-
Add to your `claude_desktop_config.json`:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
1
|
+
# ARSR MCP Server
|
|
2
|
+
|
|
3
|
+
**Adaptive Retrieval-Augmented Self-Refinement** — a closed-loop MCP server that lets LLMs iteratively verify and correct their own claims using uncertainty-guided retrieval.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
Unlike one-shot RAG (retrieve → generate), ARSR runs a refinement loop:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Generate draft → Decompose claims → Score uncertainty
|
|
11
|
+
↑ ↓
|
|
12
|
+
Decide stop ← Revise with evidence ← Retrieve for low-confidence claims
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The key insight: **retrieval is guided by uncertainty**. Only claims the model is unsure about trigger evidence fetching, and the queries are adversarial — designed to *disprove* the claim, not just confirm it.
|
|
16
|
+
|
|
17
|
+
## Architecture
|
|
18
|
+
|
|
19
|
+
The server exposes 6 MCP tools. The outer LLM (Claude, GPT, etc.) orchestrates the loop by calling them in sequence:
|
|
20
|
+
|
|
21
|
+
| # | Tool | Purpose |
|
|
22
|
+
|---|------|---------|
|
|
23
|
+
| 1 | `arsr_draft_response` | Generate initial candidate answer (returns `is_refusal` flag) |
|
|
24
|
+
| 2 | `arsr_decompose_claims` | Split into atomic verifiable claims |
|
|
25
|
+
| 3 | `arsr_score_uncertainty` | Estimate confidence via semantic entropy |
|
|
26
|
+
| 4 | `arsr_retrieve_evidence` | Web search for low-confidence claims |
|
|
27
|
+
| 5 | `arsr_revise_response` | Rewrite draft with evidence |
|
|
28
|
+
| 6 | `arsr_should_continue` | Decide: iterate or finalize |
|
|
29
|
+
|
|
30
|
+
**Inner LLM**: Tools 1-5 use Claude Haiku internally for intelligence (query generation, claim extraction, evidence evaluation). This keeps costs low while the outer model handles orchestration.
|
|
31
|
+
|
|
32
|
+
**Refusal detection**: `arsr_draft_response` returns a structured `is_refusal` flag (classified by the inner LLM) indicating whether the draft is a non-answer. When `is_refusal` is true, downstream tools (`decompose`, `revise`) pivot to extracting claims from the original query and building an answer from retrieved evidence instead of trying to refine a refusal.
|
|
33
|
+
|
|
34
|
+
**Web Search**: `arsr_retrieve_evidence` uses the Anthropic API's built-in web search tool — no external search API keys needed.
|
|
35
|
+
|
|
36
|
+
## Setup
|
|
37
|
+
|
|
38
|
+
### Prerequisites
|
|
39
|
+
|
|
40
|
+
- Node.js 18+
|
|
41
|
+
- An Anthropic API key
|
|
42
|
+
|
|
43
|
+
### Install & Build
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
cd arsr-mcp-server
|
|
47
|
+
npm install
|
|
48
|
+
npm run build
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Environment
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Run
|
|
58
|
+
|
|
59
|
+
**stdio mode** (for Claude Desktop, Cursor, etc.):
|
|
60
|
+
```bash
|
|
61
|
+
npm start
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**HTTP mode** (for remote access):
|
|
65
|
+
```bash
|
|
66
|
+
TRANSPORT=http PORT=3001 npm start
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Claude Desktop Configuration
|
|
70
|
+
|
|
71
|
+
Add to your `claude_desktop_config.json`:
|
|
72
|
+
|
|
73
|
+
Npm:
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"mcpServers": {
|
|
77
|
+
"arsr": {
|
|
78
|
+
"command": "npx",
|
|
79
|
+
"args": ["@jayarrowz/mcp-arsr"],
|
|
80
|
+
"env": {
|
|
81
|
+
"ANTHROPIC_API_KEY": "sk-ant-...",
|
|
82
|
+
"ARSR_MAX_ITERATIONS": "3",
|
|
83
|
+
"ARSR_ENTROPY_SAMPLES": "3",
|
|
84
|
+
"ARSR_RETRIEVAL_STRATEGY": "adversarial",
|
|
85
|
+
"ARSR_INNER_MODEL": "claude-haiku-4-5-20251001"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Local build:
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"arsr": {
|
|
97
|
+
"command": "node",
|
|
98
|
+
"args": ["/path/to/arsr-mcp-server/dist/src/index.js"],
|
|
99
|
+
"env": {
|
|
100
|
+
"ANTHROPIC_API_KEY": "sk-ant-...",
|
|
101
|
+
"ARSR_MAX_ITERATIONS": "3",
|
|
102
|
+
"ARSR_ENTROPY_SAMPLES": "3",
|
|
103
|
+
"ARSR_RETRIEVAL_STRATEGY": "adversarial",
|
|
104
|
+
"ARSR_INNER_MODEL": "claude-haiku-4-5-20251001"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## How the outer LLM uses it
|
|
112
|
+
|
|
113
|
+
The orchestrating LLM calls the tools in sequence:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
1. draft = arsr_draft_response({ query: "When was Tesla founded?" })
|
|
117
|
+
// draft.is_refusal indicates if the inner LLM refused to answer
|
|
118
|
+
2. claims = arsr_decompose_claims({ draft: draft.draft, original_query: "When was Tesla founded?", is_refusal: draft.is_refusal })
|
|
119
|
+
3. scored = arsr_score_uncertainty({ claims: claims.claims })
|
|
120
|
+
4. low = scored.scored.filter(c => c.confidence < 0.85)
|
|
121
|
+
5. evidence = arsr_retrieve_evidence({ claims_to_check: low })
|
|
122
|
+
6. revised = arsr_revise_response({ draft: draft.draft, evidence: evidence.evidence, scored: scored.scored, original_query: "When was Tesla founded?", is_refusal: draft.is_refusal })
|
|
123
|
+
7. decision = arsr_should_continue({ iteration: 1, scored: revised_scores })
|
|
124
|
+
→ if "continue": go to step 2 with revised text
|
|
125
|
+
→ if "stop": return revised.revised to user
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Configuration
|
|
129
|
+
|
|
130
|
+
All settings can be overridden via environment variables, falling back to defaults if unset:
|
|
131
|
+
|
|
132
|
+
| Setting | Env var | Default | Description |
|
|
133
|
+
|---------|---------|---------|-------------|
|
|
134
|
+
| `max_iterations` | `ARSR_MAX_ITERATIONS` | `3` | Budget limit for refinement loops |
|
|
135
|
+
| `confidence_threshold` | `ARSR_CONFIDENCE_THRESHOLD` | `0.85` | Claims above this skip retrieval |
|
|
136
|
+
| `entropy_samples` | `ARSR_ENTROPY_SAMPLES` | `3` | Rephrasings for semantic entropy |
|
|
137
|
+
| `retrieval_strategy` | `ARSR_RETRIEVAL_STRATEGY` | `adversarial` | `adversarial`, `confirmatory`, or `balanced` |
|
|
138
|
+
| `inner_model` | `ARSR_INNER_MODEL` | `claude-haiku-4-5-20251001` | Model for internal intelligence |
|
|
139
|
+
|
|
140
|
+
## Cost estimate
|
|
141
|
+
|
|
142
|
+
Per refinement loop iteration (assuming ~5 claims, 3 low-confidence):
|
|
143
|
+
- Inner LLM calls: ~6-10 Haiku calls ≈ $0.002-0.005
|
|
144
|
+
- Web searches: 6-9 queries ≈ included in API
|
|
145
|
+
- Typical total for 2 iterations: **< $0.02**
|
|
146
|
+
|
|
147
|
+
## Images
|
|
148
|
+
|
|
149
|
+
Before:
|
|
150
|
+
|
|
151
|
+
<img width="956" height="977" alt="claude_596yXSQSOh" src="https://github.com/user-attachments/assets/95771a10-8a29-4900-b128-67af3cbc05bd" />
|
|
152
|
+
|
|
153
|
+
After:
|
|
154
|
+
|
|
155
|
+
<img width="856" height="866" alt="claude_UagHKfgqDz" src="https://github.com/user-attachments/assets/340e8011-4c2d-4e95-9c4d-43a55e87b7be" />
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayarrowz/mcp-arsr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Adaptive Retrieval-Augmented Self-Refinement MCP Server — a closed-loop system that lets LLMs iteratively verify and correct their own claims using uncertainty-guided retrieval.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jay Arrowz (https://github.com/jayarrowz)",
|