@slashfi/agents-sdk 0.20.0 → 0.21.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/dist/client.d.ts +49 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +190 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/serialized.d.ts +64 -0
- package/dist/serialized.d.ts.map +1 -0
- package/dist/serialized.js +41 -0
- package/dist/serialized.js.map +1 -0
- package/package.json +1 -1
- package/src/client.ts +273 -0
- package/src/index.ts +20 -0
- package/src/serialized.ts +102 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Client
|
|
3
|
+
*
|
|
4
|
+
* Creates a typed client from a SerializedAgentDefinition.
|
|
5
|
+
* The client spawns (or connects to) the MCP server and proxies
|
|
6
|
+
* tool calls via JSON-RPC.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createClient } from '@slashfi/agents-sdk';
|
|
11
|
+
* import definition from './agents/notion/definition.json';
|
|
12
|
+
*
|
|
13
|
+
* const client = createClient(definition, {
|
|
14
|
+
* env: { NOTION_TOKEN: process.env.NOTION_TOKEN },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const result = await client.call('API-post-search', { query: 'meeting notes' });
|
|
18
|
+
* await client.close();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import type { SerializedAgentDefinition, SerializedTool } from "./serialized.js";
|
|
22
|
+
export interface CreateClientOptions {
|
|
23
|
+
/** Extra environment variables for the MCP server process */
|
|
24
|
+
env?: Record<string, string | undefined>;
|
|
25
|
+
/** Override the server command (defaults to definition.serverSource) */
|
|
26
|
+
serverCommand?: string;
|
|
27
|
+
/** Timeout for tool calls in ms (default: 30000) */
|
|
28
|
+
timeout?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface AgentClient {
|
|
31
|
+
/** The definition this client was created from */
|
|
32
|
+
readonly definition: SerializedAgentDefinition;
|
|
33
|
+
/** List available tools */
|
|
34
|
+
tools(): SerializedTool[];
|
|
35
|
+
/** Call a tool by name */
|
|
36
|
+
call(toolName: string, input?: Record<string, unknown>): Promise<unknown>;
|
|
37
|
+
/** Check if connected */
|
|
38
|
+
isConnected(): boolean;
|
|
39
|
+
/** Close the MCP server connection */
|
|
40
|
+
close(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an agent client from a serialized definition.
|
|
44
|
+
*
|
|
45
|
+
* The client lazily spawns the MCP server on first call and
|
|
46
|
+
* proxies tool invocations via JSON-RPC over stdio.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createClient(definition: SerializedAgentDefinition, options?: CreateClientOptions): AgentClient;
|
|
49
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EACV,yBAAyB,EACzB,cAAc,EACf,MAAM,iBAAiB,CAAC;AAMzB,MAAM,WAAW,mBAAmB;IAClC,6DAA6D;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;IAE/C,2BAA2B;IAC3B,KAAK,IAAI,cAAc,EAAE,CAAC;IAE1B,0BAA0B;IAC1B,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1E,yBAAyB;IACzB,WAAW,IAAI,OAAO,CAAC;IAEvB,sCAAsC;IACtC,KAAK,IAAI,IAAI,CAAC;CACf;AA0MD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,yBAAyB,EACrC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,WAAW,CAEb"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Client
|
|
3
|
+
*
|
|
4
|
+
* Creates a typed client from a SerializedAgentDefinition.
|
|
5
|
+
* The client spawns (or connects to) the MCP server and proxies
|
|
6
|
+
* tool calls via JSON-RPC.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createClient } from '@slashfi/agents-sdk';
|
|
11
|
+
* import definition from './agents/notion/definition.json';
|
|
12
|
+
*
|
|
13
|
+
* const client = createClient(definition, {
|
|
14
|
+
* env: { NOTION_TOKEN: process.env.NOTION_TOKEN },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const result = await client.call('API-post-search', { query: 'meeting notes' });
|
|
18
|
+
* await client.close();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import { spawn } from "node:child_process";
|
|
22
|
+
class McpStdioClient {
|
|
23
|
+
definition;
|
|
24
|
+
proc = null;
|
|
25
|
+
messageId = 0;
|
|
26
|
+
buffer = "";
|
|
27
|
+
pending = new Map();
|
|
28
|
+
initialized = false;
|
|
29
|
+
initPromise = null;
|
|
30
|
+
serverCommand;
|
|
31
|
+
env;
|
|
32
|
+
timeout;
|
|
33
|
+
constructor(definition, options = {}) {
|
|
34
|
+
this.definition = definition;
|
|
35
|
+
this.serverCommand = options.serverCommand ?? definition.serverSource ?? "";
|
|
36
|
+
this.env = options.env ?? {};
|
|
37
|
+
this.timeout = options.timeout ?? 30000;
|
|
38
|
+
if (!this.serverCommand) {
|
|
39
|
+
throw new Error(`No server command for agent "${definition.path}". Set serverSource in the definition or pass serverCommand in options.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
tools() {
|
|
43
|
+
return this.definition.tools;
|
|
44
|
+
}
|
|
45
|
+
isConnected() {
|
|
46
|
+
return this.proc !== null && !this.proc.killed;
|
|
47
|
+
}
|
|
48
|
+
async call(toolName, input = {}) {
|
|
49
|
+
// Validate tool exists
|
|
50
|
+
const tool = this.definition.tools.find((t) => t.name === toolName);
|
|
51
|
+
if (!tool) {
|
|
52
|
+
const available = this.definition.tools.map((t) => t.name).join(", ");
|
|
53
|
+
throw new Error(`Tool "${toolName}" not found. Available: ${available}`);
|
|
54
|
+
}
|
|
55
|
+
// Ensure connected + initialized
|
|
56
|
+
await this.ensureInitialized();
|
|
57
|
+
// Send tools/call
|
|
58
|
+
const result = await this.sendRequest("tools/call", {
|
|
59
|
+
name: toolName,
|
|
60
|
+
arguments: input,
|
|
61
|
+
});
|
|
62
|
+
// MCP tools/call returns { content: [{ type, text }] }
|
|
63
|
+
const resultObj = result;
|
|
64
|
+
if (resultObj && typeof resultObj === "object" && "content" in resultObj) {
|
|
65
|
+
const content = resultObj.content;
|
|
66
|
+
if (Array.isArray(content) && content.length > 0) {
|
|
67
|
+
const first = content[0];
|
|
68
|
+
if (first.type === "text") {
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(first.text);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return first.text;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return first;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
close() {
|
|
82
|
+
if (this.proc) {
|
|
83
|
+
this.proc.kill();
|
|
84
|
+
this.proc = null;
|
|
85
|
+
}
|
|
86
|
+
this.initialized = false;
|
|
87
|
+
this.initPromise = null;
|
|
88
|
+
// Reject all pending
|
|
89
|
+
for (const req of Array.from(this.pending.values())) {
|
|
90
|
+
clearTimeout(req.timer);
|
|
91
|
+
req.reject(new Error("Client closed"));
|
|
92
|
+
}
|
|
93
|
+
this.pending.clear();
|
|
94
|
+
}
|
|
95
|
+
// ── Private ──
|
|
96
|
+
async ensureInitialized() {
|
|
97
|
+
if (this.initialized)
|
|
98
|
+
return;
|
|
99
|
+
if (this.initPromise)
|
|
100
|
+
return this.initPromise;
|
|
101
|
+
this.initPromise = this.connect();
|
|
102
|
+
await this.initPromise;
|
|
103
|
+
this.initialized = true;
|
|
104
|
+
}
|
|
105
|
+
async connect() {
|
|
106
|
+
const parts = this.serverCommand.split(/\s+/);
|
|
107
|
+
this.proc = spawn(parts[0], parts.slice(1), {
|
|
108
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
109
|
+
env: { ...process.env, ...this.env },
|
|
110
|
+
});
|
|
111
|
+
this.proc.stdout?.on("data", (chunk) => this.onData(chunk));
|
|
112
|
+
this.proc.on("error", (err) => {
|
|
113
|
+
for (const req of Array.from(this.pending.values())) {
|
|
114
|
+
clearTimeout(req.timer);
|
|
115
|
+
req.reject(err);
|
|
116
|
+
}
|
|
117
|
+
this.pending.clear();
|
|
118
|
+
});
|
|
119
|
+
// Initialize handshake
|
|
120
|
+
await this.sendRequest("initialize", {
|
|
121
|
+
protocolVersion: "2024-11-05",
|
|
122
|
+
capabilities: {},
|
|
123
|
+
clientInfo: { name: "agents-sdk-client", version: "1.0.0" },
|
|
124
|
+
});
|
|
125
|
+
// Send initialized notification
|
|
126
|
+
this.sendNotification("notifications/initialized");
|
|
127
|
+
}
|
|
128
|
+
sendRequest(method, params = {}) {
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
const id = ++this.messageId;
|
|
131
|
+
const timer = setTimeout(() => {
|
|
132
|
+
this.pending.delete(id);
|
|
133
|
+
reject(new Error(`Timeout after ${this.timeout}ms calling ${method}`));
|
|
134
|
+
}, this.timeout);
|
|
135
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
136
|
+
const msg = JSON.stringify({ jsonrpc: "2.0", id, method, params });
|
|
137
|
+
this.proc?.stdin?.write(`${msg}\n`);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
sendNotification(method, params) {
|
|
141
|
+
const msg = JSON.stringify({
|
|
142
|
+
jsonrpc: "2.0",
|
|
143
|
+
method,
|
|
144
|
+
...(params ? { params } : {}),
|
|
145
|
+
});
|
|
146
|
+
this.proc?.stdin?.write(`${msg}\n`);
|
|
147
|
+
}
|
|
148
|
+
onData(chunk) {
|
|
149
|
+
this.buffer += chunk.toString();
|
|
150
|
+
const lines = this.buffer.split("\n");
|
|
151
|
+
this.buffer = lines.pop() || "";
|
|
152
|
+
for (const line of lines) {
|
|
153
|
+
const trimmed = line.trim();
|
|
154
|
+
if (!trimmed)
|
|
155
|
+
continue;
|
|
156
|
+
try {
|
|
157
|
+
const parsed = JSON.parse(trimmed);
|
|
158
|
+
if (parsed.id != null && this.pending.has(parsed.id)) {
|
|
159
|
+
const req = this.pending.get(parsed.id);
|
|
160
|
+
if (!req)
|
|
161
|
+
continue;
|
|
162
|
+
this.pending.delete(parsed.id);
|
|
163
|
+
clearTimeout(req.timer);
|
|
164
|
+
if (parsed.error) {
|
|
165
|
+
req.reject(new Error(JSON.stringify(parsed.error)));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
req.resolve(parsed.result);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// ignore non-JSON lines (stderr leakage, etc.)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// ============================================
|
|
179
|
+
// Factory
|
|
180
|
+
// ============================================
|
|
181
|
+
/**
|
|
182
|
+
* Create an agent client from a serialized definition.
|
|
183
|
+
*
|
|
184
|
+
* The client lazily spawns the MCP server on first call and
|
|
185
|
+
* proxies tool invocations via JSON-RPC over stdio.
|
|
186
|
+
*/
|
|
187
|
+
export function createClient(definition, options) {
|
|
188
|
+
return new McpStdioClient(definition, options);
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAkD9D,MAAM,cAAc;IACT,UAAU,CAA4B;IACvC,IAAI,GAAwB,IAAI,CAAC;IACjC,SAAS,GAAG,CAAC,CAAC;IACd,MAAM,GAAG,EAAE,CAAC;IACZ,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC5C,WAAW,GAAG,KAAK,CAAC;IACpB,WAAW,GAAyB,IAAI,CAAC;IACzC,aAAa,CAAS;IACtB,GAAG,CAAqC;IACxC,OAAO,CAAS;IAExB,YACE,UAAqC,EACrC,UAA+B,EAAE;QAEjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,UAAU,CAAC,YAAY,IAAI,EAAE,CAAC;QAC5E,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;QAExC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,gCAAgC,UAAU,CAAC,IAAI,yEAAyE,CACzH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IAC/B,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,I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AAC;gBACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACnC,IAAI,MAAM,CAAC,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;oBACrD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBACxC,IAAI,CAAC,GAAG;wBAAE,SAAS;oBACnB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBAC/B,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACxB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACjB,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACtD,CAAC;yBAAM,CAAC;wBACN,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBAC7B,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,+CAA+C;YACjD,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,+CAA+C;AAC/C,UAAU;AACV,+CAA+C;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAqC,EACrC,OAA6B;IAE7B,OAAO,IAAI,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -85,4 +85,8 @@ export { createRegistryConsumer } from "./registry-consumer.js";
|
|
|
85
85
|
export type { RegistryConsumer, RegistryConsumerOptions, RegistryConfiguration, AgentListing, SecretResolver, } from "./registry-consumer.js";
|
|
86
86
|
export { codegen, useAgent, listAgentTools } from "./codegen.js";
|
|
87
87
|
export type { CodegenOptions, CodegenResult, CodegenManifest, McpToolDefinition, McpServerInfo, McpTransport, ServerSource, } from "./codegen.js";
|
|
88
|
+
export { serializeAgent, serializeTool } from "./serialized.js";
|
|
89
|
+
export type { SerializedAgentDefinition, SerializedTool, } from "./serialized.js";
|
|
90
|
+
export { createClient } from "./client.js";
|
|
91
|
+
export type { AgentClient, CreateClientOptions, } from "./client.js";
|
|
88
92
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAGH,YAAY,EACV,WAAW,EACX,WAAW,EACX,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,8BAA8B,EAC9B,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGxG,OAAO,EAAE,mBAAmB,EAAE,MAAM,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AQ,EACR,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,EACZ,cAAc,GACf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,YAAY,GACb,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAGH,YAAY,EACV,WAAW,EACX,WAAW,EACX,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,8BAA8B,EAC9B,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACt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,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,EACZ,cAAc,GACf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,YAAY,GACb,MAAM,cAAc,CAAC;AAMtB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChE,YAAY,EACV,yBAAyB,EACzB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EACV,WAAW,EACX,mBAAmB,GACpB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -83,4 +83,12 @@ export { normalizeRef, normalizeRegistry, isSecretUrl, isSecretUri, } from "./de
|
|
|
83
83
|
export { createRegistryConsumer } from "./registry-consumer.js";
|
|
84
84
|
// Codegen
|
|
85
85
|
export { codegen, useAgent, listAgentTools } from "./codegen.js";
|
|
86
|
+
// ============================================
|
|
87
|
+
// Serialized Agent Definitions
|
|
88
|
+
// ============================================
|
|
89
|
+
export { serializeAgent, serializeTool } from "./serialized.js";
|
|
90
|
+
// ============================================
|
|
91
|
+
// Agent Client
|
|
92
|
+
// ============================================
|
|
93
|
+
export { createClient } from "./client.js";
|
|
86
94
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
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Serialized Agent Definition
|
|
3
|
+
*
|
|
4
|
+
* Pure-data, JSON-serializable representation of an agent.
|
|
5
|
+
* No execute functions, no runtime hooks — just schemas and metadata.
|
|
6
|
+
*
|
|
7
|
+
* This is the universal IR:
|
|
8
|
+
* - Codegen produces it (MCP introspection → SerializedAgentDefinition)
|
|
9
|
+
* - Registry stores it (JSON in DB or filesystem)
|
|
10
|
+
* - API serves it (GET /agents/:name → SerializedAgentDefinition)
|
|
11
|
+
* - createClient() hydrates it (definition → typed proxy with real calls)
|
|
12
|
+
*/
|
|
13
|
+
import type { JsonSchema, SecurityScheme } from "./types.js";
|
|
14
|
+
export interface SerializedTool {
|
|
15
|
+
/** Tool name (unique within agent) */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Short description for tool discovery */
|
|
18
|
+
description: string;
|
|
19
|
+
/** JSON Schema for input parameters */
|
|
20
|
+
inputSchema: JsonSchema;
|
|
21
|
+
/** JSON Schema for output (optional) */
|
|
22
|
+
outputSchema?: JsonSchema;
|
|
23
|
+
}
|
|
24
|
+
export interface SerializedAgentDefinition {
|
|
25
|
+
/** Agent path (e.g., 'notion', 'linear', 'github') */
|
|
26
|
+
path: string;
|
|
27
|
+
/** Human-readable name */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Short description */
|
|
30
|
+
description: string;
|
|
31
|
+
/** Version of the definition */
|
|
32
|
+
version: string;
|
|
33
|
+
/** Visibility level */
|
|
34
|
+
visibility: "public" | "private";
|
|
35
|
+
/** Auth requirements */
|
|
36
|
+
auth?: SecurityScheme;
|
|
37
|
+
/** MCP server source command (e.g., 'npx @notionhq/notion-mcp-server') */
|
|
38
|
+
serverSource?: string;
|
|
39
|
+
/** Server info from MCP introspection */
|
|
40
|
+
serverInfo?: {
|
|
41
|
+
name: string;
|
|
42
|
+
version: string;
|
|
43
|
+
};
|
|
44
|
+
/** Tool definitions (schemas only, no execute) */
|
|
45
|
+
tools: SerializedTool[];
|
|
46
|
+
/** ISO timestamp of when this was generated */
|
|
47
|
+
generatedAt?: string;
|
|
48
|
+
/** SDK version used for codegen */
|
|
49
|
+
sdkVersion?: string;
|
|
50
|
+
}
|
|
51
|
+
import type { AgentDefinition, ToolContext, ToolDefinition } from "./types.js";
|
|
52
|
+
/**
|
|
53
|
+
* Serialize an AgentDefinition to its pure-data representation.
|
|
54
|
+
* Strips execute functions, runtime hooks, listeners, etc.
|
|
55
|
+
*/
|
|
56
|
+
export declare function serializeAgent(agent: AgentDefinition, meta?: {
|
|
57
|
+
serverSource?: string;
|
|
58
|
+
version?: string;
|
|
59
|
+
}): SerializedAgentDefinition;
|
|
60
|
+
/**
|
|
61
|
+
* Serialize a single ToolDefinition to its pure-data representation.
|
|
62
|
+
*/
|
|
63
|
+
export declare function serializeTool(tool: ToolDefinition<ToolContext, unknown, unknown>): SerializedTool;
|
|
64
|
+
//# sourceMappingURL=serialized.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialized.d.ts","sourceRoot":"","sources":["../src/serialized.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAM7D,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,WAAW,EAAE,UAAU,CAAC;IACxB,wCAAwC;IACxC,YAAY,CAAC,EAAE,UAAU,CAAC;CAC3B;AAMD,MAAM,WAAW,yBAAyB;IACxC,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjC,wBAAwB;IACxB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,UAAU,CAAC,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,kDAAkD;IAClD,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE/E;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD,yBAAyB,CAY3B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,GAClD,cAAc,CAOhB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialized Agent Definition
|
|
3
|
+
*
|
|
4
|
+
* Pure-data, JSON-serializable representation of an agent.
|
|
5
|
+
* No execute functions, no runtime hooks — just schemas and metadata.
|
|
6
|
+
*
|
|
7
|
+
* This is the universal IR:
|
|
8
|
+
* - Codegen produces it (MCP introspection → SerializedAgentDefinition)
|
|
9
|
+
* - Registry stores it (JSON in DB or filesystem)
|
|
10
|
+
* - API serves it (GET /agents/:name → SerializedAgentDefinition)
|
|
11
|
+
* - createClient() hydrates it (definition → typed proxy with real calls)
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Serialize an AgentDefinition to its pure-data representation.
|
|
15
|
+
* Strips execute functions, runtime hooks, listeners, etc.
|
|
16
|
+
*/
|
|
17
|
+
export function serializeAgent(agent, meta) {
|
|
18
|
+
return {
|
|
19
|
+
path: agent.path,
|
|
20
|
+
name: agent.config?.name ?? agent.path,
|
|
21
|
+
description: agent.config?.description ?? "",
|
|
22
|
+
version: meta?.version ?? "1.0.0",
|
|
23
|
+
visibility: agent.visibility ?? "public",
|
|
24
|
+
auth: agent.config?.security,
|
|
25
|
+
serverSource: meta?.serverSource,
|
|
26
|
+
tools: agent.tools.map(serializeTool),
|
|
27
|
+
generatedAt: new Date().toISOString(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Serialize a single ToolDefinition to its pure-data representation.
|
|
32
|
+
*/
|
|
33
|
+
export function serializeTool(tool) {
|
|
34
|
+
return {
|
|
35
|
+
name: tool.name,
|
|
36
|
+
description: tool.description,
|
|
37
|
+
inputSchema: tool.inputSchema,
|
|
38
|
+
...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=serialized.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialized.js","sourceRoot":"","sources":["../src/serialized.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAyDH;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,IAAkD;IAElD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI;QACtC,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,IAAI,EAAE;QAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,OAAO;QACjC,UAAU,EAAG,KAAK,CAAC,UAAmC,IAAI,QAAQ;QAClE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ;QAC5B,YAAY,EAAE,IAAI,EAAE,YAAY;QAChC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC;QACrC,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACtC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAmD;IAEnD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/client.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Client
|
|
3
|
+
*
|
|
4
|
+
* Creates a typed client from a SerializedAgentDefinition.
|
|
5
|
+
* The client spawns (or connects to) the MCP server and proxies
|
|
6
|
+
* tool calls via JSON-RPC.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createClient } from '@slashfi/agents-sdk';
|
|
11
|
+
* import definition from './agents/notion/definition.json';
|
|
12
|
+
*
|
|
13
|
+
* const client = createClient(definition, {
|
|
14
|
+
* env: { NOTION_TOKEN: process.env.NOTION_TOKEN },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const result = await client.call('API-post-search', { query: 'meeting notes' });
|
|
18
|
+
* await client.close();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
23
|
+
import type {
|
|
24
|
+
SerializedAgentDefinition,
|
|
25
|
+
SerializedTool,
|
|
26
|
+
} from "./serialized.js";
|
|
27
|
+
|
|
28
|
+
// ============================================
|
|
29
|
+
// Client Options
|
|
30
|
+
// ============================================
|
|
31
|
+
|
|
32
|
+
export interface CreateClientOptions {
|
|
33
|
+
/** Extra environment variables for the MCP server process */
|
|
34
|
+
env?: Record<string, string | undefined>;
|
|
35
|
+
/** Override the server command (defaults to definition.serverSource) */
|
|
36
|
+
serverCommand?: string;
|
|
37
|
+
/** Timeout for tool calls in ms (default: 30000) */
|
|
38
|
+
timeout?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ============================================
|
|
42
|
+
// Agent Client
|
|
43
|
+
// ============================================
|
|
44
|
+
|
|
45
|
+
export interface AgentClient {
|
|
46
|
+
/** The definition this client was created from */
|
|
47
|
+
readonly definition: SerializedAgentDefinition;
|
|
48
|
+
|
|
49
|
+
/** List available tools */
|
|
50
|
+
tools(): SerializedTool[];
|
|
51
|
+
|
|
52
|
+
/** Call a tool by name */
|
|
53
|
+
call(toolName: string, input?: Record<string, unknown>): Promise<unknown>;
|
|
54
|
+
|
|
55
|
+
/** Check if connected */
|
|
56
|
+
isConnected(): boolean;
|
|
57
|
+
|
|
58
|
+
/** Close the MCP server connection */
|
|
59
|
+
close(): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ============================================
|
|
63
|
+
// MCP Stdio Transport
|
|
64
|
+
// ============================================
|
|
65
|
+
|
|
66
|
+
interface PendingRequest {
|
|
67
|
+
resolve: (value: unknown) => void;
|
|
68
|
+
reject: (error: Error) => void;
|
|
69
|
+
timer: ReturnType<typeof setTimeout>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class McpStdioClient implements AgentClient {
|
|
73
|
+
readonly definition: SerializedAgentDefinition;
|
|
74
|
+
private proc: ChildProcess | null = null;
|
|
75
|
+
private messageId = 0;
|
|
76
|
+
private buffer = "";
|
|
77
|
+
private pending = new Map<number, PendingRequest>();
|
|
78
|
+
private initialized = false;
|
|
79
|
+
private initPromise: Promise<void> | null = null;
|
|
80
|
+
private serverCommand: string;
|
|
81
|
+
private env: Record<string, string | undefined>;
|
|
82
|
+
private timeout: number;
|
|
83
|
+
|
|
84
|
+
constructor(
|
|
85
|
+
definition: SerializedAgentDefinition,
|
|
86
|
+
options: CreateClientOptions = {},
|
|
87
|
+
) {
|
|
88
|
+
this.definition = definition;
|
|
89
|
+
this.serverCommand = options.serverCommand ?? definition.serverSource ?? "";
|
|
90
|
+
this.env = options.env ?? {};
|
|
91
|
+
this.timeout = options.timeout ?? 30000;
|
|
92
|
+
|
|
93
|
+
if (!this.serverCommand) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`No server command for agent "${definition.path}". Set serverSource in the definition or pass serverCommand in options.`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
tools(): SerializedTool[] {
|
|
101
|
+
return this.definition.tools;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
isConnected(): boolean {
|
|
105
|
+
return this.proc !== null && !this.proc.killed;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async call(
|
|
109
|
+
toolName: string,
|
|
110
|
+
input: Record<string, unknown> = {},
|
|
111
|
+
): Promise<unknown> {
|
|
112
|
+
// Validate tool exists
|
|
113
|
+
const tool = this.definition.tools.find((t) => t.name === toolName);
|
|
114
|
+
if (!tool) {
|
|
115
|
+
const available = this.definition.tools.map((t) => t.name).join(", ");
|
|
116
|
+
throw new Error(`Tool "${toolName}" not found. Available: ${available}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Ensure connected + initialized
|
|
120
|
+
await this.ensureInitialized();
|
|
121
|
+
|
|
122
|
+
// Send tools/call
|
|
123
|
+
const result = await this.sendRequest("tools/call", {
|
|
124
|
+
name: toolName,
|
|
125
|
+
arguments: input,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// MCP tools/call returns { content: [{ type, text }] }
|
|
129
|
+
const resultObj = result as Record<string, unknown> | null;
|
|
130
|
+
if (resultObj && typeof resultObj === "object" && "content" in resultObj) {
|
|
131
|
+
const content = resultObj.content;
|
|
132
|
+
if (Array.isArray(content) && content.length > 0) {
|
|
133
|
+
const first = content[0];
|
|
134
|
+
if (first.type === "text") {
|
|
135
|
+
try {
|
|
136
|
+
return JSON.parse(first.text);
|
|
137
|
+
} catch {
|
|
138
|
+
return first.text;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return first;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
close(): void {
|
|
148
|
+
if (this.proc) {
|
|
149
|
+
this.proc.kill();
|
|
150
|
+
this.proc = null;
|
|
151
|
+
}
|
|
152
|
+
this.initialized = false;
|
|
153
|
+
this.initPromise = null;
|
|
154
|
+
// Reject all pending
|
|
155
|
+
for (const req of Array.from(this.pending.values())) {
|
|
156
|
+
clearTimeout(req.timer);
|
|
157
|
+
req.reject(new Error("Client closed"));
|
|
158
|
+
}
|
|
159
|
+
this.pending.clear();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ── Private ──
|
|
163
|
+
|
|
164
|
+
private async ensureInitialized(): Promise<void> {
|
|
165
|
+
if (this.initialized) return;
|
|
166
|
+
if (this.initPromise) return this.initPromise;
|
|
167
|
+
|
|
168
|
+
this.initPromise = this.connect();
|
|
169
|
+
await this.initPromise;
|
|
170
|
+
this.initialized = true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private async connect(): Promise<void> {
|
|
174
|
+
const parts = this.serverCommand.split(/\s+/);
|
|
175
|
+
this.proc = spawn(parts[0], parts.slice(1), {
|
|
176
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
177
|
+
env: { ...process.env, ...this.env },
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
this.proc.stdout?.on("data", (chunk: Buffer) => this.onData(chunk));
|
|
181
|
+
this.proc.on("error", (err) => {
|
|
182
|
+
for (const req of Array.from(this.pending.values())) {
|
|
183
|
+
clearTimeout(req.timer);
|
|
184
|
+
req.reject(err);
|
|
185
|
+
}
|
|
186
|
+
this.pending.clear();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Initialize handshake
|
|
190
|
+
await this.sendRequest("initialize", {
|
|
191
|
+
protocolVersion: "2024-11-05",
|
|
192
|
+
capabilities: {},
|
|
193
|
+
clientInfo: { name: "agents-sdk-client", version: "1.0.0" },
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Send initialized notification
|
|
197
|
+
this.sendNotification("notifications/initialized");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private sendRequest(
|
|
201
|
+
method: string,
|
|
202
|
+
params: Record<string, unknown> = {},
|
|
203
|
+
): Promise<unknown> {
|
|
204
|
+
return new Promise((resolve, reject) => {
|
|
205
|
+
const id = ++this.messageId;
|
|
206
|
+
const timer = setTimeout(() => {
|
|
207
|
+
this.pending.delete(id);
|
|
208
|
+
reject(new Error(`Timeout after ${this.timeout}ms calling ${method}`));
|
|
209
|
+
}, this.timeout);
|
|
210
|
+
|
|
211
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
212
|
+
|
|
213
|
+
const msg = JSON.stringify({ jsonrpc: "2.0", id, method, params });
|
|
214
|
+
this.proc?.stdin?.write(`${msg}\n`);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private sendNotification(
|
|
219
|
+
method: string,
|
|
220
|
+
params?: Record<string, unknown>,
|
|
221
|
+
): void {
|
|
222
|
+
const msg = JSON.stringify({
|
|
223
|
+
jsonrpc: "2.0",
|
|
224
|
+
method,
|
|
225
|
+
...(params ? { params } : {}),
|
|
226
|
+
});
|
|
227
|
+
this.proc?.stdin?.write(`${msg}\n`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private onData(chunk: Buffer): void {
|
|
231
|
+
this.buffer += chunk.toString();
|
|
232
|
+
const lines = this.buffer.split("\n");
|
|
233
|
+
this.buffer = lines.pop() || "";
|
|
234
|
+
|
|
235
|
+
for (const line of lines) {
|
|
236
|
+
const trimmed = line.trim();
|
|
237
|
+
if (!trimmed) continue;
|
|
238
|
+
try {
|
|
239
|
+
const parsed = JSON.parse(trimmed);
|
|
240
|
+
if (parsed.id != null && this.pending.has(parsed.id)) {
|
|
241
|
+
const req = this.pending.get(parsed.id);
|
|
242
|
+
if (!req) continue;
|
|
243
|
+
this.pending.delete(parsed.id);
|
|
244
|
+
clearTimeout(req.timer);
|
|
245
|
+
if (parsed.error) {
|
|
246
|
+
req.reject(new Error(JSON.stringify(parsed.error)));
|
|
247
|
+
} else {
|
|
248
|
+
req.resolve(parsed.result);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
// ignore non-JSON lines (stderr leakage, etc.)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ============================================
|
|
259
|
+
// Factory
|
|
260
|
+
// ============================================
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Create an agent client from a serialized definition.
|
|
264
|
+
*
|
|
265
|
+
* The client lazily spawns the MCP server on first call and
|
|
266
|
+
* proxies tool invocations via JSON-RPC over stdio.
|
|
267
|
+
*/
|
|
268
|
+
export function createClient(
|
|
269
|
+
definition: SerializedAgentDefinition,
|
|
270
|
+
options?: CreateClientOptions,
|
|
271
|
+
): AgentClient {
|
|
272
|
+
return new McpStdioClient(definition, options);
|
|
273
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -294,3 +294,23 @@ export type {
|
|
|
294
294
|
McpTransport,
|
|
295
295
|
ServerSource,
|
|
296
296
|
} from "./codegen.js";
|
|
297
|
+
|
|
298
|
+
// ============================================
|
|
299
|
+
// Serialized Agent Definitions
|
|
300
|
+
// ============================================
|
|
301
|
+
|
|
302
|
+
export { serializeAgent, serializeTool } from "./serialized.js";
|
|
303
|
+
export type {
|
|
304
|
+
SerializedAgentDefinition,
|
|
305
|
+
SerializedTool,
|
|
306
|
+
} from "./serialized.js";
|
|
307
|
+
|
|
308
|
+
// ============================================
|
|
309
|
+
// Agent Client
|
|
310
|
+
// ============================================
|
|
311
|
+
|
|
312
|
+
export { createClient } from "./client.js";
|
|
313
|
+
export type {
|
|
314
|
+
AgentClient,
|
|
315
|
+
CreateClientOptions,
|
|
316
|
+
} from "./client.js";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialized Agent Definition
|
|
3
|
+
*
|
|
4
|
+
* Pure-data, JSON-serializable representation of an agent.
|
|
5
|
+
* No execute functions, no runtime hooks — just schemas and metadata.
|
|
6
|
+
*
|
|
7
|
+
* This is the universal IR:
|
|
8
|
+
* - Codegen produces it (MCP introspection → SerializedAgentDefinition)
|
|
9
|
+
* - Registry stores it (JSON in DB or filesystem)
|
|
10
|
+
* - API serves it (GET /agents/:name → SerializedAgentDefinition)
|
|
11
|
+
* - createClient() hydrates it (definition → typed proxy with real calls)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { JsonSchema, SecurityScheme } from "./types.js";
|
|
15
|
+
|
|
16
|
+
// ============================================
|
|
17
|
+
// Serialized Tool
|
|
18
|
+
// ============================================
|
|
19
|
+
|
|
20
|
+
export interface SerializedTool {
|
|
21
|
+
/** Tool name (unique within agent) */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Short description for tool discovery */
|
|
24
|
+
description: string;
|
|
25
|
+
/** JSON Schema for input parameters */
|
|
26
|
+
inputSchema: JsonSchema;
|
|
27
|
+
/** JSON Schema for output (optional) */
|
|
28
|
+
outputSchema?: JsonSchema;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ============================================
|
|
32
|
+
// Serialized Agent Definition
|
|
33
|
+
// ============================================
|
|
34
|
+
|
|
35
|
+
export interface SerializedAgentDefinition {
|
|
36
|
+
/** Agent path (e.g., 'notion', 'linear', 'github') */
|
|
37
|
+
path: string;
|
|
38
|
+
/** Human-readable name */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Short description */
|
|
41
|
+
description: string;
|
|
42
|
+
/** Version of the definition */
|
|
43
|
+
version: string;
|
|
44
|
+
/** Visibility level */
|
|
45
|
+
visibility: "public" | "private";
|
|
46
|
+
/** Auth requirements */
|
|
47
|
+
auth?: SecurityScheme;
|
|
48
|
+
/** MCP server source command (e.g., 'npx @notionhq/notion-mcp-server') */
|
|
49
|
+
serverSource?: string;
|
|
50
|
+
/** Server info from MCP introspection */
|
|
51
|
+
serverInfo?: {
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
};
|
|
55
|
+
/** Tool definitions (schemas only, no execute) */
|
|
56
|
+
tools: SerializedTool[];
|
|
57
|
+
/** ISO timestamp of when this was generated */
|
|
58
|
+
generatedAt?: string;
|
|
59
|
+
/** SDK version used for codegen */
|
|
60
|
+
sdkVersion?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ============================================
|
|
64
|
+
// Serialization helpers
|
|
65
|
+
// ============================================
|
|
66
|
+
|
|
67
|
+
import type { AgentDefinition, ToolContext, ToolDefinition } from "./types.js";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Serialize an AgentDefinition to its pure-data representation.
|
|
71
|
+
* Strips execute functions, runtime hooks, listeners, etc.
|
|
72
|
+
*/
|
|
73
|
+
export function serializeAgent(
|
|
74
|
+
agent: AgentDefinition,
|
|
75
|
+
meta?: { serverSource?: string; version?: string },
|
|
76
|
+
): SerializedAgentDefinition {
|
|
77
|
+
return {
|
|
78
|
+
path: agent.path,
|
|
79
|
+
name: agent.config?.name ?? agent.path,
|
|
80
|
+
description: agent.config?.description ?? "",
|
|
81
|
+
version: meta?.version ?? "1.0.0",
|
|
82
|
+
visibility: (agent.visibility as "public" | "private") ?? "public",
|
|
83
|
+
auth: agent.config?.security,
|
|
84
|
+
serverSource: meta?.serverSource,
|
|
85
|
+
tools: agent.tools.map(serializeTool),
|
|
86
|
+
generatedAt: new Date().toISOString(),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Serialize a single ToolDefinition to its pure-data representation.
|
|
92
|
+
*/
|
|
93
|
+
export function serializeTool(
|
|
94
|
+
tool: ToolDefinition<ToolContext, unknown, unknown>,
|
|
95
|
+
): SerializedTool {
|
|
96
|
+
return {
|
|
97
|
+
name: tool.name,
|
|
98
|
+
description: tool.description,
|
|
99
|
+
inputSchema: tool.inputSchema,
|
|
100
|
+
...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|