@dudko.dev/agent-web-react 0.0.26 → 0.0.28
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 +125 -23
- package/dist/chunk-UUB7CE6N.js +196 -0
- package/dist/chunk-UUB7CE6N.js.map +1 -0
- package/dist/index.cjs +1135 -367
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +426 -22
- package/dist/index.d.ts +426 -22
- package/dist/index.js +1178 -547
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +91 -38
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +72 -13
- package/dist/mcp.d.ts +72 -13
- package/dist/mcp.js +89 -38
- package/dist/mcp.js.map +1 -1
- package/dist/pipeline.cjs +3485 -0
- package/dist/pipeline.cjs.map +1 -0
- package/dist/pipeline.css +1407 -0
- package/dist/pipeline.d.cts +830 -0
- package/dist/pipeline.d.ts +830 -0
- package/dist/pipeline.js +3390 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/styles.css +278 -0
- package/package.json +17 -4
package/dist/mcp.d.cts
CHANGED
|
@@ -23,10 +23,22 @@ interface McpServerResult {
|
|
|
23
23
|
error?: string;
|
|
24
24
|
needsAuthorization?: boolean;
|
|
25
25
|
}
|
|
26
|
+
/** The `instructions` one connected server returned in its `initialize` result. */
|
|
27
|
+
interface McpServerInstructions {
|
|
28
|
+
/** The server's name: its key in the configuration. */
|
|
29
|
+
server: string;
|
|
30
|
+
instructions: string;
|
|
31
|
+
}
|
|
26
32
|
interface ConnectedMcp {
|
|
27
33
|
tools: AgentToolSet;
|
|
28
34
|
catalog: McpCatalogEntry[];
|
|
29
35
|
results: McpServerResult[];
|
|
36
|
+
/**
|
|
37
|
+
* What each connected server told the agent in its handshake (newer cores; absent on older
|
|
38
|
+
* ones). THIRD-PARTY text: the core puts it in the system prompt of an agent that uses the
|
|
39
|
+
* server's tools, so a host should let the user see it.
|
|
40
|
+
*/
|
|
41
|
+
instructions?: McpServerInstructions[];
|
|
30
42
|
refreshServer?: (name: string) => Promise<void>;
|
|
31
43
|
close: () => Promise<void>;
|
|
32
44
|
}
|
|
@@ -40,6 +52,8 @@ interface McpHttpServerConfig {
|
|
|
40
52
|
interface McpOAuthCallback {
|
|
41
53
|
code?: string;
|
|
42
54
|
state?: string;
|
|
55
|
+
/** The `iss` parameter of the response (RFC 9207); the core checks it. */
|
|
56
|
+
iss?: string;
|
|
43
57
|
error?: string;
|
|
44
58
|
errorDescription?: string;
|
|
45
59
|
}
|
|
@@ -54,6 +68,8 @@ interface BrowserOAuthProviderOptions {
|
|
|
54
68
|
redirectUrl: string;
|
|
55
69
|
clientName?: string;
|
|
56
70
|
scope?: string;
|
|
71
|
+
/** Client ID metadata document URL (CIMD). Cores without it ignore the field. */
|
|
72
|
+
clientMetadataUrl?: string;
|
|
57
73
|
}
|
|
58
74
|
/** The shape of the subpath module, as far as this package uses it. */
|
|
59
75
|
interface McpModule {
|
|
@@ -73,6 +89,26 @@ interface McpModule {
|
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
|
|
92
|
+
/** The OAuth details of one server. Everything is optional. */
|
|
93
|
+
interface McpOAuthOptions {
|
|
94
|
+
/** Where the authorization server sends the user back (default: this page, without query or hash). */
|
|
95
|
+
redirectUrl?: string;
|
|
96
|
+
/** Fallback scope when the server's metadata advertises none. */
|
|
97
|
+
scope?: string;
|
|
98
|
+
/** `client_name` for dynamic registration (default: the hook's `clientName`). */
|
|
99
|
+
clientName?: string;
|
|
100
|
+
/**
|
|
101
|
+
* URL of a client ID metadata document (CIMD) your app hosts (default: the
|
|
102
|
+
* hook's `clientMetadataUrl`). An authorization server that advertises
|
|
103
|
+
* `client_id_metadata_document_supported` takes it as the `client_id` and no
|
|
104
|
+
* dynamic registration is made; any other server is registered with as
|
|
105
|
+
* before. Must be https with a non-root path, and the document must list the
|
|
106
|
+
* `redirectUrl` in its `redirect_uris` - the core refuses anything else and
|
|
107
|
+
* the server ends in `status: 'error'`. A core that does not know the option
|
|
108
|
+
* ignores it and registers dynamically.
|
|
109
|
+
*/
|
|
110
|
+
clientMetadataUrl?: string;
|
|
111
|
+
}
|
|
76
112
|
interface McpConnectOptions {
|
|
77
113
|
/** The server's StreamableHTTP endpoint. */
|
|
78
114
|
url: string;
|
|
@@ -84,15 +120,17 @@ interface McpConnectOptions {
|
|
|
84
120
|
* Authenticate with OAuth 2.1 + dynamic client registration. Requires a core
|
|
85
121
|
* that ships the OAuth provider; check `oauthSupported` before offering it.
|
|
86
122
|
*/
|
|
87
|
-
oauth?: boolean |
|
|
88
|
-
redirectUrl?: string;
|
|
89
|
-
scope?: string;
|
|
90
|
-
clientName?: string;
|
|
91
|
-
};
|
|
123
|
+
oauth?: boolean | McpOAuthOptions;
|
|
92
124
|
}
|
|
93
125
|
interface UseMcpOptions {
|
|
94
126
|
/** Client name reported to the MCP server during initialize. */
|
|
95
127
|
clientName?: string;
|
|
128
|
+
/**
|
|
129
|
+
* URL of the client ID metadata document (CIMD) this app hosts, used for
|
|
130
|
+
* every OAuth server unless its own `oauth.clientMetadataUrl` says otherwise.
|
|
131
|
+
* See `McpOAuthOptions.clientMetadataUrl`.
|
|
132
|
+
*/
|
|
133
|
+
clientMetadataUrl?: string;
|
|
96
134
|
/** Called with connector log lines — handy while debugging a server. */
|
|
97
135
|
onLog?: (level: string, message: string) => void;
|
|
98
136
|
}
|
|
@@ -101,6 +139,12 @@ interface UseMcpReturn {
|
|
|
101
139
|
/** Merge into `BrowserAgentConfig.tools` once `status === 'connected'`. */
|
|
102
140
|
tools?: AgentToolSet;
|
|
103
141
|
catalog: McpCatalogEntry[];
|
|
142
|
+
/**
|
|
143
|
+
* What the connected server told the agent in its handshake (its MCP `instructions`), when it
|
|
144
|
+
* sent any. Third-party text that the core puts in the agent's system prompt: show it to the
|
|
145
|
+
* user as the server's words, never as your own.
|
|
146
|
+
*/
|
|
147
|
+
instructions?: string;
|
|
104
148
|
error?: string;
|
|
105
149
|
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
106
150
|
authorizationUrl?: string;
|
|
@@ -121,6 +165,11 @@ interface UseMcpReturn {
|
|
|
121
165
|
/** Load the optional subpath and report whether it can do OAuth. */
|
|
122
166
|
checkOAuthSupport: () => Promise<boolean>;
|
|
123
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* The instructions the server `name` sent, or undefined when it sent none (or the core is too
|
|
170
|
+
* old to report them). The text is the server's, not the host's: show it as such.
|
|
171
|
+
*/
|
|
172
|
+
declare const mcpInstructionsOf: (connection: Pick<ConnectedMcp, "instructions">, name: string) => string | undefined;
|
|
124
173
|
/** Map a single server's connect outcome onto the hook's status. Pure. */
|
|
125
174
|
declare const describeMcpResult: (result: McpServerResult | undefined) => {
|
|
126
175
|
status: McpStatus;
|
|
@@ -146,6 +195,14 @@ declare const readCallbackParams: (href?: string) => McpOAuthCallback | undefine
|
|
|
146
195
|
*/
|
|
147
196
|
declare const stripOAuthParams: (href: string) => string;
|
|
148
197
|
declare const claimOAuthCallback: (callback: McpOAuthCallback) => boolean;
|
|
198
|
+
/**
|
|
199
|
+
* The options of the core's OAuth provider for one server: the server's own
|
|
200
|
+
* `oauth` details first, then the hook-level defaults (`clientName`,
|
|
201
|
+
* `clientMetadataUrl`), then this page as the redirect. Pure - both hooks build
|
|
202
|
+
* every provider through it, on connect, on the way back from the redirect and
|
|
203
|
+
* when forgetting, so the three always describe the same client.
|
|
204
|
+
*/
|
|
205
|
+
declare const mcpOAuthProviderOptions: (serverUrl: string, oauth?: McpOAuthOptions, defaults?: Pick<McpOAuthOptions, "clientName" | "clientMetadataUrl">) => BrowserOAuthProviderOptions;
|
|
149
206
|
/**
|
|
150
207
|
* Did this error come from the server refusing our authorization?
|
|
151
208
|
*
|
|
@@ -187,12 +244,8 @@ interface McpServerSpec {
|
|
|
187
244
|
auth?: McpAuthMode;
|
|
188
245
|
/** Bearer token for `auth: 'bearer'` — kept in memory only, never persisted. */
|
|
189
246
|
token?: string;
|
|
190
|
-
/** OAuth details for `auth: 'oauth'
|
|
191
|
-
oauth?:
|
|
192
|
-
redirectUrl?: string;
|
|
193
|
-
scope?: string;
|
|
194
|
-
clientName?: string;
|
|
195
|
-
};
|
|
247
|
+
/** OAuth details for `auth: 'oauth'` (`clientMetadataUrl` for CIMD among them). */
|
|
248
|
+
oauth?: McpOAuthOptions;
|
|
196
249
|
}
|
|
197
250
|
/** A server's live state. */
|
|
198
251
|
interface McpServerView {
|
|
@@ -204,6 +257,12 @@ interface McpServerView {
|
|
|
204
257
|
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
205
258
|
authorizationUrl?: string;
|
|
206
259
|
catalog: McpCatalogEntry[];
|
|
260
|
+
/**
|
|
261
|
+
* What the server told the agent in its handshake (its MCP `instructions`), while it is
|
|
262
|
+
* connected and if it sent any. Third-party text that the core puts in the agent's system
|
|
263
|
+
* prompt: show it to the user as the server's words.
|
|
264
|
+
*/
|
|
265
|
+
instructions?: string;
|
|
207
266
|
}
|
|
208
267
|
interface UseMcpServersOptions extends UseMcpOptions {
|
|
209
268
|
/**
|
|
@@ -261,5 +320,5 @@ interface UseMcpServersReturn {
|
|
|
261
320
|
*/
|
|
262
321
|
declare const useMcpServers: (options?: UseMcpServersOptions) => UseMcpServersReturn;
|
|
263
322
|
|
|
264
|
-
export { claimOAuthCallback, describeMcpResult, isUnauthorizedError, readCallbackParams, stripOAuthParams, useMcp, useMcpServers };
|
|
265
|
-
export type { ConnectedMcp, McpAuthMode, McpCatalogEntry, McpConnectOptions, McpModule, McpOAuthCallback, McpServerResult, McpServerSpec, McpServerView, McpStatus, UseMcpOptions, UseMcpReturn, UseMcpServersOptions, UseMcpServersReturn };
|
|
323
|
+
export { claimOAuthCallback, describeMcpResult, isUnauthorizedError, mcpInstructionsOf, mcpOAuthProviderOptions, readCallbackParams, stripOAuthParams, useMcp, useMcpServers };
|
|
324
|
+
export type { BrowserOAuthProviderOptions, ConnectedMcp, McpAuthMode, McpCatalogEntry, McpConnectOptions, McpModule, McpOAuthCallback, McpOAuthOptions, McpServerInstructions, McpServerResult, McpServerSpec, McpServerView, McpStatus, UseMcpOptions, UseMcpReturn, UseMcpServersOptions, UseMcpServersReturn };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -23,10 +23,22 @@ interface McpServerResult {
|
|
|
23
23
|
error?: string;
|
|
24
24
|
needsAuthorization?: boolean;
|
|
25
25
|
}
|
|
26
|
+
/** The `instructions` one connected server returned in its `initialize` result. */
|
|
27
|
+
interface McpServerInstructions {
|
|
28
|
+
/** The server's name: its key in the configuration. */
|
|
29
|
+
server: string;
|
|
30
|
+
instructions: string;
|
|
31
|
+
}
|
|
26
32
|
interface ConnectedMcp {
|
|
27
33
|
tools: AgentToolSet;
|
|
28
34
|
catalog: McpCatalogEntry[];
|
|
29
35
|
results: McpServerResult[];
|
|
36
|
+
/**
|
|
37
|
+
* What each connected server told the agent in its handshake (newer cores; absent on older
|
|
38
|
+
* ones). THIRD-PARTY text: the core puts it in the system prompt of an agent that uses the
|
|
39
|
+
* server's tools, so a host should let the user see it.
|
|
40
|
+
*/
|
|
41
|
+
instructions?: McpServerInstructions[];
|
|
30
42
|
refreshServer?: (name: string) => Promise<void>;
|
|
31
43
|
close: () => Promise<void>;
|
|
32
44
|
}
|
|
@@ -40,6 +52,8 @@ interface McpHttpServerConfig {
|
|
|
40
52
|
interface McpOAuthCallback {
|
|
41
53
|
code?: string;
|
|
42
54
|
state?: string;
|
|
55
|
+
/** The `iss` parameter of the response (RFC 9207); the core checks it. */
|
|
56
|
+
iss?: string;
|
|
43
57
|
error?: string;
|
|
44
58
|
errorDescription?: string;
|
|
45
59
|
}
|
|
@@ -54,6 +68,8 @@ interface BrowserOAuthProviderOptions {
|
|
|
54
68
|
redirectUrl: string;
|
|
55
69
|
clientName?: string;
|
|
56
70
|
scope?: string;
|
|
71
|
+
/** Client ID metadata document URL (CIMD). Cores without it ignore the field. */
|
|
72
|
+
clientMetadataUrl?: string;
|
|
57
73
|
}
|
|
58
74
|
/** The shape of the subpath module, as far as this package uses it. */
|
|
59
75
|
interface McpModule {
|
|
@@ -73,6 +89,26 @@ interface McpModule {
|
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
|
|
92
|
+
/** The OAuth details of one server. Everything is optional. */
|
|
93
|
+
interface McpOAuthOptions {
|
|
94
|
+
/** Where the authorization server sends the user back (default: this page, without query or hash). */
|
|
95
|
+
redirectUrl?: string;
|
|
96
|
+
/** Fallback scope when the server's metadata advertises none. */
|
|
97
|
+
scope?: string;
|
|
98
|
+
/** `client_name` for dynamic registration (default: the hook's `clientName`). */
|
|
99
|
+
clientName?: string;
|
|
100
|
+
/**
|
|
101
|
+
* URL of a client ID metadata document (CIMD) your app hosts (default: the
|
|
102
|
+
* hook's `clientMetadataUrl`). An authorization server that advertises
|
|
103
|
+
* `client_id_metadata_document_supported` takes it as the `client_id` and no
|
|
104
|
+
* dynamic registration is made; any other server is registered with as
|
|
105
|
+
* before. Must be https with a non-root path, and the document must list the
|
|
106
|
+
* `redirectUrl` in its `redirect_uris` - the core refuses anything else and
|
|
107
|
+
* the server ends in `status: 'error'`. A core that does not know the option
|
|
108
|
+
* ignores it and registers dynamically.
|
|
109
|
+
*/
|
|
110
|
+
clientMetadataUrl?: string;
|
|
111
|
+
}
|
|
76
112
|
interface McpConnectOptions {
|
|
77
113
|
/** The server's StreamableHTTP endpoint. */
|
|
78
114
|
url: string;
|
|
@@ -84,15 +120,17 @@ interface McpConnectOptions {
|
|
|
84
120
|
* Authenticate with OAuth 2.1 + dynamic client registration. Requires a core
|
|
85
121
|
* that ships the OAuth provider; check `oauthSupported` before offering it.
|
|
86
122
|
*/
|
|
87
|
-
oauth?: boolean |
|
|
88
|
-
redirectUrl?: string;
|
|
89
|
-
scope?: string;
|
|
90
|
-
clientName?: string;
|
|
91
|
-
};
|
|
123
|
+
oauth?: boolean | McpOAuthOptions;
|
|
92
124
|
}
|
|
93
125
|
interface UseMcpOptions {
|
|
94
126
|
/** Client name reported to the MCP server during initialize. */
|
|
95
127
|
clientName?: string;
|
|
128
|
+
/**
|
|
129
|
+
* URL of the client ID metadata document (CIMD) this app hosts, used for
|
|
130
|
+
* every OAuth server unless its own `oauth.clientMetadataUrl` says otherwise.
|
|
131
|
+
* See `McpOAuthOptions.clientMetadataUrl`.
|
|
132
|
+
*/
|
|
133
|
+
clientMetadataUrl?: string;
|
|
96
134
|
/** Called with connector log lines — handy while debugging a server. */
|
|
97
135
|
onLog?: (level: string, message: string) => void;
|
|
98
136
|
}
|
|
@@ -101,6 +139,12 @@ interface UseMcpReturn {
|
|
|
101
139
|
/** Merge into `BrowserAgentConfig.tools` once `status === 'connected'`. */
|
|
102
140
|
tools?: AgentToolSet;
|
|
103
141
|
catalog: McpCatalogEntry[];
|
|
142
|
+
/**
|
|
143
|
+
* What the connected server told the agent in its handshake (its MCP `instructions`), when it
|
|
144
|
+
* sent any. Third-party text that the core puts in the agent's system prompt: show it to the
|
|
145
|
+
* user as the server's words, never as your own.
|
|
146
|
+
*/
|
|
147
|
+
instructions?: string;
|
|
104
148
|
error?: string;
|
|
105
149
|
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
106
150
|
authorizationUrl?: string;
|
|
@@ -121,6 +165,11 @@ interface UseMcpReturn {
|
|
|
121
165
|
/** Load the optional subpath and report whether it can do OAuth. */
|
|
122
166
|
checkOAuthSupport: () => Promise<boolean>;
|
|
123
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* The instructions the server `name` sent, or undefined when it sent none (or the core is too
|
|
170
|
+
* old to report them). The text is the server's, not the host's: show it as such.
|
|
171
|
+
*/
|
|
172
|
+
declare const mcpInstructionsOf: (connection: Pick<ConnectedMcp, "instructions">, name: string) => string | undefined;
|
|
124
173
|
/** Map a single server's connect outcome onto the hook's status. Pure. */
|
|
125
174
|
declare const describeMcpResult: (result: McpServerResult | undefined) => {
|
|
126
175
|
status: McpStatus;
|
|
@@ -146,6 +195,14 @@ declare const readCallbackParams: (href?: string) => McpOAuthCallback | undefine
|
|
|
146
195
|
*/
|
|
147
196
|
declare const stripOAuthParams: (href: string) => string;
|
|
148
197
|
declare const claimOAuthCallback: (callback: McpOAuthCallback) => boolean;
|
|
198
|
+
/**
|
|
199
|
+
* The options of the core's OAuth provider for one server: the server's own
|
|
200
|
+
* `oauth` details first, then the hook-level defaults (`clientName`,
|
|
201
|
+
* `clientMetadataUrl`), then this page as the redirect. Pure - both hooks build
|
|
202
|
+
* every provider through it, on connect, on the way back from the redirect and
|
|
203
|
+
* when forgetting, so the three always describe the same client.
|
|
204
|
+
*/
|
|
205
|
+
declare const mcpOAuthProviderOptions: (serverUrl: string, oauth?: McpOAuthOptions, defaults?: Pick<McpOAuthOptions, "clientName" | "clientMetadataUrl">) => BrowserOAuthProviderOptions;
|
|
149
206
|
/**
|
|
150
207
|
* Did this error come from the server refusing our authorization?
|
|
151
208
|
*
|
|
@@ -187,12 +244,8 @@ interface McpServerSpec {
|
|
|
187
244
|
auth?: McpAuthMode;
|
|
188
245
|
/** Bearer token for `auth: 'bearer'` — kept in memory only, never persisted. */
|
|
189
246
|
token?: string;
|
|
190
|
-
/** OAuth details for `auth: 'oauth'
|
|
191
|
-
oauth?:
|
|
192
|
-
redirectUrl?: string;
|
|
193
|
-
scope?: string;
|
|
194
|
-
clientName?: string;
|
|
195
|
-
};
|
|
247
|
+
/** OAuth details for `auth: 'oauth'` (`clientMetadataUrl` for CIMD among them). */
|
|
248
|
+
oauth?: McpOAuthOptions;
|
|
196
249
|
}
|
|
197
250
|
/** A server's live state. */
|
|
198
251
|
interface McpServerView {
|
|
@@ -204,6 +257,12 @@ interface McpServerView {
|
|
|
204
257
|
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
205
258
|
authorizationUrl?: string;
|
|
206
259
|
catalog: McpCatalogEntry[];
|
|
260
|
+
/**
|
|
261
|
+
* What the server told the agent in its handshake (its MCP `instructions`), while it is
|
|
262
|
+
* connected and if it sent any. Third-party text that the core puts in the agent's system
|
|
263
|
+
* prompt: show it to the user as the server's words.
|
|
264
|
+
*/
|
|
265
|
+
instructions?: string;
|
|
207
266
|
}
|
|
208
267
|
interface UseMcpServersOptions extends UseMcpOptions {
|
|
209
268
|
/**
|
|
@@ -261,5 +320,5 @@ interface UseMcpServersReturn {
|
|
|
261
320
|
*/
|
|
262
321
|
declare const useMcpServers: (options?: UseMcpServersOptions) => UseMcpServersReturn;
|
|
263
322
|
|
|
264
|
-
export { claimOAuthCallback, describeMcpResult, isUnauthorizedError, readCallbackParams, stripOAuthParams, useMcp, useMcpServers };
|
|
265
|
-
export type { ConnectedMcp, McpAuthMode, McpCatalogEntry, McpConnectOptions, McpModule, McpOAuthCallback, McpServerResult, McpServerSpec, McpServerView, McpStatus, UseMcpOptions, UseMcpReturn, UseMcpServersOptions, UseMcpServersReturn };
|
|
323
|
+
export { claimOAuthCallback, describeMcpResult, isUnauthorizedError, mcpInstructionsOf, mcpOAuthProviderOptions, readCallbackParams, stripOAuthParams, useMcp, useMcpServers };
|
|
324
|
+
export type { BrowserOAuthProviderOptions, ConnectedMcp, McpAuthMode, McpCatalogEntry, McpConnectOptions, McpModule, McpOAuthCallback, McpOAuthOptions, McpServerInstructions, McpServerResult, McpServerSpec, McpServerView, McpStatus, UseMcpOptions, UseMcpReturn, UseMcpServersOptions, UseMcpServersReturn };
|
package/dist/mcp.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// src/hooks/use-mcp.ts
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
var mcpInstructionsOf = (connection, name) => {
|
|
4
|
+
const list = Array.isArray(connection.instructions) ? connection.instructions : [];
|
|
5
|
+
const text = list.find((i) => i?.server === name)?.instructions;
|
|
6
|
+
return typeof text === "string" && text.trim() ? text : void 0;
|
|
7
|
+
};
|
|
3
8
|
var OAUTH_UNSUPPORTED = "The installed @dudko.dev/agent-web has no MCP OAuth support. Upgrade the core to a version exporting BrowserOAuthProvider, or use a static Authorization header.";
|
|
4
9
|
var PENDING_KEY = "agent-web-react:mcp:pending";
|
|
5
10
|
var OAUTH_KEY = "agent-web-react:mcp:oauth";
|
|
@@ -42,6 +47,9 @@ var readCallbackParams = (href) => {
|
|
|
42
47
|
return {
|
|
43
48
|
code,
|
|
44
49
|
state: params.get("state") ?? void 0,
|
|
50
|
+
// RFC 9207: the core's `finishMcpOAuth` checks it against the authorization
|
|
51
|
+
// server the flow was started with, before the code is exchanged.
|
|
52
|
+
iss: params.get("iss") ?? void 0,
|
|
45
53
|
error,
|
|
46
54
|
errorDescription: params.get("error_description") ?? void 0
|
|
47
55
|
};
|
|
@@ -82,6 +90,17 @@ var writeRecord = (key, value) => {
|
|
|
82
90
|
}
|
|
83
91
|
};
|
|
84
92
|
var defaultRedirectUrl = () => typeof globalThis.location === "undefined" ? "" : `${globalThis.location.origin}${globalThis.location.pathname}`;
|
|
93
|
+
var mcpOAuthProviderOptions = (serverUrl, oauth = {}, defaults = {}) => {
|
|
94
|
+
const clientMetadataUrl = oauth.clientMetadataUrl ?? defaults.clientMetadataUrl;
|
|
95
|
+
return {
|
|
96
|
+
serverUrl,
|
|
97
|
+
redirectUrl: oauth.redirectUrl ?? defaultRedirectUrl(),
|
|
98
|
+
clientName: oauth.clientName ?? defaults.clientName,
|
|
99
|
+
scope: oauth.scope,
|
|
100
|
+
// Left out when unset: a provider built without it keeps registering dynamically.
|
|
101
|
+
...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
85
104
|
var isUnauthorizedError = (err, mod) => {
|
|
86
105
|
if (!(err instanceof Error)) return false;
|
|
87
106
|
if (mod?.UnauthorizedError && err instanceof mod.UnauthorizedError) return true;
|
|
@@ -115,6 +134,7 @@ var useMcp = (options = {}) => {
|
|
|
115
134
|
const [status, setStatus] = useState("idle");
|
|
116
135
|
const [tools, setTools] = useState(void 0);
|
|
117
136
|
const [catalog, setCatalog] = useState([]);
|
|
137
|
+
const [instructions, setInstructions] = useState(void 0);
|
|
118
138
|
const [error, setError] = useState(void 0);
|
|
119
139
|
const [authorizationUrl, setAuthorizationUrl] = useState(void 0);
|
|
120
140
|
const [oauthSupported, setOauthSupported] = useState(void 0);
|
|
@@ -154,6 +174,7 @@ var useMcp = (options = {}) => {
|
|
|
154
174
|
setAuthorizationUrl(void 0);
|
|
155
175
|
setTools(void 0);
|
|
156
176
|
setCatalog([]);
|
|
177
|
+
setInstructions(void 0);
|
|
157
178
|
try {
|
|
158
179
|
const mod = await loadMcp();
|
|
159
180
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
@@ -161,21 +182,21 @@ var useMcp = (options = {}) => {
|
|
|
161
182
|
let authProvider;
|
|
162
183
|
if (opts.oauth) {
|
|
163
184
|
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
164
|
-
const
|
|
185
|
+
const providerOptions = mcpOAuthProviderOptions(
|
|
186
|
+
opts.url,
|
|
187
|
+
typeof opts.oauth === "object" ? opts.oauth : {},
|
|
188
|
+
optionsRef.current
|
|
189
|
+
);
|
|
165
190
|
const record = {
|
|
166
191
|
url: opts.url,
|
|
167
192
|
name,
|
|
168
|
-
redirectUrl:
|
|
169
|
-
scope:
|
|
170
|
-
clientName:
|
|
193
|
+
redirectUrl: providerOptions.redirectUrl,
|
|
194
|
+
scope: providerOptions.scope,
|
|
195
|
+
clientName: providerOptions.clientName,
|
|
196
|
+
clientMetadataUrl: providerOptions.clientMetadataUrl,
|
|
171
197
|
startedAt: Date.now()
|
|
172
198
|
};
|
|
173
|
-
authProvider = new mod.BrowserOAuthProvider(
|
|
174
|
-
serverUrl: record.url,
|
|
175
|
-
redirectUrl: record.redirectUrl,
|
|
176
|
-
clientName: record.clientName,
|
|
177
|
-
scope: record.scope
|
|
178
|
-
});
|
|
199
|
+
authProvider = new mod.BrowserOAuthProvider(providerOptions);
|
|
179
200
|
providerRef.current = authProvider;
|
|
180
201
|
writeRecord(PENDING_KEY, record);
|
|
181
202
|
writeRecord(OAUTH_KEY, record);
|
|
@@ -220,6 +241,7 @@ var useMcp = (options = {}) => {
|
|
|
220
241
|
})
|
|
221
242
|
);
|
|
222
243
|
setCatalog(connection.catalog);
|
|
244
|
+
setInstructions(mcpInstructionsOf(connection, name));
|
|
223
245
|
setStatus("connected");
|
|
224
246
|
} catch (err) {
|
|
225
247
|
if (!current()) return;
|
|
@@ -234,6 +256,7 @@ var useMcp = (options = {}) => {
|
|
|
234
256
|
await closeConnection();
|
|
235
257
|
setTools(void 0);
|
|
236
258
|
setCatalog([]);
|
|
259
|
+
setInstructions(void 0);
|
|
237
260
|
setAuthorizationUrl(void 0);
|
|
238
261
|
setError(void 0);
|
|
239
262
|
setStatus("idle");
|
|
@@ -251,12 +274,10 @@ var useMcp = (options = {}) => {
|
|
|
251
274
|
if (!provider && record) {
|
|
252
275
|
const mod = await loadMcp().catch(() => void 0);
|
|
253
276
|
if (mod?.BrowserOAuthProvider) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
scope: record.scope
|
|
259
|
-
});
|
|
277
|
+
try {
|
|
278
|
+
provider = new mod.BrowserOAuthProvider(mcpOAuthProviderOptions(record.url, record));
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
260
281
|
}
|
|
261
282
|
}
|
|
262
283
|
await provider?.reset().catch(() => {
|
|
@@ -289,17 +310,21 @@ var useMcp = (options = {}) => {
|
|
|
289
310
|
const mod = await loadMcp();
|
|
290
311
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
291
312
|
if (!mod.BrowserOAuthProvider || !mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
|
|
292
|
-
const provider = new mod.BrowserOAuthProvider(
|
|
293
|
-
serverUrl: pending.url,
|
|
294
|
-
redirectUrl: pending.redirectUrl ?? defaultRedirectUrl(),
|
|
295
|
-
clientName: pending.clientName,
|
|
296
|
-
scope: pending.scope
|
|
297
|
-
});
|
|
313
|
+
const provider = new mod.BrowserOAuthProvider(mcpOAuthProviderOptions(pending.url, pending));
|
|
298
314
|
providerRef.current = provider;
|
|
299
315
|
await mod.finishMcpOAuth(provider, callback);
|
|
300
316
|
writeRecord(PENDING_KEY, void 0);
|
|
301
317
|
setCompletingAuthorization(false);
|
|
302
|
-
await connect({
|
|
318
|
+
await connect({
|
|
319
|
+
url: pending.url,
|
|
320
|
+
name: pending.name,
|
|
321
|
+
oauth: {
|
|
322
|
+
redirectUrl: pending.redirectUrl,
|
|
323
|
+
scope: pending.scope,
|
|
324
|
+
clientName: pending.clientName,
|
|
325
|
+
clientMetadataUrl: pending.clientMetadataUrl
|
|
326
|
+
}
|
|
327
|
+
});
|
|
303
328
|
} catch (err) {
|
|
304
329
|
writeRecord(PENDING_KEY, void 0);
|
|
305
330
|
setError(err instanceof Error ? err.message : String(err));
|
|
@@ -320,6 +345,7 @@ var useMcp = (options = {}) => {
|
|
|
320
345
|
status,
|
|
321
346
|
tools,
|
|
322
347
|
catalog,
|
|
348
|
+
instructions,
|
|
323
349
|
error,
|
|
324
350
|
authorizationUrl,
|
|
325
351
|
oauthSupported,
|
|
@@ -348,9 +374,10 @@ var useMcpServers = (options = {}) => {
|
|
|
348
374
|
const storageKey = options.storageKey ?? DEFAULT_KEY;
|
|
349
375
|
const pendingKey = `${storageKey}:pending`;
|
|
350
376
|
const persist = options.persist !== false;
|
|
351
|
-
const [
|
|
352
|
-
() => persist ?
|
|
377
|
+
const [stored] = useState2(
|
|
378
|
+
() => persist ? readRecord(storageKey) ?? [] : []
|
|
353
379
|
);
|
|
380
|
+
const [servers, setServers] = useState2(() => stored.map((s) => view(s)));
|
|
354
381
|
const [oauthSupported, setOauthSupported] = useState2(void 0);
|
|
355
382
|
const [completingAuthorization, setCompleting] = useState2(
|
|
356
383
|
() => readCallbackParams() !== void 0 && readRecord(pendingKey) !== void 0
|
|
@@ -359,8 +386,15 @@ var useMcpServers = (options = {}) => {
|
|
|
359
386
|
const liveRef = useRef2(/* @__PURE__ */ new Map());
|
|
360
387
|
const specsRef = useRef2(/* @__PURE__ */ new Map());
|
|
361
388
|
if (specsRef.current.size === 0 && servers.length > 0) {
|
|
362
|
-
for (const s of servers)
|
|
363
|
-
|
|
389
|
+
for (const s of servers) {
|
|
390
|
+
const oauth = stored.find((x) => x.name === s.name && x.url === s.url)?.oauth;
|
|
391
|
+
specsRef.current.set(s.name, {
|
|
392
|
+
name: s.name,
|
|
393
|
+
url: s.url,
|
|
394
|
+
auth: s.auth,
|
|
395
|
+
...oauth && typeof oauth === "object" ? { oauth } : {}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
364
398
|
}
|
|
365
399
|
const optionsRef = useRef2(options);
|
|
366
400
|
optionsRef.current = options;
|
|
@@ -396,12 +430,9 @@ var useMcpServers = (options = {}) => {
|
|
|
396
430
|
}, []);
|
|
397
431
|
const providerFor = (mod, spec) => {
|
|
398
432
|
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
399
|
-
return new mod.BrowserOAuthProvider(
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
403
|
-
scope: spec.oauth?.scope
|
|
404
|
-
});
|
|
433
|
+
return new mod.BrowserOAuthProvider(
|
|
434
|
+
mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)
|
|
435
|
+
);
|
|
405
436
|
};
|
|
406
437
|
const connectServer = useCallback2(
|
|
407
438
|
async (name) => {
|
|
@@ -419,7 +450,8 @@ var useMcpServers = (options = {}) => {
|
|
|
419
450
|
status: "connecting",
|
|
420
451
|
error: void 0,
|
|
421
452
|
authorizationUrl: void 0,
|
|
422
|
-
catalog: []
|
|
453
|
+
catalog: [],
|
|
454
|
+
instructions: void 0
|
|
423
455
|
});
|
|
424
456
|
try {
|
|
425
457
|
const mod = await loadMcp();
|
|
@@ -473,7 +505,11 @@ var useMcpServers = (options = {}) => {
|
|
|
473
505
|
});
|
|
474
506
|
});
|
|
475
507
|
setToolsVersion((v) => v + 1);
|
|
476
|
-
patch(name, {
|
|
508
|
+
patch(name, {
|
|
509
|
+
status: "connected",
|
|
510
|
+
catalog: connection.catalog,
|
|
511
|
+
instructions: mcpInstructionsOf(connection, name)
|
|
512
|
+
});
|
|
477
513
|
} catch (err) {
|
|
478
514
|
if (!current()) return;
|
|
479
515
|
patch(name, { status: "error", error: err instanceof Error ? err.message : String(err) });
|
|
@@ -536,6 +572,7 @@ var useMcpServers = (options = {}) => {
|
|
|
536
572
|
redirectUrl: spec.oauth?.redirectUrl ?? defaultRedirectUrl(),
|
|
537
573
|
scope: spec.oauth?.scope,
|
|
538
574
|
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
575
|
+
clientMetadataUrl: spec.oauth?.clientMetadataUrl ?? optionsRef.current.clientMetadataUrl,
|
|
539
576
|
startedAt: Date.now()
|
|
540
577
|
};
|
|
541
578
|
writeRecord(pendingKey, pending);
|
|
@@ -550,7 +587,12 @@ var useMcpServers = (options = {}) => {
|
|
|
550
587
|
let provider = l?.provider;
|
|
551
588
|
if (!provider && spec?.auth === "oauth") {
|
|
552
589
|
const mod = await loadMcp().catch(() => void 0);
|
|
553
|
-
if (mod?.BrowserOAuthProvider)
|
|
590
|
+
if (mod?.BrowserOAuthProvider) {
|
|
591
|
+
try {
|
|
592
|
+
provider = providerFor(mod, spec);
|
|
593
|
+
} catch {
|
|
594
|
+
}
|
|
595
|
+
}
|
|
554
596
|
}
|
|
555
597
|
await provider?.reset().catch(() => {
|
|
556
598
|
});
|
|
@@ -558,7 +600,13 @@ var useMcpServers = (options = {}) => {
|
|
|
558
600
|
const pending = readRecord(pendingKey);
|
|
559
601
|
if (pending?.name === name) writeRecord(pendingKey, void 0);
|
|
560
602
|
await closeServer(name);
|
|
561
|
-
patch(name, {
|
|
603
|
+
patch(name, {
|
|
604
|
+
status: "idle",
|
|
605
|
+
authorizationUrl: void 0,
|
|
606
|
+
catalog: [],
|
|
607
|
+
instructions: void 0,
|
|
608
|
+
error: void 0
|
|
609
|
+
});
|
|
562
610
|
},
|
|
563
611
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
564
612
|
[closeServer, patch, pendingKey]
|
|
@@ -606,7 +654,8 @@ var useMcpServers = (options = {}) => {
|
|
|
606
654
|
oauth: {
|
|
607
655
|
redirectUrl: pending.redirectUrl,
|
|
608
656
|
scope: pending.scope,
|
|
609
|
-
clientName: pending.clientName
|
|
657
|
+
clientName: pending.clientName,
|
|
658
|
+
clientMetadataUrl: pending.clientMetadataUrl
|
|
610
659
|
}
|
|
611
660
|
});
|
|
612
661
|
live(spec.name).provider = provider;
|
|
@@ -660,6 +709,8 @@ export {
|
|
|
660
709
|
claimOAuthCallback,
|
|
661
710
|
describeMcpResult,
|
|
662
711
|
isUnauthorizedError,
|
|
712
|
+
mcpInstructionsOf,
|
|
713
|
+
mcpOAuthProviderOptions,
|
|
663
714
|
readCallbackParams,
|
|
664
715
|
stripOAuthParams,
|
|
665
716
|
useMcp,
|