prompt-clarifier-mcp 2.0.0 → 3.0.0
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/LICENSE +21 -0
- package/README.md +120 -77
- package/dist/clarifier.d.ts +3 -1
- package/dist/clarifier.d.ts.map +1 -1
- package/dist/clarifier.js +48 -34
- package/dist/clarifier.js.map +1 -1
- package/dist/index.js +30 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Didou555
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,92 +1,115 @@
|
|
|
1
1
|
# Prompt Clarifier — MCP Agent
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Stop the back-and-forth with your LLM. This agent asks the right questions before executing your request.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## How it works
|
|
6
6
|
|
|
7
7
|
```
|
|
8
|
-
|
|
8
|
+
You write: "Create an ONNX model without opset"
|
|
9
9
|
↓
|
|
10
|
-
|
|
10
|
+
The MCP server detects the domain and returns a system prompt
|
|
11
11
|
↓
|
|
12
|
-
|
|
12
|
+
Your IDE's own LLM asks targeted questions (no external LLM)
|
|
13
13
|
↓
|
|
14
|
-
|
|
14
|
+
You answer (or type "go" to stop)
|
|
15
15
|
↓
|
|
16
|
-
|
|
16
|
+
An enriched, precise prompt is generated
|
|
17
|
+
↓
|
|
18
|
+
Your LLM produces exactly what you wanted — on the first try
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
---
|
|
20
22
|
|
|
21
|
-
##
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
The MCP server is **LLM-agnostic**: it makes no external API calls and requires no API key.
|
|
26
|
+
|
|
27
|
+
| Responsibility | Who handles it |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| Domain detection | MCP server |
|
|
30
|
+
| Session state (Q&A history) | MCP server |
|
|
31
|
+
| Question generation | Your IDE's LLM (Junie, Cursor, Claude Code, Copilot…) |
|
|
32
|
+
| Knowledge base search | Your IDE's LLM (Confluence, Notion, etc.) |
|
|
33
|
+
|
|
34
|
+
**Call flow:**
|
|
35
|
+
|
|
36
|
+
- **First call** (`prompt`) — the server creates a session, detects the domain, and returns a `system_prompt` + `user_message` that your IDE injects into its LLM to generate the first question.
|
|
37
|
+
- **Subsequent calls** (`session_id` + `answer`) — the server saves the answer and returns an updated `system_prompt`. After 5 answers or the word "go", it returns the enriched `final_prompt`.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Automatically detected domains
|
|
42
|
+
|
|
43
|
+
| Domain | Detected patterns | Question focus |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| `ml_onnx` | `onnx` | runtime, opset, tensor shapes, operators |
|
|
46
|
+
| `ml_h2o` | `h2o`, `automl`, `gbm`, `mojo`, `pojo` | algorithm type, target variable, export format |
|
|
47
|
+
| `data_table` | `datatable`, `schema`, `dataframe`, `column` | schema, data types, volume, use case |
|
|
48
|
+
| `ml_general` | `pytorch`, `tensorflow`, `sklearn`, `model`… | framework, task type, data format |
|
|
49
|
+
| `general` | (everything else) | objective, environment, existing context |
|
|
22
50
|
|
|
23
|
-
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Knowledge base search
|
|
24
54
|
|
|
25
|
-
|
|
26
|
-
- Crée-en une sur [console.anthropic.com](https://console.anthropic.com)
|
|
27
|
-
- Ajoute-la dans la config MCP de ton outil (voir exemples ci-dessous)
|
|
55
|
+
The returned system prompt instructs your IDE's LLM to **search connected knowledge bases first** (Confluence, Notion, or any connected documentation tool) before formulating questions. This produces questions tailored to your organization's actual standards and workflows rather than generic ones.
|
|
28
56
|
|
|
29
57
|
---
|
|
30
58
|
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
> **No API key required.** The server makes no external LLM calls.
|
|
62
|
+
|
|
31
63
|
### Cursor
|
|
32
64
|
|
|
33
|
-
|
|
65
|
+
Open `~/.cursor/mcp.json` (create it if it does not exist):
|
|
34
66
|
|
|
35
67
|
```json
|
|
36
68
|
{
|
|
37
69
|
"mcpServers": {
|
|
38
70
|
"prompt-clarifier": {
|
|
39
71
|
"command": "npx",
|
|
40
|
-
"args": ["-y", "prompt-clarifier-mcp"]
|
|
41
|
-
"env": {
|
|
42
|
-
"ANTHROPIC_API_KEY": "sk-ant-..."
|
|
43
|
-
}
|
|
72
|
+
"args": ["-y", "prompt-clarifier-mcp"]
|
|
44
73
|
}
|
|
45
74
|
}
|
|
46
75
|
}
|
|
47
76
|
```
|
|
48
77
|
|
|
49
|
-
|
|
78
|
+
Restart Cursor. The `clarify` tool is now available.
|
|
50
79
|
|
|
51
80
|
---
|
|
52
81
|
|
|
53
82
|
### Claude Desktop
|
|
54
83
|
|
|
55
|
-
|
|
56
|
-
- **Windows
|
|
57
|
-
- **macOS
|
|
84
|
+
Open the config file:
|
|
85
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
86
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
58
87
|
|
|
59
88
|
```json
|
|
60
89
|
{
|
|
61
90
|
"mcpServers": {
|
|
62
91
|
"prompt-clarifier": {
|
|
63
92
|
"command": "npx",
|
|
64
|
-
"args": ["-y", "prompt-clarifier-mcp"]
|
|
65
|
-
"env": {
|
|
66
|
-
"ANTHROPIC_API_KEY": "sk-ant-..."
|
|
67
|
-
}
|
|
93
|
+
"args": ["-y", "prompt-clarifier-mcp"]
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
96
|
}
|
|
71
97
|
```
|
|
72
98
|
|
|
73
|
-
|
|
99
|
+
Restart Claude Desktop.
|
|
74
100
|
|
|
75
101
|
---
|
|
76
102
|
|
|
77
|
-
### VS Code (
|
|
103
|
+
### VS Code (with GitHub Copilot or Continue)
|
|
78
104
|
|
|
79
|
-
|
|
105
|
+
Create or open `.vscode/mcp.json` at the root of your project:
|
|
80
106
|
|
|
81
107
|
```json
|
|
82
108
|
{
|
|
83
109
|
"servers": {
|
|
84
110
|
"prompt-clarifier": {
|
|
85
111
|
"command": "npx",
|
|
86
|
-
"args": ["-y", "prompt-clarifier-mcp"]
|
|
87
|
-
"env": {
|
|
88
|
-
"ANTHROPIC_API_KEY": "sk-ant-..."
|
|
89
|
-
}
|
|
112
|
+
"args": ["-y", "prompt-clarifier-mcp"]
|
|
90
113
|
}
|
|
91
114
|
}
|
|
92
115
|
}
|
|
@@ -94,20 +117,18 @@ Crée ou ouvre `.vscode/mcp.json` à la racine de ton projet :
|
|
|
94
117
|
|
|
95
118
|
---
|
|
96
119
|
|
|
97
|
-
### IntelliJ IDEA / PyCharm (
|
|
120
|
+
### IntelliJ IDEA / PyCharm (2025.1+)
|
|
98
121
|
|
|
99
|
-
1.
|
|
100
|
-
2.
|
|
101
|
-
3.
|
|
102
|
-
4.
|
|
103
|
-
- **Name
|
|
104
|
-
- **Command
|
|
105
|
-
- **Arguments
|
|
106
|
-
|
|
107
|
-
5. Clique `OK` et redémarre l'IDE
|
|
122
|
+
1. Open `Settings` → `Tools` → `AI Assistant` → `Model Context Protocol (MCP)`
|
|
123
|
+
2. Click `+` to add a new server
|
|
124
|
+
3. Choose **"Command"** as the type
|
|
125
|
+
4. Fill in:
|
|
126
|
+
- **Name**: `prompt-clarifier`
|
|
127
|
+
- **Command**: `npx`
|
|
128
|
+
- **Arguments**: `-y prompt-clarifier-mcp`
|
|
129
|
+
5. Click `OK` and restart the IDE
|
|
108
130
|
|
|
109
|
-
>
|
|
110
|
-
> Active le mode **"Codebase"** dans le chat AI Assistant pour que les outils MCP soient disponibles.
|
|
131
|
+
> Enable **"Codebase"** mode in the AI Assistant chat for MCP tools to be available.
|
|
111
132
|
|
|
112
133
|
---
|
|
113
134
|
|
|
@@ -117,66 +138,88 @@ Crée ou ouvre `.vscode/mcp.json` à la racine de ton projet :
|
|
|
117
138
|
claude mcp add prompt-clarifier npx -- -y prompt-clarifier-mcp
|
|
118
139
|
```
|
|
119
140
|
|
|
120
|
-
Puis ajoute la clé API dans ton environnement ou dans `.claude/settings.json` :
|
|
121
|
-
```json
|
|
122
|
-
{
|
|
123
|
-
"env": {
|
|
124
|
-
"ANTHROPIC_API_KEY": "sk-ant-..."
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
141
|
---
|
|
130
142
|
|
|
131
|
-
##
|
|
143
|
+
## Usage
|
|
132
144
|
|
|
133
|
-
|
|
145
|
+
In any IDE chat, call the `clarify` tool with your prompt:
|
|
134
146
|
|
|
135
|
-
**Exemple :**
|
|
136
147
|
```
|
|
137
|
-
|
|
148
|
+
Use the clarify tool with this prompt: "Create an ONNX model without opset"
|
|
138
149
|
```
|
|
139
150
|
|
|
140
|
-
|
|
141
|
-
1.
|
|
142
|
-
2.
|
|
143
|
-
3.
|
|
151
|
+
The server will:
|
|
152
|
+
1. Detect the domain (`ml_onnx` in this example)
|
|
153
|
+
2. Return a system prompt your LLM uses to ask targeted questions
|
|
154
|
+
3. Record each answer in the session
|
|
155
|
+
4. Generate the enriched prompt after 5 answers or as soon as you type **"go"**
|
|
156
|
+
|
|
157
|
+
**To stop questions at any time**, simply write:
|
|
158
|
+
- `go` / `commence` / `start` / `proceed` / `just do it` / `enough`
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Response format
|
|
163
|
+
|
|
164
|
+
**First call:**
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"session_id": "uuid",
|
|
168
|
+
"system_prompt": "...",
|
|
169
|
+
"user_message": "Here is the user prompt to clarify: ...",
|
|
170
|
+
"instructions": "Ask the first clarifying question now. Include the session_id..."
|
|
171
|
+
}
|
|
172
|
+
```
|
|
144
173
|
|
|
145
|
-
**
|
|
146
|
-
|
|
174
|
+
**Subsequent calls:**
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"session_id": "uuid",
|
|
178
|
+
"system_prompt": "...",
|
|
179
|
+
"user_message": "The user answered: ... Ask the next question.",
|
|
180
|
+
"qa_count": 2
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Final response:**
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"final_prompt": "Initial prompt\n\n## Additional context collected\n..."
|
|
188
|
+
}
|
|
189
|
+
```
|
|
147
190
|
|
|
148
191
|
---
|
|
149
192
|
|
|
150
|
-
##
|
|
193
|
+
## Requirements
|
|
151
194
|
|
|
152
|
-
- Node.js 18
|
|
153
|
-
-
|
|
195
|
+
- Node.js 18 or higher
|
|
196
|
+
- An IDE with MCP support (see list above)
|
|
154
197
|
|
|
155
198
|
---
|
|
156
199
|
|
|
157
|
-
##
|
|
200
|
+
## Local development
|
|
158
201
|
|
|
159
202
|
```bash
|
|
160
|
-
git clone https://github.com/
|
|
161
|
-
cd prompt-
|
|
203
|
+
git clone https://github.com/Didou555/prompt-clarifer
|
|
204
|
+
cd prompt-clarifer
|
|
162
205
|
npm install
|
|
163
206
|
npm run build
|
|
164
207
|
|
|
165
|
-
#
|
|
208
|
+
# Test with the MCP inspector
|
|
166
209
|
npx @modelcontextprotocol/inspector node dist/index.js
|
|
167
210
|
```
|
|
168
211
|
|
|
169
212
|
---
|
|
170
213
|
|
|
171
|
-
##
|
|
214
|
+
## Contributing
|
|
172
215
|
|
|
173
|
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
216
|
+
Contributions are welcome! In particular:
|
|
217
|
+
- New domain detection patterns (`src/clarifier.ts` → `detectDomain`)
|
|
218
|
+
- New stop keywords in other languages (`GO_KEYWORDS`)
|
|
219
|
+
- New question angles per domain (`DOMAIN_ANGLES`)
|
|
177
220
|
|
|
178
221
|
---
|
|
179
222
|
|
|
180
|
-
##
|
|
223
|
+
## License
|
|
181
224
|
|
|
182
|
-
MIT
|
|
225
|
+
MIT
|
package/dist/clarifier.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { QA } from "./session.js";
|
|
2
2
|
export declare function isGoSignal(text: string): boolean;
|
|
3
|
-
export
|
|
3
|
+
export type Domain = "ml_onnx" | "ml_h2o" | "data_table" | "ml_general" | "general";
|
|
4
|
+
export declare function detectDomain(prompt: string): Domain;
|
|
5
|
+
export declare function buildClarifySystemPrompt(initialPrompt: string, qaHistory: QA[], domain: Domain): string;
|
|
4
6
|
export declare function buildEnrichedPrompt(initialPrompt: string, qaHistory: QA[]): string;
|
|
5
7
|
//# sourceMappingURL=clarifier.d.ts.map
|
package/dist/clarifier.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clarifier.d.ts","sourceRoot":"","sources":["../src/clarifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clarifier.d.ts","sourceRoot":"","sources":["../src/clarifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAOlC,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQhD;AAED,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;AAEpF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnD;AAmBD,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,EAAE,EAAE,EACf,MAAM,EAAE,MAAM,GACb,MAAM,CAmCR;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,MAAM,CAelF"}
|
package/dist/clarifier.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.isGoSignal = isGoSignal;
|
|
7
|
-
exports.
|
|
4
|
+
exports.detectDomain = detectDomain;
|
|
5
|
+
exports.buildClarifySystemPrompt = buildClarifySystemPrompt;
|
|
8
6
|
exports.buildEnrichedPrompt = buildEnrichedPrompt;
|
|
9
|
-
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
10
7
|
const GO_KEYWORDS = [
|
|
11
8
|
"go", "commence", "start", "c'est bon", "lance toi", "lance-toi",
|
|
12
9
|
"démarre", "ok go", "assez", "enough", "proceed", "just do it",
|
|
@@ -17,42 +14,59 @@ function isGoSignal(text) {
|
|
|
17
14
|
normalized.startsWith(kw + " ") ||
|
|
18
15
|
normalized.endsWith(" " + kw));
|
|
19
16
|
}
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
function detectDomain(prompt) {
|
|
18
|
+
if (/onnx/i.test(prompt))
|
|
19
|
+
return "ml_onnx";
|
|
20
|
+
if (/h2o|automl|gbm|mojo|pojo/i.test(prompt))
|
|
21
|
+
return "ml_h2o";
|
|
22
|
+
if (/data.?table|schema|dataframe|column/i.test(prompt))
|
|
23
|
+
return "data_table";
|
|
24
|
+
if (/machine.?learn|deep.?learn|neural|pytorch|tensorflow|sklearn|model|train|predict|classif|regress/i.test(prompt))
|
|
25
|
+
return "ml_general";
|
|
26
|
+
return "general";
|
|
27
|
+
}
|
|
28
|
+
const KB_PREAMBLE = `Before asking your first question, search your connected knowledge bases (Confluence, Notion, or any connected documentation tool) for pages related to the user's request and to your company's internal standards, processes, and best practices relevant to this topic. Use that context to ask questions that are specific to your organization's actual workflow and constraints, rather than generic questions. If no relevant internal documentation is found, fall back to domain best practices.
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
Examples of what to search for depending on the detected domain:
|
|
31
|
+
- ONNX model → model validation process, opset standards, deployment pipeline
|
|
32
|
+
- H2O model → AutoML configuration, MOJO export standards, validation criteria
|
|
33
|
+
- Data table → schema conventions, naming standards, data governance rules
|
|
34
|
+
- General coding → architecture guidelines, code review standards, tech stack
|
|
35
|
+
- General request → any internal process or standard related to the topic`;
|
|
36
|
+
const DOMAIN_ANGLES = {
|
|
37
|
+
ml_onnx: "Focus on: runtime, opset version, input/output tensor shapes, operators needed.",
|
|
38
|
+
ml_h2o: "Focus on: algorithm type (GBM/DRF/AutoML), target variable, feature types, export format (MOJO/POJO), training constraints.",
|
|
39
|
+
data_table: "Focus on: schema/columns, data types, volume, relationships, use case (reporting/ML/API).",
|
|
40
|
+
ml_general: "Focus on: framework, task type, data format, performance constraints.",
|
|
41
|
+
general: "Focus on: objective, language/environment, existing context, edge cases.",
|
|
42
|
+
};
|
|
43
|
+
function buildClarifySystemPrompt(initialPrompt, qaHistory, domain) {
|
|
32
44
|
const historyText = qaHistory.length > 0
|
|
33
45
|
? qaHistory
|
|
34
|
-
.map((qa, i) =>
|
|
46
|
+
.map((qa, i) => qa.question
|
|
47
|
+
? `Q${i + 1}: ${qa.question}\nA${i + 1}: ${qa.answer}`
|
|
48
|
+
: `A${i + 1}: ${qa.answer}`)
|
|
35
49
|
.join("\n\n")
|
|
36
|
-
: "
|
|
37
|
-
const
|
|
38
|
-
|
|
50
|
+
: "No questions asked yet.";
|
|
51
|
+
const shouldStop = qaHistory.length >= 5 ||
|
|
52
|
+
(qaHistory.length > 0 && isGoSignal(qaHistory[qaHistory.length - 1].answer));
|
|
53
|
+
return `${KB_PREAMBLE}
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
You are a prompt clarification assistant. Your task is to iteratively refine a user's prompt by asking targeted questions.
|
|
39
58
|
|
|
40
|
-
|
|
59
|
+
Initial prompt: "${initialPrompt}"
|
|
60
|
+
|
|
61
|
+
Q&A history so far:
|
|
41
62
|
${historyText}
|
|
42
63
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
const text = response.content[0].type === "text"
|
|
51
|
-
? response.content[0].text.trim()
|
|
52
|
-
: "";
|
|
53
|
-
if (text.toUpperCase() === "DONE" || text === "")
|
|
54
|
-
return null;
|
|
55
|
-
return text;
|
|
64
|
+
Detected domain: ${domain}
|
|
65
|
+
${DOMAIN_ANGLES[domain]}
|
|
66
|
+
|
|
67
|
+
${shouldStop
|
|
68
|
+
? "You have enough information. Return ONLY the final enriched prompt, incorporating all answers collected so far. Do not ask any more questions."
|
|
69
|
+
: "Ask the single most relevant next clarifying question for this domain and context. Output ONLY the question — no preamble, no explanation, no punctuation beyond the question mark."}`;
|
|
56
70
|
}
|
|
57
71
|
function buildEnrichedPrompt(initialPrompt, qaHistory) {
|
|
58
72
|
if (qaHistory.length === 0)
|
package/dist/clarifier.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clarifier.js","sourceRoot":"","sources":["../src/clarifier.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clarifier.js","sourceRoot":"","sources":["../src/clarifier.ts"],"names":[],"mappings":";;AAOA,gCAQC;AAID,oCAMC;AAmBD,4DAuCC;AAED,kDAeC;AAlGD,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW;IAChE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY;CAC/D,CAAC;AAEF,SAAgB,UAAU,CAAC,IAAY;IACrC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7C,OAAO,WAAW,CAAC,IAAI,CACrB,CAAC,EAAE,EAAE,EAAE,CACL,UAAU,KAAK,EAAE;QACjB,UAAU,CAAC,UAAU,CAAC,EAAE,GAAG,GAAG,CAAC;QAC/B,UAAU,CAAC,QAAQ,CAAC,GAAG,GAAG,EAAE,CAAC,CAChC,CAAC;AACJ,CAAC;AAID,SAAgB,YAAY,CAAC,MAAc;IACzC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC9D,IAAI,sCAAsC,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,YAAY,CAAC;IAC7E,IAAI,mGAAmG,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,YAAY,CAAC;IAC1I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AM,OAAO,GAAG,SAAS;SACtB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC;SACjD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO,GAAG,aAAa;;;;EAIvB,OAAO;;;8EAGqE,CAAC;AAC/E,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,26 +6,26 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
|
6
6
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
7
7
|
const session_js_1 = require("./session.js");
|
|
8
8
|
const clarifier_js_1 = require("./clarifier.js");
|
|
9
|
-
const server = new index_js_1.Server({ name: "prompt-clarifier", version: "
|
|
9
|
+
const server = new index_js_1.Server({ name: "prompt-clarifier", version: "3.0.0" }, { capabilities: { tools: {} } });
|
|
10
10
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
|
|
11
11
|
tools: [
|
|
12
12
|
{
|
|
13
13
|
name: "clarify",
|
|
14
|
-
description: "
|
|
14
|
+
description: "Returns a system prompt and user message that instruct the IDE's own LLM to ask targeted clarifying questions one at a time, then produces an enriched prompt once enough context is gathered. The MCP server manages session state only — no LLM calls are made server-side.",
|
|
15
15
|
inputSchema: {
|
|
16
16
|
type: "object",
|
|
17
17
|
properties: {
|
|
18
18
|
prompt: {
|
|
19
19
|
type: "string",
|
|
20
|
-
description: "
|
|
20
|
+
description: "The initial user prompt (required on first call).",
|
|
21
21
|
},
|
|
22
22
|
session_id: {
|
|
23
23
|
type: "string",
|
|
24
|
-
description: "ID
|
|
24
|
+
description: "Session ID returned by a previous call (to continue the conversation).",
|
|
25
25
|
},
|
|
26
26
|
answer: {
|
|
27
27
|
type: "string",
|
|
28
|
-
description: "
|
|
28
|
+
description: "The user's answer to the last clarifying question.",
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
required: [],
|
|
@@ -35,33 +35,27 @@ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
|
|
|
35
35
|
}));
|
|
36
36
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
37
37
|
if (request.params.name !== "clarify") {
|
|
38
|
-
return { content: [{ type: "text", text: `
|
|
38
|
+
return { content: [{ type: "text", text: `Unknown tool: ${request.params.name}` }] };
|
|
39
39
|
}
|
|
40
40
|
const args = request.params.arguments;
|
|
41
41
|
// --- New session ---
|
|
42
42
|
if (!args.session_id) {
|
|
43
43
|
if (!args.prompt) {
|
|
44
44
|
return {
|
|
45
|
-
content: [{ type: "text", text: "
|
|
45
|
+
content: [{ type: "text", text: "Error: `prompt` is required to start a session." }],
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
const session = (0, session_js_1.createSession)(args.prompt);
|
|
49
|
-
const
|
|
50
|
-
if (!firstQuestion) {
|
|
51
|
-
(0, session_js_1.deleteSession)(session.id);
|
|
52
|
-
return {
|
|
53
|
-
content: [{ type: "text", text: (0, clarifier_js_1.buildEnrichedPrompt)(session.initialPrompt, []) }],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
(0, session_js_1.saveSession)(session);
|
|
49
|
+
const domain = (0, clarifier_js_1.detectDomain)(args.prompt);
|
|
57
50
|
return {
|
|
58
51
|
content: [
|
|
59
52
|
{
|
|
60
53
|
type: "text",
|
|
61
54
|
text: JSON.stringify({
|
|
62
55
|
session_id: session.id,
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
system_prompt: (0, clarifier_js_1.buildClarifySystemPrompt)(args.prompt, [], domain),
|
|
57
|
+
user_message: `Here is the user prompt to clarify: ${args.prompt}`,
|
|
58
|
+
instructions: "Ask the first clarifying question now. Include the session_id in your response so the user knows to pass it back.",
|
|
65
59
|
}),
|
|
66
60
|
},
|
|
67
61
|
],
|
|
@@ -71,48 +65,44 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
71
65
|
const session = (0, session_js_1.loadSession)(args.session_id);
|
|
72
66
|
if (!session) {
|
|
73
67
|
return {
|
|
74
|
-
content: [{ type: "text", text: `Session
|
|
68
|
+
content: [{ type: "text", text: `Session not found: ${args.session_id}` }],
|
|
75
69
|
};
|
|
76
70
|
}
|
|
77
71
|
const answer = args.answer ?? "";
|
|
78
|
-
//
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
(0, session_js_1.
|
|
82
|
-
return { content: [{ type: "text", text: enriched }] };
|
|
83
|
-
}
|
|
84
|
-
// Record the answer to the last question asked
|
|
85
|
-
if (session.lastQuestion && answer.trim()) {
|
|
86
|
-
session.qaHistory.push({ question: session.lastQuestion, answer });
|
|
72
|
+
// Save the answer to session
|
|
73
|
+
if (answer.trim()) {
|
|
74
|
+
session.qaHistory.push({ question: "", answer });
|
|
75
|
+
(0, session_js_1.saveSession)(session);
|
|
87
76
|
}
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
if (!nextQuestion) {
|
|
77
|
+
// Go signal or max questions reached → return final enriched prompt
|
|
78
|
+
if ((0, clarifier_js_1.isGoSignal)(answer) || session.qaHistory.length >= 5) {
|
|
91
79
|
const enriched = (0, clarifier_js_1.buildEnrichedPrompt)(session.initialPrompt, session.qaHistory);
|
|
92
80
|
(0, session_js_1.deleteSession)(session.id);
|
|
93
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: JSON.stringify({ final_prompt: enriched }),
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
94
89
|
}
|
|
95
|
-
|
|
96
|
-
(0, session_js_1.saveSession)(session);
|
|
90
|
+
const domain = (0, clarifier_js_1.detectDomain)(session.initialPrompt);
|
|
97
91
|
return {
|
|
98
92
|
content: [
|
|
99
93
|
{
|
|
100
94
|
type: "text",
|
|
101
95
|
text: JSON.stringify({
|
|
102
96
|
session_id: session.id,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
system_prompt: (0, clarifier_js_1.buildClarifySystemPrompt)(session.initialPrompt, session.qaHistory, domain),
|
|
98
|
+
user_message: `The user answered: ${answer}. Ask the next question.`,
|
|
99
|
+
qa_count: session.qaHistory.length,
|
|
106
100
|
}),
|
|
107
101
|
},
|
|
108
102
|
],
|
|
109
103
|
};
|
|
110
104
|
});
|
|
111
105
|
async function main() {
|
|
112
|
-
if (!process.env.ANTHROPIC_API_KEY) {
|
|
113
|
-
process.stderr.write("Erreur : ANTHROPIC_API_KEY non définie.\n");
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
106
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
117
107
|
await server.connect(transport);
|
|
118
108
|
process.stderr.write("Prompt Clarifier MCP server v2.0 started (stdio)\n");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,wEAAmE;AACnE,wEAAiF;AACjF,iEAG4C;AAE5C,6CAKsB;AACtB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,wEAAmE;AACnE,wEAAiF;AACjF,iEAG4C;AAE5C,6CAKsB;AACtB,iDAKwB;AAExB,MAAM,MAAM,GAAG,IAAI,iBAAM,CACvB,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,EAC9C,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;AAEF,MAAM,CAAC,iBAAiB,CAAC,iCAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IAC5D,KAAK,EAAE;QACL;YACE,IAAI,EAAE,SAAS;YACf,WAAW,EACT,+QAA+Q;YACjR,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;w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O,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,UAAU,EAAE,OAAO,CAAC,EAAE;oBACtB,aAAa,EAAE,IAAA,uCAAwB,EAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC;oBACzF,YAAY,EAAE,sBAAsB,MAAM,0BAA0B;oBACpE,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,MAAM;iBACnC,CAAC;aACH;SACF;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;AAC7E,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prompt-clarifier-mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "MCP agent that clarifies user prompts before sending them to any LLM — works in Cursor, VS Code, IntelliJ, PyCharm, Claude Desktop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -23,10 +23,9 @@
|
|
|
23
23
|
"intellij",
|
|
24
24
|
"jetbrains"
|
|
25
25
|
],
|
|
26
|
-
"author": "
|
|
26
|
+
"author": "",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@anthropic-ai/sdk": "^0.39.0",
|
|
30
29
|
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|