modality-ai 0.8.1 → 0.8.3
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 {};
|
|
@@ -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" */
|
|
@@ -46,6 +46,15 @@ interface CLIBrowserOAuthProviderOptions {
|
|
|
46
46
|
*/
|
|
47
47
|
serverUrl?: string | null;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Per-server OAuth client identity override.
|
|
51
|
+
* Some MCP servers whitelist specific client_name values during dynamic
|
|
52
|
+
* registration — use this map to supply the expected identity automatically.
|
|
53
|
+
*/
|
|
54
|
+
interface ServerClientIdentity {
|
|
55
|
+
client_name: string;
|
|
56
|
+
client_uri: string;
|
|
57
|
+
}
|
|
49
58
|
/**
|
|
50
59
|
* OAuthClientProvider for CLI tools.
|
|
51
60
|
*
|
|
@@ -93,6 +102,12 @@ export declare class CLIBrowserOAuthProvider implements OAuthClientProvider {
|
|
|
93
102
|
private _tokens?;
|
|
94
103
|
private _discoveryState?;
|
|
95
104
|
constructor(options?: CLIBrowserOAuthProviderOptions);
|
|
105
|
+
/**
|
|
106
|
+
* Clear cached clientInfo when its redirect_uris don't match the current redirectUrl.
|
|
107
|
+
* This handles the case where the user switches --callback-port or the cache is stale.
|
|
108
|
+
* Skip invalidation when clientId is explicitly provided (no redirect_uris expected).
|
|
109
|
+
*/
|
|
110
|
+
private _invalidateStaleCache;
|
|
96
111
|
get redirectUrl(): string;
|
|
97
112
|
get clientMetadata(): OAuthClientMetadata;
|
|
98
113
|
clientInformation(): OAuthClientInformationMixed | undefined;
|
|
@@ -149,4 +164,89 @@ export declare class CLIBrowserOAuthProvider implements OAuthClientProvider {
|
|
|
149
164
|
private _persistCache;
|
|
150
165
|
private _handleCallback;
|
|
151
166
|
}
|
|
167
|
+
/** Escape HTML special characters to prevent XSS from attacker-controlled strings. */
|
|
168
|
+
export declare function escapeHtml(s: string): string;
|
|
169
|
+
/** Short stable hash of a string — used to derive a cache file name from a URL. */
|
|
170
|
+
export declare function urlStorageKey(url: string): string;
|
|
171
|
+
/**
|
|
172
|
+
* Returns a whitelisted client identity for the given server URL, or null
|
|
173
|
+
* if none matches. Matching is hostname-suffix based: a key "figma.com"
|
|
174
|
+
* matches "mcp.figma.com", "api.figma.com", etc.
|
|
175
|
+
*/
|
|
176
|
+
export declare function resolveServerIdentity(serverUrl: string): ServerClientIdentity | null;
|
|
177
|
+
/** Options for {@link createHostedOAuth}. */
|
|
178
|
+
export interface HostedOAuthOptions {
|
|
179
|
+
/**
|
|
180
|
+
* Path the host server exposes for the OAuth redirect, e.g. "/oauth/callback".
|
|
181
|
+
* Wire your route to forward requests to the returned `handleCallback`.
|
|
182
|
+
*/
|
|
183
|
+
callbackPath: string;
|
|
184
|
+
/**
|
|
185
|
+
* Returns the port the host server is bound to. Called per flow, so it can
|
|
186
|
+
* reflect the live runtime port (e.g. parsed from a getHonoUrl() helper)
|
|
187
|
+
* instead of a hardcoded guess.
|
|
188
|
+
*/
|
|
189
|
+
getPort: () => number | Promise<number>;
|
|
190
|
+
/** Host used in the redirect_uri. Default "127.0.0.1". */
|
|
191
|
+
host?: string;
|
|
192
|
+
/** OAuth client display name registered with the server. Default "mcp-cli". */
|
|
193
|
+
clientName?: string;
|
|
194
|
+
}
|
|
195
|
+
/** Outcome of a hosted OAuth flow. */
|
|
196
|
+
export interface HostedOAuthResult {
|
|
197
|
+
status: "authorized" | "already_authorized";
|
|
198
|
+
message: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Input accepted by {@link HostedOAuth.handleCallback}: either a raw web
|
|
202
|
+
* `Request` (e.g. from `Bun.serve`) or any object exposing one at `req.raw`,
|
|
203
|
+
* which a Hono `Context` satisfies structurally. This lets the handler be
|
|
204
|
+
* passed directly to `app.get(path, oauth.handleCallback)` with no wrapper,
|
|
205
|
+
* while staying framework-agnostic (no `hono` dependency).
|
|
206
|
+
*/
|
|
207
|
+
export type OAuthCallbackInput = Request | {
|
|
208
|
+
req: {
|
|
209
|
+
raw: Request;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
/** The two functions a host server wires in to enable hosted OAuth. */
|
|
213
|
+
export interface HostedOAuth {
|
|
214
|
+
/**
|
|
215
|
+
* Handle a browser redirect forwarded from the host's callback route.
|
|
216
|
+
* Correlates the request to the awaiting provider by its `state`, resolves
|
|
217
|
+
* that flow, and returns the page to render in the tab. Returns a 400 when no
|
|
218
|
+
* matching flow is pending (unknown/expired state).
|
|
219
|
+
*
|
|
220
|
+
* Accepts a raw `Request` or a Hono `Context` — pass it straight to a route:
|
|
221
|
+
* app.get("/oauth/callback", oauth.handleCallback) // Hono
|
|
222
|
+
* Bun.serve({ fetch: oauth.handleCallback }) // raw Request
|
|
223
|
+
*/
|
|
224
|
+
handleCallback(input: OAuthCallbackInput): Response;
|
|
225
|
+
/**
|
|
226
|
+
* Run — or short-circuit if already authorized — the OAuth flow for an MCP
|
|
227
|
+
* server URL. Shape-compatible with modality-mcp-kit's OAuthAllowAccessFn, so
|
|
228
|
+
* it can be passed straight to `mcpProxyHandler`.
|
|
229
|
+
*/
|
|
230
|
+
allowAccess(serverUrl: string, mcpName: string): Promise<HostedOAuthResult>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Build a reusable server-side OAuth integration around
|
|
234
|
+
* {@link CLIBrowserOAuthProvider}'s externalCallback mode: the OAuth redirect
|
|
235
|
+
* rides on the host's own HTTP server instead of a separate local port, so
|
|
236
|
+
* there is no extra port to collide with and the redirect_uri stays stable.
|
|
237
|
+
*
|
|
238
|
+
* The returned object owns a private `state → provider` map that correlates
|
|
239
|
+
* each inbound callback to the flow awaiting it, so concurrent flows (e.g.
|
|
240
|
+
* multiple MCP servers) never cross wires.
|
|
241
|
+
*
|
|
242
|
+
* Usage (Hono):
|
|
243
|
+
* const oauth = createHostedOAuth({
|
|
244
|
+
* callbackPath: "/oauth/callback",
|
|
245
|
+
* clientName: "mcp-proxy",
|
|
246
|
+
* getPort: async () => Number(new URL(getHonoUrl()).port),
|
|
247
|
+
* });
|
|
248
|
+
* app.get("/oauth/callback", oauth.handleCallback);
|
|
249
|
+
* app.use("/proxy/:mcpName", mcpProxyHandler(SERVERS, oauth.allowAccess));
|
|
250
|
+
*/
|
|
251
|
+
export declare function createHostedOAuth(options: HostedOAuthOptions): HostedOAuth;
|
|
152
252
|
export {};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.
|
|
2
|
+
"version": "0.8.3",
|
|
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": {
|