@xiaozhiclaw/mcp-host-config 0.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/LICENSE +21 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +335 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Peter Steinberger
|
|
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type McpBindingV1, type McpInstallationRecordV1, type SecretRefV1 } from "@xiaozhiclaw/mcp-contract";
|
|
2
|
+
export declare const MCP_HOST_CONFIG_FORMATS: readonly ["xiaozhi", "vscode", "codex", "claude-desktop"];
|
|
3
|
+
export type McpHostConfigFormat = (typeof MCP_HOST_CONFIG_FORMATS)[number];
|
|
4
|
+
export interface McpHostProjectionV1 {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly installation: McpInstallationRecordV1;
|
|
7
|
+
readonly binding: McpBindingV1;
|
|
8
|
+
}
|
|
9
|
+
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
10
|
+
[key: string]: JsonValue;
|
|
11
|
+
};
|
|
12
|
+
type JsonObject = {
|
|
13
|
+
[key: string]: JsonValue;
|
|
14
|
+
};
|
|
15
|
+
export type ParsedMcpHostConfigV1 = {
|
|
16
|
+
readonly format: "xiaozhi";
|
|
17
|
+
readonly value: JsonObject;
|
|
18
|
+
} | {
|
|
19
|
+
readonly format: "vscode";
|
|
20
|
+
readonly value: JsonObject;
|
|
21
|
+
} | {
|
|
22
|
+
readonly format: "claude-desktop";
|
|
23
|
+
readonly value: JsonObject;
|
|
24
|
+
} | {
|
|
25
|
+
readonly format: "codex";
|
|
26
|
+
readonly source: string;
|
|
27
|
+
readonly occupiedNames: readonly string[];
|
|
28
|
+
readonly additions: readonly McpHostProjectionV1[];
|
|
29
|
+
};
|
|
30
|
+
export interface McpHostConfigConflictV1 {
|
|
31
|
+
readonly code: "MCP_HOST_CONFIG_COLLISION";
|
|
32
|
+
readonly format: McpHostConfigFormat;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly path: string;
|
|
35
|
+
}
|
|
36
|
+
export type McpHostConfigMergePlanV1 = {
|
|
37
|
+
readonly ok: true;
|
|
38
|
+
readonly document: ParsedMcpHostConfigV1;
|
|
39
|
+
} | {
|
|
40
|
+
readonly ok: false;
|
|
41
|
+
readonly conflicts: readonly McpHostConfigConflictV1[];
|
|
42
|
+
};
|
|
43
|
+
export declare function parseMcpHostConfig(format: McpHostConfigFormat, source: string): ParsedMcpHostConfigV1;
|
|
44
|
+
export declare function renderSecretRefPlaceholder(secretRef: SecretRefV1): string;
|
|
45
|
+
export declare function planMcpHostConfigMerge(document: ParsedMcpHostConfigV1, values: readonly McpHostProjectionV1[]): McpHostConfigMergePlanV1;
|
|
46
|
+
export declare function renderMcpHostConfig(document: ParsedMcpHostConfigV1): string;
|
|
47
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { parseMcpBindingV1, parseMcpInstallationRecordV1, } from "@xiaozhiclaw/mcp-contract";
|
|
2
|
+
import { parse as parseToml, stringify as stringifyToml } from "@iarna/toml";
|
|
3
|
+
export const MCP_HOST_CONFIG_FORMATS = [
|
|
4
|
+
"xiaozhi",
|
|
5
|
+
"vscode",
|
|
6
|
+
"codex",
|
|
7
|
+
"claude-desktop",
|
|
8
|
+
];
|
|
9
|
+
function fail(path, message) {
|
|
10
|
+
throw new TypeError(`${path}: ${message}`);
|
|
11
|
+
}
|
|
12
|
+
function compareUnicodeCodePoints(left, right) {
|
|
13
|
+
const leftCodePoints = Array.from(left);
|
|
14
|
+
const rightCodePoints = Array.from(right);
|
|
15
|
+
const sharedLength = Math.min(leftCodePoints.length, rightCodePoints.length);
|
|
16
|
+
for (let index = 0; index < sharedLength; index += 1) {
|
|
17
|
+
const difference = leftCodePoints[index].codePointAt(0) - rightCodePoints[index].codePointAt(0);
|
|
18
|
+
if (difference !== 0)
|
|
19
|
+
return difference;
|
|
20
|
+
}
|
|
21
|
+
return leftCodePoints.length - rightCodePoints.length;
|
|
22
|
+
}
|
|
23
|
+
function assertValidUnicode(value, path) {
|
|
24
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
25
|
+
const codeUnit = value.charCodeAt(index);
|
|
26
|
+
if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
|
|
27
|
+
const nextCodeUnit = value.charCodeAt(index + 1);
|
|
28
|
+
if (index + 1 >= value.length || nextCodeUnit < 0xdc00 || nextCodeUnit > 0xdfff) {
|
|
29
|
+
fail(path, "contains an unpaired Unicode surrogate");
|
|
30
|
+
}
|
|
31
|
+
index += 1;
|
|
32
|
+
}
|
|
33
|
+
else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
|
|
34
|
+
fail(path, "contains an unpaired Unicode surrogate");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function hasOwn(value, key) {
|
|
39
|
+
return Object.hasOwn(value, key);
|
|
40
|
+
}
|
|
41
|
+
function setOwn(target, key, value) {
|
|
42
|
+
Object.defineProperty(target, key, {
|
|
43
|
+
configurable: true,
|
|
44
|
+
enumerable: true,
|
|
45
|
+
value,
|
|
46
|
+
writable: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function emptyJsonObject() {
|
|
50
|
+
return Object.create(null);
|
|
51
|
+
}
|
|
52
|
+
function object(value, path) {
|
|
53
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
54
|
+
fail(path, "expected object");
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
function cloneJson(value) {
|
|
58
|
+
return JSON.parse(JSON.stringify(value));
|
|
59
|
+
}
|
|
60
|
+
function parseJsonRoot(source, path) {
|
|
61
|
+
let value;
|
|
62
|
+
try {
|
|
63
|
+
value = JSON.parse(source.trim() === "" ? "{}" : source);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
fail(path, error instanceof Error ? error.message : "invalid JSON");
|
|
67
|
+
}
|
|
68
|
+
return object(value, `${path} root`);
|
|
69
|
+
}
|
|
70
|
+
function parseCodexNames(value) {
|
|
71
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
72
|
+
fail("codex TOML", "expected object root");
|
|
73
|
+
const servers = value.mcp_servers;
|
|
74
|
+
if (servers === undefined)
|
|
75
|
+
return [];
|
|
76
|
+
if (!servers || typeof servers !== "object" || Array.isArray(servers)) {
|
|
77
|
+
return fail("codex TOML mcp_servers", "expected table");
|
|
78
|
+
}
|
|
79
|
+
return Object.keys(servers).sort(compareUnicodeCodePoints);
|
|
80
|
+
}
|
|
81
|
+
export function parseMcpHostConfig(format, source) {
|
|
82
|
+
if (typeof source !== "string")
|
|
83
|
+
fail("source", "expected string");
|
|
84
|
+
if (format === "codex") {
|
|
85
|
+
let parsed;
|
|
86
|
+
try {
|
|
87
|
+
parsed = parseToml(source);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
fail("codex TOML", error instanceof Error ? error.message : "parse failed");
|
|
91
|
+
}
|
|
92
|
+
return Object.freeze({
|
|
93
|
+
format,
|
|
94
|
+
source,
|
|
95
|
+
occupiedNames: Object.freeze(parseCodexNames(parsed)),
|
|
96
|
+
additions: Object.freeze([]),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const value = parseJsonRoot(source, format);
|
|
100
|
+
if (format === "xiaozhi") {
|
|
101
|
+
if (value.installations !== undefined)
|
|
102
|
+
object(value.installations, "xiaozhi.installations");
|
|
103
|
+
if (value.bindings !== undefined)
|
|
104
|
+
object(value.bindings, "xiaozhi.bindings");
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const key = format === "vscode" ? "servers" : "mcpServers";
|
|
108
|
+
if (value[key] !== undefined)
|
|
109
|
+
object(value[key], `${format}.${key}`);
|
|
110
|
+
}
|
|
111
|
+
return Object.freeze({ format, value: cloneJson(value) });
|
|
112
|
+
}
|
|
113
|
+
export function renderSecretRefPlaceholder(secretRef) {
|
|
114
|
+
if (secretRef?.kind !== "secret-ref" || typeof secretRef.id !== "string" || secretRef.id.length === 0) {
|
|
115
|
+
return fail("secretRef", "expected SecretRefV1");
|
|
116
|
+
}
|
|
117
|
+
return `<secret-ref:${secretRef.id}>`;
|
|
118
|
+
}
|
|
119
|
+
function definitionValue(value, binding) {
|
|
120
|
+
if (value.kind === "literal")
|
|
121
|
+
return value.value;
|
|
122
|
+
if (value.valueKind === "text") {
|
|
123
|
+
const input = binding.inputValues[value.inputKey];
|
|
124
|
+
if (!input)
|
|
125
|
+
return fail(`binding.inputValues.${value.inputKey}`, "required by installation template");
|
|
126
|
+
return input.value;
|
|
127
|
+
}
|
|
128
|
+
const secretRef = binding.secretRefs[value.inputKey];
|
|
129
|
+
if (!secretRef)
|
|
130
|
+
return fail(`binding.secretRefs.${value.inputKey}`, "required by installation template");
|
|
131
|
+
return renderSecretRefPlaceholder(secretRef);
|
|
132
|
+
}
|
|
133
|
+
function valueRecord(values, binding) {
|
|
134
|
+
if (!values)
|
|
135
|
+
return undefined;
|
|
136
|
+
return Object.fromEntries(Object.keys(values).sort(compareUnicodeCodePoints).map((key) => [key, definitionValue(values[key], binding)]));
|
|
137
|
+
}
|
|
138
|
+
function externalDefinition(format, definition, binding) {
|
|
139
|
+
if (definition.transport === "stdio") {
|
|
140
|
+
const projected = { command: definition.commandPath };
|
|
141
|
+
if (definition.args)
|
|
142
|
+
projected.args = definition.args.map((value) => definitionValue(value, binding));
|
|
143
|
+
if (definition.cwd)
|
|
144
|
+
projected.cwd = definition.cwd;
|
|
145
|
+
const environment = valueRecord(definition.environment, binding);
|
|
146
|
+
if (environment)
|
|
147
|
+
projected.env = environment;
|
|
148
|
+
if (format === "vscode")
|
|
149
|
+
projected.type = "stdio";
|
|
150
|
+
return projected;
|
|
151
|
+
}
|
|
152
|
+
const projected = { url: definition.url };
|
|
153
|
+
const headers = valueRecord(definition.headers, binding);
|
|
154
|
+
if (headers)
|
|
155
|
+
projected[format === "codex" ? "http_headers" : "headers"] = headers;
|
|
156
|
+
if (format !== "codex")
|
|
157
|
+
projected.type = "http";
|
|
158
|
+
return projected;
|
|
159
|
+
}
|
|
160
|
+
function projection(value) {
|
|
161
|
+
if (!value || typeof value !== "object")
|
|
162
|
+
fail("projection", "expected object");
|
|
163
|
+
if (typeof value.name === "string")
|
|
164
|
+
assertValidUnicode(value.name, "projection.name");
|
|
165
|
+
if (typeof value.name !== "string" || value.name.length === 0 || value.name.length > 128 || /[\u0000-\u001f\u007f]/.test(value.name)) {
|
|
166
|
+
fail("projection.name", "expected non-empty display key without control characters");
|
|
167
|
+
}
|
|
168
|
+
const installation = parseMcpInstallationRecordV1(value.installation);
|
|
169
|
+
const binding = parseMcpBindingV1(value.binding);
|
|
170
|
+
if (binding.installationId !== installation.installationId) {
|
|
171
|
+
fail("projection.binding.installationId", "must match installation.installationId");
|
|
172
|
+
}
|
|
173
|
+
const definitionValues = installation.definition.transport === "stdio"
|
|
174
|
+
? [...(installation.definition.args ?? []), ...Object.values(installation.definition.environment ?? {})]
|
|
175
|
+
: Object.values(installation.definition.headers ?? {});
|
|
176
|
+
for (const definitionValue of definitionValues) {
|
|
177
|
+
if (definitionValue.kind !== "binding-input-ref")
|
|
178
|
+
continue;
|
|
179
|
+
if (definitionValue.valueKind === "text") {
|
|
180
|
+
if (!Object.hasOwn(binding.inputValues, definitionValue.inputKey))
|
|
181
|
+
fail(`projection.binding.inputValues.${definitionValue.inputKey}`, "required by installation template");
|
|
182
|
+
if (Object.hasOwn(binding.secretRefs, definitionValue.inputKey))
|
|
183
|
+
fail(`projection.binding.${definitionValue.inputKey}`, "text template input cannot use a SecretRef");
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (!Object.hasOwn(binding.secretRefs, definitionValue.inputKey))
|
|
187
|
+
fail(`projection.binding.secretRefs.${definitionValue.inputKey}`, "SecretRef required by installation template");
|
|
188
|
+
if (Object.hasOwn(binding.inputValues, definitionValue.inputKey))
|
|
189
|
+
fail(`projection.binding.inputValues.${definitionValue.inputKey}`, "secret template input must never contain plaintext");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return Object.freeze({ name: value.name, installation, binding });
|
|
193
|
+
}
|
|
194
|
+
function conflict(format, entry, path) {
|
|
195
|
+
return Object.freeze({ code: "MCP_HOST_CONFIG_COLLISION", format, name: entry.name, path });
|
|
196
|
+
}
|
|
197
|
+
function stableJsonValue(value) {
|
|
198
|
+
if (Array.isArray(value))
|
|
199
|
+
return value.map(stableJsonValue);
|
|
200
|
+
if (value && typeof value === "object") {
|
|
201
|
+
const stable = emptyJsonObject();
|
|
202
|
+
for (const key of Object.keys(value).sort(compareUnicodeCodePoints)) {
|
|
203
|
+
setOwn(stable, key, stableJsonValue(value[key]));
|
|
204
|
+
}
|
|
205
|
+
return stable;
|
|
206
|
+
}
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
function jsonPlan(document, entries) {
|
|
210
|
+
const value = cloneJson(document.value);
|
|
211
|
+
const conflicts = [];
|
|
212
|
+
const seenNames = new Set();
|
|
213
|
+
if (document.format === "xiaozhi") {
|
|
214
|
+
const installations = value.installations === undefined ? emptyJsonObject() : object(value.installations, "xiaozhi.installations");
|
|
215
|
+
const bindings = value.bindings === undefined ? emptyJsonObject() : object(value.bindings, "xiaozhi.bindings");
|
|
216
|
+
const batchInstallationIds = new Set();
|
|
217
|
+
const batchBindingIds = new Set();
|
|
218
|
+
for (const entry of entries) {
|
|
219
|
+
if (seenNames.has(entry.name))
|
|
220
|
+
conflicts.push(conflict(document.format, entry, `projections.${entry.name}`));
|
|
221
|
+
if (hasOwn(installations, entry.installation.installationId)) {
|
|
222
|
+
conflicts.push(conflict(document.format, entry, `installations.${entry.installation.installationId}`));
|
|
223
|
+
}
|
|
224
|
+
else if (hasOwn(bindings, entry.binding.bindingId)) {
|
|
225
|
+
conflicts.push(conflict(document.format, entry, `bindings.${entry.binding.bindingId}`));
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
if (batchInstallationIds.has(entry.installation.installationId)) {
|
|
229
|
+
conflicts.push(conflict(document.format, entry, `installations.${entry.installation.installationId}`));
|
|
230
|
+
}
|
|
231
|
+
if (batchBindingIds.has(entry.binding.bindingId)) {
|
|
232
|
+
conflicts.push(conflict(document.format, entry, `bindings.${entry.binding.bindingId}`));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
seenNames.add(entry.name);
|
|
236
|
+
batchInstallationIds.add(entry.installation.installationId);
|
|
237
|
+
batchBindingIds.add(entry.binding.bindingId);
|
|
238
|
+
}
|
|
239
|
+
if (conflicts.length > 0)
|
|
240
|
+
return { ok: false, conflicts: Object.freeze(conflicts) };
|
|
241
|
+
for (const entry of entries) {
|
|
242
|
+
setOwn(installations, entry.installation.installationId, cloneJson(entry.installation));
|
|
243
|
+
setOwn(bindings, entry.binding.bindingId, cloneJson(entry.binding));
|
|
244
|
+
}
|
|
245
|
+
value.installations = installations;
|
|
246
|
+
value.bindings = bindings;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
const key = document.format === "vscode" ? "servers" : "mcpServers";
|
|
250
|
+
const servers = value[key] === undefined ? emptyJsonObject() : object(value[key], `${document.format}.${key}`);
|
|
251
|
+
for (const entry of entries) {
|
|
252
|
+
if (seenNames.has(entry.name) || hasOwn(servers, entry.name))
|
|
253
|
+
conflicts.push(conflict(document.format, entry, `${key}.${entry.name}`));
|
|
254
|
+
seenNames.add(entry.name);
|
|
255
|
+
}
|
|
256
|
+
if (conflicts.length > 0)
|
|
257
|
+
return { ok: false, conflicts: Object.freeze(conflicts) };
|
|
258
|
+
for (const entry of entries)
|
|
259
|
+
setOwn(servers, entry.name, externalDefinition(document.format, entry.installation.definition, entry.binding));
|
|
260
|
+
value[key] = servers;
|
|
261
|
+
}
|
|
262
|
+
return { ok: true, document: Object.freeze({ format: document.format, value }) };
|
|
263
|
+
}
|
|
264
|
+
export function planMcpHostConfigMerge(document, values) {
|
|
265
|
+
if (!Array.isArray(values))
|
|
266
|
+
fail("projections", "expected array");
|
|
267
|
+
const entries = values.map(projection).sort((left, right) => compareUnicodeCodePoints(left.name, right.name));
|
|
268
|
+
if (document.format !== "codex")
|
|
269
|
+
return jsonPlan(document, entries);
|
|
270
|
+
const occupied = new Set([
|
|
271
|
+
...document.occupiedNames,
|
|
272
|
+
...document.additions.map((entry) => entry.name),
|
|
273
|
+
]);
|
|
274
|
+
const conflicts = [];
|
|
275
|
+
for (const entry of entries) {
|
|
276
|
+
if (occupied.has(entry.name))
|
|
277
|
+
conflicts.push(conflict("codex", entry, `mcp_servers.${entry.name}`));
|
|
278
|
+
occupied.add(entry.name);
|
|
279
|
+
}
|
|
280
|
+
if (conflicts.length > 0)
|
|
281
|
+
return { ok: false, conflicts: Object.freeze(conflicts) };
|
|
282
|
+
return {
|
|
283
|
+
ok: true,
|
|
284
|
+
document: Object.freeze({
|
|
285
|
+
format: "codex",
|
|
286
|
+
source: document.source,
|
|
287
|
+
occupiedNames: Object.freeze([...document.occupiedNames]),
|
|
288
|
+
additions: Object.freeze([...document.additions, ...entries].sort((left, right) => compareUnicodeCodePoints(left.name, right.name))),
|
|
289
|
+
}),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function tomlString(value) {
|
|
293
|
+
assertValidUnicode(value, "TOML string");
|
|
294
|
+
return stringifyToml.value(value);
|
|
295
|
+
}
|
|
296
|
+
function tomlArray(values) {
|
|
297
|
+
return `[${values.map(tomlString).join(", ")}]`;
|
|
298
|
+
}
|
|
299
|
+
function tomlInlineTable(values) {
|
|
300
|
+
return `{ ${Object.keys(values).sort(compareUnicodeCodePoints).map((key) => `${tomlString(key)} = ${tomlString(values[key])}`).join(", ")} }`;
|
|
301
|
+
}
|
|
302
|
+
function renderCodexEntry(entry) {
|
|
303
|
+
const definition = entry.installation.definition;
|
|
304
|
+
const lines = [`[mcp_servers.${tomlString(entry.name)}]`];
|
|
305
|
+
if (definition.transport === "stdio") {
|
|
306
|
+
lines.push(`command = ${tomlString(definition.commandPath)}`);
|
|
307
|
+
if (definition.args)
|
|
308
|
+
lines.push(`args = ${tomlArray(definition.args.map((value) => definitionValue(value, entry.binding)))}`);
|
|
309
|
+
if (definition.cwd)
|
|
310
|
+
lines.push(`cwd = ${tomlString(definition.cwd)}`);
|
|
311
|
+
const environment = valueRecord(definition.environment, entry.binding);
|
|
312
|
+
if (environment)
|
|
313
|
+
lines.push(`env = ${tomlInlineTable(environment)}`);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
lines.push(`url = ${tomlString(definition.url)}`);
|
|
317
|
+
const headers = valueRecord(definition.headers, entry.binding);
|
|
318
|
+
if (headers)
|
|
319
|
+
lines.push(`http_headers = ${tomlInlineTable(headers)}`);
|
|
320
|
+
}
|
|
321
|
+
return lines.join("\n");
|
|
322
|
+
}
|
|
323
|
+
export function renderMcpHostConfig(document) {
|
|
324
|
+
if (document.format !== "codex") {
|
|
325
|
+
return `${JSON.stringify(stableJsonValue(document.value), null, 2)}\n`;
|
|
326
|
+
}
|
|
327
|
+
if (document.additions.length === 0)
|
|
328
|
+
return document.source;
|
|
329
|
+
let source = document.source;
|
|
330
|
+
if (source.length > 0 && !source.endsWith("\n"))
|
|
331
|
+
source += "\n";
|
|
332
|
+
if (source.length > 0 && !source.endsWith("\n\n"))
|
|
333
|
+
source += "\n";
|
|
334
|
+
return `${source}${document.additions.map(renderCodexEntry).join("\n\n")}\n`;
|
|
335
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xiaozhiclaw/mcp-host-config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pure MCP configuration projections for Xiaozhi and external Hosts",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@iarna/toml": "2.2.5",
|
|
25
|
+
"@xiaozhiclaw/mcp-contract": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"vitest": "^3.2.6"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"pack:check": "node scripts/check-pack.mjs"
|
|
36
|
+
}
|
|
37
|
+
}
|