@majkapp/majk-chat-mcp 1.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/README.md +854 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +287 -0
- package/dist/client/mcp-client.d.ts +22 -0
- package/dist/client/mcp-client.d.ts.map +1 -0
- package/dist/client/mcp-client.js +136 -0
- package/dist/config/parser.d.ts +14 -0
- package/dist/config/parser.d.ts.map +1 -0
- package/dist/config/parser.js +142 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +165 -0
- package/dist/tools/dynamic-executor.d.ts +32 -0
- package/dist/tools/dynamic-executor.d.ts.map +1 -0
- package/dist/tools/dynamic-executor.js +257 -0
- package/dist/tools/mcp-tool-executor.d.ts +16 -0
- package/dist/tools/mcp-tool-executor.d.ts.map +1 -0
- package/dist/tools/mcp-tool-executor.js +93 -0
- package/dist/tools/permission-handler.d.ts +18 -0
- package/dist/tools/permission-handler.d.ts.map +1 -0
- package/dist/tools/permission-handler.js +91 -0
- package/dist/tools/tool-filter.d.ts +20 -0
- package/dist/tools/tool-filter.d.ts.map +1 -0
- package/dist/tools/tool-filter.js +93 -0
- package/dist/types/config.d.ts +56 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
# @majkapp/majk-chat-mcp
|
|
2
|
+
|
|
3
|
+
A comprehensive MCP (Model Context Protocol) plugin for majk-chat that enables seamless integration with MCP servers and dynamic shell command execution.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Features](#features)
|
|
9
|
+
- [Quick Start](#quick-start)
|
|
10
|
+
- [Traditional MCP Servers](#traditional-mcp-servers)
|
|
11
|
+
- [Dynamic MCP Servers](#dynamic-mcp-servers)
|
|
12
|
+
- [CLI Tool](#cli-tool)
|
|
13
|
+
- [Permission System](#permission-system)
|
|
14
|
+
- [Tool Filtering](#tool-filtering)
|
|
15
|
+
- [Configuration Reference](#configuration-reference)
|
|
16
|
+
- [API Reference](#api-reference)
|
|
17
|
+
- [Examples](#examples)
|
|
18
|
+
- [Troubleshooting](#troubleshooting)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @majkapp/majk-chat-mcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
🔌 **Dual MCP Support**
|
|
29
|
+
- Traditional stdio MCP servers
|
|
30
|
+
- Dynamic shell command execution (no external servers needed)
|
|
31
|
+
|
|
32
|
+
🛡️ **Advanced Permission System**
|
|
33
|
+
- Dynamic input modification before tool execution
|
|
34
|
+
- Allow/deny with custom logic
|
|
35
|
+
- Parameter filtering and augmentation
|
|
36
|
+
|
|
37
|
+
🎯 **Smart Tool Filtering**
|
|
38
|
+
- Wildcard support (`mcp__*`, `mcp__filesystem__*`)
|
|
39
|
+
- Allow/disallow lists with pattern matching
|
|
40
|
+
- Fine-grained control over tool availability
|
|
41
|
+
|
|
42
|
+
📝 **Flexible Configuration**
|
|
43
|
+
- File-based or inline JSON configuration
|
|
44
|
+
- Environment variable expansion
|
|
45
|
+
- Home directory path resolution
|
|
46
|
+
|
|
47
|
+
🔧 **Template Engine**
|
|
48
|
+
- Handlebars-style templating for dynamic commands
|
|
49
|
+
- Conditional execution (`{{#if}}`)
|
|
50
|
+
- Array iteration (`{{#each}}`)
|
|
51
|
+
- Variable substitution (`{{variable}}`)
|
|
52
|
+
|
|
53
|
+
🏃 **Standalone CLI Tool**
|
|
54
|
+
- Run dynamic servers as real stdio MCP servers
|
|
55
|
+
- Configuration validation
|
|
56
|
+
- Easy deployment and testing
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
### Using with majk-chat CLI
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Simple dynamic server
|
|
64
|
+
majk-chat chat \
|
|
65
|
+
--mcp-config '{"mcpServers":{"tools":{"commands":[{"name":"echo_test","description":"Echo test","parameters":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]},"exec":{"path":"echo","args":["{{message}}"],"expect":"text"}}]}}}' \
|
|
66
|
+
-p "Say hello world" \
|
|
67
|
+
--provider anthropic
|
|
68
|
+
|
|
69
|
+
# Traditional MCP server
|
|
70
|
+
majk-chat chat \
|
|
71
|
+
--mcp-config '{"mcpServers":{"filesystem":{"command":"npx","args":["@modelcontextprotocol/server-filesystem","/workspace"]}}}' \
|
|
72
|
+
-p "List files in the workspace" \
|
|
73
|
+
--provider anthropic
|
|
74
|
+
|
|
75
|
+
# With permissions and filtering
|
|
76
|
+
majk-chat chat \
|
|
77
|
+
--mcp-config ./mcp-config.json \
|
|
78
|
+
--permission-prompt-tool "mcp__permissions__check" \
|
|
79
|
+
--allowed-tools "mcp__filesystem__read*,mcp__tools__safe*" \
|
|
80
|
+
--disallowed-tools "mcp__*__delete*" \
|
|
81
|
+
-p "Analyze the project structure" \
|
|
82
|
+
--provider anthropic
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Traditional MCP Servers
|
|
86
|
+
|
|
87
|
+
Connect to existing MCP servers via stdio transport.
|
|
88
|
+
|
|
89
|
+
### Configuration
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"mcpServers": {
|
|
94
|
+
"filesystem": {
|
|
95
|
+
"command": "npx",
|
|
96
|
+
"args": ["@modelcontextprotocol/server-filesystem", "/workspace"],
|
|
97
|
+
"env": {
|
|
98
|
+
"LOG_LEVEL": "info"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"github": {
|
|
102
|
+
"command": "npx",
|
|
103
|
+
"args": ["@modelcontextprotocol/server-github", "--token", "$GITHUB_TOKEN"],
|
|
104
|
+
"env": {
|
|
105
|
+
"GITHUB_TOKEN": "$GITHUB_TOKEN"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### CLI Usage
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# From file
|
|
116
|
+
majk-chat chat --mcp-config ./mcp-servers.json -p "List files"
|
|
117
|
+
|
|
118
|
+
# Inline JSON
|
|
119
|
+
majk-chat chat --mcp-config '{"mcpServers":{...}}' -p "Query GitHub"
|
|
120
|
+
|
|
121
|
+
# Legacy option (deprecated)
|
|
122
|
+
majk-chat chat --mcp-servers '{"mcpServers":{...}}' -p "Execute task"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Dynamic MCP Servers
|
|
126
|
+
|
|
127
|
+
Execute shell commands directly without external MCP servers. Perfect for integrating existing CLI tools.
|
|
128
|
+
|
|
129
|
+
### Basic Example
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"shell_tools": {
|
|
135
|
+
"commands": [
|
|
136
|
+
{
|
|
137
|
+
"name": "get_weather",
|
|
138
|
+
"description": "Get current weather for a city",
|
|
139
|
+
"parameters": {
|
|
140
|
+
"type": "object",
|
|
141
|
+
"properties": {
|
|
142
|
+
"city": {
|
|
143
|
+
"type": "string",
|
|
144
|
+
"description": "City name"
|
|
145
|
+
},
|
|
146
|
+
"unit": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"enum": ["celsius", "fahrenheit"],
|
|
149
|
+
"default": "celsius"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"required": ["city"]
|
|
153
|
+
},
|
|
154
|
+
"exec": {
|
|
155
|
+
"path": "curl",
|
|
156
|
+
"args": [
|
|
157
|
+
"-s",
|
|
158
|
+
"http://api.openweathermap.org/data/2.5/weather?q={{city}}&appid=$WEATHER_API_KEY&units={{unit}}"
|
|
159
|
+
],
|
|
160
|
+
"env": {
|
|
161
|
+
"WEATHER_API_KEY": "$WEATHER_API_KEY"
|
|
162
|
+
},
|
|
163
|
+
"timeoutMs": 10000,
|
|
164
|
+
"expect": "json"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Advanced Templating
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"commands": [
|
|
178
|
+
{
|
|
179
|
+
"name": "process_files",
|
|
180
|
+
"description": "Process multiple files with options",
|
|
181
|
+
"parameters": {
|
|
182
|
+
"type": "object",
|
|
183
|
+
"properties": {
|
|
184
|
+
"files": {
|
|
185
|
+
"type": "array",
|
|
186
|
+
"items": {"type": "string"}
|
|
187
|
+
},
|
|
188
|
+
"verbose": {"type": "boolean", "default": false},
|
|
189
|
+
"format": {"type": "string", "default": "json"}
|
|
190
|
+
},
|
|
191
|
+
"required": ["files"]
|
|
192
|
+
},
|
|
193
|
+
"exec": {
|
|
194
|
+
"path": "processor",
|
|
195
|
+
"args": [
|
|
196
|
+
"{{#if verbose}}--verbose{{/if}}",
|
|
197
|
+
"--format={{format}}",
|
|
198
|
+
"{{#each files}}--file={{this}}{{/each}}"
|
|
199
|
+
],
|
|
200
|
+
"cwd": "~/workspace",
|
|
201
|
+
"env": {
|
|
202
|
+
"PROCESSOR_CONFIG": "$HOME/.processor.conf"
|
|
203
|
+
},
|
|
204
|
+
"timeoutMs": 60000,
|
|
205
|
+
"expect": "json"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Template Syntax
|
|
213
|
+
|
|
214
|
+
| Syntax | Description | Example |
|
|
215
|
+
|--------|-------------|---------|
|
|
216
|
+
| `{{var}}` | Variable substitution | `{{city}}` → `"Paris"` |
|
|
217
|
+
| `{{#if var}}text{{/if}}` | Conditional inclusion | `{{#if verbose}}--verbose{{/if}}` |
|
|
218
|
+
| `{{#each array}}{{this}}{{/each}}` | Array iteration | `{{#each files}}--file={{this}}{{/each}}` |
|
|
219
|
+
| `$VAR` | Environment variable | `$API_KEY` → `process.env.API_KEY` |
|
|
220
|
+
|
|
221
|
+
## CLI Tool
|
|
222
|
+
|
|
223
|
+
The package includes a standalone CLI tool for running dynamic servers as real stdio MCP servers.
|
|
224
|
+
|
|
225
|
+
### Installation
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
npm install -g @majkapp/majk-chat-mcp
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Usage
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Start server from config file
|
|
235
|
+
majk-mcp-server serve --config dynamic-config.json
|
|
236
|
+
|
|
237
|
+
# Start server from JSON string
|
|
238
|
+
majk-mcp-server serve --config-json '{"commands":[...]}'
|
|
239
|
+
|
|
240
|
+
# Validate configuration
|
|
241
|
+
majk-mcp-server validate --config dynamic-config.json
|
|
242
|
+
|
|
243
|
+
# Get help
|
|
244
|
+
majk-mcp-server --help
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Example: Weather Service
|
|
248
|
+
|
|
249
|
+
1. **Create config** (`weather-server.json`):
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"commands": [
|
|
253
|
+
{
|
|
254
|
+
"name": "get_weather",
|
|
255
|
+
"description": "Get weather for a city",
|
|
256
|
+
"parameters": {
|
|
257
|
+
"type": "object",
|
|
258
|
+
"properties": {
|
|
259
|
+
"city": {"type": "string"}
|
|
260
|
+
},
|
|
261
|
+
"required": ["city"]
|
|
262
|
+
},
|
|
263
|
+
"exec": {
|
|
264
|
+
"path": "curl",
|
|
265
|
+
"args": ["-s", "wttr.in/{{city}}?format=3"],
|
|
266
|
+
"timeoutMs": 5000,
|
|
267
|
+
"expect": "text"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
2. **Run server**:
|
|
275
|
+
```bash
|
|
276
|
+
majk-mcp-server serve --config weather-server.json
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
3. **Use with majk-chat**:
|
|
280
|
+
```bash
|
|
281
|
+
majk-chat chat \
|
|
282
|
+
--mcp-config '{"mcpServers":{"weather":{"command":"majk-mcp-server","args":["serve","--config","weather-server.json"]}}}' \
|
|
283
|
+
-p "What's the weather in Tokyo?" \
|
|
284
|
+
--provider anthropic
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Permission System
|
|
288
|
+
|
|
289
|
+
The permission system allows dynamic modification of tool inputs before execution, enabling sophisticated security policies.
|
|
290
|
+
|
|
291
|
+
### Permission Tool Format
|
|
292
|
+
|
|
293
|
+
**Request**:
|
|
294
|
+
```json
|
|
295
|
+
{
|
|
296
|
+
"tool_name": "Bash",
|
|
297
|
+
"input": {"command": "rm file.txt", "description": "Delete file"},
|
|
298
|
+
"tool_use_id": "unique-id-12345",
|
|
299
|
+
"user_id": "user123",
|
|
300
|
+
"request_id": "req456"
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Response**:
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"behavior": "allow",
|
|
308
|
+
"updatedInput": {
|
|
309
|
+
"command": "rm file.txt --dry-run",
|
|
310
|
+
"description": "Delete file (dry run mode)",
|
|
311
|
+
"safety_mode": true
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Permission Responses
|
|
317
|
+
|
|
318
|
+
| Response | Behavior |
|
|
319
|
+
|----------|----------|
|
|
320
|
+
| `{"behavior": "allow"}` | Use original input |
|
|
321
|
+
| `{"behavior": "allow", "updatedInput": {...}}` | Use modified input |
|
|
322
|
+
| `{"behavior": "allow", "updatedInput": {}}` | Clear all arguments |
|
|
323
|
+
| `{"behavior": "deny"}` | Block execution |
|
|
324
|
+
|
|
325
|
+
### CLI Usage
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
majk-chat chat \
|
|
329
|
+
--mcp-config ./config.json \
|
|
330
|
+
--permission-prompt-tool "mcp__permissions__check_permission" \
|
|
331
|
+
-p "Delete all temporary files"
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Tool Filtering
|
|
335
|
+
|
|
336
|
+
Control which tools are available with powerful pattern matching.
|
|
337
|
+
|
|
338
|
+
### Wildcard Patterns
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
# Allow all MCP tools
|
|
342
|
+
--allowed-tools "mcp__*"
|
|
343
|
+
|
|
344
|
+
# Allow filesystem tools only
|
|
345
|
+
--allowed-tools "mcp__filesystem__*"
|
|
346
|
+
|
|
347
|
+
# Block all delete operations
|
|
348
|
+
--disallowed-tools "mcp__*__delete*"
|
|
349
|
+
|
|
350
|
+
# Mixed patterns
|
|
351
|
+
--allowed-tools "mcp__filesystem__read*,mcp__tools__safe*,Bash"
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### CLI Options
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
# Comma or space separated
|
|
358
|
+
--allowed-tools "tool1,tool2,tool3"
|
|
359
|
+
--allowed-tools "tool1 tool2 tool3"
|
|
360
|
+
|
|
361
|
+
# Wildcard patterns
|
|
362
|
+
--disallowed-tools "mcp__*__delete* mcp__*__remove*"
|
|
363
|
+
|
|
364
|
+
# Both options (disallowed takes precedence)
|
|
365
|
+
--allowed-tools "mcp__*" --disallowed-tools "mcp__*__dangerous*"
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Configuration Reference
|
|
369
|
+
|
|
370
|
+
### Traditional MCP Server
|
|
371
|
+
|
|
372
|
+
```json
|
|
373
|
+
{
|
|
374
|
+
"mcpServers": {
|
|
375
|
+
"server_name": {
|
|
376
|
+
"command": "npx",
|
|
377
|
+
"args": ["@package/mcp-server", "--option", "value"],
|
|
378
|
+
"env": {
|
|
379
|
+
"API_KEY": "$API_KEY",
|
|
380
|
+
"CONFIG_PATH": "~/.config/app.conf"
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Dynamic MCP Server
|
|
388
|
+
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"mcpServers": {
|
|
392
|
+
"dynamic_tools": {
|
|
393
|
+
"commands": [
|
|
394
|
+
{
|
|
395
|
+
"name": "tool_name",
|
|
396
|
+
"description": "Tool description",
|
|
397
|
+
"parameters": {
|
|
398
|
+
"type": "object",
|
|
399
|
+
"properties": {
|
|
400
|
+
"param1": {"type": "string"},
|
|
401
|
+
"param2": {"type": "number", "default": 42}
|
|
402
|
+
},
|
|
403
|
+
"required": ["param1"]
|
|
404
|
+
},
|
|
405
|
+
"exec": {
|
|
406
|
+
"path": "/usr/bin/command",
|
|
407
|
+
"args": ["--param1", "{{param1}}", "--param2", "{{param2}}"],
|
|
408
|
+
"cwd": "~/workspace",
|
|
409
|
+
"env": {
|
|
410
|
+
"CUSTOM_VAR": "$ENV_VAR"
|
|
411
|
+
},
|
|
412
|
+
"timeoutMs": 30000,
|
|
413
|
+
"expect": "json",
|
|
414
|
+
"stream": false
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Configuration Options
|
|
424
|
+
|
|
425
|
+
| Field | Type | Description | Default |
|
|
426
|
+
|-------|------|-------------|---------|
|
|
427
|
+
| `path` | string | Command to execute | Required |
|
|
428
|
+
| `args` | string[] | Command arguments with templating | Required |
|
|
429
|
+
| `cwd` | string | Working directory (`~` expanded) | `process.cwd()` |
|
|
430
|
+
| `env` | object | Environment variables | `{}` |
|
|
431
|
+
| `timeoutMs` | number | Execution timeout in milliseconds | `30000` |
|
|
432
|
+
| `expect` | "text" \| "json" | Expected output format | `"text"` |
|
|
433
|
+
| `stream` | boolean | Stream output (future feature) | `false` |
|
|
434
|
+
|
|
435
|
+
## API Reference
|
|
436
|
+
|
|
437
|
+
### MCPPlugin
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
import { MCPPlugin } from '@majkapp/majk-chat-mcp';
|
|
441
|
+
|
|
442
|
+
const plugin = new MCPPlugin({
|
|
443
|
+
configPath: './mcp-config.json',
|
|
444
|
+
allowedTools: ['mcp__*'],
|
|
445
|
+
disallowedTools: ['mcp__*__delete*'],
|
|
446
|
+
permissionPromptTool: 'mcp__permissions__check',
|
|
447
|
+
quiet: true // Suppress console output
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
await plugin.initialize(toolRegistry);
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### MCPClient
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
import { MCPClient } from '@majkapp/majk-chat-mcp';
|
|
457
|
+
|
|
458
|
+
const client = new MCPClient(quiet);
|
|
459
|
+
const connection = await client.connect('server-name', {
|
|
460
|
+
command: 'npx',
|
|
461
|
+
args: ['@package/mcp-server'],
|
|
462
|
+
env: { API_KEY: 'secret' }
|
|
463
|
+
});
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### DynamicCommandExecutor
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
import { DynamicCommandExecutor } from '@majkapp/majk-chat-mcp';
|
|
470
|
+
|
|
471
|
+
const executor = new DynamicCommandExecutor('server-name', {
|
|
472
|
+
name: 'my_tool',
|
|
473
|
+
description: 'My custom tool',
|
|
474
|
+
parameters: { type: 'object', properties: {...} },
|
|
475
|
+
exec: {
|
|
476
|
+
path: 'my-command',
|
|
477
|
+
args: ['{{param}}'],
|
|
478
|
+
expect: 'json'
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
## Examples
|
|
484
|
+
|
|
485
|
+
### 1. Weather Service
|
|
486
|
+
|
|
487
|
+
```bash
|
|
488
|
+
majk-chat chat \
|
|
489
|
+
--mcp-config '{
|
|
490
|
+
"mcpServers": {
|
|
491
|
+
"weather": {
|
|
492
|
+
"commands": [{
|
|
493
|
+
"name": "get_weather",
|
|
494
|
+
"description": "Get weather for a city",
|
|
495
|
+
"parameters": {
|
|
496
|
+
"type": "object",
|
|
497
|
+
"properties": {"city": {"type": "string"}},
|
|
498
|
+
"required": ["city"]
|
|
499
|
+
},
|
|
500
|
+
"exec": {
|
|
501
|
+
"path": "curl",
|
|
502
|
+
"args": ["-s", "wttr.in/{{city}}?format=3"],
|
|
503
|
+
"timeoutMs": 5000,
|
|
504
|
+
"expect": "text"
|
|
505
|
+
}
|
|
506
|
+
}]
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}' \
|
|
510
|
+
-p "What's the weather in London?" \
|
|
511
|
+
--provider anthropic
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### 2. File Processing Pipeline
|
|
515
|
+
|
|
516
|
+
```bash
|
|
517
|
+
majk-chat chat \
|
|
518
|
+
--mcp-config '{
|
|
519
|
+
"mcpServers": {
|
|
520
|
+
"file_tools": {
|
|
521
|
+
"commands": [
|
|
522
|
+
{
|
|
523
|
+
"name": "analyze_files",
|
|
524
|
+
"description": "Analyze files with custom options",
|
|
525
|
+
"parameters": {
|
|
526
|
+
"type": "object",
|
|
527
|
+
"properties": {
|
|
528
|
+
"files": {"type": "array", "items": {"type": "string"}},
|
|
529
|
+
"depth": {"type": "number", "default": 1},
|
|
530
|
+
"include_tests": {"type": "boolean", "default": false}
|
|
531
|
+
},
|
|
532
|
+
"required": ["files"]
|
|
533
|
+
},
|
|
534
|
+
"exec": {
|
|
535
|
+
"path": "analyzer",
|
|
536
|
+
"args": [
|
|
537
|
+
"--depth={{depth}}",
|
|
538
|
+
"{{#if include_tests}}--include-tests{{/if}}",
|
|
539
|
+
"{{#each files}}--file={{this}}{{/each}}"
|
|
540
|
+
],
|
|
541
|
+
"env": {"ANALYZER_CONFIG": "$HOME/.analyzer.json"},
|
|
542
|
+
"timeoutMs": 60000,
|
|
543
|
+
"expect": "json"
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
]
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}' \
|
|
550
|
+
-p "Analyze main.js and utils.js with tests included" \
|
|
551
|
+
--provider anthropic
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
### 3. Permission-Controlled Operations
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
majk-chat chat \
|
|
558
|
+
--mcp-config '{
|
|
559
|
+
"mcpServers": {
|
|
560
|
+
"permissions": {
|
|
561
|
+
"command": "npx",
|
|
562
|
+
"args": ["@majkapp/mcp-permissions-server"]
|
|
563
|
+
},
|
|
564
|
+
"system_tools": {
|
|
565
|
+
"commands": [{
|
|
566
|
+
"name": "system_command",
|
|
567
|
+
"description": "Execute system command",
|
|
568
|
+
"parameters": {
|
|
569
|
+
"type": "object",
|
|
570
|
+
"properties": {"cmd": {"type": "string"}},
|
|
571
|
+
"required": ["cmd"]
|
|
572
|
+
},
|
|
573
|
+
"exec": {
|
|
574
|
+
"path": "sh",
|
|
575
|
+
"args": ["-c", "{{cmd}}"],
|
|
576
|
+
"timeoutMs": 30000,
|
|
577
|
+
"expect": "text"
|
|
578
|
+
}
|
|
579
|
+
}]
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}' \
|
|
583
|
+
--permission-prompt-tool "mcp__permissions__check_system_command" \
|
|
584
|
+
-p "Check disk usage" \
|
|
585
|
+
--provider anthropic
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### 4. Stream JSON Output
|
|
589
|
+
|
|
590
|
+
```bash
|
|
591
|
+
majk-chat chat \
|
|
592
|
+
--mcp-config ./config.json \
|
|
593
|
+
-p "Process the data pipeline" \
|
|
594
|
+
--output-format stream-json \
|
|
595
|
+
--provider anthropic | jq .
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### 5. Tool Filtering
|
|
599
|
+
|
|
600
|
+
```bash
|
|
601
|
+
# Allow only read operations
|
|
602
|
+
majk-chat chat \
|
|
603
|
+
--mcp-config ./config.json \
|
|
604
|
+
--allowed-tools "mcp__*__read* mcp__*__list* mcp__*__get*" \
|
|
605
|
+
-p "Analyze the project"
|
|
606
|
+
|
|
607
|
+
# Block dangerous operations
|
|
608
|
+
majk-chat chat \
|
|
609
|
+
--mcp-config ./config.json \
|
|
610
|
+
--disallowed-tools "mcp__*__delete* mcp__*__remove* mcp__*__destroy*" \
|
|
611
|
+
-p "Clean up the workspace"
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
## CLI Tool Reference
|
|
615
|
+
|
|
616
|
+
### majk-mcp-server
|
|
617
|
+
|
|
618
|
+
Run dynamic MCP servers as standalone stdio servers.
|
|
619
|
+
|
|
620
|
+
#### Commands
|
|
621
|
+
|
|
622
|
+
```bash
|
|
623
|
+
# Start server
|
|
624
|
+
majk-mcp-server serve [options]
|
|
625
|
+
|
|
626
|
+
# Validate configuration
|
|
627
|
+
majk-mcp-server validate [options]
|
|
628
|
+
|
|
629
|
+
# Show help
|
|
630
|
+
majk-mcp-server --help
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
#### Options
|
|
634
|
+
|
|
635
|
+
| Option | Description | Example |
|
|
636
|
+
|--------|-------------|---------|
|
|
637
|
+
| `-c, --config <file>` | Configuration file path | `--config weather.json` |
|
|
638
|
+
| `--config-json <json>` | Configuration as JSON string | `--config-json '{"commands":[...]}'` |
|
|
639
|
+
|
|
640
|
+
#### Example Usage
|
|
641
|
+
|
|
642
|
+
```bash
|
|
643
|
+
# Create config
|
|
644
|
+
cat > weather-tools.json << 'EOF'
|
|
645
|
+
{
|
|
646
|
+
"commands": [
|
|
647
|
+
{
|
|
648
|
+
"name": "weather",
|
|
649
|
+
"description": "Get weather info",
|
|
650
|
+
"parameters": {
|
|
651
|
+
"type": "object",
|
|
652
|
+
"properties": {"city": {"type": "string"}},
|
|
653
|
+
"required": ["city"]
|
|
654
|
+
},
|
|
655
|
+
"exec": {
|
|
656
|
+
"path": "curl",
|
|
657
|
+
"args": ["-s", "wttr.in/{{city}}?format=j1"],
|
|
658
|
+
"expect": "json"
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
]
|
|
662
|
+
}
|
|
663
|
+
EOF
|
|
664
|
+
|
|
665
|
+
# Validate config
|
|
666
|
+
majk-mcp-server validate --config weather-tools.json
|
|
667
|
+
|
|
668
|
+
# Run as stdio server
|
|
669
|
+
majk-mcp-server serve --config weather-tools.json
|
|
670
|
+
|
|
671
|
+
# Use with majk-chat
|
|
672
|
+
majk-chat chat \
|
|
673
|
+
--mcp-config '{"mcpServers":{"weather":{"command":"majk-mcp-server","args":["serve","--config","weather-tools.json"]}}}' \
|
|
674
|
+
-p "Weather in Seattle?"
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
## Tool Naming Convention
|
|
678
|
+
|
|
679
|
+
All tools are namespaced to prevent conflicts:
|
|
680
|
+
|
|
681
|
+
- **Traditional MCP**: `mcp__<server_name>__<tool_name>`
|
|
682
|
+
- **Dynamic Commands**: `mcp__<server_name>__<command_name>`
|
|
683
|
+
|
|
684
|
+
Examples:
|
|
685
|
+
- `mcp__filesystem__read_file`
|
|
686
|
+
- `mcp__weather__get_current_weather`
|
|
687
|
+
- `mcp__permissions__check_permission`
|
|
688
|
+
|
|
689
|
+
## Output Formats
|
|
690
|
+
|
|
691
|
+
### Text Format (Default)
|
|
692
|
+
|
|
693
|
+
Human-readable output with colors, spinners, and formatting:
|
|
694
|
+
|
|
695
|
+
```
|
|
696
|
+
🔧 Calling tool: mcp__weather__get_weather
|
|
697
|
+
{
|
|
698
|
+
"city": "Paris"
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
✅ Tool result:
|
|
702
|
+
Weather in Paris is 22°C, sunny
|
|
703
|
+
|
|
704
|
+
📊 Tokens: 45 (prompt: 20, completion: 25)
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
### Stream JSON Format
|
|
708
|
+
|
|
709
|
+
Structured JSON events for programmatic consumption:
|
|
710
|
+
|
|
711
|
+
```json
|
|
712
|
+
{"type":"system","subtype":"init","session_id":"...","tools":["mcp__weather__get_weather"],...}
|
|
713
|
+
{"type":"assistant","message":{"content":[{"type":"tool_use","name":"mcp__weather__get_weather","input":{"city":"Paris"}}],...}}
|
|
714
|
+
{"type":"user","message":{"content":[{"type":"tool_result","tool_use_id":"...","content":"Weather in Paris is 22°C"}],...}}
|
|
715
|
+
{"type":"result","subtype":"success","total_cost_usd":0.001234,...}
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
## Troubleshooting
|
|
719
|
+
|
|
720
|
+
### Common Issues
|
|
721
|
+
|
|
722
|
+
**1. MCP Server Connection Failed**
|
|
723
|
+
```
|
|
724
|
+
Failed to connect to MCP server "my-server": Connection closed
|
|
725
|
+
```
|
|
726
|
+
- Check if the server command/path is correct
|
|
727
|
+
- Verify server is installed and accessible
|
|
728
|
+
- Check environment variables are set
|
|
729
|
+
|
|
730
|
+
**2. Dynamic Command Not Found**
|
|
731
|
+
```
|
|
732
|
+
Command failed with exit code 127: command not found
|
|
733
|
+
```
|
|
734
|
+
- Verify the command path is correct
|
|
735
|
+
- Check if command is in PATH
|
|
736
|
+
- Use absolute path if needed
|
|
737
|
+
|
|
738
|
+
**3. Template Variables Not Resolved**
|
|
739
|
+
```
|
|
740
|
+
Weather in {{city}} is sunny
|
|
741
|
+
```
|
|
742
|
+
- Check parameter names match template variables
|
|
743
|
+
- Ensure required parameters are provided
|
|
744
|
+
- Verify JSON parameter structure
|
|
745
|
+
|
|
746
|
+
**4. Permission Denied**
|
|
747
|
+
```
|
|
748
|
+
Permission denied for tool: mcp__tools__dangerous_command
|
|
749
|
+
```
|
|
750
|
+
- Check permission tool configuration
|
|
751
|
+
- Verify permission server is running
|
|
752
|
+
- Review tool filtering rules
|
|
753
|
+
|
|
754
|
+
### Debug Mode
|
|
755
|
+
|
|
756
|
+
Enable detailed logging in text mode:
|
|
757
|
+
|
|
758
|
+
```bash
|
|
759
|
+
majk-chat chat \
|
|
760
|
+
--mcp-config ./config.json \
|
|
761
|
+
-p "Debug this issue" \
|
|
762
|
+
--output-format text \
|
|
763
|
+
--provider anthropic
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
### Configuration Validation
|
|
767
|
+
|
|
768
|
+
```bash
|
|
769
|
+
# Validate traditional MCP config
|
|
770
|
+
majk-chat chat --mcp-config ./config.json --help
|
|
771
|
+
|
|
772
|
+
# Validate dynamic server config
|
|
773
|
+
majk-mcp-server validate --config dynamic-config.json
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
## Integration Examples
|
|
777
|
+
|
|
778
|
+
### CI/CD Pipeline
|
|
779
|
+
|
|
780
|
+
```bash
|
|
781
|
+
#!/bin/bash
|
|
782
|
+
# Process pull request with AI analysis
|
|
783
|
+
|
|
784
|
+
majk-chat chat \
|
|
785
|
+
--mcp-config '{
|
|
786
|
+
"mcpServers": {
|
|
787
|
+
"ci_tools": {
|
|
788
|
+
"commands": [
|
|
789
|
+
{
|
|
790
|
+
"name": "run_tests",
|
|
791
|
+
"description": "Run test suite",
|
|
792
|
+
"parameters": {"type": "object", "properties": {}},
|
|
793
|
+
"exec": {"path": "npm", "args": ["test"], "expect": "text"}
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
"name": "lint_code",
|
|
797
|
+
"description": "Run linter",
|
|
798
|
+
"parameters": {"type": "object", "properties": {}},
|
|
799
|
+
"exec": {"path": "npm", "args": ["run", "lint"], "expect": "text"}
|
|
800
|
+
}
|
|
801
|
+
]
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}' \
|
|
805
|
+
-p "Run tests and linting, then analyze the results" \
|
|
806
|
+
--output-format stream-json \
|
|
807
|
+
--provider anthropic > analysis.json
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
### Development Workflow
|
|
811
|
+
|
|
812
|
+
```bash
|
|
813
|
+
# Interactive development with tools
|
|
814
|
+
majk-chat interactive \
|
|
815
|
+
--mcp-config ./dev-tools.json \
|
|
816
|
+
--allowed-tools "mcp__dev__* Read Write Edit" \
|
|
817
|
+
--system "You are a helpful development assistant" \
|
|
818
|
+
--provider anthropic
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
### Automated Analysis
|
|
822
|
+
|
|
823
|
+
```bash
|
|
824
|
+
# Batch file analysis
|
|
825
|
+
echo "Analyze main.py" > prompts.txt
|
|
826
|
+
echo "Check test coverage" >> prompts.txt
|
|
827
|
+
echo "Suggest improvements" >> prompts.txt
|
|
828
|
+
|
|
829
|
+
majk-chat chat \
|
|
830
|
+
--prompts prompts.txt \
|
|
831
|
+
--mcp-config ./analysis-tools.json \
|
|
832
|
+
--output-format stream-json \
|
|
833
|
+
--provider anthropic
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
## Security Notes
|
|
837
|
+
|
|
838
|
+
- 🔒 **Dynamic commands execute with full shell access** - use permission system
|
|
839
|
+
- 🛡️ **Template injection protection** - validate inputs carefully
|
|
840
|
+
- 🔐 **Environment variables** - avoid exposing secrets in args
|
|
841
|
+
- ⚠️ **Timeout protection** - commands are killed after timeout
|
|
842
|
+
- 🚫 **Permission system** - implement deny-by-default policies
|
|
843
|
+
|
|
844
|
+
## License
|
|
845
|
+
|
|
846
|
+
MIT
|
|
847
|
+
|
|
848
|
+
## Contributing
|
|
849
|
+
|
|
850
|
+
Issues and pull requests welcome at [majk-chat repository].
|
|
851
|
+
|
|
852
|
+
---
|
|
853
|
+
|
|
854
|
+
*For more examples and advanced usage, see the [majk-chat-cli documentation](../majk-chat-cli/README.md).*
|