Using with Open AI Agent Builder
Closed this issue · 7 comments
Summary:
When using the MCP server with HTTP transport behind an Nginx reverse proxy, the Open AI agent builder can detect the server and list available tools. However, tool calls fail most of the time (>90%), returning:
Tool: mcp_mongo.connect
Response: { "code": 32600, "message": "Session terminated" }
Expected behavior:
Tool calls should consistently succeed once the MCP server is reachable.
Observed behavior:
Most requests to /mcp end with a Session terminated error, even though initial handshake and occasional tool calls succeed.
Condensed Server Log:
nginx | "POST /mcp" 200 / 202 responses alternating
mongo-mcp | [INFO] Server started (StreamableHTTPServerTransport)
mongo-mcp | [INFO] Attempting MongoDB connection...
mongo-mcp | [DEBUG] Telemetry: start → stop sequence repeats within seconds
mongo-mcp | [INFO] Server shutdown / "Session terminated"
- Repeated server restarts and session closures observed within 1–2 seconds.
- Same behavior across multiple session IDs.
- Nginx reverse proxy appears to receive valid POST/DELETE cycles but connections terminate immediately after.
I am running the MCP server via docker:
mongo-mcp:
image: mongodb/mongodb-mcp-server:latest
restart: always
env_file:
- .env
environment:
MDB_MCP_CONNECTION_STRING: ${MDB_MCP_CONNECTION_STRING}
MDB_MCP_READ_ONLY: ${MDB_MCP_READ_ONLY:-true}
MDB_MCP_TRANSPORT: ${MDB_MCP_TRANSPORT:-http}
MDB_MCP_HTTP_HOST: ${MDB_MCP_HTTP_HOST:-0.0.0.0}
MDB_MCP_HTTP_PORT: ${MDB_MCP_HTTP_PORT:-8080}
MDB_MCP_API_CLIENT_ID: ${MDB_MCP_API_CLIENT_ID}
MDB_MCP_API_CLIENT_SECRET: ${MDB_MCP_API_CLIENT_SECRET}
MDB_MCP_LOGGERS: "disk,stderr"
Thanks for opening this issue. The ticket MCP-267 was created for internal tracking.
Thank you for reporting this issue! The detailed logs and Docker configuration are very helpful.
To help us reproduce this problem, could you please share your Nginx configuration? Specifically the server block that proxies to your MCP server, including any timeout or connection handling settings you have configured.
This will help us set up a similar environment and better understand what might be causing the session terminations.
Hi @jeroenvervaeke
Below is the nginx config:
gzip on;
gzip_min_length 1000; # recommended minimum length for compression
gzip_proxied any; # ensures gzip compression works even for proxied requests
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on; # tells proxies to cache both gzipped and non-gzipped versions
upstream app_server {
server app:8000;
}
upstream mcp_upstream {
server mongo-mcp:8080;
}
#map $http_x_use_mcp $route_to_mcp {
# default 0;
# "secret-header" 1;
#}
server {
listen 80;
listen [::]:80;
server_name localhost;
location /mcp {
proxy_pass http://mcp_upstream;
proxy_http_version 1.1;
proxy_read_timeout 1h;
proxy_send_timeout 1h;
proxy_buffering off;
proxy_request_buffering off;
proxy_set_header Connection "keep-alive";
proxy_set_header Proxy-Connection "keep-alive";
proxy_set_header X-Accel-Buffering no;
proxy_set_header Keep-Alive "timeout=3600";
proxy_set_header Upgrade $http_upgrade;
# Standard proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
#if ($route_to_mcp = 1) {
# rewrite ^ /mcp break;
#}
proxy_pass http://app_server;
proxy_http_version 1.1;
proxy_connect_timeout 180s;
proxy_read_timeout 180s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
error_page 500 502 503 504 /50x.html;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name localhost;
ssl_certificate /root/ssl/cert.pem;
ssl_certificate_key /root/ssl/key.pem;
location /mcp {
proxy_pass http://mcp_upstream;
proxy_http_version 1.1;
proxy_buffering off;
proxy_request_buffering off;
proxy_set_header Connection "keep-alive";
proxy_set_header Proxy-Connection "keep-alive";
proxy_set_header X-Accel-Buffering no;
proxy_read_timeout 1h; # long-running calls
proxy_send_timeout 1h;
proxy_set_header Keep-Alive "timeout=3600";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
#if ($route_to_mcp = 1) {
# rewrite ^ /mcp break;
#}
proxy_pass http://app_server;
proxy_http_version 1.1;
proxy_connect_timeout 180s;
proxy_read_timeout 180s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
error_page 500 502 503 504 /50x.html;
}
Can you please verify that your nginx configuration does in fact pass through the mcp-session-id header, required by the MCP Server, to keep the session alive?
You might need to use this directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass_header
Edit:
I've tested your nginx configuration with the MCP Server, using a docker-compose environment and it works fine, as expected. It seems to be an issue unrelated to the MCP Server, but with the agent. I've tested Copilot and Claude, and both work fine.
It might be a bug from the Agent Builder, maybe you'll have to contact OpenAI support for this one: https://community.openai.com/t/agent-builder-remote-mcp-session-id/1362772
Looks like you were one step ahead of me @kmruiz.
I did the exact same thing and can confirm that everything works fine locally.
I've used the MCP inspector to verify and I can call tools as expected.
I did not manage to get the disconnect logs.
mongo-mcp | [DEBUG] 1006008 - streamableHttpTransport: Sending ping (124, sessionId=0c9d7b1d-3441-4faa-abc6-b37edb1835a9)
mongo-mcp | [DEBUG] 1003001 - tool: Executing tool list-databases (124, sessionId=0c9d7b1d-3441-4faa-abc6-b37edb1835a9)
mongo-mcp | [DEBUG] 1003001 - tool: Executed tool list-databases (124, sessionId=0c9d7b1d-3441-4faa-abc6-b37edb1835a9)
nginx | 172.64.66.1 - - [21/Oct/2025:16:15:19 +0000] "POST /mcp HTTP/1.1" 200 1159 "-" "node-fetch"
mongo-mcp | [DEBUG] 1006008 - streamableHttpTransport: Sending ping (124, sessionId=0c9d7b1d-3441-4faa-abc6-b37edb1835a9)
mongo-mcp | [DEBUG] 1003001 - tool: Executing tool list-collections (124, sessionId=0c9d7b1d-3441-4faa-abc6-b37edb1835a9)
mongo-mcp | [DEBUG] 1003001 - tool: Executed tool list-collections (124, sessionId=0c9d7b1d-3441-4faa-abc6-b37edb1835a9)
nginx | 172.64.66.1 - - [21/Oct/2025:16:15:34 +0000] "POST /mcp HTTP/1.1" 200 1153 "-" "node-fetch"
Looks like the issue now resolved. It must have been an error with OpenAI.
The corresponding JIRA ticket has been automatically closed.