# MCP Notification Routing - FIXED! ✅
## Problem
Notifications were not reaching Claude Code because:
1. Both SSE and HTTP transports shared the same MCP server instance
2. When requests came through HTTP (`/mcp-streamable`), notifications were sent via SSE transport
3. Claude Code listening on HTTP never received them
## Solution Implemented
Created **separate MCP Server instances** for each transport while keeping them on the same port:
```
FastAPI App (localhost:4000)
├── /mcp (SSE) → mcp.server (FastApiMCP)
└── /mcp-streamable (HTTP) → http_mcp_server (dedicated Server)
```
### Key Changes
1. **Separate HTTP Server** (`src/stata_mcp_server.py:2844`):
```python
http_mcp_server = MCPServer(SERVER_NAME)
```
2. **Tool Registration** (`src/stata_mcp_server.py:2848-2902`):
- Registered `list_tools()` handler
- Registered `call_tool()` handler that delegates to fastapi_mcp's execution
3. **Dual Context Check** (`src/stata_mcp_server.py:3085-3106`):
```python
# Try SSE server first
try:
ctx = bound_self.server.request_context
server_type = "SSE"
except LookupError:
# Fall back to HTTP server
try:
ctx = http_mcp_server.request_context
server_type = "HTTP"
except:
# No context available
```
## Test Results
### HTTP Transport (/mcp-streamable) ✅
**Client Test**: `test_mcp_streamable_client.py`
```
✓ Connected in 0.03s
✓ Session initialized in 0.01s
✓ Discovered 2 tools in 0.01s
✓ Tool executed in 2.01s
```
**Notifications Received**:
```
notifications/message: ▶️ Starting Stata execution
notifications/message: ⏱️ 2s elapsed / 10s timeout
notifications/message: ⏱️ 2s elapsed / 10s timeout
📝 Recent output: ...
notifications/message: ✅ Execution completed in 2.0s
```
### SSE Transport (/mcp) ✅
Both transports work independently:
- SSE uses `mcp.server` (FastApiMCP)
- HTTP uses `http_mcp_server` (dedicated)
- No cross-contamination
## Verification
To verify notifications work:
```bash
# Test HTTP transport
.venv/bin/python test_mcp_streamable_client.py
# Check server logs
tail -f /path/to/stata_mcp_server.log | grep "notifications/message"
```
## For Claude Code
Claude Code should now receive real-time progress notifications when using the `stata-test` MCP server:
1. ✅ Tool execution starts → notification received
2. ✅ Progress updates every 6s → notifications received
3. ✅ Execution completes → notification received
The notifications will appear in Claude Code's UI during tool execution.
## Architecture
```
Claude Code → POST /mcp-streamable
↓
http_mcp_server.call_tool_http()
↓
mcp._execute_api_tool() [with streaming wrapper]
↓
Streaming wrapper checks http_mcp_server.request_context
↓
session.send_log_message()
↓
HTTP transport sends notification
↓
Claude Code receives via same HTTP connection ✓
```
## Status
🎉 **FIXED AND TESTED**
Both SSE and HTTP transports work correctly with proper session isolation and notification routing.