modality-ai 0.8.0 → 0.8.2
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { setupStdioToHttpTools, createStdioClient, } from "./setupStdioToHttpToo
|
|
|
4
4
|
export type { ModalityClientInstance } from "./ModalityClient";
|
|
5
5
|
export type { ModelMessage } from "ai";
|
|
6
6
|
export type { StdioClientOptions } from "./setupStdioToHttpTools";
|
|
7
|
-
export { CLIBrowserOAuthProvider } from "./mcp-oauth-provider";
|
|
7
|
+
export { CLIBrowserOAuthProvider, createHostedOAuth } from "./mcp-oauth-provider";
|
|
8
|
+
export type { HostedOAuth, HostedOAuthOptions, HostedOAuthResult, OAuthCallbackInput } from "./mcp-oauth-provider";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OAuthClientProvider, type OAuthDiscoveryState, type AddClientAuthentication } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
2
|
import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
3
3
|
interface CLIBrowserOAuthProviderOptions {
|
|
4
4
|
/** Display name registered with the OAuth server. Default: "mcp-cli" */
|
|
@@ -87,6 +87,7 @@ export declare class CLIBrowserOAuthProvider implements OAuthClientProvider {
|
|
|
87
87
|
private _resolveCode?;
|
|
88
88
|
private _rejectCode?;
|
|
89
89
|
private _pendingCode;
|
|
90
|
+
private _codeSettled;
|
|
90
91
|
private _codeVerifier?;
|
|
91
92
|
private _clientInfo?;
|
|
92
93
|
private _tokens?;
|
|
@@ -148,4 +149,79 @@ export declare class CLIBrowserOAuthProvider implements OAuthClientProvider {
|
|
|
148
149
|
private _persistCache;
|
|
149
150
|
private _handleCallback;
|
|
150
151
|
}
|
|
152
|
+
/** Options for {@link createHostedOAuth}. */
|
|
153
|
+
export interface HostedOAuthOptions {
|
|
154
|
+
/**
|
|
155
|
+
* Path the host server exposes for the OAuth redirect, e.g. "/oauth/callback".
|
|
156
|
+
* Wire your route to forward requests to the returned `handleCallback`.
|
|
157
|
+
*/
|
|
158
|
+
callbackPath: string;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the port the host server is bound to. Called per flow, so it can
|
|
161
|
+
* reflect the live runtime port (e.g. parsed from a getHonoUrl() helper)
|
|
162
|
+
* instead of a hardcoded guess.
|
|
163
|
+
*/
|
|
164
|
+
getPort: () => number | Promise<number>;
|
|
165
|
+
/** Host used in the redirect_uri. Default "127.0.0.1". */
|
|
166
|
+
host?: string;
|
|
167
|
+
/** OAuth client display name registered with the server. Default "mcp-cli". */
|
|
168
|
+
clientName?: string;
|
|
169
|
+
}
|
|
170
|
+
/** Outcome of a hosted OAuth flow. */
|
|
171
|
+
export interface HostedOAuthResult {
|
|
172
|
+
status: "authorized" | "already_authorized";
|
|
173
|
+
message: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Input accepted by {@link HostedOAuth.handleCallback}: either a raw web
|
|
177
|
+
* `Request` (e.g. from `Bun.serve`) or any object exposing one at `req.raw`,
|
|
178
|
+
* which a Hono `Context` satisfies structurally. This lets the handler be
|
|
179
|
+
* passed directly to `app.get(path, oauth.handleCallback)` with no wrapper,
|
|
180
|
+
* while staying framework-agnostic (no `hono` dependency).
|
|
181
|
+
*/
|
|
182
|
+
export type OAuthCallbackInput = Request | {
|
|
183
|
+
req: {
|
|
184
|
+
raw: Request;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
/** The two functions a host server wires in to enable hosted OAuth. */
|
|
188
|
+
export interface HostedOAuth {
|
|
189
|
+
/**
|
|
190
|
+
* Handle a browser redirect forwarded from the host's callback route.
|
|
191
|
+
* Correlates the request to the awaiting provider by its `state`, resolves
|
|
192
|
+
* that flow, and returns the page to render in the tab. Returns a 400 when no
|
|
193
|
+
* matching flow is pending (unknown/expired state).
|
|
194
|
+
*
|
|
195
|
+
* Accepts a raw `Request` or a Hono `Context` — pass it straight to a route:
|
|
196
|
+
* app.get("/oauth/callback", oauth.handleCallback) // Hono
|
|
197
|
+
* Bun.serve({ fetch: oauth.handleCallback }) // raw Request
|
|
198
|
+
*/
|
|
199
|
+
handleCallback(input: OAuthCallbackInput): Response;
|
|
200
|
+
/**
|
|
201
|
+
* Run — or short-circuit if already authorized — the OAuth flow for an MCP
|
|
202
|
+
* server URL. Shape-compatible with modality-mcp-kit's OAuthAllowAccessFn, so
|
|
203
|
+
* it can be passed straight to `mcpProxyHandler`.
|
|
204
|
+
*/
|
|
205
|
+
allowAccess(serverUrl: string, mcpName: string): Promise<HostedOAuthResult>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Build a reusable server-side OAuth integration around
|
|
209
|
+
* {@link CLIBrowserOAuthProvider}'s externalCallback mode: the OAuth redirect
|
|
210
|
+
* rides on the host's own HTTP server instead of a separate local port, so
|
|
211
|
+
* there is no extra port to collide with and the redirect_uri stays stable.
|
|
212
|
+
*
|
|
213
|
+
* The returned object owns a private `state → provider` map that correlates
|
|
214
|
+
* each inbound callback to the flow awaiting it, so concurrent flows (e.g.
|
|
215
|
+
* multiple MCP servers) never cross wires.
|
|
216
|
+
*
|
|
217
|
+
* Usage (Hono):
|
|
218
|
+
* const oauth = createHostedOAuth({
|
|
219
|
+
* callbackPath: "/oauth/callback",
|
|
220
|
+
* clientName: "mcp-proxy",
|
|
221
|
+
* getPort: async () => Number(new URL(getHonoUrl()).port),
|
|
222
|
+
* });
|
|
223
|
+
* app.get("/oauth/callback", oauth.handleCallback);
|
|
224
|
+
* app.use("/proxy/:mcpName", mcpProxyHandler(SERVERS, oauth.allowAccess));
|
|
225
|
+
*/
|
|
226
|
+
export declare function createHostedOAuth(options: HostedOAuthOptions): HostedOAuth;
|
|
151
227
|
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.
|
|
2
|
+
"version": "0.8.2",
|
|
3
3
|
"name": "modality-ai",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
15
|
-
"modality-mcp-kit": "^2.0
|
|
15
|
+
"modality-mcp-kit": "^2.1.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@ai-sdk/google": "^4.0.
|
|
19
|
-
"ai": "^7.0.
|
|
18
|
+
"@ai-sdk/google": "^4.0.24",
|
|
19
|
+
"ai": "^7.0.37"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "^1.3.14",
|
|
23
|
-
"modality-bun-kit": "^1.3.14",
|
|
23
|
+
"modality-bun-kit": "^1.3.14-2",
|
|
24
24
|
"typescript": "^7.0.2"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|