@knightcodeai/cli-linux-x64 0.11.1 → 0.11.2
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/bin/CHANGELOG.md +24 -0
- package/bin/docs/cli.md +3 -3
- package/bin/docs/extensions.md +2 -2
- package/bin/docs/mcp.md +123 -82
- package/bin/docs/sdk.md +1 -1
- package/bin/docs/settings.md +1 -1
- package/bin/knightcode +2 -2
- package/bin/package.json +6 -6
- package/package.json +1 -1
package/bin/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @knightcodeai/cli
|
|
2
2
|
|
|
3
|
+
## 0.11.2
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added an `oauth.clientName` setting for MCP servers (`knightcode mcp add --oauth-client-name`) to change the client name sent during OAuth client registration, for servers such as Figma that only accept known clients.
|
|
8
|
+
|
|
9
|
+
- Added a `description` field for MCP servers (`knightcode mcp add --description`), shown next to the server in the `codemode` and `tool_search` descriptions, and a `describeNamespace(name)` codemode helper that returns a namespace's instructions and tool names.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Changed the `codemode` description to list MCP servers instead of their tools, so it no longer changes when a server's tool list changes. Scripts find tools with `searchTools()` and read server instructions with `describeNamespace()`; `codemode-deferred` is now an alias for `codemode`, and `direct` exposure keeps tools visible to the model.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Fixed codemode `image()` accepting malformed base64 data or unsupported image types, which stored an invalid image block that made every later provider request fail with HTTP 400. It now throws a `TypeError` unless the data is valid base64 of a PNG, JPEG, GIF, or WebP image, takes the MIME type from the image signature, and strips line breaks from wrapped base64.
|
|
18
|
+
|
|
19
|
+
- Fixed codemode failing to start its script worker from the standalone Windows executable.
|
|
20
|
+
|
|
21
|
+
- Fixed the `/mcp` sign-in URL not being clickable when it wraps across lines. It is now a terminal hyperlink with a `Cmd/Ctrl+click to open` line, like `/login`.
|
|
22
|
+
|
|
23
|
+
- Fixed new sessions intermittently ignoring the saved default model, or warning that no models are available, when it belongs to an extension-registered native provider with a stored credential.
|
|
24
|
+
|
|
25
|
+
- Fixed context overflow errors from the Z.AI China endpoint ("Prompt exceeds max length") not being recognised, so compaction and retry now trigger for them as they do for the global endpoint.
|
|
26
|
+
|
|
3
27
|
## 0.11.1
|
|
4
28
|
|
|
5
29
|
### Added
|
package/bin/docs/cli.md
CHANGED
|
@@ -173,7 +173,7 @@ A script may start with an options line such as `// @options: {"max_output_token
|
|
|
173
173
|
|
|
174
174
|
While `codemode` is active, `codemode.mode` in [settings](settings.md#tools) decides how the other tools are presented. With `on` (default) declared tools keep being declared and their descriptions show how to call them from scripts. With `only` they are hidden from the model and listed in the `codemode` description instead, so the model calls them through scripts.
|
|
175
175
|
|
|
176
|
-
The `codemode` description lists the callable tools with their TypeScript declarations, grouped by namespace (for example one MCP server). Declarations share a budget of 3000 estimated tokens (`codemode.inlineBudget` in [settings](settings.md#tools))
|
|
176
|
+
The `codemode` description lists the callable tools with their TypeScript declarations, grouped by namespace (for example one MCP server). Tools with `deferred` exposure, which includes MCP tools with the default `codemode` exposure, are not listed; their namespace is listed with its description. Declarations share a budget of 3000 estimated tokens (`codemode.inlineBudget` in [settings](settings.md#tools)), and the description says whether the list is complete. Scripts find the rest with `await searchTools(query, { limit, namespace })`, which ranks tools with BM25, and `await describeTool(name)`, or by filtering `ALL_TOOLS`. `await describeNamespace(name)` returns a namespace's description, its instructions (for MCP servers, the server instructions), and the names of its tools.
|
|
177
177
|
|
|
178
178
|
Tools with an output schema resolve to structured values: `bash` to `{ output, truncated, full_output_path?, exit_code, wall_time_seconds }`, also for non-zero exit codes, and MCP tools to their `CallToolResult`. Other tools resolve to their text output. The `output` of `bash` is not limited to the 2000 lines or 50KB the model sees: it holds up to 1 MiB, and longer output keeps its first and last 512 KiB around an omission marker, with `truncated` set and the full output in `full_output_path`.
|
|
179
179
|
|
|
@@ -320,12 +320,12 @@ These commands work outside a session, so agents can run them through `bash`. Se
|
|
|
320
320
|
| Command | Description |
|
|
321
321
|
|---|---|
|
|
322
322
|
| `knightcode mcp add <server> [options] -- <command> [args...]` | Add or replace a stdio server in `mcp.json`; `--env KEY=VALUE` (repeatable) and `--cwd <dir>` set its environment and working directory. Arguments after the command are passed to it |
|
|
323
|
-
| `knightcode mcp add <server> [options] --url <url>` | Add or replace a streamable HTTP server; `--header KEY=VALUE` (repeatable), `--bearer-token-env-var <NAME>` (sends `Authorization: Bearer ${NAME}`), `--oauth-client-id`, `--oauth-client-secret`, and `--oauth-
|
|
323
|
+
| `knightcode mcp add <server> [options] --url <url>` | Add or replace a streamable HTTP server; `--header KEY=VALUE` (repeatable), `--bearer-token-env-var <NAME>` (sends `Authorization: Bearer ${NAME}`), `--oauth-client-id`, `--oauth-client-secret`, `--oauth-callback-port`, and `--oauth-client-name` configure authentication |
|
|
324
324
|
| `knightcode mcp remove <server>` | Remove a server from `mcp.json`; stored OAuth credentials are kept |
|
|
325
325
|
| `knightcode mcp list [--json]` | Connect to every enabled server and print its state, tools, and errors; exit with `1` when a config entry is invalid or an enabled server is not connected |
|
|
326
326
|
| `knightcode mcp login <server> [--timeout <seconds>]` | Sign in to an OAuth server: open the authorization page and wait for the browser (default 300 seconds); a terminal also accepts the pasted redirect URL |
|
|
327
327
|
| `knightcode mcp logout <server>` | Delete the stored OAuth credentials of a server |
|
|
328
328
|
|
|
329
|
-
`add` and `remove` change `~/.knightcode/agent/mcp.json`, or `.knightcode/mcp.json` in the current directory with `--local` (`-l`). `add` also takes `--exposure <mode>` (see [Exposure](mcp.md#exposure)) and does not connect; run `knightcode mcp list` to check the server.
|
|
329
|
+
`add` and `remove` change `~/.knightcode/agent/mcp.json`, or `.knightcode/mcp.json` in the current directory with `--local` (`-l`). `add` also takes `--exposure <mode>` (see [Exposure](mcp.md#exposure)) and `--description <text>` and does not connect; run `knightcode mcp list` to check the server.
|
|
330
330
|
|
|
331
331
|
Project `.knightcode/mcp.json` files are only read for projects that are already trusted.
|
package/bin/docs/extensions.md
CHANGED
|
@@ -159,7 +159,7 @@ See [`hello.ts`](../examples/extensions/hello.ts), [`todo.ts`](../examples/exten
|
|
|
159
159
|
- `deferred`: like `codemode`, but codemode tools do not list it; `tool_search` can find and activate it.
|
|
160
160
|
- `hidden`: registered but unreachable. Re-register a tool with `exposure: "hidden"` to withdraw it, since tools cannot be unregistered.
|
|
161
161
|
|
|
162
|
-
`namespace: { name, description }` groups related tools, as MCP servers do. Codemode tools list a namespace under one heading
|
|
162
|
+
`namespace: { name, description, instructions }` groups related tools, as MCP servers do. Codemode tools list a namespace under one heading with its `description`. `instructions` holds longer usage guidance; it is not listed, and codemode scripts read it with `describeNamespace(name)`.
|
|
163
163
|
|
|
164
164
|
Registering a `direct` or `model-only` tool activates it; the other exposures are not activated on registration. The active set (`knightcode.getActiveTools()`, `knightcode.setActiveTools()`) is the set of tools declared to the model. `knightcode.getAllTools()` reports each tool's `exposure`, `namespace`, and `annotations`.
|
|
165
165
|
|
|
@@ -187,7 +187,7 @@ KnightCode records the initial prompt and tool set in the transcript's first sys
|
|
|
187
187
|
|
|
188
188
|
### MCP servers
|
|
189
189
|
|
|
190
|
-
`knightcode.registerMcpServer(name, config)` adds an MCP server for the current session. `config` has the shape of an `mcpServers` entry in [`mcp.json`](mcp.md): `command`, `args`, `env`, and `cwd` for stdio servers, `url`, `headers`, and `oauth` for HTTP servers, plus `exposure`, `toolExposure`, `enabled`, and `timeout`.
|
|
190
|
+
`knightcode.registerMcpServer(name, config)` adds an MCP server for the current session. `config` has the shape of an `mcpServers` entry in [`mcp.json`](mcp.md): `command`, `args`, `env`, and `cwd` for stdio servers, `url`, `headers`, and `oauth` for HTTP servers, plus `exposure`, `toolExposure`, `description`, `enabled`, and `timeout`.
|
|
191
191
|
|
|
192
192
|
```typescript
|
|
193
193
|
knightcode.registerMcpServer("jira", { url: "https://mcp.example.com/jira", exposure: "codemode" });
|
package/bin/docs/mcp.md
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
# MCP Servers
|
|
2
2
|
|
|
3
|
-
KnightCode connects to [Model Context Protocol](https://modelcontextprotocol.io) servers over stdio or streamable HTTP and makes their tools available to the model.
|
|
3
|
+
KnightCode connects to [Model Context Protocol](https://modelcontextprotocol.io) servers over stdio or streamable HTTP and makes their tools and resources available to the model.
|
|
4
|
+
|
|
5
|
+
## Quick setup
|
|
6
|
+
|
|
7
|
+
Add a local stdio server, check the connection, then start KnightCode:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
knightcode mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem .
|
|
11
|
+
knightcode mcp list
|
|
12
|
+
knightcode
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For a remote server:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
knightcode mcp add docs --url https://example.com/mcp --bearer-token-env-var DOCS_TOKEN
|
|
19
|
+
knightcode mcp list
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
These commands add user-level servers by default. Add `--local` or `-l` to write the project configuration instead:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
knightcode mcp add -l tools --env API_KEY='${TOOLS_KEY}' -- uvx tools-mcp
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use `/mcp` inside an interactive session to inspect connections, sign in, reconnect, change exposure, or enable and disable servers. Run `/reload` after adding, removing, or changing a server outside the session.
|
|
4
29
|
|
|
5
30
|
## Configure servers
|
|
6
31
|
|
|
7
|
-
|
|
32
|
+
KnightCode reads user-level servers from `~/.knightcode/agent/mcp.json` and project servers from `.knightcode/mcp.json`. Project configuration is read only after [project trust](security.md#understand-project-trust) is granted. A project entry replaces a user-level entry with the same name.
|
|
33
|
+
|
|
34
|
+
The format matches other MCP clients:
|
|
8
35
|
|
|
9
36
|
```json
|
|
10
37
|
{
|
|
@@ -16,77 +43,66 @@ Add servers to `~/.knightcode/agent/mcp.json`, or to `.knightcode/mcp.json` in a
|
|
|
16
43
|
"docs": {
|
|
17
44
|
"url": "https://example.com/mcp",
|
|
18
45
|
"headers": { "Authorization": "Bearer ${DOCS_TOKEN}" },
|
|
19
|
-
"
|
|
46
|
+
"description": "Search and read the product documentation"
|
|
20
47
|
}
|
|
21
48
|
}
|
|
22
49
|
}
|
|
23
50
|
```
|
|
24
51
|
|
|
25
|
-
|
|
26
|
-
- HTTP servers take `url`, `headers`, and `oauth` (see [Sign in with OAuth](#sign-in-with-oauth)). The legacy SSE transport is not supported.
|
|
27
|
-
- `env` and `headers` values can reference environment variables (`${NAME}`) or commands (`!command`), like provider API keys.
|
|
28
|
-
- `timeout` sets the per-request timeout in seconds (default 60). Progress notifications from the server reset it.
|
|
29
|
-
- `enabled: false` keeps an entry without connecting to it.
|
|
52
|
+
Stdio servers use `command`, `args`, `env`, and `cwd`. Relative `cwd` values resolve against the session directory. A leading `~/` in `command`, an argument, or `cwd` names the home directory.
|
|
30
53
|
|
|
31
|
-
|
|
54
|
+
HTTP servers use `url`, `headers`, and `oauth` (see [Authenticate with OAuth](#authenticate-with-oauth)). The legacy SSE transport is not supported.
|
|
32
55
|
|
|
33
|
-
|
|
56
|
+
Both server types support:
|
|
34
57
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
- `timeout`: per-request timeout in seconds (default 60). Progress notifications reset it.
|
|
59
|
+
- `enabled: false`: keep the entry without connecting to it.
|
|
60
|
+
- `exposure` and `toolExposure`: control how tools reach the model (see [Control tool exposure](#control-tool-exposure)).
|
|
61
|
+
- `description`: what the server offers, in a sentence. The `codemode` and `tool_search` descriptions show it next to the server, so the model knows what to search for.
|
|
62
|
+
|
|
63
|
+
Keep personal servers and servers with credentials in the user-level file. Use the project file only for servers the project requires, and only in trusted projects.
|
|
41
64
|
|
|
42
|
-
|
|
65
|
+
### Configuration rules
|
|
43
66
|
|
|
44
|
-
- Server names may only
|
|
45
|
-
- `type` is optional
|
|
46
|
-
- `
|
|
47
|
-
-
|
|
48
|
-
-
|
|
67
|
+
- Server names may contain only letters, digits, `_`, and `-`. Tools are named `mcp__<server>__<tool>`.
|
|
68
|
+
- `type` is optional. A `command` selects stdio and a `url` selects streamable HTTP. When present, `type` must be `stdio`, `http`, or `streamable-http`.
|
|
69
|
+
- `sse` is rejected. Servers that document an SSE endpoint often also provide streamable HTTP, commonly at `/mcp` instead of `/sse`.
|
|
70
|
+
- `command` is one executable and `args` contains its arguments. It is not a shell command string.
|
|
71
|
+
- `env` and `headers` values can use environment variables such as `${GITHUB_TOKEN}`. They can also run a command with `!command`, but the command must make up the whole value, for example `"Authorization": "!echo Bearer $(gh auth token)"`.
|
|
72
|
+
- Invalid entries are reported and skipped without preventing other servers from connecting.
|
|
49
73
|
|
|
50
|
-
|
|
74
|
+
`knightcode mcp add` and `knightcode mcp remove` cover common changes from a shell. See [MCP commands](cli.md#mcp-commands) for their options.
|
|
51
75
|
|
|
52
|
-
|
|
76
|
+
### Inspect or change a server
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
2. Convert entries written for other clients:
|
|
56
|
-
- Claude Desktop, Claude Code, and Cursor use the same `mcpServers` shape; copy the entry.
|
|
57
|
-
- VS Code uses a top-level `servers` object and `inputs` prompts; move the entry under `mcpServers` and replace `${input:...}` with `${NAME}` environment variables.
|
|
58
|
-
- Codex uses TOML (`[mcp_servers.<name>]` with `command`, `args`, `env`, or `url`); write the same fields as JSON.
|
|
59
|
-
- opencode uses `"type": "local"` with `command` as an array (split it into `command` and `args`), `"type": "remote"` for URLs, `environment` for `env`, and `{env:NAME}` for `${NAME}`.
|
|
60
|
-
3. Run `knightcode mcp list` to check the entry. It connects to every enabled server and prints the state, the tools, and errors such as the stderr of a stdio server that failed to start. It exits with 1 while anything is wrong.
|
|
61
|
-
4. For a server that needs a sign-in, run `knightcode mcp login <server>`. It opens the authorization page in the user's browser and waits until the user approves access; tell the user to approve it. A running session uses the new credentials on its next turn.
|
|
62
|
-
5. Tell the user to run `/reload` (or start a new session) so the running session connects to added or changed servers.
|
|
78
|
+
`/mcp` lists configured servers with their state, tool count, exposure, and configuration source. Servers that need attention appear first. Select a server to inspect its tools and connection details, reconnect, sign in or out, change exposure, or enable and disable it.
|
|
63
79
|
|
|
64
|
-
|
|
80
|
+
Exposure and enabled-state changes are saved to the file that defines the server without replacing unrelated content. Disabled servers remain listed. Outside the interactive TUI, `/mcp` prints server status; `/mcp login <server>`, `/mcp logout <server>`, and `/mcp reconnect <server>` perform those actions directly.
|
|
65
81
|
|
|
66
|
-
|
|
82
|
+
Shell commands work without a session: `knightcode mcp add`, `knightcode mcp remove`, `knightcode mcp list`, `knightcode mcp login`, and `knightcode mcp logout`. Shell commands do not load extensions.
|
|
67
83
|
|
|
68
|
-
|
|
84
|
+
### Diagnose connection problems
|
|
69
85
|
|
|
70
|
-
|
|
86
|
+
Run `knightcode mcp list` to connect to every enabled server and print its state, tools, and errors. It exits with status 1 when an entry is invalid or an enabled server is not connected. `/mcp` shows the full connection error and the tail of stderr from a failed stdio server.
|
|
71
87
|
|
|
72
|
-
|
|
88
|
+
KnightCode reports configuration errors, failed connections, and required sign-ins once after startup. Server logging notifications are appended to `~/.knightcode/agent/mcp.log` as `<time> [<server>] <level> <logger>: <message>`. The file moves to `mcp.log.1` after it grows past 5 MB.
|
|
73
89
|
|
|
74
|
-
|
|
75
|
-
- see its tools, its command or URL, and the full connection error, including the tail of a stdio server's stderr
|
|
76
|
-
- reconnect
|
|
77
|
-
- sign out, which deletes the stored OAuth credentials
|
|
78
|
-
- change its exposure (see [Exposure](#exposure))
|
|
79
|
-
- disable or enable it
|
|
90
|
+
KnightCode connects when a session starts. The first prompt waits up to 10 seconds for startup connections; tools from slower servers become available when they connect. HTTP network errors and transient statuses (408, 429, and 5xx) are retried twice. A dropped connection is shown as disconnected and reconnects on the next call. When a server announces a changed tool list, new tools are added and withdrawn tools become unreachable.
|
|
80
91
|
|
|
81
|
-
|
|
92
|
+
Stopping a stdio server closes its stdin, sends SIGTERM, then sends SIGKILL to its process group. This also stops servers launched through wrappers such as `npx` or `uvx`.
|
|
82
93
|
|
|
83
|
-
|
|
94
|
+
## Migrate configuration from another client
|
|
84
95
|
|
|
85
|
-
|
|
96
|
+
Move the converted entry under `mcpServers` in `mcp.json`, then run `knightcode mcp list` to validate it.
|
|
86
97
|
|
|
87
|
-
|
|
98
|
+
| Client | Conversion |
|
|
99
|
+
|---|---|
|
|
100
|
+
| Claude Desktop, Claude Code, or Cursor | Copy the existing `mcpServers` entry. |
|
|
101
|
+
| VS Code | Move an entry from the top-level `servers` object and replace `${input:...}` prompts with `${NAME}` environment variables. |
|
|
102
|
+
| Codex | Convert `[mcp_servers.<name>]` TOML fields such as `command`, `args`, `env`, and `url` to JSON. |
|
|
103
|
+
| OpenCode | Convert `"type": "local"` to a stdio entry, split its `command` array into `command` and `args`, rename `environment` to `env`, and replace `{env:NAME}` with `${NAME}`. Convert `"type": "remote"` to a URL entry. |
|
|
88
104
|
|
|
89
|
-
##
|
|
105
|
+
## Authenticate with OAuth
|
|
90
106
|
|
|
91
107
|
Remote servers that use OAuth, such as Sentry, need no credentials in `mcp.json`:
|
|
92
108
|
|
|
@@ -98,11 +114,11 @@ Remote servers that use OAuth, such as Sentry, need no credentials in `mcp.json`
|
|
|
98
114
|
}
|
|
99
115
|
```
|
|
100
116
|
|
|
101
|
-
When
|
|
117
|
+
When the server rejects an unauthenticated connection, `/mcp` shows that it needs sign-in. Select "Sign in", run `/mcp login sentry`, or run `knightcode mcp login sentry`. KnightCode opens the authorization page and waits for approval. If the browser runs on another machine, such as over SSH, paste its redirected URL into the sign-in screen. A running session uses the new credentials on its next turn.
|
|
102
118
|
|
|
103
|
-
KnightCode registers itself with the authorization server
|
|
119
|
+
KnightCode registers itself with the authorization server, stores tokens in `~/.knightcode/agent/mcp-auth.json`, and refreshes access tokens when they expire or the server rejects them. If a server later requests additional scope, KnightCode asks for sign-in again. Signing out deletes the stored credentials.
|
|
104
120
|
|
|
105
|
-
OAuth applies to HTTP servers without an `Authorization` header. For
|
|
121
|
+
OAuth applies to HTTP servers without an `Authorization` header. For a server that does not support dynamic client registration, configure a registered client:
|
|
106
122
|
|
|
107
123
|
```json
|
|
108
124
|
{
|
|
@@ -115,21 +131,38 @@ OAuth applies to HTTP servers without an `Authorization` header. For authorizati
|
|
|
115
131
|
}
|
|
116
132
|
```
|
|
117
133
|
|
|
118
|
-
The redirect URI must match the
|
|
134
|
+
The redirect URI must match the registered URI. `callbackPort` uses `http://127.0.0.1:<port>/callback`. To use another URI, set `callbackUrl`; it must use HTTP on `localhost`, `127.0.0.1`, or `[::1]`. KnightCode sends it exactly as written. When `callbackUrl` omits a port, KnightCode uses `callbackPort` or a free port and adds it to the URI, as allowed for loopback redirects by RFC 8252. `clientSecret` is optional and can use an environment variable or command.
|
|
135
|
+
|
|
136
|
+
Set `scope` to a space-separated list for servers that do not advertise their required scopes. Otherwise, KnightCode requests the advertised scopes. Later scope requests are added to the configured value.
|
|
137
|
+
|
|
138
|
+
KnightCode registers as `knightcode`. Some servers only accept registrations from known clients. Set `clientName` to send another name:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"mcpServers": {
|
|
143
|
+
"figma": { "url": "https://mcp.figma.com/mcp", "oauth": { "clientName": "Claude Code" } }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The name is only sent when KnightCode registers a client. To register again under a new name, sign out first.
|
|
149
|
+
|
|
150
|
+
## Control tool exposure
|
|
119
151
|
|
|
120
|
-
|
|
152
|
+
Each server tool is registered as `mcp__<server>__<tool>`. The server's `exposure` determines how the model reaches it:
|
|
121
153
|
|
|
122
|
-
|
|
154
|
+
| Exposure | Behavior | Typical use |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| `codemode` (default) | Callable from [`codemode`](cli.md#tools) scripts, but neither declared to the model nor listed one by one. The codemode description lists the server with its `description`; scripts find tools with `searchTools()`, `describeTool()`, or `ALL_TOOLS`. | General MCP servers, especially when scripts should combine or filter calls. |
|
|
157
|
+
| `deferred` | Not declared until [`tool_search`](cli.md#tools) loads a match for the next model call. | Large servers whose tools should be called directly after discovery. |
|
|
158
|
+
| `direct` | Declared to the model like a built-in tool and also callable from codemode. | Small, frequently used tool sets. |
|
|
159
|
+
| `hidden` | Registered but unreachable. | Servers or tools that should remain unavailable. |
|
|
123
160
|
|
|
124
|
-
|
|
161
|
+
`codemode-deferred` is accepted as an alias for `codemode`.
|
|
125
162
|
|
|
126
|
-
|
|
127
|
-
- `codemode-deferred`: like `codemode`, but the tools are not listed in the `codemode` tool's description either; it only names the server and its tool count. Scripts call them by name and find them with `searchTools()` or in `ALL_TOOLS`. Use it for large servers that codemode scripts use rarely.
|
|
128
|
-
- `deferred`: the tools are not declared to the model until the [`tool_search`](cli.md#tools) tool loads them. The model searches, and the matches are declared from its next call on and called directly, without codemode. KnightCode activates the `tool_search` tool when such a server connects. Use it for large servers without codemode.
|
|
129
|
-
- `direct`: the tools are declared to the model like built-in tools, and are also callable from codemode.
|
|
130
|
-
- `hidden`: the tools are registered but cannot be called.
|
|
163
|
+
KnightCode activates `codemode` when a server with `codemode` exposure connects. It activates `tool_search` for a server with `deferred` exposure. To make the model see a tool without searching, give it `direct` exposure with `toolExposure`.
|
|
131
164
|
|
|
132
|
-
`toolExposure`
|
|
165
|
+
`toolExposure` overrides the server exposure for individual tools. Keys are exact server tool names or patterns where `*` matches any characters. Exact names win over patterns; among patterns, the first match wins. A server with `hidden` exposure can expose only selected tools:
|
|
133
166
|
|
|
134
167
|
```json
|
|
135
168
|
{
|
|
@@ -147,42 +180,50 @@ Each server's tools are registered as `mcp__<server>__<tool>`. The `exposure` se
|
|
|
147
180
|
}
|
|
148
181
|
```
|
|
149
182
|
|
|
150
|
-
`knightcode mcp list` marks tools whose exposure differs from
|
|
183
|
+
`knightcode mcp list` marks tools whose exposure differs from their server. The Tools view in `/mcp` also shows the effective exposure.
|
|
151
184
|
|
|
152
|
-
Tools
|
|
185
|
+
Tools with `codemode` or `deferred` exposure can be reached through either indirect mechanism: codemode scripts can call them, and `tool_search` can load them. Codemode calls do not depend on the active tool set, so they remain available after `/tree`, resume, and fork. Tools loaded by `tool_search` are recorded in the transcript and remain declared on that branch.
|
|
153
186
|
|
|
154
|
-
|
|
187
|
+
To keep `codemode` active without MCP servers, add `"defaultTools": ["+codemode"]` to [settings](settings.md#tools). To prevent automatic codemode activation, set `"autoEnableCodemode": false` beside `mcpServers`. A project value overrides the user-level value. KnightCode warns once when neither `codemode` nor `tool_search` is active and non-direct tools cannot be called.
|
|
155
188
|
|
|
156
|
-
Text results over
|
|
189
|
+
Text results over 20 KB reach the model with their middle removed around a `…N chars truncated…` marker. The full text is saved to a temporary file named in the result. Codemode scripts receive the complete result and can reduce it before returning output to the model.
|
|
157
190
|
|
|
158
|
-
Codemode scripts receive
|
|
191
|
+
Codemode scripts receive the complete MCP `CallToolResult`, including `content`, `structuredContent`, and `isError`. A result with `isError` resolves inside scripts but is reported as an error for direct calls. `image(result.content[0])` forwards an image block. Server instructions are not part of any tool description; scripts read them with `describeNamespace("mcp__<server>")`, which also returns the server's tool names.
|
|
159
192
|
|
|
160
|
-
##
|
|
193
|
+
## Use resources
|
|
161
194
|
|
|
162
|
-
When a connected server offers [resources](https://modelcontextprotocol.io/specification/2025-11-25/server/resources),
|
|
195
|
+
When a connected server offers [resources](https://modelcontextprotocol.io/specification/2025-11-25/server/resources), KnightCode adds the resource tools used by Codex and OpenCode:
|
|
163
196
|
|
|
164
|
-
- `list_mcp_resources` lists resources as JSON: `{ server?, resources: [{ server, uri, name, ... }], nextCursor? }`. With `server`, it lists one page
|
|
165
|
-
- `list_mcp_resource_templates` lists URI templates for resources the servers do not list
|
|
166
|
-
- `read_mcp_resource` reads a resource
|
|
197
|
+
- `list_mcp_resources` lists resources as JSON: `{ server?, resources: [{ server, uri, name, ... }], nextCursor? }`. With `server`, it lists one page; `cursor` continues with the next page. Without `server`, it lists every resource from every server.
|
|
198
|
+
- `list_mcp_resource_templates` lists URI templates for resources the servers do not list directly.
|
|
199
|
+
- `read_mcp_resource` reads a resource by `server` and `uri`. Text reaches the model as text and images as images. Other binary resources are saved to temporary files, and the model receives the path. Scripts receive `{ server, uri, contents }`.
|
|
167
200
|
|
|
168
|
-
|
|
201
|
+
These tools reach every enabled, non-hidden server with resources. Their exposure is the widest exposure among those servers: `direct`, then `codemode` or `deferred`. Resource links in tool results identify `read_mcp_resource` and the server.
|
|
169
202
|
|
|
170
|
-
Resources for MCP Apps
|
|
203
|
+
Resources for MCP Apps, identified by `ui://` URIs or `text/html;profile=mcp-app`, are omitted because KnightCode does not render them. Resource icons are also omitted.
|
|
171
204
|
|
|
172
|
-
Reading and listing resources is retried once after a transient HTTP error (408, 429, 5xx). Tool calls are not retried
|
|
205
|
+
Reading and listing resources is retried once after a transient HTTP error (408, 429, or 5xx). Tool calls are not retried because the server may already have performed them.
|
|
173
206
|
|
|
174
207
|
## Permissions
|
|
175
208
|
|
|
176
|
-
Every MCP call
|
|
209
|
+
Every MCP call passes through KnightCode's tool pipeline. Extension `tool_call` and `tool_result` handlers, including permission gates, therefore apply to MCP tools. Calls made from codemode scripts carry the codemode call ID as `parentToolCallId`.
|
|
210
|
+
|
|
211
|
+
`knightcode.getAllTools()` reports the annotations declared by each server: `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint`. Permission extensions can use these hints to decide which calls require confirmation (see [Tool exposure](extensions.md#tool-exposure)). Resource tools are marked read-only.
|
|
212
|
+
|
|
213
|
+
## Extensions and SDK
|
|
214
|
+
|
|
215
|
+
### Add servers from extensions
|
|
216
|
+
|
|
217
|
+
Extensions can add servers for the current session with `knightcode.registerMcpServer(name, config)`, using the same shape as an `mcpServers` entry (see [MCP servers in extensions](extensions.md#mcp-servers)). Registered servers connect like configured servers and appear in `/mcp` with the extension as their source.
|
|
177
218
|
|
|
178
|
-
|
|
219
|
+
Changes to enabled state or exposure apply only to the current session. A file-configured server with the same name takes precedence, and `/mcp` lists the overridden registration. `knightcode mcp` shell commands do not load extensions and only see file-configured servers.
|
|
179
220
|
|
|
180
|
-
|
|
221
|
+
### Replace the built-in MCP support
|
|
181
222
|
|
|
182
|
-
|
|
223
|
+
An installed extension that registers `/mcp`, such as `knightcode-mcp-adapter`, replaces the built-in MCP support for sessions. KnightCode then does not read `mcp.json` or connect its servers in a session, and `/mcp` belongs to the extension. Remove the extension to restore the built-in behavior. To disable built-in MCP support without a replacement, disable `mcp` under Built-in in `knightcode config`, or set `"extensions": ["-builtin:mcp"]` in [settings](settings.md#resources).
|
|
183
224
|
|
|
184
|
-
An
|
|
225
|
+
An extension that registers `codemode` or `tool_search` similarly replaces the built-in tool with that name. Shell-level `knightcode mcp` commands always use the built-in implementation.
|
|
185
226
|
|
|
186
|
-
|
|
227
|
+
### Use MCP from the SDK
|
|
187
228
|
|
|
188
|
-
SDK sessions do not load
|
|
229
|
+
SDK sessions do not load built-in extensions. Add the MCP extension, the codemode extension for `codemode` servers, and the tool-search extension for `deferred` servers to the resource loader. See [Codemode and MCP](sdk.md#codemode-mcp).
|
package/bin/docs/sdk.md
CHANGED
|
@@ -113,7 +113,7 @@ Inline extension factories can be supplied through `DefaultResourceLoader`. Give
|
|
|
113
113
|
|
|
114
114
|
<a id="codemode-mcp"></a>
|
|
115
115
|
|
|
116
|
-
The CLI loads `codemode`, `tool_search`, and MCP as built-in extensions. SDK sessions do not; add `createCodemodeExtension()`, `createToolSearchExtension()`, and `createMcpExtension()` to the `extensionFactories` of `DefaultResourceLoader`. `codemode` and `tool_search` are registered inactive: enable them through the `defaultTools` setting (`["+codemode", "+tool_search"]` keeps the other default tools), or let the MCP extension activate them: `codemode` for servers with `codemode`
|
|
116
|
+
The CLI loads `codemode`, `tool_search`, and MCP as built-in extensions. SDK sessions do not; add `createCodemodeExtension()`, `createToolSearchExtension()`, and `createMcpExtension()` to the `extensionFactories` of `DefaultResourceLoader`. `codemode` and `tool_search` are registered inactive: enable them through the `defaultTools` setting (`["+codemode", "+tool_search"]` keeps the other default tools), or let the MCP extension activate them: `codemode` for servers with `codemode` exposure, `tool_search` for servers with `deferred` exposure. The MCP extension connects its servers on `session_start`, so call `session.bindExtensions()`. See [Codemode and MCP](../examples/sdk/14-codemode-mcp.ts).
|
|
117
117
|
|
|
118
118
|
See the focused examples for [models](../examples/sdk/02-custom-model.ts), [tools](../examples/sdk/05-tools.ts), [extensions](../examples/sdk/06-extensions.ts), and [full control](../examples/sdk/12-full-control.ts).
|
|
119
119
|
|
package/bin/docs/settings.md
CHANGED
|
@@ -38,7 +38,7 @@ See [Choose a Model](models.md) for model selection and thinking controls.
|
|
|
38
38
|
| Setting | Type | Default | Description |
|
|
39
39
|
|---|---|---|---|
|
|
40
40
|
| `defaultTools` | `string[]` | `read`, `bash`, `edit`, `write` | Tools enabled at startup. Plain names replace the defaults; `+name` adds a tool and `-name` removes one. An empty array disables all built-in tools but not extension or SDK tools. |
|
|
41
|
-
| `codemode.mode` | `"on"` \| `"only"` | `"on"` | How the `codemode` tool presents tools while it is active. `on`: declared tools get their `codemode` declaration appended to their description, and `codemode` lists only tools that are not declared
|
|
41
|
+
| `codemode.mode` | `"on"` \| `"only"` | `"on"` | How the `codemode` tool presents tools while it is active. `on`: declared tools get their `codemode` declaration appended to their description, and `codemode` lists only tools that are not declared. `only`: `codemode` lists every tool scripts can call, and active built-in and extension tools are hidden from the model, so it reaches them through `codemode`. |
|
|
42
42
|
| `codemode.inlineBudget` | number | `3000` | Estimated tokens (characters / 4) the `codemode` tool's description may spend on tool declarations. Tools that do not fit are left out and found with `searchTools()`. `0` lists only namespaces. |
|
|
43
43
|
|
|
44
44
|
Available built-in tools are `read`, `bash`, `powershell`, `edit`, `write`, `grep`, `find`, and `ls`. `defaultTools` can also name `codemode` and `tool_search`, which built-in extensions register inactive, and other extension tools registered inactive.
|
package/bin/knightcode
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/knightcode
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 119395055 bytes
|
|
4
|
+
sha256: d60c458eebe031960e565ec6ee7a94434ae1e7e29d1a56b64f06eda7a8333858
|
package/bin/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knightcodeai/cli",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "KnightCode — a local, BYOK terminal coding agent powered by OpenRouter.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"test": "vitest --run"
|
|
38
38
|
},
|
|
39
39
|
"optionalDependencies": {
|
|
40
|
-
"@knightcodeai/cli-linux-x64": "0.11.
|
|
41
|
-
"@knightcodeai/cli-linux-arm64": "0.11.
|
|
42
|
-
"@knightcodeai/cli-darwin-x64": "0.11.
|
|
43
|
-
"@knightcodeai/cli-darwin-arm64": "0.11.
|
|
44
|
-
"@knightcodeai/cli-win32-x64": "0.11.
|
|
40
|
+
"@knightcodeai/cli-linux-x64": "0.11.2",
|
|
41
|
+
"@knightcodeai/cli-linux-arm64": "0.11.2",
|
|
42
|
+
"@knightcodeai/cli-darwin-x64": "0.11.2",
|
|
43
|
+
"@knightcodeai/cli-darwin-arm64": "0.11.2",
|
|
44
|
+
"@knightcodeai/cli-win32-x64": "0.11.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@agentclientprotocol/sdk": "1.4.0",
|