@kilncraft/mcp 1.0.0 → 1.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 +172 -0
- package/package.json +3 -3
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.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@kilncraft/core": "1.
|
|
19
|
-
"@kilncraft/shared": "1.
|
|
18
|
+
"@kilncraft/core": "1.1.1",
|
|
19
|
+
"@kilncraft/shared": "1.1.1",
|
|
20
20
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
21
21
|
"zod": "4.6.7"
|
|
22
22
|
},
|