@getbourdon/client 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 +157 -0
- package/README.md +32 -0
- package/dist/index.cjs +161 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +134 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
125
|
+
|
|
126
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
127
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
128
|
+
unless required by applicable law (such as deliberate and grossly
|
|
129
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
130
|
+
liable to You for damages, including any direct, indirect, special,
|
|
131
|
+
incidental, or consequential damages of any character arising as a
|
|
132
|
+
result of this License or out of the use or inability to use the
|
|
133
|
+
Work.
|
|
134
|
+
|
|
135
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
136
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
137
|
+
charge a fee for, acceptance of support, warranty, indemnity, or
|
|
138
|
+
other liability obligations and/or rights consistent with this
|
|
139
|
+
License. However, in accepting such obligations, You may act only
|
|
140
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
141
|
+
of any other Contributor.
|
|
142
|
+
|
|
143
|
+
END OF TERMS AND CONDITIONS
|
|
144
|
+
|
|
145
|
+
Copyright 2026 RADLAB LLC
|
|
146
|
+
|
|
147
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
148
|
+
you may not use this file except in compliance with the License.
|
|
149
|
+
You may obtain a copy of the License at
|
|
150
|
+
|
|
151
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
152
|
+
|
|
153
|
+
Unless required by applicable law or agreed to in writing, software
|
|
154
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
155
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
156
|
+
See the License for the specific language governing permissions and
|
|
157
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @getbourdon/client
|
|
2
|
+
|
|
3
|
+
The **Bourdon L6 federation MCP client** for TypeScript/Node. Query a running
|
|
4
|
+
[Bourdon](https://bourdon.ai) L6 server — over a spawned `python -m core.l6_server`
|
|
5
|
+
stdio subprocess, or a long-lived Streamable-HTTP service — from any JS agent.
|
|
6
|
+
|
|
7
|
+
Wire-compatible with the Python L6 server: results are JSON-parsed from the server's
|
|
8
|
+
`TextContent` envelope, exactly as a Python peer does. Built on `@modelcontextprotocol/sdk`.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { BourdonL6Client } from "@getbourdon/client";
|
|
12
|
+
|
|
13
|
+
// Spawn the Python L6 server over stdio (Python is the oracle):
|
|
14
|
+
const bourdon = new BourdonL6Client({ transport: "stdio", library: "~/agent-library" });
|
|
15
|
+
await bourdon.findEntity({ name: "Castmore" });
|
|
16
|
+
await bourdon.listRecentWork({ limit: 10 });
|
|
17
|
+
await bourdon.prepareRecognitionContext({ prompt: userMessage });
|
|
18
|
+
await bourdon.close();
|
|
19
|
+
|
|
20
|
+
// Or a remote federation peer over Streamable HTTP with a Bearer token:
|
|
21
|
+
const peer = new BourdonL6Client({ transport: "http", url: "https://peer/mcp", token });
|
|
22
|
+
await peer.listAgents();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
All ten L6 tools are exposed: `queryAgentMemory`, `listRecentWork`, `findEntity`,
|
|
26
|
+
`listAgents`, `exportAgents`, `getCrossAgentSummary`, `prepareRecognitionContext`,
|
|
27
|
+
`getDeeperContext`, `compileCodexTurn`, `commitToFederation`. The server applies its own
|
|
28
|
+
per-tool `access_level` defaults (public for queries, team for recognition), so omitted
|
|
29
|
+
args are dropped rather than defaulted client-side.
|
|
30
|
+
|
|
31
|
+
License: Apache-2.0 (interop client). The Bourdon engine is BUSL-1.1; the canonical
|
|
32
|
+
implementation is the Python project.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BourdonL6Client: () => BourdonL6Client
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/l6-client.ts
|
|
28
|
+
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
29
|
+
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
30
|
+
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
31
|
+
var BourdonL6Client = class {
|
|
32
|
+
client = null;
|
|
33
|
+
transport = null;
|
|
34
|
+
connectPromise = null;
|
|
35
|
+
config;
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.config = config;
|
|
38
|
+
}
|
|
39
|
+
/** Connect lazily on first call; subsequent calls reuse the live client. */
|
|
40
|
+
async ensureConnected() {
|
|
41
|
+
if (this.client) return this.client;
|
|
42
|
+
if (this.connectPromise) {
|
|
43
|
+
await this.connectPromise;
|
|
44
|
+
if (!this.client) throw new Error("Bourdon L6 client failed to initialize");
|
|
45
|
+
return this.client;
|
|
46
|
+
}
|
|
47
|
+
this.connectPromise = this.connect();
|
|
48
|
+
try {
|
|
49
|
+
await this.connectPromise;
|
|
50
|
+
} finally {
|
|
51
|
+
this.connectPromise = null;
|
|
52
|
+
}
|
|
53
|
+
if (!this.client) throw new Error("Bourdon L6 client failed to initialize");
|
|
54
|
+
return this.client;
|
|
55
|
+
}
|
|
56
|
+
async connect() {
|
|
57
|
+
const transport = this.buildTransport(this.config);
|
|
58
|
+
const client = new import_client.Client({ name: "@getbourdon/client", version: "0.1.0" }, { capabilities: {} });
|
|
59
|
+
await client.connect(transport);
|
|
60
|
+
this.client = client;
|
|
61
|
+
this.transport = transport;
|
|
62
|
+
}
|
|
63
|
+
buildTransport(config) {
|
|
64
|
+
if (config.transport === "custom") return config.instance;
|
|
65
|
+
if (config.transport === "stdio") {
|
|
66
|
+
const args = [...config.args ?? ["-m", "core.l6_server"]];
|
|
67
|
+
if (config.library && !args.includes("--library")) {
|
|
68
|
+
args.push("--library", config.library);
|
|
69
|
+
}
|
|
70
|
+
return new import_stdio.StdioClientTransport({
|
|
71
|
+
command: config.command ?? "python",
|
|
72
|
+
args,
|
|
73
|
+
cwd: config.cwd,
|
|
74
|
+
env: config.env
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const opts = config.token === void 0 ? void 0 : { requestInit: { headers: { Authorization: `Bearer ${config.token}` } } };
|
|
78
|
+
return new import_streamableHttp.StreamableHTTPClientTransport(new URL(config.url), opts);
|
|
79
|
+
}
|
|
80
|
+
/** Close the client and underlying transport. Idempotent. */
|
|
81
|
+
async close() {
|
|
82
|
+
if (this.client) {
|
|
83
|
+
await this.client.close().catch(() => {
|
|
84
|
+
});
|
|
85
|
+
this.client = null;
|
|
86
|
+
}
|
|
87
|
+
if (this.transport) {
|
|
88
|
+
await this.transport.close?.().catch(() => {
|
|
89
|
+
});
|
|
90
|
+
this.transport = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Generic call. Unwraps the server's TextContent JSON envelope to the payload.
|
|
95
|
+
* Prefer the typed methods below.
|
|
96
|
+
*/
|
|
97
|
+
async callTool(name, args = {}) {
|
|
98
|
+
const client = await this.ensureConnected();
|
|
99
|
+
const result = await client.callTool({ name, arguments: args });
|
|
100
|
+
return parseToolResult(result);
|
|
101
|
+
}
|
|
102
|
+
// -- the ten L6 tools (typed) ------------------------------------------------
|
|
103
|
+
queryAgentMemory(args) {
|
|
104
|
+
return this.callTool("query_agent_memory", argsToRecord(args));
|
|
105
|
+
}
|
|
106
|
+
listRecentWork(args = {}) {
|
|
107
|
+
return this.callTool("list_recent_work", argsToRecord(args));
|
|
108
|
+
}
|
|
109
|
+
findEntity(args) {
|
|
110
|
+
return this.callTool("find_entity", argsToRecord(args));
|
|
111
|
+
}
|
|
112
|
+
listAgents() {
|
|
113
|
+
return this.callTool("list_agents", {});
|
|
114
|
+
}
|
|
115
|
+
exportAgents() {
|
|
116
|
+
return this.callTool("export_agents", {});
|
|
117
|
+
}
|
|
118
|
+
getCrossAgentSummary(args) {
|
|
119
|
+
return this.callTool("get_cross_agent_summary", argsToRecord(args));
|
|
120
|
+
}
|
|
121
|
+
prepareRecognitionContext(args) {
|
|
122
|
+
return this.callTool("prepare_recognition_context", argsToRecord(args));
|
|
123
|
+
}
|
|
124
|
+
getDeeperContext(args) {
|
|
125
|
+
return this.callTool("get_deeper_context", argsToRecord(args));
|
|
126
|
+
}
|
|
127
|
+
compileCodexTurn(args) {
|
|
128
|
+
return this.callTool("compile_codex_turn", argsToRecord(args));
|
|
129
|
+
}
|
|
130
|
+
commitToFederation(args) {
|
|
131
|
+
return this.callTool("commit_to_federation", argsToRecord(args));
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function parseToolResult(result) {
|
|
135
|
+
const content = result.content;
|
|
136
|
+
if (Array.isArray(content)) {
|
|
137
|
+
const textBlock = content.find(
|
|
138
|
+
(c) => typeof c === "object" && c !== null && c.type === "text" && typeof c.text === "string"
|
|
139
|
+
);
|
|
140
|
+
if (textBlock) {
|
|
141
|
+
try {
|
|
142
|
+
return JSON.parse(textBlock.text);
|
|
143
|
+
} catch {
|
|
144
|
+
return textBlock.text;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
function argsToRecord(args) {
|
|
151
|
+
const out = {};
|
|
152
|
+
for (const [k, v] of Object.entries(args)) {
|
|
153
|
+
if (v !== void 0) out[k] = v;
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
BourdonL6Client
|
|
160
|
+
});
|
|
161
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/l6-client.ts"],"sourcesContent":["export {\n BourdonL6Client,\n type AccessLevel,\n type L6Config,\n type L6StdioConfig,\n type L6HttpConfig,\n type L6CustomConfig,\n type CommonToolArgs,\n type QueryAgentMemoryArgs,\n type ListRecentWorkArgs,\n type FindEntityArgs,\n type GetCrossAgentSummaryArgs,\n type RecognitionArgs,\n type CompileCodexTurnArgs,\n type CommitToFederationArgs,\n type L6ToolResult,\n} from \"./l6-client.js\";\n","/**\n * Bourdon L6 federation MCP client.\n *\n * Connects to a running Bourdon L6 server — spawned as a `python -m core.l6_server`\n * stdio subprocess (default) or a long-lived Streamable-HTTP service — and proxies\n * the ten L6 tools it exposes. Wraps the official `@modelcontextprotocol/sdk`\n * client so JSON-RPC framing is not re-implemented.\n *\n * Lifted and extended from the proven openclaw-bourdon-plugin client:\n * - all TEN tools (the plugin proxied six read tools)\n * - Streamable HTTP transport (SSE is deprecated in the SDK)\n * - results are JSON-parsed from the server's TextContent envelope\n * (the L6 server returns `{content:[{type:'text', text: JSON.stringify(payload)}]}`,\n * so a raw CallToolResult is unwrapped to the payload here)\n * - an injectable transport (`{transport:'custom'}`) for in-memory testing\n *\n * Tool surface mirrored from bourdon/core/l6_server.py. The server applies\n * per-tool `access_level` defaults (public for queries, team for recognition),\n * so this client never hardcodes them — omitted args are dropped, not defaulted.\n */\n\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport type { Transport } from \"@modelcontextprotocol/sdk/shared/transport.js\";\n\n/** Federation visibility level. Mirrors the Python `Visibility` enum values. */\nexport type AccessLevel = \"public\" | \"team\" | \"private\";\n\nexport interface L6StdioConfig {\n transport: \"stdio\";\n /** Defaults to `python`. */\n command?: string;\n /** Defaults to `[\"-m\", \"core.l6_server\"]`. */\n args?: string[];\n /** Optional library path forwarded to L6 via `--library`. */\n library?: string;\n /** cwd for the subprocess (so `core.l6_server` is importable when not installed). */\n cwd?: string;\n /** Optional environment passed to the subprocess. */\n env?: Record<string, string>;\n}\n\nexport interface L6HttpConfig {\n transport: \"http\";\n url: string;\n /** Bearer token sent as `Authorization: Bearer <token>` (federation peer auth). */\n token?: string;\n}\n\n/** Inject a pre-built transport (used for in-memory testing). */\nexport interface L6CustomConfig {\n transport: \"custom\";\n instance: Transport;\n}\n\nexport type L6Config = L6StdioConfig | L6HttpConfig | L6CustomConfig;\n\nexport interface CommonToolArgs {\n access_level?: AccessLevel;\n include_private?: boolean;\n}\n\nexport interface QueryAgentMemoryArgs extends CommonToolArgs {\n agent: string;\n topic: string;\n}\n\nexport interface ListRecentWorkArgs extends CommonToolArgs {\n /** ISO 8601 date or datetime. */\n since?: string;\n agent?: string;\n limit?: number;\n cursor?: string;\n summary?: boolean;\n}\n\nexport interface FindEntityArgs extends CommonToolArgs {\n name: string;\n}\n\nexport interface GetCrossAgentSummaryArgs extends CommonToolArgs {\n project: string;\n}\n\nexport interface RecognitionArgs extends CommonToolArgs {\n prompt: string;\n}\n\nexport interface CompileCodexTurnArgs {\n prompt: string;\n cwd?: string;\n access_level?: AccessLevel;\n max_items?: number;\n max_chars?: number;\n}\n\nexport interface CommitToFederationArgs {\n agent_id: string;\n agent_type?: string;\n instance?: string;\n role_narrative?: string;\n entities?: Record<string, unknown>[];\n sessions?: Record<string, unknown>[];\n /** `merge` (default) or `replace`. */\n mode?: string;\n}\n\n/** The parsed payload returned by an L6 tool (server-defined JSON shape). */\nexport type L6ToolResult = unknown;\n\nexport class BourdonL6Client {\n private client: Client | null = null;\n private transport: Transport | null = null;\n private connectPromise: Promise<void> | null = null;\n private readonly config: L6Config;\n\n constructor(config: L6Config) {\n this.config = config;\n }\n\n /** Connect lazily on first call; subsequent calls reuse the live client. */\n private async ensureConnected(): Promise<Client> {\n if (this.client) return this.client;\n if (this.connectPromise) {\n await this.connectPromise;\n if (!this.client) throw new Error(\"Bourdon L6 client failed to initialize\");\n return this.client;\n }\n this.connectPromise = this.connect();\n try {\n await this.connectPromise;\n } finally {\n this.connectPromise = null;\n }\n if (!this.client) throw new Error(\"Bourdon L6 client failed to initialize\");\n return this.client;\n }\n\n private async connect(): Promise<void> {\n const transport = this.buildTransport(this.config);\n const client = new Client({ name: \"@getbourdon/client\", version: \"0.1.0\" }, { capabilities: {} });\n await client.connect(transport);\n this.client = client;\n this.transport = transport;\n }\n\n private buildTransport(config: L6Config): Transport {\n if (config.transport === \"custom\") return config.instance;\n if (config.transport === \"stdio\") {\n const args = [...(config.args ?? [\"-m\", \"core.l6_server\"])];\n if (config.library && !args.includes(\"--library\")) {\n args.push(\"--library\", config.library);\n }\n return new StdioClientTransport({\n command: config.command ?? \"python\",\n args,\n cwd: config.cwd,\n env: config.env,\n });\n }\n // Streamable HTTP (replaces deprecated SSE). Bearer auth via request headers.\n const opts =\n config.token === undefined\n ? undefined\n : { requestInit: { headers: { Authorization: `Bearer ${config.token}` } } };\n return new StreamableHTTPClientTransport(new URL(config.url), opts);\n }\n\n /** Close the client and underlying transport. Idempotent. */\n async close(): Promise<void> {\n if (this.client) {\n await this.client.close().catch(() => {\n /* best-effort shutdown */\n });\n this.client = null;\n }\n if (this.transport) {\n await this.transport.close?.().catch(() => {});\n this.transport = null;\n }\n }\n\n /**\n * Generic call. Unwraps the server's TextContent JSON envelope to the payload.\n * Prefer the typed methods below.\n */\n async callTool(name: string, args: Record<string, unknown> = {}): Promise<L6ToolResult> {\n const client = await this.ensureConnected();\n const result = await client.callTool({ name, arguments: args });\n return parseToolResult(result);\n }\n\n // -- the ten L6 tools (typed) ------------------------------------------------\n\n queryAgentMemory(args: QueryAgentMemoryArgs): Promise<L6ToolResult> {\n return this.callTool(\"query_agent_memory\", argsToRecord(args));\n }\n\n listRecentWork(args: ListRecentWorkArgs = {}): Promise<L6ToolResult> {\n return this.callTool(\"list_recent_work\", argsToRecord(args));\n }\n\n findEntity(args: FindEntityArgs): Promise<L6ToolResult> {\n return this.callTool(\"find_entity\", argsToRecord(args));\n }\n\n listAgents(): Promise<L6ToolResult> {\n return this.callTool(\"list_agents\", {});\n }\n\n exportAgents(): Promise<L6ToolResult> {\n return this.callTool(\"export_agents\", {});\n }\n\n getCrossAgentSummary(args: GetCrossAgentSummaryArgs): Promise<L6ToolResult> {\n return this.callTool(\"get_cross_agent_summary\", argsToRecord(args));\n }\n\n prepareRecognitionContext(args: RecognitionArgs): Promise<L6ToolResult> {\n return this.callTool(\"prepare_recognition_context\", argsToRecord(args));\n }\n\n getDeeperContext(args: RecognitionArgs): Promise<L6ToolResult> {\n return this.callTool(\"get_deeper_context\", argsToRecord(args));\n }\n\n compileCodexTurn(args: CompileCodexTurnArgs): Promise<L6ToolResult> {\n return this.callTool(\"compile_codex_turn\", argsToRecord(args));\n }\n\n commitToFederation(args: CommitToFederationArgs): Promise<L6ToolResult> {\n return this.callTool(\"commit_to_federation\", argsToRecord(args));\n }\n}\n\n/* -- internals ------------------------------------------------------------- */\n\n/**\n * Unwrap an MCP CallToolResult to the L6 payload. The L6 server JSON-stringifies\n * its payload into a single `text` content block (so cross-language peers parse\n * it with `json.loads(item.text)`); we mirror that on the read side. Falls back to\n * the raw text, then the raw result, if the envelope is unexpected.\n */\nfunction parseToolResult(result: unknown): L6ToolResult {\n const content = (result as { content?: unknown }).content;\n if (Array.isArray(content)) {\n const textBlock = content.find(\n (c): c is { type: \"text\"; text: string } =>\n typeof c === \"object\" &&\n c !== null &&\n (c as { type?: unknown }).type === \"text\" &&\n typeof (c as { text?: unknown }).text === \"string\",\n );\n if (textBlock) {\n try {\n return JSON.parse(textBlock.text);\n } catch {\n return textBlock.text;\n }\n }\n }\n return result;\n}\n\n/** Drop undefined fields so the server applies its own per-tool defaults. */\nfunction argsToRecord(args: object): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(args as Record<string, unknown>)) {\n if (v !== undefined) out[k] = v;\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqBA,oBAAuB;AACvB,mBAAqC;AACrC,4BAA8C;AAwFvC,IAAM,kBAAN,MAAsB;AAAA,EACnB,SAAwB;AAAA,EACxB,YAA8B;AAAA,EAC9B,iBAAuC;AAAA,EAC9B;AAAA,EAEjB,YAAY,QAAkB;AAC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aAAa,IAAI,CAAC;AAAA,EAC/D;AAAA,EAEA,iBAAiB,MAAmD;AAClE,WAAO,KAAK,SAAS,sBAAsB,aAAa,IAAI,CAAC;AAAA,EAC/D;AAAA,EAEA,mBAAmB,MAAqD;AACtE,WAAO,KAAK,SAAS,wBAAwB,aAAa,IAAI,CAAC;AAAA,EACjE;AACF;AAUA,SAAS,gBAAgB,QAA+B;AACtD,QAAM,UAAW,OAAiC;AAClD,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,UAAM,YAAY,QAAQ;AAAA,MACxB,CAAC,MACC,OAAO,MAAM,YACb,MAAM,QACL,EAAyB,SAAS,UACnC,OAAQ,EAAyB,SAAS;AAAA,IAC9C;AACA,QAAI,WAAW;AACb,UAAI;AACF,eAAO,KAAK,MAAM,UAAU,IAAI;AAAA,MAClC,QAAQ;AACN,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAGA,SAAS,aAAa,MAAuC;AAC3D,QAAM,MAA+B,CAAC;AACtC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,IAA+B,GAAG;AACpE,QAAI,MAAM,OAAW,KAAI,CAAC,IAAI;AAAA,EAChC;AACA,SAAO;AACT;","names":[]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/l6-client.ts
|
|
2
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
5
|
+
var BourdonL6Client = class {
|
|
6
|
+
client = null;
|
|
7
|
+
transport = null;
|
|
8
|
+
connectPromise = null;
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
/** Connect lazily on first call; subsequent calls reuse the live client. */
|
|
14
|
+
async ensureConnected() {
|
|
15
|
+
if (this.client) return this.client;
|
|
16
|
+
if (this.connectPromise) {
|
|
17
|
+
await this.connectPromise;
|
|
18
|
+
if (!this.client) throw new Error("Bourdon L6 client failed to initialize");
|
|
19
|
+
return this.client;
|
|
20
|
+
}
|
|
21
|
+
this.connectPromise = this.connect();
|
|
22
|
+
try {
|
|
23
|
+
await this.connectPromise;
|
|
24
|
+
} finally {
|
|
25
|
+
this.connectPromise = null;
|
|
26
|
+
}
|
|
27
|
+
if (!this.client) throw new Error("Bourdon L6 client failed to initialize");
|
|
28
|
+
return this.client;
|
|
29
|
+
}
|
|
30
|
+
async connect() {
|
|
31
|
+
const transport = this.buildTransport(this.config);
|
|
32
|
+
const client = new Client({ name: "@getbourdon/client", version: "0.1.0" }, { capabilities: {} });
|
|
33
|
+
await client.connect(transport);
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.transport = transport;
|
|
36
|
+
}
|
|
37
|
+
buildTransport(config) {
|
|
38
|
+
if (config.transport === "custom") return config.instance;
|
|
39
|
+
if (config.transport === "stdio") {
|
|
40
|
+
const args = [...config.args ?? ["-m", "core.l6_server"]];
|
|
41
|
+
if (config.library && !args.includes("--library")) {
|
|
42
|
+
args.push("--library", config.library);
|
|
43
|
+
}
|
|
44
|
+
return new StdioClientTransport({
|
|
45
|
+
command: config.command ?? "python",
|
|
46
|
+
args,
|
|
47
|
+
cwd: config.cwd,
|
|
48
|
+
env: config.env
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const opts = config.token === void 0 ? void 0 : { requestInit: { headers: { Authorization: `Bearer ${config.token}` } } };
|
|
52
|
+
return new StreamableHTTPClientTransport(new URL(config.url), opts);
|
|
53
|
+
}
|
|
54
|
+
/** Close the client and underlying transport. Idempotent. */
|
|
55
|
+
async close() {
|
|
56
|
+
if (this.client) {
|
|
57
|
+
await this.client.close().catch(() => {
|
|
58
|
+
});
|
|
59
|
+
this.client = null;
|
|
60
|
+
}
|
|
61
|
+
if (this.transport) {
|
|
62
|
+
await this.transport.close?.().catch(() => {
|
|
63
|
+
});
|
|
64
|
+
this.transport = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generic call. Unwraps the server's TextContent JSON envelope to the payload.
|
|
69
|
+
* Prefer the typed methods below.
|
|
70
|
+
*/
|
|
71
|
+
async callTool(name, args = {}) {
|
|
72
|
+
const client = await this.ensureConnected();
|
|
73
|
+
const result = await client.callTool({ name, arguments: args });
|
|
74
|
+
return parseToolResult(result);
|
|
75
|
+
}
|
|
76
|
+
// -- the ten L6 tools (typed) ------------------------------------------------
|
|
77
|
+
queryAgentMemory(args) {
|
|
78
|
+
return this.callTool("query_agent_memory", argsToRecord(args));
|
|
79
|
+
}
|
|
80
|
+
listRecentWork(args = {}) {
|
|
81
|
+
return this.callTool("list_recent_work", argsToRecord(args));
|
|
82
|
+
}
|
|
83
|
+
findEntity(args) {
|
|
84
|
+
return this.callTool("find_entity", argsToRecord(args));
|
|
85
|
+
}
|
|
86
|
+
listAgents() {
|
|
87
|
+
return this.callTool("list_agents", {});
|
|
88
|
+
}
|
|
89
|
+
exportAgents() {
|
|
90
|
+
return this.callTool("export_agents", {});
|
|
91
|
+
}
|
|
92
|
+
getCrossAgentSummary(args) {
|
|
93
|
+
return this.callTool("get_cross_agent_summary", argsToRecord(args));
|
|
94
|
+
}
|
|
95
|
+
prepareRecognitionContext(args) {
|
|
96
|
+
return this.callTool("prepare_recognition_context", argsToRecord(args));
|
|
97
|
+
}
|
|
98
|
+
getDeeperContext(args) {
|
|
99
|
+
return this.callTool("get_deeper_context", argsToRecord(args));
|
|
100
|
+
}
|
|
101
|
+
compileCodexTurn(args) {
|
|
102
|
+
return this.callTool("compile_codex_turn", argsToRecord(args));
|
|
103
|
+
}
|
|
104
|
+
commitToFederation(args) {
|
|
105
|
+
return this.callTool("commit_to_federation", argsToRecord(args));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function parseToolResult(result) {
|
|
109
|
+
const content = result.content;
|
|
110
|
+
if (Array.isArray(content)) {
|
|
111
|
+
const textBlock = content.find(
|
|
112
|
+
(c) => typeof c === "object" && c !== null && c.type === "text" && typeof c.text === "string"
|
|
113
|
+
);
|
|
114
|
+
if (textBlock) {
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(textBlock.text);
|
|
117
|
+
} catch {
|
|
118
|
+
return textBlock.text;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function argsToRecord(args) {
|
|
125
|
+
const out = {};
|
|
126
|
+
for (const [k, v] of Object.entries(args)) {
|
|
127
|
+
if (v !== void 0) out[k] = v;
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
BourdonL6Client
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/l6-client.ts"],"sourcesContent":["/**\n * Bourdon L6 federation MCP client.\n *\n * Connects to a running Bourdon L6 server — spawned as a `python -m core.l6_server`\n * stdio subprocess (default) or a long-lived Streamable-HTTP service — and proxies\n * the ten L6 tools it exposes. Wraps the official `@modelcontextprotocol/sdk`\n * client so JSON-RPC framing is not re-implemented.\n *\n * Lifted and extended from the proven openclaw-bourdon-plugin client:\n * - all TEN tools (the plugin proxied six read tools)\n * - Streamable HTTP transport (SSE is deprecated in the SDK)\n * - results are JSON-parsed from the server's TextContent envelope\n * (the L6 server returns `{content:[{type:'text', text: JSON.stringify(payload)}]}`,\n * so a raw CallToolResult is unwrapped to the payload here)\n * - an injectable transport (`{transport:'custom'}`) for in-memory testing\n *\n * Tool surface mirrored from bourdon/core/l6_server.py. The server applies\n * per-tool `access_level` defaults (public for queries, team for recognition),\n * so this client never hardcodes them — omitted args are dropped, not defaulted.\n */\n\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport type { Transport } from \"@modelcontextprotocol/sdk/shared/transport.js\";\n\n/** Federation visibility level. Mirrors the Python `Visibility` enum values. */\nexport type AccessLevel = \"public\" | \"team\" | \"private\";\n\nexport interface L6StdioConfig {\n transport: \"stdio\";\n /** Defaults to `python`. */\n command?: string;\n /** Defaults to `[\"-m\", \"core.l6_server\"]`. */\n args?: string[];\n /** Optional library path forwarded to L6 via `--library`. */\n library?: string;\n /** cwd for the subprocess (so `core.l6_server` is importable when not installed). */\n cwd?: string;\n /** Optional environment passed to the subprocess. */\n env?: Record<string, string>;\n}\n\nexport interface L6HttpConfig {\n transport: \"http\";\n url: string;\n /** Bearer token sent as `Authorization: Bearer <token>` (federation peer auth). */\n token?: string;\n}\n\n/** Inject a pre-built transport (used for in-memory testing). */\nexport interface L6CustomConfig {\n transport: \"custom\";\n instance: Transport;\n}\n\nexport type L6Config = L6StdioConfig | L6HttpConfig | L6CustomConfig;\n\nexport interface CommonToolArgs {\n access_level?: AccessLevel;\n include_private?: boolean;\n}\n\nexport interface QueryAgentMemoryArgs extends CommonToolArgs {\n agent: string;\n topic: string;\n}\n\nexport interface ListRecentWorkArgs extends CommonToolArgs {\n /** ISO 8601 date or datetime. */\n since?: string;\n agent?: string;\n limit?: number;\n cursor?: string;\n summary?: boolean;\n}\n\nexport interface FindEntityArgs extends CommonToolArgs {\n name: string;\n}\n\nexport interface GetCrossAgentSummaryArgs extends CommonToolArgs {\n project: string;\n}\n\nexport interface RecognitionArgs extends CommonToolArgs {\n prompt: string;\n}\n\nexport interface CompileCodexTurnArgs {\n prompt: string;\n cwd?: string;\n access_level?: AccessLevel;\n max_items?: number;\n max_chars?: number;\n}\n\nexport interface CommitToFederationArgs {\n agent_id: string;\n agent_type?: string;\n instance?: string;\n role_narrative?: string;\n entities?: Record<string, unknown>[];\n sessions?: Record<string, unknown>[];\n /** `merge` (default) or `replace`. */\n mode?: string;\n}\n\n/** The parsed payload returned by an L6 tool (server-defined JSON shape). */\nexport type L6ToolResult = unknown;\n\nexport class BourdonL6Client {\n private client: Client | null = null;\n private transport: Transport | null = null;\n private connectPromise: Promise<void> | null = null;\n private readonly config: L6Config;\n\n constructor(config: L6Config) {\n this.config = config;\n }\n\n /** Connect lazily on first call; subsequent calls reuse the live client. */\n private async ensureConnected(): Promise<Client> {\n if (this.client) return this.client;\n if (this.connectPromise) {\n await this.connectPromise;\n if (!this.client) throw new Error(\"Bourdon L6 client failed to initialize\");\n return this.client;\n }\n this.connectPromise = this.connect();\n try {\n await this.connectPromise;\n } finally {\n this.connectPromise = null;\n }\n if (!this.client) throw new Error(\"Bourdon L6 client failed to initialize\");\n return this.client;\n }\n\n private async connect(): Promise<void> {\n const transport = this.buildTransport(this.config);\n const client = new Client({ name: \"@getbourdon/client\", version: \"0.1.0\" }, { capabilities: {} });\n await client.connect(transport);\n this.client = client;\n this.transport = transport;\n }\n\n private buildTransport(config: L6Config): Transport {\n if (config.transport === \"custom\") return config.instance;\n if (config.transport === \"stdio\") {\n const args = [...(config.args ?? [\"-m\", \"core.l6_server\"])];\n if (config.library && !args.includes(\"--library\")) {\n args.push(\"--library\", config.library);\n }\n return new StdioClientTransport({\n command: config.command ?? \"python\",\n args,\n cwd: config.cwd,\n env: config.env,\n });\n }\n // Streamable HTTP (replaces deprecated SSE). Bearer auth via request headers.\n const opts =\n config.token === undefined\n ? undefined\n : { requestInit: { headers: { Authorization: `Bearer ${config.token}` } } };\n return new StreamableHTTPClientTransport(new URL(config.url), opts);\n }\n\n /** Close the client and underlying transport. Idempotent. */\n async close(): Promise<void> {\n if (this.client) {\n await this.client.close().catch(() => {\n /* best-effort shutdown */\n });\n this.client = null;\n }\n if (this.transport) {\n await this.transport.close?.().catch(() => {});\n this.transport = null;\n }\n }\n\n /**\n * Generic call. Unwraps the server's TextContent JSON envelope to the payload.\n * Prefer the typed methods below.\n */\n async callTool(name: string, args: Record<string, unknown> = {}): Promise<L6ToolResult> {\n const client = await this.ensureConnected();\n const result = await client.callTool({ name, arguments: args });\n return parseToolResult(result);\n }\n\n // -- the ten L6 tools (typed) ------------------------------------------------\n\n queryAgentMemory(args: QueryAgentMemoryArgs): Promise<L6ToolResult> {\n return this.callTool(\"query_agent_memory\", argsToRecord(args));\n }\n\n listRecentWork(args: ListRecentWorkArgs = {}): Promise<L6ToolResult> {\n return this.callTool(\"list_recent_work\", argsToRecord(args));\n }\n\n findEntity(args: FindEntityArgs): Promise<L6ToolResult> {\n return this.callTool(\"find_entity\", argsToRecord(args));\n }\n\n listAgents(): Promise<L6ToolResult> {\n return this.callTool(\"list_agents\", {});\n }\n\n exportAgents(): Promise<L6ToolResult> {\n return this.callTool(\"export_agents\", {});\n }\n\n getCrossAgentSummary(args: GetCrossAgentSummaryArgs): Promise<L6ToolResult> {\n return this.callTool(\"get_cross_agent_summary\", argsToRecord(args));\n }\n\n prepareRecognitionContext(args: RecognitionArgs): Promise<L6ToolResult> {\n return this.callTool(\"prepare_recognition_context\", argsToRecord(args));\n }\n\n getDeeperContext(args: RecognitionArgs): Promise<L6ToolResult> {\n return this.callTool(\"get_deeper_context\", argsToRecord(args));\n }\n\n compileCodexTurn(args: CompileCodexTurnArgs): Promise<L6ToolResult> {\n return this.callTool(\"compile_codex_turn\", argsToRecord(args));\n }\n\n commitToFederation(args: CommitToFederationArgs): Promise<L6ToolResult> {\n return this.callTool(\"commit_to_federation\", argsToRecord(args));\n }\n}\n\n/* -- internals ------------------------------------------------------------- */\n\n/**\n * Unwrap an MCP CallToolResult to the L6 payload. The L6 server JSON-stringifies\n * its payload into a single `text` content block (so cross-language peers parse\n * it with `json.loads(item.text)`); we mirror that on the read side. Falls back to\n * the raw text, then the raw result, if the envelope is unexpected.\n */\nfunction parseToolResult(result: unknown): L6ToolResult {\n const content = (result as { content?: unknown }).content;\n if (Array.isArray(content)) {\n const textBlock = content.find(\n (c): c is { type: \"text\"; text: string } =>\n typeof c === \"object\" &&\n c !== null &&\n (c as { type?: unknown }).type === \"text\" &&\n typeof (c as { text?: unknown }).text === \"string\",\n );\n if (textBlock) {\n try {\n return JSON.parse(textBlock.text);\n } catch {\n return textBlock.text;\n }\n }\n }\n return result;\n}\n\n/** Drop undefined fields so the server applies its own per-tool defaults. */\nfunction argsToRecord(args: object): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(args as Record<string, unknown>)) {\n if (v !== undefined) out[k] = v;\n }\n return out;\n}\n"],"mappings":";AAqBA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,qCAAqC;AAwFvC,IAAM,kBAAN,MAAsB;AAAA,EACnB,SAAwB;AAAA,EACxB,YAA8B;AAAA,EAC9B,iBAAuC;AAAA,EAC9B;AAAA,EAEjB,YAAY,QAAkB;AAC5B,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGA,MAAc,kBAAmC;AAC/C,QAAI,KAAK,OAAQ,QAAO,KAAK;AAC7B,QAAI,KAAK,gBAAgB;AACvB,YAAM,KAAK;AACX,UAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,MAAM,wCAAwC;AAC1E,aAAO,KAAK;AAAA,IACd;AACA,SAAK,iBAAiB,KAAK,QAAQ;AACnC,QAAI;AACF,YAAM,KAAK;AAAA,IACb,UAAE;AACA,WAAK,iBAAiB;AAAA,IACxB;AACA,QAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,MAAM,wCAAwC;AAC1E,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAc,UAAyB;AACrC,UAAM,YAAY,KAAK,eAAe,KAAK,MAAM;AACjD,UAAM,SAAS,IAAI,OAAO,EAAE,MAAM,sBAAsB,SAAS,QAAQ,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC;AAChG,UAAM,OAAO,QAAQ,SAAS;AAC9B,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEQ,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AA+B,GAAG;AACpE,QAAI,MAAM,OAAW,KAAI,CAAC,IAAI;AAAA,EAChC;AACA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getbourdon/client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bourdon L6 federation MCP client for TypeScript/Node — query a running Bourdon L6 server (stdio or Streamable HTTP) over @modelcontextprotocol/sdk. Python (pip install bourdon) is the oracle; this client is wire-compatible with its L6 server.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": false
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://bourdon.ai",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/getbourdon/bourdon-js.git",
|
|
31
|
+
"directory": "packages/client"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.29.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
}
|
|
40
|
+
}
|