@getbourdon/client 0.1.0 → 0.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/dist/index.d.cts +124 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -134
- package/dist/l6-client.d.ts +120 -0
- package/dist/l6-client.js +168 -0
- package/package.json +2 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bourdon L6 federation MCP client.
|
|
5
|
+
*
|
|
6
|
+
* Connects to a running Bourdon L6 server — spawned as a `python -m core.l6_server`
|
|
7
|
+
* stdio subprocess (default) or a long-lived Streamable-HTTP service — and proxies
|
|
8
|
+
* the ten L6 tools it exposes. Wraps the official `@modelcontextprotocol/sdk`
|
|
9
|
+
* client so JSON-RPC framing is not re-implemented.
|
|
10
|
+
*
|
|
11
|
+
* Lifted and extended from the proven openclaw-bourdon-plugin client:
|
|
12
|
+
* - all TEN tools (the plugin proxied six read tools)
|
|
13
|
+
* - Streamable HTTP transport (SSE is deprecated in the SDK)
|
|
14
|
+
* - results are JSON-parsed from the server's TextContent envelope
|
|
15
|
+
* (the L6 server returns `{content:[{type:'text', text: JSON.stringify(payload)}]}`,
|
|
16
|
+
* so a raw CallToolResult is unwrapped to the payload here)
|
|
17
|
+
* - an injectable transport (`{transport:'custom'}`) for in-memory testing
|
|
18
|
+
*
|
|
19
|
+
* Tool surface mirrored from bourdon/core/l6_server.py. The server applies
|
|
20
|
+
* per-tool `access_level` defaults (public for queries, team for recognition),
|
|
21
|
+
* so this client never hardcodes them — omitted args are dropped, not defaulted.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** Federation visibility level. Mirrors the Python `Visibility` enum values. */
|
|
25
|
+
type AccessLevel = "public" | "team" | "private";
|
|
26
|
+
interface L6StdioConfig {
|
|
27
|
+
transport: "stdio";
|
|
28
|
+
/** Defaults to `python`. */
|
|
29
|
+
command?: string;
|
|
30
|
+
/** Defaults to `["-m", "core.l6_server"]`. */
|
|
31
|
+
args?: string[];
|
|
32
|
+
/** Optional library path forwarded to L6 via `--library`. */
|
|
33
|
+
library?: string;
|
|
34
|
+
/** cwd for the subprocess (so `core.l6_server` is importable when not installed). */
|
|
35
|
+
cwd?: string;
|
|
36
|
+
/** Optional environment passed to the subprocess. */
|
|
37
|
+
env?: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
interface L6HttpConfig {
|
|
40
|
+
transport: "http";
|
|
41
|
+
url: string;
|
|
42
|
+
/** Bearer token sent as `Authorization: Bearer <token>` (federation peer auth). */
|
|
43
|
+
token?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Inject a pre-built transport (used for in-memory testing). */
|
|
46
|
+
interface L6CustomConfig {
|
|
47
|
+
transport: "custom";
|
|
48
|
+
instance: Transport;
|
|
49
|
+
}
|
|
50
|
+
type L6Config = L6StdioConfig | L6HttpConfig | L6CustomConfig;
|
|
51
|
+
interface CommonToolArgs {
|
|
52
|
+
access_level?: AccessLevel;
|
|
53
|
+
include_private?: boolean;
|
|
54
|
+
}
|
|
55
|
+
interface QueryAgentMemoryArgs extends CommonToolArgs {
|
|
56
|
+
agent: string;
|
|
57
|
+
topic: string;
|
|
58
|
+
}
|
|
59
|
+
interface ListRecentWorkArgs extends CommonToolArgs {
|
|
60
|
+
/** ISO 8601 date or datetime. */
|
|
61
|
+
since?: string;
|
|
62
|
+
agent?: string;
|
|
63
|
+
limit?: number;
|
|
64
|
+
cursor?: string;
|
|
65
|
+
summary?: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface FindEntityArgs extends CommonToolArgs {
|
|
68
|
+
name: string;
|
|
69
|
+
}
|
|
70
|
+
interface GetCrossAgentSummaryArgs extends CommonToolArgs {
|
|
71
|
+
project: string;
|
|
72
|
+
}
|
|
73
|
+
interface RecognitionArgs extends CommonToolArgs {
|
|
74
|
+
prompt: string;
|
|
75
|
+
}
|
|
76
|
+
interface CompileCodexTurnArgs {
|
|
77
|
+
prompt: string;
|
|
78
|
+
cwd?: string;
|
|
79
|
+
access_level?: AccessLevel;
|
|
80
|
+
max_items?: number;
|
|
81
|
+
max_chars?: number;
|
|
82
|
+
}
|
|
83
|
+
interface CommitToFederationArgs {
|
|
84
|
+
agent_id: string;
|
|
85
|
+
agent_type?: string;
|
|
86
|
+
instance?: string;
|
|
87
|
+
role_narrative?: string;
|
|
88
|
+
entities?: Record<string, unknown>[];
|
|
89
|
+
sessions?: Record<string, unknown>[];
|
|
90
|
+
/** `merge` (default) or `replace`. */
|
|
91
|
+
mode?: string;
|
|
92
|
+
}
|
|
93
|
+
/** The parsed payload returned by an L6 tool (server-defined JSON shape). */
|
|
94
|
+
type L6ToolResult = unknown;
|
|
95
|
+
declare class BourdonL6Client {
|
|
96
|
+
private client;
|
|
97
|
+
private transport;
|
|
98
|
+
private connectPromise;
|
|
99
|
+
private readonly config;
|
|
100
|
+
constructor(config: L6Config);
|
|
101
|
+
/** Connect lazily on first call; subsequent calls reuse the live client. */
|
|
102
|
+
private ensureConnected;
|
|
103
|
+
private connect;
|
|
104
|
+
private buildTransport;
|
|
105
|
+
/** Close the client and underlying transport. Idempotent. */
|
|
106
|
+
close(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Generic call. Unwraps the server's TextContent JSON envelope to the payload.
|
|
109
|
+
* Prefer the typed methods below.
|
|
110
|
+
*/
|
|
111
|
+
callTool(name: string, args?: Record<string, unknown>): Promise<L6ToolResult>;
|
|
112
|
+
queryAgentMemory(args: QueryAgentMemoryArgs): Promise<L6ToolResult>;
|
|
113
|
+
listRecentWork(args?: ListRecentWorkArgs): Promise<L6ToolResult>;
|
|
114
|
+
findEntity(args: FindEntityArgs): Promise<L6ToolResult>;
|
|
115
|
+
listAgents(): Promise<L6ToolResult>;
|
|
116
|
+
exportAgents(): Promise<L6ToolResult>;
|
|
117
|
+
getCrossAgentSummary(args: GetCrossAgentSummaryArgs): Promise<L6ToolResult>;
|
|
118
|
+
prepareRecognitionContext(args: RecognitionArgs): Promise<L6ToolResult>;
|
|
119
|
+
getDeeperContext(args: RecognitionArgs): Promise<L6ToolResult>;
|
|
120
|
+
compileCodexTurn(args: CompileCodexTurnArgs): Promise<L6ToolResult>;
|
|
121
|
+
commitToFederation(args: CommitToFederationArgs): Promise<L6ToolResult>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { type AccessLevel, BourdonL6Client, type CommitToFederationArgs, type CommonToolArgs, type CompileCodexTurnArgs, type FindEntityArgs, type GetCrossAgentSummaryArgs, type L6Config, type L6CustomConfig, type L6HttpConfig, type L6StdioConfig, type L6ToolResult, type ListRecentWorkArgs, type QueryAgentMemoryArgs, type RecognitionArgs };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BourdonL6Client, type AccessLevel, type L6Config, type L6StdioConfig, type L6HttpConfig, type L6CustomConfig, type CommonToolArgs, type QueryAgentMemoryArgs, type ListRecentWorkArgs, type FindEntityArgs, type GetCrossAgentSummaryArgs, type RecognitionArgs, type CompileCodexTurnArgs, type CommitToFederationArgs, type L6ToolResult, } from "./l6-client.js";
|
package/dist/index.js
CHANGED
|
@@ -1,134 +1 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
export { BourdonL6Client, } from "./l6-client.js";
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bourdon L6 federation MCP client.
|
|
3
|
+
*
|
|
4
|
+
* Connects to a running Bourdon L6 server — spawned as a `python -m core.l6_server`
|
|
5
|
+
* stdio subprocess (default) or a long-lived Streamable-HTTP service — and proxies
|
|
6
|
+
* the ten L6 tools it exposes. Wraps the official `@modelcontextprotocol/sdk`
|
|
7
|
+
* client so JSON-RPC framing is not re-implemented.
|
|
8
|
+
*
|
|
9
|
+
* Lifted and extended from the proven openclaw-bourdon-plugin client:
|
|
10
|
+
* - all TEN tools (the plugin proxied six read tools)
|
|
11
|
+
* - Streamable HTTP transport (SSE is deprecated in the SDK)
|
|
12
|
+
* - results are JSON-parsed from the server's TextContent envelope
|
|
13
|
+
* (the L6 server returns `{content:[{type:'text', text: JSON.stringify(payload)}]}`,
|
|
14
|
+
* so a raw CallToolResult is unwrapped to the payload here)
|
|
15
|
+
* - an injectable transport (`{transport:'custom'}`) for in-memory testing
|
|
16
|
+
*
|
|
17
|
+
* Tool surface mirrored from bourdon/core/l6_server.py. The server applies
|
|
18
|
+
* per-tool `access_level` defaults (public for queries, team for recognition),
|
|
19
|
+
* so this client never hardcodes them — omitted args are dropped, not defaulted.
|
|
20
|
+
*/
|
|
21
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
22
|
+
/** Federation visibility level. Mirrors the Python `Visibility` enum values. */
|
|
23
|
+
export type AccessLevel = "public" | "team" | "private";
|
|
24
|
+
export interface L6StdioConfig {
|
|
25
|
+
transport: "stdio";
|
|
26
|
+
/** Defaults to `python`. */
|
|
27
|
+
command?: string;
|
|
28
|
+
/** Defaults to `["-m", "core.l6_server"]`. */
|
|
29
|
+
args?: string[];
|
|
30
|
+
/** Optional library path forwarded to L6 via `--library`. */
|
|
31
|
+
library?: string;
|
|
32
|
+
/** cwd for the subprocess (so `core.l6_server` is importable when not installed). */
|
|
33
|
+
cwd?: string;
|
|
34
|
+
/** Optional environment passed to the subprocess. */
|
|
35
|
+
env?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
export interface L6HttpConfig {
|
|
38
|
+
transport: "http";
|
|
39
|
+
url: string;
|
|
40
|
+
/** Bearer token sent as `Authorization: Bearer <token>` (federation peer auth). */
|
|
41
|
+
token?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Inject a pre-built transport (used for in-memory testing). */
|
|
44
|
+
export interface L6CustomConfig {
|
|
45
|
+
transport: "custom";
|
|
46
|
+
instance: Transport;
|
|
47
|
+
}
|
|
48
|
+
export type L6Config = L6StdioConfig | L6HttpConfig | L6CustomConfig;
|
|
49
|
+
export interface CommonToolArgs {
|
|
50
|
+
access_level?: AccessLevel;
|
|
51
|
+
include_private?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface QueryAgentMemoryArgs extends CommonToolArgs {
|
|
54
|
+
agent: string;
|
|
55
|
+
topic: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ListRecentWorkArgs extends CommonToolArgs {
|
|
58
|
+
/** ISO 8601 date or datetime. */
|
|
59
|
+
since?: string;
|
|
60
|
+
agent?: string;
|
|
61
|
+
limit?: number;
|
|
62
|
+
cursor?: string;
|
|
63
|
+
summary?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface FindEntityArgs extends CommonToolArgs {
|
|
66
|
+
name: string;
|
|
67
|
+
}
|
|
68
|
+
export interface GetCrossAgentSummaryArgs extends CommonToolArgs {
|
|
69
|
+
project: string;
|
|
70
|
+
}
|
|
71
|
+
export interface RecognitionArgs extends CommonToolArgs {
|
|
72
|
+
prompt: string;
|
|
73
|
+
}
|
|
74
|
+
export interface CompileCodexTurnArgs {
|
|
75
|
+
prompt: string;
|
|
76
|
+
cwd?: string;
|
|
77
|
+
access_level?: AccessLevel;
|
|
78
|
+
max_items?: number;
|
|
79
|
+
max_chars?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface CommitToFederationArgs {
|
|
82
|
+
agent_id: string;
|
|
83
|
+
agent_type?: string;
|
|
84
|
+
instance?: string;
|
|
85
|
+
role_narrative?: string;
|
|
86
|
+
entities?: Record<string, unknown>[];
|
|
87
|
+
sessions?: Record<string, unknown>[];
|
|
88
|
+
/** `merge` (default) or `replace`. */
|
|
89
|
+
mode?: string;
|
|
90
|
+
}
|
|
91
|
+
/** The parsed payload returned by an L6 tool (server-defined JSON shape). */
|
|
92
|
+
export type L6ToolResult = unknown;
|
|
93
|
+
export declare class BourdonL6Client {
|
|
94
|
+
private client;
|
|
95
|
+
private transport;
|
|
96
|
+
private connectPromise;
|
|
97
|
+
private readonly config;
|
|
98
|
+
constructor(config: L6Config);
|
|
99
|
+
/** Connect lazily on first call; subsequent calls reuse the live client. */
|
|
100
|
+
private ensureConnected;
|
|
101
|
+
private connect;
|
|
102
|
+
private buildTransport;
|
|
103
|
+
/** Close the client and underlying transport. Idempotent. */
|
|
104
|
+
close(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Generic call. Unwraps the server's TextContent JSON envelope to the payload.
|
|
107
|
+
* Prefer the typed methods below.
|
|
108
|
+
*/
|
|
109
|
+
callTool(name: string, args?: Record<string, unknown>): Promise<L6ToolResult>;
|
|
110
|
+
queryAgentMemory(args: QueryAgentMemoryArgs): Promise<L6ToolResult>;
|
|
111
|
+
listRecentWork(args?: ListRecentWorkArgs): Promise<L6ToolResult>;
|
|
112
|
+
findEntity(args: FindEntityArgs): Promise<L6ToolResult>;
|
|
113
|
+
listAgents(): Promise<L6ToolResult>;
|
|
114
|
+
exportAgents(): Promise<L6ToolResult>;
|
|
115
|
+
getCrossAgentSummary(args: GetCrossAgentSummaryArgs): Promise<L6ToolResult>;
|
|
116
|
+
prepareRecognitionContext(args: RecognitionArgs): Promise<L6ToolResult>;
|
|
117
|
+
getDeeperContext(args: RecognitionArgs): Promise<L6ToolResult>;
|
|
118
|
+
compileCodexTurn(args: CompileCodexTurnArgs): Promise<L6ToolResult>;
|
|
119
|
+
commitToFederation(args: CommitToFederationArgs): Promise<L6ToolResult>;
|
|
120
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bourdon L6 federation MCP client.
|
|
3
|
+
*
|
|
4
|
+
* Connects to a running Bourdon L6 server — spawned as a `python -m core.l6_server`
|
|
5
|
+
* stdio subprocess (default) or a long-lived Streamable-HTTP service — and proxies
|
|
6
|
+
* the ten L6 tools it exposes. Wraps the official `@modelcontextprotocol/sdk`
|
|
7
|
+
* client so JSON-RPC framing is not re-implemented.
|
|
8
|
+
*
|
|
9
|
+
* Lifted and extended from the proven openclaw-bourdon-plugin client:
|
|
10
|
+
* - all TEN tools (the plugin proxied six read tools)
|
|
11
|
+
* - Streamable HTTP transport (SSE is deprecated in the SDK)
|
|
12
|
+
* - results are JSON-parsed from the server's TextContent envelope
|
|
13
|
+
* (the L6 server returns `{content:[{type:'text', text: JSON.stringify(payload)}]}`,
|
|
14
|
+
* so a raw CallToolResult is unwrapped to the payload here)
|
|
15
|
+
* - an injectable transport (`{transport:'custom'}`) for in-memory testing
|
|
16
|
+
*
|
|
17
|
+
* Tool surface mirrored from bourdon/core/l6_server.py. The server applies
|
|
18
|
+
* per-tool `access_level` defaults (public for queries, team for recognition),
|
|
19
|
+
* so this client never hardcodes them — omitted args are dropped, not defaulted.
|
|
20
|
+
*/
|
|
21
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
22
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
23
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
24
|
+
export class BourdonL6Client {
|
|
25
|
+
client = null;
|
|
26
|
+
transport = null;
|
|
27
|
+
connectPromise = null;
|
|
28
|
+
config;
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
/** Connect lazily on first call; subsequent calls reuse the live client. */
|
|
33
|
+
async ensureConnected() {
|
|
34
|
+
if (this.client)
|
|
35
|
+
return this.client;
|
|
36
|
+
if (this.connectPromise) {
|
|
37
|
+
await this.connectPromise;
|
|
38
|
+
if (!this.client)
|
|
39
|
+
throw new Error("Bourdon L6 client failed to initialize");
|
|
40
|
+
return this.client;
|
|
41
|
+
}
|
|
42
|
+
this.connectPromise = this.connect();
|
|
43
|
+
try {
|
|
44
|
+
await this.connectPromise;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
this.connectPromise = null;
|
|
48
|
+
}
|
|
49
|
+
if (!this.client)
|
|
50
|
+
throw new Error("Bourdon L6 client failed to initialize");
|
|
51
|
+
return this.client;
|
|
52
|
+
}
|
|
53
|
+
async connect() {
|
|
54
|
+
const transport = this.buildTransport(this.config);
|
|
55
|
+
const client = new Client({ name: "@getbourdon/client", version: "0.1.0" }, { capabilities: {} });
|
|
56
|
+
await client.connect(transport);
|
|
57
|
+
this.client = client;
|
|
58
|
+
this.transport = transport;
|
|
59
|
+
}
|
|
60
|
+
buildTransport(config) {
|
|
61
|
+
if (config.transport === "custom")
|
|
62
|
+
return config.instance;
|
|
63
|
+
if (config.transport === "stdio") {
|
|
64
|
+
const args = [...(config.args ?? ["-m", "core.l6_server"])];
|
|
65
|
+
if (config.library && !args.includes("--library")) {
|
|
66
|
+
args.push("--library", config.library);
|
|
67
|
+
}
|
|
68
|
+
return new StdioClientTransport({
|
|
69
|
+
command: config.command ?? "python",
|
|
70
|
+
args,
|
|
71
|
+
cwd: config.cwd,
|
|
72
|
+
env: config.env,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// Streamable HTTP (replaces deprecated SSE). Bearer auth via request headers.
|
|
76
|
+
const opts = config.token === undefined
|
|
77
|
+
? undefined
|
|
78
|
+
: { requestInit: { headers: { Authorization: `Bearer ${config.token}` } } };
|
|
79
|
+
return new StreamableHTTPClientTransport(new URL(config.url), opts);
|
|
80
|
+
}
|
|
81
|
+
/** Close the client and underlying transport. Idempotent. */
|
|
82
|
+
async close() {
|
|
83
|
+
if (this.client) {
|
|
84
|
+
await this.client.close().catch(() => {
|
|
85
|
+
/* best-effort shutdown */
|
|
86
|
+
});
|
|
87
|
+
this.client = null;
|
|
88
|
+
}
|
|
89
|
+
if (this.transport) {
|
|
90
|
+
await this.transport.close?.().catch(() => { });
|
|
91
|
+
this.transport = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generic call. Unwraps the server's TextContent JSON envelope to the payload.
|
|
96
|
+
* Prefer the typed methods below.
|
|
97
|
+
*/
|
|
98
|
+
async callTool(name, args = {}) {
|
|
99
|
+
const client = await this.ensureConnected();
|
|
100
|
+
const result = await client.callTool({ name, arguments: args });
|
|
101
|
+
return parseToolResult(result);
|
|
102
|
+
}
|
|
103
|
+
// -- the ten L6 tools (typed) ------------------------------------------------
|
|
104
|
+
queryAgentMemory(args) {
|
|
105
|
+
return this.callTool("query_agent_memory", argsToRecord(args));
|
|
106
|
+
}
|
|
107
|
+
listRecentWork(args = {}) {
|
|
108
|
+
return this.callTool("list_recent_work", argsToRecord(args));
|
|
109
|
+
}
|
|
110
|
+
findEntity(args) {
|
|
111
|
+
return this.callTool("find_entity", argsToRecord(args));
|
|
112
|
+
}
|
|
113
|
+
listAgents() {
|
|
114
|
+
return this.callTool("list_agents", {});
|
|
115
|
+
}
|
|
116
|
+
exportAgents() {
|
|
117
|
+
return this.callTool("export_agents", {});
|
|
118
|
+
}
|
|
119
|
+
getCrossAgentSummary(args) {
|
|
120
|
+
return this.callTool("get_cross_agent_summary", argsToRecord(args));
|
|
121
|
+
}
|
|
122
|
+
prepareRecognitionContext(args) {
|
|
123
|
+
return this.callTool("prepare_recognition_context", argsToRecord(args));
|
|
124
|
+
}
|
|
125
|
+
getDeeperContext(args) {
|
|
126
|
+
return this.callTool("get_deeper_context", argsToRecord(args));
|
|
127
|
+
}
|
|
128
|
+
compileCodexTurn(args) {
|
|
129
|
+
return this.callTool("compile_codex_turn", argsToRecord(args));
|
|
130
|
+
}
|
|
131
|
+
commitToFederation(args) {
|
|
132
|
+
return this.callTool("commit_to_federation", argsToRecord(args));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/* -- internals ------------------------------------------------------------- */
|
|
136
|
+
/**
|
|
137
|
+
* Unwrap an MCP CallToolResult to the L6 payload. The L6 server JSON-stringifies
|
|
138
|
+
* its payload into a single `text` content block (so cross-language peers parse
|
|
139
|
+
* it with `json.loads(item.text)`); we mirror that on the read side. Falls back to
|
|
140
|
+
* the raw text, then the raw result, if the envelope is unexpected.
|
|
141
|
+
*/
|
|
142
|
+
function parseToolResult(result) {
|
|
143
|
+
const content = result.content;
|
|
144
|
+
if (Array.isArray(content)) {
|
|
145
|
+
const textBlock = content.find((c) => typeof c === "object" &&
|
|
146
|
+
c !== null &&
|
|
147
|
+
c.type === "text" &&
|
|
148
|
+
typeof c.text === "string");
|
|
149
|
+
if (textBlock) {
|
|
150
|
+
try {
|
|
151
|
+
return JSON.parse(textBlock.text);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return textBlock.text;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
/** Drop undefined fields so the server applies its own per-tool defaults. */
|
|
161
|
+
function argsToRecord(args) {
|
|
162
|
+
const out = {};
|
|
163
|
+
for (const [k, v] of Object.entries(args)) {
|
|
164
|
+
if (v !== undefined)
|
|
165
|
+
out[k] = v;
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getbourdon/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
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
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public",
|
|
25
|
-
"provenance":
|
|
25
|
+
"provenance": true
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://bourdon.ai",
|
|
28
28
|
"repository": {
|