@letta-ai/letta-agent-sdk 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -8
- package/dist/app-server-session.d.ts +1 -0
- package/dist/app-server-session.d.ts.map +1 -1
- package/dist/client-entry.js +43 -3
- package/dist/client-entry.js.map +6 -5
- package/dist/cloud-session.d.ts +1 -0
- package/dist/cloud-session.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22428 -7518
- package/dist/index.js.map +122 -6
- package/dist/mcp-runtime.d.ts +15 -0
- package/dist/mcp-runtime.d.ts.map +1 -0
- package/dist/mcp.d.ts +9 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/app-server-session.ts +19 -1
- package/src/cloud-session.ts +18 -1
- package/src/index.ts +6 -0
- package/src/mcp-runtime.ts +39 -0
- package/src/mcp.ts +203 -0
- package/src/types.ts +27 -0
package/README.md
CHANGED
|
@@ -10,14 +10,6 @@ Build applications with stateful agents powered by the [Letta agent harness](htt
|
|
|
10
10
|
npm install @letta-ai/letta-agent-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
The `0.4.x` SDK line requires the matching single-socket
|
|
14
|
-
`@letta-ai/letta-code` app-server release. Release `letta-code` first, then
|
|
15
|
-
replace the SDK's package dependency with that published version before
|
|
16
|
-
publishing `0.4.0`; the development branch intentionally does not name an
|
|
17
|
-
unpublished package version.
|
|
18
|
-
|
|
19
|
-
Local execution requires Node.js 22.19 or newer.
|
|
20
|
-
|
|
21
13
|
## Quick start
|
|
22
14
|
|
|
23
15
|
```ts
|
|
@@ -127,6 +119,32 @@ await using session = client.createSession(agentId, {
|
|
|
127
119
|
});
|
|
128
120
|
```
|
|
129
121
|
|
|
122
|
+
Local execution (embedded Letta Code harness / app server) requires Node.js 22.19 or newer.
|
|
123
|
+
|
|
124
|
+
### MCP tools
|
|
125
|
+
|
|
126
|
+
Pass stdio MCP servers as session options. The SDK starts them in the session
|
|
127
|
+
cwd, namespaces their tools as `mcp__<server>__<tool>`, and exposes them through
|
|
128
|
+
Letta Code's external-tool protocol. Servers are closed with the session.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
await using session = client.createSession(agentId, {
|
|
132
|
+
cwd: process.cwd(),
|
|
133
|
+
mcpServers: [
|
|
134
|
+
{
|
|
135
|
+
name: "filesystem",
|
|
136
|
+
command: "npx",
|
|
137
|
+
args: ["-y", "@modelcontextprotocol/server-filesystem", process.cwd()],
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
MCP stdio processes require the Node package entry; they are not available from
|
|
144
|
+
`@letta-ai/letta-agent-sdk/client` in browser or React Native environments. For
|
|
145
|
+
a simple smoke test, the official `@modelcontextprotocol/server-everything`
|
|
146
|
+
package runs over stdio with `npx -y @modelcontextprotocol/server-everything`.
|
|
147
|
+
|
|
130
148
|
### Managed Cloud sandbox repositories
|
|
131
149
|
|
|
132
150
|
Cloud sessions can clone up to 10 GitHub repositories into the managed
|
|
@@ -66,6 +66,7 @@ export declare class AppServerSession extends RemoteClientSessionCore {
|
|
|
66
66
|
private readonly remoteOptions;
|
|
67
67
|
private ownedConnection;
|
|
68
68
|
private externalTools;
|
|
69
|
+
private mcpBridge;
|
|
69
70
|
private removeExternalToolHandler;
|
|
70
71
|
private removeControlRequestHandler;
|
|
71
72
|
constructor(remoteOptions: AppServerSessionOptions, mode: AppServerSessionMode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-server-session.d.ts","sourceRoot":"","sources":["../src/app-server-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,gCAAgC,EAEtC,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"app-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AI,IAAI;CAGd;AAED,qBAAa,gBAAiB,SAAQ,uBAAuB;IAQzD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,yBAAyB,CAA6B;IAC9D,OAAO,CAAC,2BAA2B,CAA6B;gBAG7C,aAAa,EAAE,uBAAuB,EACvD,IAAI,EAAE,oBAAoB;cAYT,iBAAiB,CAAC,OAAO,EAAE,6BAA6B,GAAG,kBAAkB,GAAG,OAAO;cAKjF,2BAA2B,IAAI,OAAO,CAAC,kBAAkB,CAAC;cAwEhE,WAAW,IAAI,IAAI;YAWxB,mBAAmB;YAenB,YAAY;YAOZ,wBAAwB;YAiExB,0BAA0B;CAqBzC"}
|
package/dist/client-entry.js
CHANGED
|
@@ -8615,6 +8615,20 @@ function buildCanUseToolContext(request, requestId) {
|
|
|
8615
8615
|
return context;
|
|
8616
8616
|
}
|
|
8617
8617
|
|
|
8618
|
+
// src/mcp-runtime.ts
|
|
8619
|
+
var connector = null;
|
|
8620
|
+
async function connectMcpServers(servers, options = {}) {
|
|
8621
|
+
if (!servers || servers.length === 0) {
|
|
8622
|
+
return { tools: [], close: async () => {
|
|
8623
|
+
return;
|
|
8624
|
+
} };
|
|
8625
|
+
}
|
|
8626
|
+
if (!connector) {
|
|
8627
|
+
throw new Error("MCP stdio servers require the Node package entry '@letta-ai/letta-agent-sdk'; they are not available from '@letta-ai/letta-agent-sdk/client'.");
|
|
8628
|
+
}
|
|
8629
|
+
return connector(servers, options);
|
|
8630
|
+
}
|
|
8631
|
+
|
|
8618
8632
|
// src/remote-session-protocol.ts
|
|
8619
8633
|
var FAILURE_STOP_REASONS = new Set([
|
|
8620
8634
|
"error",
|
|
@@ -10403,6 +10417,7 @@ class AppServerSession extends RemoteClientSessionCore {
|
|
|
10403
10417
|
remoteOptions;
|
|
10404
10418
|
ownedConnection = null;
|
|
10405
10419
|
externalTools = new Map;
|
|
10420
|
+
mcpBridge = null;
|
|
10406
10421
|
removeExternalToolHandler = null;
|
|
10407
10422
|
removeControlRequestHandler = null;
|
|
10408
10423
|
constructor(remoteOptions, mode) {
|
|
@@ -10429,6 +10444,14 @@ class AppServerSession extends RemoteClientSessionCore {
|
|
|
10429
10444
|
...this.remoteOptions.WebSocket ? { WebSocket: this.remoteOptions.WebSocket } : {},
|
|
10430
10445
|
...this.remoteOptions.requestTimeoutMs !== undefined ? { requestTimeoutMs: this.remoteOptions.requestTimeoutMs } : {}
|
|
10431
10446
|
}));
|
|
10447
|
+
const options = this.currentOptions();
|
|
10448
|
+
this.mcpBridge = await connectMcpServers("mcpServers" in options ? options.mcpServers : undefined, {
|
|
10449
|
+
cwd: options.cwd,
|
|
10450
|
+
reservedToolNames: this.externalTools.keys()
|
|
10451
|
+
});
|
|
10452
|
+
for (const tool of this.mcpBridge.tools) {
|
|
10453
|
+
this.externalTools.set(tool.name, tool);
|
|
10454
|
+
}
|
|
10432
10455
|
this.removeControlRequestHandler = registerAppServerControlRequestHandler({
|
|
10433
10456
|
client,
|
|
10434
10457
|
getRuntime: () => this.runtime,
|
|
@@ -10458,6 +10481,8 @@ class AppServerSession extends RemoteClientSessionCore {
|
|
|
10458
10481
|
this.removeExternalToolHandler = null;
|
|
10459
10482
|
this.removeControlRequestHandler?.();
|
|
10460
10483
|
this.removeControlRequestHandler = null;
|
|
10484
|
+
this.mcpBridge?.close();
|
|
10485
|
+
this.mcpBridge = null;
|
|
10461
10486
|
client.close();
|
|
10462
10487
|
throw error;
|
|
10463
10488
|
}
|
|
@@ -10467,6 +10492,8 @@ class AppServerSession extends RemoteClientSessionCore {
|
|
|
10467
10492
|
this.removeExternalToolHandler = null;
|
|
10468
10493
|
this.removeControlRequestHandler?.();
|
|
10469
10494
|
this.removeControlRequestHandler = null;
|
|
10495
|
+
this.mcpBridge?.close();
|
|
10496
|
+
this.mcpBridge = null;
|
|
10470
10497
|
this.ownedConnection?.close();
|
|
10471
10498
|
this.ownedConnection = null;
|
|
10472
10499
|
}
|
|
@@ -10504,7 +10531,7 @@ class AppServerSession extends RemoteClientSessionCore {
|
|
|
10504
10531
|
if (options.skillSources !== undefined) {
|
|
10505
10532
|
command.skill_sources = [...new Set(options.skillSources)];
|
|
10506
10533
|
}
|
|
10507
|
-
const groups = externalToolGroups(
|
|
10534
|
+
const groups = externalToolGroups([...this.externalTools.values()]);
|
|
10508
10535
|
if (groups)
|
|
10509
10536
|
command.external_tools = groups;
|
|
10510
10537
|
if (this.mode.kind === "create-agent") {
|
|
@@ -11124,6 +11151,7 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11124
11151
|
removeExternalToolHandler = null;
|
|
11125
11152
|
removeControlRequestHandler = null;
|
|
11126
11153
|
externalTools = new Map;
|
|
11154
|
+
mcpBridge = null;
|
|
11127
11155
|
managedSandbox = null;
|
|
11128
11156
|
sandboxRefreshTimer = null;
|
|
11129
11157
|
sandboxRefreshInFlight = null;
|
|
@@ -11171,6 +11199,14 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11171
11199
|
}),
|
|
11172
11200
|
requestTimeoutMs: this.cloudOptions.requestTimeoutMs ?? DEFAULT_TURN_TIMEOUT_MS
|
|
11173
11201
|
}));
|
|
11202
|
+
const options = this.currentOptions();
|
|
11203
|
+
this.mcpBridge = await connectMcpServers("mcpServers" in options ? options.mcpServers : undefined, {
|
|
11204
|
+
cwd: options.cwd,
|
|
11205
|
+
reservedToolNames: this.externalTools.keys()
|
|
11206
|
+
});
|
|
11207
|
+
for (const tool of this.mcpBridge.tools) {
|
|
11208
|
+
this.externalTools.set(tool.name, tool);
|
|
11209
|
+
}
|
|
11174
11210
|
this.removeControlRequestHandler = registerAppServerControlRequestHandler({
|
|
11175
11211
|
client,
|
|
11176
11212
|
getRuntime: () => this.runtime,
|
|
@@ -11202,6 +11238,8 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11202
11238
|
this.removeExternalToolHandler = null;
|
|
11203
11239
|
this.removeControlRequestHandler?.();
|
|
11204
11240
|
this.removeControlRequestHandler = null;
|
|
11241
|
+
this.mcpBridge?.close();
|
|
11242
|
+
this.mcpBridge = null;
|
|
11205
11243
|
client.close();
|
|
11206
11244
|
await this.cleanupManagedSandbox();
|
|
11207
11245
|
await this.cleanupSessionRepositories(resolved.runtime.agent_id, resolved.runtime.conversation_id);
|
|
@@ -11228,7 +11266,7 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11228
11266
|
if (options.skillSources !== undefined) {
|
|
11229
11267
|
command.skill_sources = [...new Set(options.skillSources)];
|
|
11230
11268
|
}
|
|
11231
|
-
const groups = externalToolGroups(
|
|
11269
|
+
const groups = externalToolGroups([...this.externalTools.values()]);
|
|
11232
11270
|
if (groups)
|
|
11233
11271
|
command.external_tools = groups;
|
|
11234
11272
|
return await client.runtimeStart(command);
|
|
@@ -11254,6 +11292,8 @@ class CloudEnvironmentSession extends RemoteClientSessionCore {
|
|
|
11254
11292
|
this.removeExternalToolHandler = null;
|
|
11255
11293
|
this.removeControlRequestHandler?.();
|
|
11256
11294
|
this.removeControlRequestHandler = null;
|
|
11295
|
+
this.mcpBridge?.close();
|
|
11296
|
+
this.mcpBridge = null;
|
|
11257
11297
|
this.cleanupManagedSandbox();
|
|
11258
11298
|
if (this.runtime?.agent_id) {
|
|
11259
11299
|
this.cleanupSessionRepositories(this.runtime.agent_id, this.runtime.conversation_id);
|
|
@@ -12209,4 +12249,4 @@ export {
|
|
|
12209
12249
|
CloudManagedSandboxExpiredError
|
|
12210
12250
|
};
|
|
12211
12251
|
|
|
12212
|
-
//# debugId=
|
|
12252
|
+
//# debugId=6301765BD48499AE64756E2164756E21
|