Fix Copilot Studio MCP session timeout issues with enhanced session management #14
+1,400
−35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Copilot Studio users experienced MCP session timeout issues after 15-30 minutes of extended chat sessions, resulting in
{"jsonrpc":"2.0","id":"","error":{"Code":-32001,"Message":"Session not found"}}
errors. Users had to start new chat sessions to recover functionality, disrupting the user experience.Root Cause
The MCP server was using default ASP.NET Core session management settings with short timeouts and limited session persistence mechanisms, causing sessions to expire during extended Copilot Studio interactions.
Solution
This PR implements comprehensive session management improvements specifically designed for long-lived Copilot Studio integrations:
🔧 Core Session Management Enhancements
SameSite=None
cookies for Copilot Studio integration🎯 Custom MCP Session Tracking
Implemented a dedicated
McpSessionManager
service that provides:🛡️ Enhanced Error Handling
Created
McpErrorHandler
service with structured error responses:📊 Monitoring and Debugging
Added comprehensive monitoring endpoints:
GET /status
- Enhanced with session management info and active session countsGET /session-health
- Session validation and health checksGET /sessions
- Session management overview with metrics🧪 Session Validation Middleware
Implemented middleware that:
initialize
method calls for new session establishmentTesting
Created comprehensive test suite (
test-mcp-sessions.sh
) that validates:Impact
Before:
After:
This implementation resolves the Copilot Studio integration issues while maintaining backward compatibility and providing enhanced debugging capabilities for production deployments.
Compatibility
The enhanced session management is now ready for production deployment and should significantly improve the Copilot Studio user experience by eliminating unexpected session timeouts during extended conversations.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.