-
Notifications
You must be signed in to change notification settings - Fork 200
Add Streamable HTTP Support and Graceful Shutdown for Postgres MCP Server #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@jssmith Hello, sorry for pinging you on this. Would you please review the PR and merge if the review is passed. Thank you. |
|
When I run the MCP inspector, it shows this now with SSE |
|
@jssmith | @mdashti | @greglearns can we merge this PR? :) We would like to migrate all the MCP servers we use to streamable http |
|
This fixes #102 |
|
Is this on the release schedule anywhere? Streamable HTTP seems like a pretty important use case. |
|
Unfortunately, there is no reponse for merging this change. I saw 2 options
{
"mcpServers": {
"postgres": {
"type": "http",
"url": "https://postgres-url.com/sse"
}
}
}
Or switch to another one: https://www.pulsemcp.com/servers/modelcontextprotocol-postgres |
Thanks for your reply. I saw that there were others who wanted this to move forward, I was hoping a little more interest might get a bump here but I'll take a look at alternatives. |
|
FYI I pinged @jssmith directly on LinkedIn and he said he'll take a look this week :) maybe he'd promote sb to be a maintainer |
Hi @mavogel |
Add support for the streamable-http transport option alongside the existing stdio and sse transports. This addresses the deprecation of SSE transport in favor of streamable HTTP. Changes: - Add 'streamable-http' as a transport choice - Add --streamable-http-host and --streamable-http-port arguments - Call mcp.run_streamable_http_async() for streamable-http transport - Add comprehensive tests for all transport options Based on work by @ahmedmustahid in #78. Closes #102 Co-Authored-By: Ahmed Mustahid <ahmedmustahid@users.noreply.github.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Thanks for this contribution @ahmedmustahid! We've created #134 which extracts just the streamable HTTP transport functionality from this PR, with tests added. It credits you as a co-author. The signal handling improvements from this PR will be addressed in a separate follow-up PR to keep the changes focused and easier to review. If #134 is merged, this PR can be closed (or updated to focus only on the signal handling portion if you'd like to continue with that). |
Replace complex signal-based shutdown with simpler try/finally cleanup: - Remove custom signal handlers that called sys.exit() from async code - Use try/finally in main() to ensure cleanup() is always called - Handle KeyboardInterrupt in __init__.py to suppress traceback on Ctrl+C - Remove unused imports (asyncio, signal, sys) from server.py - Rename shutdown() to cleanup() to reflect its simpler purpose This approach: - Lets Python's default signal handling work naturally - Avoids "asyncio.run() cannot be called from a running event loop" errors - Ensures database connections are closed on any exit path - Is simpler and more maintainable Based on work by @ahmedmustahid in #78. Co-Authored-By: Ahmed Mustahid <ahmedmustahid@users.noreply.github.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
This PR implements streamable HTTP transport support and fixes graceful shutdown handling for the Postgres MCP server, addressing issues with signal handling in stdio transport environments.
Changes Made
Core Improvements
Modified Files
src/postgres_mcp/__init__.py: Simplified main entry point to properly delegate to server.main()src/postgres_mcp/server.py: Enhanced with streamable HTTP support and robust shutdown handlingKey Features
Problem Solved
Previously,
Solution
Testing
Backward Compatibility
Usage Examples
Default MCP Usage (stdio)
uv run postgres-mcp # Uses stdio transport as beforeStreamable HTTP Usage
Notes
Type: Enhancement, Bug Fix
Breaking Changes: None
Requires Migration: No
Fixes #102