@mcpstack/agent-sdk 1.0.0-pr.16.7572c080abaa.13.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Emcy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # @mcpstack/agent-sdk
2
+
3
+ Use MCP Stack agents in your app.
4
+
5
+ This package now has one public model for custom product integrations: `App Agent`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @mcpstack/agent-sdk
11
+ ```
12
+
13
+ ## Package surfaces
14
+
15
+ ### `@mcpstack/agent-sdk`
16
+
17
+ Low-level runtime:
18
+
19
+ - `McpStackAgent`
20
+ - core auth helpers
21
+ - core transport and types
22
+
23
+ ### `@mcpstack/agent-sdk/app`
24
+
25
+ Framework-agnostic agent experience helpers:
26
+
27
+ - `createAppAgent`
28
+ - `AppAgentController`
29
+ - message / tool derivation helpers
30
+ - resume / pending-turn / formatting helpers
31
+
32
+ ### `@mcpstack/agent-sdk/react`
33
+
34
+ React app integration:
35
+
36
+ - `useAppAgent`
37
+ - `AppAgentProvider`
38
+ - `useAppAgentContext`
39
+
40
+ ### `@mcpstack/agent-sdk/react-native`
41
+
42
+ React Native app integration:
43
+
44
+ - `useAppAgent`
45
+ - `AppAgentProvider`
46
+ - `useAppAgentContext`
47
+
48
+ ### `@mcpstack/agent-sdk/react-embed`
49
+
50
+ Drop-in web widget:
51
+
52
+ - `McpStackChat`
53
+
54
+ ## Start here
55
+
56
+ ### 1. Drop-in web embed
57
+
58
+ ```tsx
59
+ import { McpStackChat } from "@mcpstack/agent-sdk/react-embed";
60
+
61
+ export function App() {
62
+ return (
63
+ <div style={{ height: 640 }}>
64
+ <McpStackChat
65
+ apiKey="mcpstack_sk_xxxx"
66
+ agentId="ag_xxxxx"
67
+ appSessionKey={session.id}
68
+ userIdentity={{
69
+ subject: session.user.id,
70
+ email: session.user.email,
71
+ organizationId: session.organizationId,
72
+ }}
73
+ auth={{
74
+ mode: "app-token",
75
+ getToken: () => session.getAccessToken(),
76
+ }}
77
+ mode="inline"
78
+ title="Support Agent"
79
+ />
80
+ </div>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ### 2. Custom React app UI
86
+
87
+ ```tsx
88
+ import { useAppAgent } from "@mcpstack/agent-sdk/react";
89
+
90
+ export function CustomAssistant() {
91
+ const agent = useAppAgent({
92
+ apiKey: "mcpstack_sk_xxxx",
93
+ agentId: "ag_xxxxx",
94
+ appSessionKey: session.id,
95
+ userIdentity: {
96
+ subject: session.user.id,
97
+ email: session.user.email,
98
+ organizationId: session.organizationId,
99
+ },
100
+ auth: {
101
+ mode: "app-token",
102
+ getToken: () => session.getAccessToken(),
103
+ },
104
+ clientTools,
105
+ appContext,
106
+ });
107
+
108
+ return null;
109
+ }
110
+ ```
111
+
112
+ ### 3. Custom React Native UI
113
+
114
+ ```tsx
115
+ import { useAppAgent } from "@mcpstack/agent-sdk/react-native";
116
+
117
+ export function AssistantShell() {
118
+ const agent = useAppAgent({
119
+ apiKey: "mcpstack_sk_xxxx",
120
+ agentId: "ag_xxxxx",
121
+ appSessionKey: session.id,
122
+ userIdentity: {
123
+ subject: session.user.id,
124
+ email: session.user.email,
125
+ organizationId: session.organizationId,
126
+ },
127
+ clientTools,
128
+ appContext,
129
+ platform,
130
+ });
131
+
132
+ const toolMessages = agent.conversation.toolMessages;
133
+ return null;
134
+ }
135
+ ```
136
+
137
+ ### 4. Raw runtime
138
+
139
+ ```ts
140
+ import { McpStackAgent } from "@mcpstack/agent-sdk";
141
+
142
+ const agent = new McpStackAgent({
143
+ apiKey: "mcpstack_sk_xxxx",
144
+ agentId: "ag_xxxxx",
145
+ authSessionKey: session.id,
146
+ });
147
+
148
+ await agent.init();
149
+ await agent.sendMessage("Hello");
150
+ ```
151
+
152
+ ### Microphone turn detection
153
+
154
+ Microphone end-of-speech detection is owned by the SDK for both embedded and
155
+ headless integrations. By default, the SDK listens for real speech, adapts to
156
+ the local noise floor, then commits the utterance after a short trailing pause.
157
+ Apps can tune the behavior without implementing their own VAD:
158
+
159
+ ```ts
160
+ const agent = new McpStackAgent({
161
+ apiKey: "mcpstack_sk_xxxx",
162
+ agentId: "ag_xxxxx",
163
+ audioInput: {
164
+ turnDetection: {
165
+ silenceDurationMs: 850,
166
+ minSpeechDurationMs: 180,
167
+ noSpeechTimeoutMs: 12000,
168
+ autoSubmit: true,
169
+ },
170
+ },
171
+ });
172
+ ```
173
+
174
+ ## Core app-agent config
175
+
176
+ ### `apiKey`
177
+
178
+ Your MCP Stack API key.
179
+
180
+ ### `agentId`
181
+
182
+ The agent to run.
183
+
184
+ ### `appSessionKey`
185
+
186
+ Your host app’s current signed-in session boundary.
187
+
188
+ Pass this so persisted MCP auth and resumed conversations do not leak across logout/login cycles.
189
+
190
+ ### `userIdentity`
191
+
192
+ The signed-in host user:
193
+
194
+ ```ts
195
+ userIdentity: {
196
+ subject: session.user.id,
197
+ email: session.user.email,
198
+ organizationId: session.organizationId,
199
+ }
200
+ ```
201
+
202
+ ### `auth`
203
+
204
+ For embedded products where the user already signed in, let your app keep auth
205
+ ownership and give the SDK a token getter:
206
+
207
+ ```ts
208
+ auth: {
209
+ mode: "app-token",
210
+ getToken: () => session.getAccessToken(),
211
+ }
212
+ ```
213
+
214
+ `getToken` should return the current app token each time it is called. If your
215
+ auth library refreshes tokens, read from that current session source rather than
216
+ capturing a token from the first render.
217
+
218
+ The SDK exchanges that app token at Gateway for an MCP-facing token without
219
+ OAuth client registration. External MCP clients can still use the same
220
+ Gateway-backed server through standard OAuth discovery, registration, and
221
+ authorization.
222
+
223
+ ### `clientTools`
224
+
225
+ App-owned functions the agent can call locally for UI work or host orchestration.
226
+
227
+ ### `appContext`
228
+
229
+ Extra host context or policy instructions for the agent.
230
+
231
+ ## OAuth
232
+
233
+ If an external MCP client needs user-scoped OAuth:
234
+
235
+ - pass `userIdentity`
236
+ - let MCP Stack manage the popup flow by default
237
+ - override with `onAuthRequired` only when you need custom host auth UX
238
+
239
+ For embedded apps, prefer `auth.mode = "app-token"` instead of a popup flow.
240
+
241
+ ## Localhost defaults
242
+
243
+ When `serviceUrl` points to localhost, popup helper URLs default to:
244
+
245
+ - `http://localhost:3100/oauth/callback`
246
+ - `http://localhost:3100/.well-known/oauth-client-metadata.json`
247
+
248
+ ## In one sentence
249
+
250
+ Use `react-embed` for the fastest hosted widget, and use `react` or `react-native` when the assistant is part of your product.
251
+
252
+ ## License
253
+
254
+ MIT