LibreChat/packages/api/src/mcp/oauth
Dustin Healy abeaab6e17
⚠️ fix: OAuth Error and Token Expiry Detection and Reporting Improvements (#10922)
* fix: create new flows on invalid_grant errors

* chore: fix failing test

* chore: keep isOAuthError test function in sync with implementation

* test: add tests for OAuth error detection on invalid grant errors

* test: add tests for creating new flows when token expires

* test: add test for flow clean up prior to creation

* refactor: consolidate token expiration handling in FlowStateManager

- Removed the old token expiration checks and replaced them with a new method, `isTokenExpired`, to streamline the logic.
- Introduced `normalizeExpirationTimestamp` to handle timestamp normalization for both seconds and milliseconds.
- Updated tests to ensure proper functionality of flow management with token expiration scenarios.

* fix: conditionally setup cleanup handlers in FlowStateManager

- Updated the FlowStateManager constructor to only call setupCleanupHandlers if the ci parameter is not set, improving flexibility in flow management.

* chore: enhance OAuth token refresh logging

- Introduced a new method, `processRefreshResponse`, to streamline the processing of token refresh responses from the OAuth server.
- Improved logging to provide detailed information about token refresh operations, including whether new tokens were received and if the refresh token was rotated.
- Updated existing token handling logic to utilize the new method, ensuring consistency and clarity in token management.

* chore: enhance logging for MCP server reinitialization

- Updated the logging in the reinitMCPServer function to provide more detailed information about the response, including success status, OAuth requirements, presence of the OAuth URL, and the count of tools involved. This improves the clarity and usefulness of logs for debugging purposes.

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
2025-12-12 13:51:28 -05:00
..
detectOAuth.test.ts 🛜 feat: Support Legacy OAuth Servers without .well-known Metadata (#10917) 2025-12-11 12:31:24 -05:00
detectOAuth.ts 🛜 feat: Support Legacy OAuth Servers without .well-known Metadata (#10917) 2025-12-11 12:31:24 -05:00
handler.ts ⚠️ fix: OAuth Error and Token Expiry Detection and Reporting Improvements (#10922) 2025-12-12 13:51:28 -05:00
index.ts ♻️ refactor: MCPManager for Scalability, Fix App-Level Detection, Add Lazy Connections (#8930) 2025-08-13 11:45:06 -04:00
OAuthReconnectionManager.test.ts 🧬 refactor: Wire Database Methods into MCP Package via Registry Pattern (#10715) 2025-12-11 16:37:12 -05:00
OAuthReconnectionManager.ts 🧬 refactor: Wire Database Methods into MCP Package via Registry Pattern (#10715) 2025-12-11 16:37:12 -05:00
OAuthReconnectionTracker.test.ts refactor: MCP OAuth Polling with Gradual Backoff and Timeout Handling (#9752) 2025-09-21 22:58:19 -04:00
OAuthReconnectionTracker.ts refactor: MCP OAuth Polling with Gradual Backoff and Timeout Handling (#9752) 2025-09-21 22:58:19 -04:00
tokens.ts ⚠️ fix: OAuth Error and Token Expiry Detection and Reporting Improvements (#10922) 2025-12-12 13:51:28 -05:00
types.ts 🛜 feat: Support Legacy OAuth Servers without .well-known Metadata (#10917) 2025-12-11 12:31:24 -05:00