@kilncraft/mcp 1.0.0 → 1.1.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 +172 -0
- package/package.json +10 -10
- package/LICENSE +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @kilncraft/mcp
|
|
2
|
+
|
|
3
|
+
Model Context Protocol integration for Kilncraft: connect to MCP servers, expose
|
|
4
|
+
their tools to the agent, and serve Kilncraft's own tools over MCP.
|
|
5
|
+
|
|
6
|
+
Supports both stdio and Streamable HTTP transports.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm i @kilncraft/mcp
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Node.js >= 24.
|
|
15
|
+
|
|
16
|
+
## Client: connect to an MCP server
|
|
17
|
+
|
|
18
|
+
An MCP server is either a local command or an HTTP URL:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { connectMcpServer } from "@kilncraft/mcp";
|
|
22
|
+
|
|
23
|
+
const connection = await connectMcpServer("files", {
|
|
24
|
+
command: "npx",
|
|
25
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log(connection.tools.map((tool) => tool.id));
|
|
29
|
+
await connection.close();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
HTTP transport:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const connection = await connectMcpServer("remote", {
|
|
36
|
+
url: "https://mcp.example.com/mcp",
|
|
37
|
+
headers: { authorization: "Bearer …" },
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`connectMcpServer` returns `McpConnection`:
|
|
42
|
+
|
|
43
|
+
| Field | Type | Purpose |
|
|
44
|
+
| -------- | --------------------- | -------------------------- |
|
|
45
|
+
| `name` | string | Config key |
|
|
46
|
+
| `client` | MCP `Client` | Underlying protocol client |
|
|
47
|
+
| `tools` | `ToolDefinition[]` | Kilncraft tool adapters |
|
|
48
|
+
| `close` | `() => Promise<void>` | Disconnect |
|
|
49
|
+
|
|
50
|
+
Each remote tool becomes a Kilncraft tool named
|
|
51
|
+
`mcp_<server>_<tool>`. It is registered as non-read-only with
|
|
52
|
+
`defaultDecision: "ask"` and a 120-second timeout, so destructive MCP tools still
|
|
53
|
+
go through the permission system.
|
|
54
|
+
|
|
55
|
+
## Register many servers
|
|
56
|
+
|
|
57
|
+
`mcp.servers` in `config.json` is the usual source:
|
|
58
|
+
|
|
59
|
+
```jsonc
|
|
60
|
+
{
|
|
61
|
+
"mcp": {
|
|
62
|
+
"servers": {
|
|
63
|
+
"files": {
|
|
64
|
+
"command": "npx",
|
|
65
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
|
|
66
|
+
},
|
|
67
|
+
"remote": {
|
|
68
|
+
"url": "https://mcp.example.com/mcp",
|
|
69
|
+
"headers": { "authorization": "Bearer …" }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Register them into a tool registry:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { registerMcpTools } from "@kilncraft/mcp";
|
|
80
|
+
import { createDefaultToolRegistry } from "@kilncraft/core";
|
|
81
|
+
import { loadConfig } from "@kilncraft/shared";
|
|
82
|
+
|
|
83
|
+
const { config } = await loadConfig();
|
|
84
|
+
const tools = createDefaultToolRegistry();
|
|
85
|
+
const connections = await registerMcpTools(tools, config.mcp.servers);
|
|
86
|
+
|
|
87
|
+
// later
|
|
88
|
+
await Promise.all(connections.map((connection) => connection.close()));
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
One failing server is logged and skipped; the rest still load.
|
|
92
|
+
|
|
93
|
+
## Server: expose Kilncraft tools over MCP
|
|
94
|
+
|
|
95
|
+
Stdio (used by `kilncraft mcp serve`):
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { startMcpStdioServer } from "@kilncraft/mcp";
|
|
99
|
+
import { createDefaultToolRegistry } from "@kilncraft/core";
|
|
100
|
+
|
|
101
|
+
const tools = createDefaultToolRegistry();
|
|
102
|
+
await startMcpStdioServer(tools.list());
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Only read-only tools are exposed by default. Pass `allowDestructive: true` to
|
|
106
|
+
expose mutating tools:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
await startMcpStdioServer(tools.list(), { allowDestructive: true });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Streamable HTTP handler:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { createMcpHttpHandler } from "@kilncraft/mcp";
|
|
116
|
+
import { createDefaultToolRegistry } from "@kilncraft/core";
|
|
117
|
+
|
|
118
|
+
const handler = await createMcpHttpHandler(createDefaultToolRegistry().list());
|
|
119
|
+
const response = await handler(
|
|
120
|
+
new Request("http://localhost/mcp", {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: { "content-type": "application/json" },
|
|
123
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} }),
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The HTTP handler manages MCP session ids via the `mcp-session-id` header and
|
|
129
|
+
closes transports when sessions end.
|
|
130
|
+
|
|
131
|
+
## Tool output mapping
|
|
132
|
+
|
|
133
|
+
`mcpContentFromOutput` converts a Kilncraft `ToolOutput` into MCP content:
|
|
134
|
+
|
|
135
|
+
| Kilncraft output | MCP content |
|
|
136
|
+
| --------------------- | -------------------------------------- |
|
|
137
|
+
| `text` | text |
|
|
138
|
+
| `json` / `structured` | pretty-printed JSON text |
|
|
139
|
+
| `diff` | diff text |
|
|
140
|
+
| `terminal` | stdout, stderr, and exit code as text |
|
|
141
|
+
| `image` | image content with `mimeType` and data |
|
|
142
|
+
|
|
143
|
+
`mcpResultToOutput` converts an MCP result back into a Kilncraft `ToolOutput`:
|
|
144
|
+
text is joined, image content becomes an image output, errors become text, and
|
|
145
|
+
other results become JSON.
|
|
146
|
+
|
|
147
|
+
## Permissions
|
|
148
|
+
|
|
149
|
+
Remote MCP tools default to `ask`, so the agent cannot silently run a destructive
|
|
150
|
+
server tool. The CLI's `mcp serve --allow-destructive` is an explicit opt-in for
|
|
151
|
+
trusted clients. Treat any MCP server you connect as code you are willing to run.
|
|
152
|
+
|
|
153
|
+
## Timeouts and cancellation
|
|
154
|
+
|
|
155
|
+
Tool calls use a 120-second timeout and forward the agent's `AbortSignal`, so
|
|
156
|
+
aborting a turn cancels in-flight MCP requests.
|
|
157
|
+
|
|
158
|
+
## Development
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
pnpm --filter @kilncraft/mcp build
|
|
162
|
+
pnpm --filter @kilncraft/mcp test
|
|
163
|
+
pnpm --filter @kilncraft/mcp typecheck
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Related packages
|
|
167
|
+
|
|
168
|
+
- `@kilncraft/core` — tool registry and agent loop
|
|
169
|
+
- `@kilncraft/server` — exposes `/mcp` over HTTP
|
|
170
|
+
- `@kilncraft/cli` — `kilncraft mcp list|serve`
|
|
171
|
+
- `@kilncraft/shared` — tool contracts
|
|
172
|
+
- [Root README](../../README.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kilncraft/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,9 +14,15 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"clean": "rm -rf dist .turbo coverage"
|
|
22
|
+
},
|
|
17
23
|
"dependencies": {
|
|
18
|
-
"@kilncraft/core": "
|
|
19
|
-
"@kilncraft/shared": "
|
|
24
|
+
"@kilncraft/core": "workspace:*",
|
|
25
|
+
"@kilncraft/shared": "workspace:*",
|
|
20
26
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
21
27
|
"zod": "4.6.7"
|
|
22
28
|
},
|
|
@@ -29,11 +35,5 @@
|
|
|
29
35
|
},
|
|
30
36
|
"publishConfig": {
|
|
31
37
|
"access": "public"
|
|
32
|
-
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"build": "tsup",
|
|
35
|
-
"typecheck": "tsc --noEmit",
|
|
36
|
-
"test": "vitest run",
|
|
37
|
-
"clean": "rm -rf dist .turbo coverage"
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Kilncraft contributors
|
|
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.
|