@kontexted/mcp-cli 0.1.0 → 0.1.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 +346 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Kontexted MCP CLI
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
**MCP client and proxy for connecting AI assistants to Kontexted.**
|
|
6
|
+
|
|
7
|
+
The Kontexted MCP CLI bridges AI coding assistants (opencode, Claude Code, etc.) with your Kontexted instance. It handles authentication, profile management, and translates MCP requests to your Kontexted server's API.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## What is this?
|
|
12
|
+
|
|
13
|
+
The [Kontexted](https://github.com/kontexted/kontexted) server provides an MCP (Model Context Protocol) endpoint that allows AI assistants to query your notes. Since Kontexted is open source, you can host multiple instances for different teams or environments, and each instance contains multiple workspaces.
|
|
14
|
+
|
|
15
|
+
This CLI helps you manage these scenarios by:
|
|
16
|
+
|
|
17
|
+
- **OAuth 2.0 Authentication** - Handles full OAuth flow with PKCE code verifier
|
|
18
|
+
- **Profile Management** - Store and switch between multiple Kontexted instances and workspaces
|
|
19
|
+
- **Workspace Scoping** - Narrows the LLM's context to a single workspace per profile
|
|
20
|
+
- **MCP Proxy Server** - Translates MCP stdio requests to HTTP calls to Kontexted
|
|
21
|
+
- **Tool Filtering** - Injects workspace context and controls write access per-profile
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### Prerequisites
|
|
28
|
+
|
|
29
|
+
- Kontexted server running at your instance
|
|
30
|
+
|
|
31
|
+
### Using npx / bunx (Recommended)
|
|
32
|
+
|
|
33
|
+
The easiest way to run Kontexted MCP CLI without installing:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Using bunx
|
|
37
|
+
bunx @kontexted/mcp-cli
|
|
38
|
+
|
|
39
|
+
# Using npx
|
|
40
|
+
npx @kontexted/mcp-cli
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
No installation required - just replace `kontexted-mcp` with `bunx @kontexted/mcp-cli` or `npx @kontexted/mcp-cli` in all examples below.
|
|
44
|
+
|
|
45
|
+
### Global Install (Optional)
|
|
46
|
+
|
|
47
|
+
If you prefer a shorter command, install globally:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bun install -g @kontexted/mcp-cli
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then run directly:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
kontexted-mcp
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### 1. Login
|
|
64
|
+
|
|
65
|
+
Authenticate with your Kontexted instance and store a profile:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
kontexted-mcp login --url <mcp-server-url> --workspace <workspace-slug>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Required flags:**
|
|
72
|
+
- `--url`: MCP server URL (e.g., `http://localhost:3000/api/mcp` or `https://app.example.com/api/mcp`)
|
|
73
|
+
- `--workspace`: Workspace slug from your Kontexted instance
|
|
74
|
+
|
|
75
|
+
**Optional flags:**
|
|
76
|
+
- `--alias <name>`: Store profile under a custom name (defaults to workspace name)
|
|
77
|
+
- `--write`: Enable write operations (create folders/notes) for this profile
|
|
78
|
+
|
|
79
|
+
**Examples:**
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Login to local development instance
|
|
83
|
+
kontexted-mcp login --url http://localhost:3000/api/mcp --workspace my-project
|
|
84
|
+
|
|
85
|
+
# Login to production with alias
|
|
86
|
+
kontexted-mcp login --url https://app.mycompany.com/api/mcp --workspace my-project --alias prod
|
|
87
|
+
|
|
88
|
+
# Login with write access enabled
|
|
89
|
+
kontexted-mcp login --url http://localhost:3000/api/mcp --workspace my-project --write
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**What happens during login:**
|
|
93
|
+
|
|
94
|
+
1. CLI starts a temporary local HTTP server on port 8788
|
|
95
|
+
2. Opens your browser to Kontexted's OAuth authorization page
|
|
96
|
+
3. You sign in with Keycloak and authorize the MCP client
|
|
97
|
+
4. Kontexted redirects to the callback URL with an authorization code
|
|
98
|
+
5. CLI exchanges the code for access and refresh tokens
|
|
99
|
+
6. Tokens and client information are stored in `~/.kontexted/mcp.json`
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### 2. View Stored Profiles
|
|
104
|
+
|
|
105
|
+
Show all configured profiles:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
kontexted-mcp show-config
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Output example:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"profiles": {
|
|
116
|
+
"my-project": {
|
|
117
|
+
"serverUrl": "http://localhost:3000/api/mcp",
|
|
118
|
+
"workspace": "my-project",
|
|
119
|
+
"write": false,
|
|
120
|
+
"oauth": {
|
|
121
|
+
"tokens": { "...": "..." },
|
|
122
|
+
"codeVerifier": "...",
|
|
123
|
+
"clientInformation": { "...": "..." }
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"prod": {
|
|
127
|
+
"serverUrl": "https://app.mycompany.com/api/mcp",
|
|
128
|
+
"workspace": "my-project",
|
|
129
|
+
"write": true,
|
|
130
|
+
"oauth": { "...": "..." }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### 3. Start MCP Proxy Server
|
|
139
|
+
|
|
140
|
+
Run the MCP proxy server (default command when no subcommand is provided):
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
kontexted-mcp [--alias <name> | --workspace <slug>] [--write | --write-off]
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Required flags (one or the other):**
|
|
147
|
+
- `--alias <name>`: Use profile by alias
|
|
148
|
+
- `--workspace <slug>`: Find profile by workspace name
|
|
149
|
+
|
|
150
|
+
**Optional flags:**
|
|
151
|
+
- `--write`: Override profile to enable write operations
|
|
152
|
+
- `--write-off`: Override profile to disable write operations
|
|
153
|
+
|
|
154
|
+
**Examples:**
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Start with default read-only access
|
|
158
|
+
kontexted-mcp --alias prod
|
|
159
|
+
|
|
160
|
+
# Start with write access for this session only
|
|
161
|
+
kontexted-mcp --alias my-project --write
|
|
162
|
+
|
|
163
|
+
# Start using workspace name instead of alias
|
|
164
|
+
kontexted-mcp --workspace my-project
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The CLI will:
|
|
168
|
+
1. Load the specified profile from `~/.kontexted/mcp.json`
|
|
169
|
+
2. Connect to Kontexted's MCP server using stored tokens
|
|
170
|
+
3. List available tools and register them with MCP stdio transport
|
|
171
|
+
4. Remove `workspaceSlug` from tool input schemas (injected automatically)
|
|
172
|
+
5. Filter out write tools unless `--write` is specified
|
|
173
|
+
6. Wait for MCP requests from your AI assistant
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### 4. Logout
|
|
178
|
+
|
|
179
|
+
Remove one or all stored profiles:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Remove specific profile by alias
|
|
183
|
+
kontexted-mcp logout --alias prod
|
|
184
|
+
|
|
185
|
+
# Remove specific profile by workspace
|
|
186
|
+
kontexted-mcp logout --workspace my-project
|
|
187
|
+
|
|
188
|
+
# Remove all profiles
|
|
189
|
+
kontexted-mcp logout
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Integrating with opencode
|
|
195
|
+
|
|
196
|
+
The Kontexted MCP CLI is designed to work as an MCP server that can be configured in opencode.
|
|
197
|
+
|
|
198
|
+
### Step 1: Add MCP Server to opencode.json
|
|
199
|
+
|
|
200
|
+
Edit your project's `opencode.json`:
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"$schema": "https://opencode.ai/config.json",
|
|
205
|
+
"mcp": {
|
|
206
|
+
"kontexted": {
|
|
207
|
+
"type": "local",
|
|
208
|
+
"enabled": true,
|
|
209
|
+
"command": ["kontexted-mcp", "--alias", "prod"],
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Replace `--alias` with your profile name or use `--workspace` instead.
|
|
216
|
+
|
|
217
|
+
### Step 2: Configure Write Access (Optional)
|
|
218
|
+
|
|
219
|
+
If you want opencode to create notes or folders in Kontexted:
|
|
220
|
+
|
|
221
|
+
1. Enable write access during login: `kontexted-mcp login --url <url> --workspace <slug> --write`
|
|
222
|
+
2. Or override per-session: `"args": ["--alias", "prod", "--write"]`
|
|
223
|
+
|
|
224
|
+
### Step 3: Restart opencode
|
|
225
|
+
|
|
226
|
+
Restart your opencode session to load the MCP server.
|
|
227
|
+
|
|
228
|
+
### Step 4: Use Kontexted Tools
|
|
229
|
+
|
|
230
|
+
opencode can now access Kontexted MCP tools:
|
|
231
|
+
|
|
232
|
+
- `getWorkspaceTree` - Fetch workspace structure (folders and notes)
|
|
233
|
+
- `searchNotesByQuery` - Search notes by name or title
|
|
234
|
+
- `getNoteById` - Retrieve a specific note's content
|
|
235
|
+
- `createFolder` - Create a new folder (requires `--write`)
|
|
236
|
+
- `createNote` - Create a new note (requires `--write`)
|
|
237
|
+
|
|
238
|
+
The CLI automatically injects your configured `workspaceSlug` into all requests, so you don't need to specify it manually.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Tool Filtering
|
|
243
|
+
|
|
244
|
+
The CLI filters MCP tools based on your profile's write settings:
|
|
245
|
+
|
|
246
|
+
| Tool | Read-Only | With Write |
|
|
247
|
+
|-------|------------|------------|
|
|
248
|
+
| `getWorkspaceTree` | ✅ | ✅ |
|
|
249
|
+
| `searchNotesByQuery` | ✅ | ✅ |
|
|
250
|
+
| `getNoteById` | ✅ | ✅ |
|
|
251
|
+
| `createFolder` | ❌ | ✅ |
|
|
252
|
+
| `createNote` | ❌ | ✅ |
|
|
253
|
+
|
|
254
|
+
By default, profiles are created in read-only mode. Use `--write` during login or session start to enable write operations.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Configuration File
|
|
259
|
+
|
|
260
|
+
Profiles are stored in:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
~/.kontexted/mcp.json
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Each profile contains:
|
|
267
|
+
- `serverUrl`: Kontexted MCP server URL
|
|
268
|
+
- `workspace`: Workspace slug
|
|
269
|
+
- `write`: Default write access setting
|
|
270
|
+
- `oauth.tokens`: OAuth access and refresh tokens
|
|
271
|
+
- `oauth.codeVerifier`: PKCE code verifier for token refresh
|
|
272
|
+
- `oauth.clientInformation`: OAuth client metadata
|
|
273
|
+
|
|
274
|
+
**Security Note:** Tokens are stored in plain text on disk. Ensure your system's `~/.kontexted` directory has appropriate permissions.
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Troubleshooting
|
|
279
|
+
|
|
280
|
+
### "Unauthorized. Run 'kontexted-mcp login' first."
|
|
281
|
+
|
|
282
|
+
Your tokens have expired or are missing. Run login again:
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
kontexted-mcp login --url <url> --workspace <workspace>
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
The CLI will automatically refresh expired tokens when possible.
|
|
289
|
+
|
|
290
|
+
### "Failed to open browser"
|
|
291
|
+
|
|
292
|
+
The CLI couldn't automatically open your browser. Copy the URL from your terminal and open it manually.
|
|
293
|
+
|
|
294
|
+
### Port 8788 already in use
|
|
295
|
+
|
|
296
|
+
The OAuth callback server requires port 8788. If it's occupied:
|
|
297
|
+
|
|
298
|
+
1. Close other processes using the port, or
|
|
299
|
+
2. Manually copy the authorization URL from the CLI output
|
|
300
|
+
|
|
301
|
+
### Profile not found
|
|
302
|
+
|
|
303
|
+
Check your stored profiles:
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
kontexted-mcp show-config
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Use the exact alias or workspace name shown in the output.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Development
|
|
314
|
+
|
|
315
|
+
For contributing or running from source code:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
# Clone repository
|
|
319
|
+
git clone https://github.com/kontexted/kontexted-mcp-cli.git
|
|
320
|
+
cd kontexted-mcp-cli
|
|
321
|
+
|
|
322
|
+
# Install dependencies
|
|
323
|
+
bun install
|
|
324
|
+
|
|
325
|
+
# Run from source
|
|
326
|
+
bun run start
|
|
327
|
+
|
|
328
|
+
# Build distribution
|
|
329
|
+
bun run build
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
**Note:** Building from source is only necessary for development. For regular use, run with `bunx` or `npx` instead.
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## License
|
|
337
|
+
|
|
338
|
+
[MIT License](LICENSE) - Copyright (c) 2026 Rabbyte
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Links
|
|
343
|
+
|
|
344
|
+
- [Kontexted Server](https://github.com/kontexted/kontexted) - Main Kontexted application
|
|
345
|
+
- [Issues & Bug Reports](https://github.com/kontexted/kontexted-mcp-cli/issues)
|
|
346
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/) - MCP specification
|