deepset-ai / deepset-ai/haystack-core-integrations
mcp: Implement Automatic OAuth Callback Handling with Local Server
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 203
- Forks
- 332
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 80
Description
Scope
For the Authorization Code flow, automate the callback capture using a temporary local HTTP server that listens on the redirect_uri, eliminating the need for manual copy-paste in most scenarios.
Haystack MCP Integration Details
Callback Server Design:
- Use Python's
http.serverorstarlettefor lightweight local server - Server should bind to the
redirect_urihost/port (must be localhost/127.0.0.1) - Server should shut down cleanly after receiving callback
- Handle timeout (e.g., 5 minutes) if no callback received
Browser Integration:
- Use
webbrowsermodule to automatically open authorization URL - Gracefully handle cases where browser cannot be opened (headless environments)
- Display success message in browser after callback capture
Fallback Strategy:
- If server cannot bind (port in use, permissions) → fallback to manual paste
- If no callback received within timeout → fallback to manual paste
- If running in headless environment → fallback to manual paste
- Keep
on_authorization_urlcallback hook customizable for advanced use cases
Integration with OAuth Flow:
- Callback server should be started before redirecting user to authorization URL
- Server should extract
codeandstatefrom query parameters - Verify
stateparameter matches the one sent (CSRF protection) - Return extracted
codeto OAuth flow for token exchange - Display friendly success message in browser
Requirements
- Implement local HTTP server that binds to
redirect_uri(if localhost) - Automatically open system browser to authorization URL (when possible)
- Capture callback request and extract
codeandstateparameters - Verify
stateparameter for CSRF protection - Display success message in browser (HTML response)
- Shut down server cleanly after callback
- Fallback to manual paste if:
- Server cannot bind (port in use, permissions)
- No callback received within timeout (e.g., 5 minutes)
- Running in headless environment
- Browser cannot be opened
- Make
on_authorization_urlcallback hook still customizable for advanced use cases - Handle random port selection if
redirect_uriport is 0 or unspecified - Add tests for automatic callback capture (mock server)
- Add tests for fallback scenarios
- Add tests for state verification
Implementation Notes
- Consider using
threadingorasynciofor server (must work in sync context) - Server should be single-request (shutdown after first callback)
- Ensure proper error handling and cleanup
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing OAuth Authorization Code flow and its on_authorization_url callback hook, then trace the current manual-paste path. Implement and test local callback capture, state verification, browser handling, cleanup, timeout, and fallback behavior, including mock-server and fallback tests described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- authentication, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100