oauth-callback 2.1.0 → 2.2.0

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 CHANGED
@@ -127,6 +127,8 @@ import { browserAuth, inMemoryStore } from "oauth-callback/mcp";
127
127
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
128
128
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
129
129
 
130
+ const serverUrl = new URL("https://mcp.notion.com/mcp");
131
+
130
132
  // Create MCP-compatible OAuth provider
131
133
  const authProvider = browserAuth({
132
134
  port: 3000,
@@ -135,18 +137,29 @@ const authProvider = browserAuth({
135
137
  store: inMemoryStore(), // Or fileStore() for persistence
136
138
  });
137
139
 
138
- // Use with MCP SDK transport
139
- const transport = new StreamableHTTPClientTransport(
140
- new URL("https://mcp.notion.com/mcp"),
141
- { authProvider },
142
- );
143
-
144
140
  const client = new Client(
145
141
  { name: "my-app", version: "1.0.0" },
146
142
  { capabilities: {} },
147
143
  );
148
144
 
149
- await client.connect(transport);
145
+ // Connect with OAuth retry: first attempt completes OAuth and saves tokens,
146
+ // but SDK returns before checking them. Second attempt succeeds.
147
+ async function connectWithOAuthRetry() {
148
+ const transport = new StreamableHTTPClientTransport(serverUrl, {
149
+ authProvider,
150
+ });
151
+ try {
152
+ await client.connect(transport);
153
+ } catch (error: any) {
154
+ if (error.message === "Unauthorized") {
155
+ await client.connect(
156
+ new StreamableHTTPClientTransport(serverUrl, { authProvider }),
157
+ );
158
+ } else throw error;
159
+ }
160
+ }
161
+
162
+ await connectWithOAuthRetry();
150
163
  ```
151
164
 
152
165
  #### Token Storage Options
@@ -275,7 +288,7 @@ class OAuthError extends Error {
275
288
 
276
289
  ### `browserAuth(options)`
277
290
 
278
- Available from `oauth-callback/mcp`. Creates an MCP SDK-compatible OAuth provider for browser-based flows. Handles Dynamic Client Registration (DCR), token storage, and automatic refresh.
291
+ Available from `oauth-callback/mcp`. Creates an MCP SDK-compatible OAuth provider for browser-based flows. Handles Dynamic Client Registration (DCR) and token storage. Expired tokens trigger re-authentication.
279
292
 
280
293
  #### Parameters
281
294
 
@@ -1,4 +1,4 @@
1
- import type { BrowserAuthOptions } from "../mcp-types";
1
+ import { type BrowserAuthOptions } from "../mcp-types";
2
2
  import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
3
3
  /**
4
4
  * Factory for MCP SDK-compatible OAuth provider using browser flow.
@@ -1 +1 @@
1
- {"version":3,"file":"browser-auth.d.ts","sourceRoot":"","sources":["../../src/auth/browser-auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAMnB,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAQpF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CAErB"}
1
+ {"version":3,"file":"browser-auth.d.ts","sourceRoot":"","sources":["../../src/auth/browser-auth.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,kBAAkB,EAKxB,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAYpF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CAErB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,YAAY,EAAE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