@mcpstack/agent-sdk 1.0.0-pr.16.7572c080abaa.13.1 → 1.0.0-pr.18.bbb0c016bc21.17.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/README.md +46 -23
- package/dist/app/index.d.mts +25 -9
- package/dist/app/index.d.ts +25 -9
- package/dist/app/index.js +403 -95
- package/dist/app/index.js.map +1 -1
- package/dist/app/index.mjs +403 -95
- package/dist/app/index.mjs.map +1 -1
- package/dist/index.d.mts +25 -9
- package/dist/index.d.ts +25 -9
- package/dist/index.js +403 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +403 -95
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +25 -9
- package/dist/react/index.d.ts +25 -9
- package/dist/react/index.js +403 -95
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +403 -95
- package/dist/react/index.mjs.map +1 -1
- package/dist/react-embed/index.js +403 -95
- package/dist/react-embed/index.js.map +1 -1
- package/dist/react-embed/index.mjs +403 -95
- package/dist/react-embed/index.mjs.map +1 -1
- package/dist/react-native/index.d.mts +25 -9
- package/dist/react-native/index.d.ts +25 -9
- package/dist/react-native/index.js +403 -95
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/index.mjs +403 -95
- package/dist/react-native/index.mjs.map +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Use MCP Stack agents in your app.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
AgentSDK is MCP Stack's first-party AG-UI client. Your app talks AG-UI to the agent; MCP Stack keeps server tools on MCP through Gateway, AuthGateway, budgets, logs, and permissions.
|
|
6
|
+
|
|
7
|
+
This package has one public model for custom product integrations: `App Agent`.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
@@ -62,21 +64,21 @@ export function App() {
|
|
|
62
64
|
return (
|
|
63
65
|
<div style={{ height: 640 }}>
|
|
64
66
|
<McpStackChat
|
|
65
|
-
apiKey="
|
|
67
|
+
apiKey="mcpstack_pk_xxxx"
|
|
66
68
|
agentId="ag_xxxxx"
|
|
67
69
|
appSessionKey={session.id}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
userIdentity={{
|
|
71
|
+
subject: session.user.id,
|
|
72
|
+
email: session.user.email,
|
|
73
|
+
organizationId: session.organizationId,
|
|
74
|
+
}}
|
|
75
|
+
auth={{
|
|
76
|
+
mode: "app-token",
|
|
77
|
+
getToken: () => session.getAccessToken(),
|
|
78
|
+
}}
|
|
79
|
+
mode="inline"
|
|
80
|
+
title="Support Agent"
|
|
81
|
+
/>
|
|
80
82
|
</div>
|
|
81
83
|
);
|
|
82
84
|
}
|
|
@@ -89,7 +91,7 @@ import { useAppAgent } from "@mcpstack/agent-sdk/react";
|
|
|
89
91
|
|
|
90
92
|
export function CustomAssistant() {
|
|
91
93
|
const agent = useAppAgent({
|
|
92
|
-
apiKey: "
|
|
94
|
+
apiKey: "mcpstack_pk_xxxx",
|
|
93
95
|
agentId: "ag_xxxxx",
|
|
94
96
|
appSessionKey: session.id,
|
|
95
97
|
userIdentity: {
|
|
@@ -116,7 +118,7 @@ import { useAppAgent } from "@mcpstack/agent-sdk/react-native";
|
|
|
116
118
|
|
|
117
119
|
export function AssistantShell() {
|
|
118
120
|
const agent = useAppAgent({
|
|
119
|
-
apiKey: "
|
|
121
|
+
apiKey: "mcpstack_pk_xxxx",
|
|
120
122
|
agentId: "ag_xxxxx",
|
|
121
123
|
appSessionKey: session.id,
|
|
122
124
|
userIdentity: {
|
|
@@ -140,7 +142,7 @@ export function AssistantShell() {
|
|
|
140
142
|
import { McpStackAgent } from "@mcpstack/agent-sdk";
|
|
141
143
|
|
|
142
144
|
const agent = new McpStackAgent({
|
|
143
|
-
apiKey: "
|
|
145
|
+
apiKey: "mcpstack_pk_xxxx",
|
|
144
146
|
agentId: "ag_xxxxx",
|
|
145
147
|
authSessionKey: session.id,
|
|
146
148
|
});
|
|
@@ -158,7 +160,7 @@ Apps can tune the behavior without implementing their own VAD:
|
|
|
158
160
|
|
|
159
161
|
```ts
|
|
160
162
|
const agent = new McpStackAgent({
|
|
161
|
-
apiKey: "
|
|
163
|
+
apiKey: "mcpstack_pk_xxxx",
|
|
162
164
|
agentId: "ag_xxxxx",
|
|
163
165
|
audioInput: {
|
|
164
166
|
turnDetection: {
|
|
@@ -175,7 +177,7 @@ const agent = new McpStackAgent({
|
|
|
175
177
|
|
|
176
178
|
### `apiKey`
|
|
177
179
|
|
|
178
|
-
Your MCP Stack
|
|
180
|
+
Your MCP Stack public agent key, usually an `mcpstack_pk_*` embed key scoped to the agent and allowed browser origins.
|
|
179
181
|
|
|
180
182
|
### `agentId`
|
|
181
183
|
|
|
@@ -215,19 +217,40 @@ auth: {
|
|
|
215
217
|
auth library refreshes tokens, read from that current session source rather than
|
|
216
218
|
capturing a token from the first render.
|
|
217
219
|
|
|
218
|
-
The SDK
|
|
219
|
-
OAuth client registration. External MCP clients can still use the same
|
|
220
|
-
Gateway-backed server through standard OAuth discovery, registration, and
|
|
221
|
-
authorization.
|
|
220
|
+
The SDK forwards that app token with the AG-UI run. When the agent needs a server MCP tool, MCP Stack exchanges the app token at Gateway for an MCP-facing token without OAuth client registration. External MCP clients can still use the same Gateway-backed server through standard OAuth discovery, registration, and authorization.
|
|
222
221
|
|
|
223
222
|
### `clientTools`
|
|
224
223
|
|
|
225
224
|
App-owned functions the agent can call locally for UI work or host orchestration.
|
|
226
225
|
|
|
226
|
+
AgentSDK sends these as AG-UI frontend tool schemas. They run in your app and should stay focused on route changes, current-screen reads, drafting, filtering, approvals, and other local UI work. Use server MCP tools for authoritative backend reads and writes.
|
|
227
|
+
|
|
227
228
|
### `appContext`
|
|
228
229
|
|
|
229
230
|
Extra host context or policy instructions for the agent.
|
|
230
231
|
|
|
232
|
+
## Protocol boundary
|
|
233
|
+
|
|
234
|
+
AgentSDK uses AG-UI for agent turns:
|
|
235
|
+
|
|
236
|
+
```text
|
|
237
|
+
AgentSDK / custom AG-UI frontend
|
|
238
|
+
-> AG-UI
|
|
239
|
+
MCP Stack Agent
|
|
240
|
+
-> MCP
|
|
241
|
+
MCP Stack Server
|
|
242
|
+
-> Gateway / AuthGateway
|
|
243
|
+
-> SaaS API
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
That means:
|
|
247
|
+
|
|
248
|
+
- assistant text and tool progress stream as AG-UI events
|
|
249
|
+
- `clientTools` map to AG-UI frontend tools
|
|
250
|
+
- server MCP tools execute server-side through Gateway/AuthGateway
|
|
251
|
+
- budgets, logs, and permissions still apply to server-side work
|
|
252
|
+
- existing `useAppAgent`, `createAppAgent`, and `McpStackChat` integrations do not need a major rewrite
|
|
253
|
+
|
|
231
254
|
## OAuth
|
|
232
255
|
|
|
233
256
|
If an external MCP client needs user-scoped OAuth:
|
package/dist/app/index.d.mts
CHANGED
|
@@ -106,7 +106,7 @@ interface McpStackAgentConfig {
|
|
|
106
106
|
oauthClientMetadataUrl?: string;
|
|
107
107
|
/**
|
|
108
108
|
* Callback to get the auth token for MCP Stack API requests.
|
|
109
|
-
* If provided, called before each
|
|
109
|
+
* If provided, called before each agent run request.
|
|
110
110
|
* Use this when your session token may expire and needs refresh (e.g., dashboard playground).
|
|
111
111
|
* If not provided, uses the static `apiKey` value.
|
|
112
112
|
*/
|
|
@@ -429,8 +429,9 @@ type EventHandler<T> = (data: T) => void;
|
|
|
429
429
|
* Framework-agnostic — works in any JavaScript environment.
|
|
430
430
|
*
|
|
431
431
|
* Handles:
|
|
432
|
-
* - Communication with the MCP Stack
|
|
433
|
-
* -
|
|
432
|
+
* - Communication with the MCP Stack AG-UI run endpoint (SSE streaming)
|
|
433
|
+
* - AG-UI frontend tool execution via configured clientTools
|
|
434
|
+
* - MCP server auth/session helpers for legacy and explicit auth flows
|
|
434
435
|
* - Conversation state management
|
|
435
436
|
* - Event emission for UI updates
|
|
436
437
|
*/
|
|
@@ -497,6 +498,11 @@ declare class McpStackAgent {
|
|
|
497
498
|
submitFeedback(input: SubmitConversationFeedbackRequest): Promise<ConversationFeedback>;
|
|
498
499
|
/** Convert client tools to the API schema format. */
|
|
499
500
|
private clientToolsToSchemas;
|
|
501
|
+
private clientToolsToAgUiTools;
|
|
502
|
+
private buildAgUiContext;
|
|
503
|
+
private buildAgUiForwardedProps;
|
|
504
|
+
private buildAgUiUserRunInput;
|
|
505
|
+
private buildAgUiToolResultRunInput;
|
|
500
506
|
private resolveExternalUserId;
|
|
501
507
|
private buildExternalUserContext;
|
|
502
508
|
/** Latest runtime budget snapshot for the current SDK identity. */
|
|
@@ -596,18 +602,28 @@ declare class McpStackAgent {
|
|
|
596
602
|
private resolveToken;
|
|
597
603
|
/**
|
|
598
604
|
* The core orchestration loop:
|
|
599
|
-
* 1. Send message to
|
|
600
|
-
* 2. Stream
|
|
601
|
-
* 3. If
|
|
602
|
-
* 4.
|
|
605
|
+
* 1. Send message to the AG-UI run endpoint
|
|
606
|
+
* 2. Stream assistant text, server MCP tool progress, and frontend tool requests
|
|
607
|
+
* 3. If an AG-UI frontend tool is requested, execute the matching clientTool locally
|
|
608
|
+
* 4. Send the frontend tool result back as an AG-UI tool message and continue
|
|
603
609
|
*/
|
|
604
610
|
private runChatLoop;
|
|
605
|
-
private
|
|
611
|
+
private executeClientTool;
|
|
612
|
+
private callAgUiApi;
|
|
613
|
+
private processAgUiStream;
|
|
614
|
+
private recordToolResult;
|
|
615
|
+
private recordToolError;
|
|
616
|
+
private serializeToolContent;
|
|
617
|
+
private parseToolContent;
|
|
618
|
+
private parseToolArguments;
|
|
619
|
+
private getRecordField;
|
|
620
|
+
private getStringField;
|
|
621
|
+
private getNumberField;
|
|
606
622
|
private fetchConversationMessages;
|
|
607
623
|
private applyConversationPage;
|
|
608
624
|
private mapReplayMessage;
|
|
609
625
|
/**
|
|
610
|
-
* Process
|
|
626
|
+
* Process a legacy chat SSE stream.
|
|
611
627
|
* Returns when the stream ends (either message_end or tool_call).
|
|
612
628
|
*/
|
|
613
629
|
private processSseStream;
|
package/dist/app/index.d.ts
CHANGED
|
@@ -106,7 +106,7 @@ interface McpStackAgentConfig {
|
|
|
106
106
|
oauthClientMetadataUrl?: string;
|
|
107
107
|
/**
|
|
108
108
|
* Callback to get the auth token for MCP Stack API requests.
|
|
109
|
-
* If provided, called before each
|
|
109
|
+
* If provided, called before each agent run request.
|
|
110
110
|
* Use this when your session token may expire and needs refresh (e.g., dashboard playground).
|
|
111
111
|
* If not provided, uses the static `apiKey` value.
|
|
112
112
|
*/
|
|
@@ -429,8 +429,9 @@ type EventHandler<T> = (data: T) => void;
|
|
|
429
429
|
* Framework-agnostic — works in any JavaScript environment.
|
|
430
430
|
*
|
|
431
431
|
* Handles:
|
|
432
|
-
* - Communication with the MCP Stack
|
|
433
|
-
* -
|
|
432
|
+
* - Communication with the MCP Stack AG-UI run endpoint (SSE streaming)
|
|
433
|
+
* - AG-UI frontend tool execution via configured clientTools
|
|
434
|
+
* - MCP server auth/session helpers for legacy and explicit auth flows
|
|
434
435
|
* - Conversation state management
|
|
435
436
|
* - Event emission for UI updates
|
|
436
437
|
*/
|
|
@@ -497,6 +498,11 @@ declare class McpStackAgent {
|
|
|
497
498
|
submitFeedback(input: SubmitConversationFeedbackRequest): Promise<ConversationFeedback>;
|
|
498
499
|
/** Convert client tools to the API schema format. */
|
|
499
500
|
private clientToolsToSchemas;
|
|
501
|
+
private clientToolsToAgUiTools;
|
|
502
|
+
private buildAgUiContext;
|
|
503
|
+
private buildAgUiForwardedProps;
|
|
504
|
+
private buildAgUiUserRunInput;
|
|
505
|
+
private buildAgUiToolResultRunInput;
|
|
500
506
|
private resolveExternalUserId;
|
|
501
507
|
private buildExternalUserContext;
|
|
502
508
|
/** Latest runtime budget snapshot for the current SDK identity. */
|
|
@@ -596,18 +602,28 @@ declare class McpStackAgent {
|
|
|
596
602
|
private resolveToken;
|
|
597
603
|
/**
|
|
598
604
|
* The core orchestration loop:
|
|
599
|
-
* 1. Send message to
|
|
600
|
-
* 2. Stream
|
|
601
|
-
* 3. If
|
|
602
|
-
* 4.
|
|
605
|
+
* 1. Send message to the AG-UI run endpoint
|
|
606
|
+
* 2. Stream assistant text, server MCP tool progress, and frontend tool requests
|
|
607
|
+
* 3. If an AG-UI frontend tool is requested, execute the matching clientTool locally
|
|
608
|
+
* 4. Send the frontend tool result back as an AG-UI tool message and continue
|
|
603
609
|
*/
|
|
604
610
|
private runChatLoop;
|
|
605
|
-
private
|
|
611
|
+
private executeClientTool;
|
|
612
|
+
private callAgUiApi;
|
|
613
|
+
private processAgUiStream;
|
|
614
|
+
private recordToolResult;
|
|
615
|
+
private recordToolError;
|
|
616
|
+
private serializeToolContent;
|
|
617
|
+
private parseToolContent;
|
|
618
|
+
private parseToolArguments;
|
|
619
|
+
private getRecordField;
|
|
620
|
+
private getStringField;
|
|
621
|
+
private getNumberField;
|
|
606
622
|
private fetchConversationMessages;
|
|
607
623
|
private applyConversationPage;
|
|
608
624
|
private mapReplayMessage;
|
|
609
625
|
/**
|
|
610
|
-
* Process
|
|
626
|
+
* Process a legacy chat SSE stream.
|
|
611
627
|
* Returns when the stream ends (either message_end or tool_call).
|
|
612
628
|
*/
|
|
613
629
|
private processSseStream;
|