Back to Blog
March 17, 2026

Avoiding Session Errors in Microsoft 365 Copilot MCP Servers: Building Stateless MCP

Share

Avoiding Session Errors in Microsoft 365 Copilot MCP Servers: Building Stateless MCP

Date: 2026-03-17

Struggling with session errors when integrating MCP Servers with Copilot Studio? Learn why stateless MCP Servers are the robust workaround and how to implement them.

Tags: ["Microsoft 365", "Copilot", "MCP", "Azure", "Developer Tips"]

Avoiding Session Errors in Microsoft 365 Copilot MCP Servers: Building Stateless MCP

As organizations ramp up adoption of Microsoft 365 Copilot and build custom Copilot Agents with Microsoft’s Model Context Protocol (MCP), a recurring challenge has emerged around session management. You may have noticed errors like "Session not found" appearing in your Copilot Studio backend logs, disrupting seamless AI interactions. The root cause often traces back to stateful MCP Servers that hold session state in volatile environments such as serverless platforms.

In this post, we’ll explain why session state leads to failures in current MCP Server deployments, and offer a practical, simple workaround: building stateless MCP Servers. By switching to a stateless design, your MCP Server sidesteps session validity concerns altogether, resulting in more reliable Copilot Agent integrations. We’ll also dig into how to configure the Microsoft .NET MCP SDK to enable stateless mode, what the tradeoffs are, and why this approach fits nicely with serverless hosting.

Whether you’re an Azure developer, Microsoft 365 integrator, or exploring extending Copilot Studio with custom logic, this post arms you with the insight and code tweaks required to stop session errors and improve user experience.

Architecture Overview

┌────────────────────────────────────────────┐
│Architecture                                │
├────────────────────────────────────────────┤
│• Enterprise data sources                   │
│• Foundry platform                          │
│• AI applications                           │
└────────────────────────────────────────────┘

Key Technical Observations

  • Stateful MCP Servers Depend on Session Persistence — MCP Servers built with session state management require persisting session IDs to track ongoing conversations. Without reliable persistence, session validity quickly expires, causing errors.

  • Serverless Platforms Implicitly Cause Session Volatility — Hosting MCP Servers on serverless platforms (e.g., Azure Functions) can lead to instances being shut down during idle times, losing any in-memory session state, and making session continuation impossible.

  • Stateless Mode Removes Session ID Dependency — The .NET MCP SDK includes a Stateless configuration option that disables session ID usage, preventing the need to track session state and removing /sse endpoint usage.

  • Disabling Sessions Affects Bidirectional Communication — Stateless MCP Servers cannot support unsolicited server-to-client messages or server-initiated requests, limiting some advanced interaction patterns.

  • Simple Configuration Change via WithHttpTransport Enables Stateless — Changing to stateless is as simple as setting the Stateless flag to true in the HttpServerTransportOptions when configuring the MCP Server HTTP transport.

  • Errors Manifest as JSON-RPC Session Not Found Codes — The "error": { "code": -32001, "message": "Session not found" } JSON-RPC response clearly indicates when the MCP Server lost session context, a key troubleshooting insight.

How It Works: Building a Stateless MCP Server with .NET MCP SDK

Understanding State vs Stateless MCP Servers

Stateful MCP Servers maintain session IDs to manage conversation context, using the MCP-Session-Id HTTP header. This enables the server to track conversation progress over multiple requests. However, this requires the server to reliably preserve session state between calls, either in-memory or via persistent storage.

Stateless MCP Servers, by contrast, do not generate or require session IDs. Each request is treated independently. The MCP-Session-Id header is ignored and the /sse (server-sent events) endpoint is disabled. This model fits best when MCP Servers run in ephemeral environments and can't guarantee session retention.

Switching to Stateless Mode in Code

With the .NET MCP SDK, configuring your MCP Server to be stateless revolves around HttpServerTransportOptions. Here is a simplified snippet to illustrate:

using ModelContextProtocol.AspNetCore;

var server = new McpServer()
    .WithHttpTransport(new HttpServerTransportOptions
    {
        Stateless = true // Enable stateless behavior
    });

// Start the server normally after configuration
await server.StartAsync();

When Stateless is set to true, the server:

  • Sets SessionId to null.
  • Ignores the MCP-Session-Id header.
  • Calls the session handler once per request rather than managing a session lifecycle.
  • Disables /sse endpoint to prevent server-to-client push messages.

This results in a simpler interaction — one where no session expiration errors can occur.

Why Stateless Works Better in Serverless Environments

Serverless compute environments such as Azure Functions or ephemeral containers frequently recycle instances to optimize resources, wiping in-memory state. By removing session requirements, stateless MCP Servers become inherently compatible with these hosting models without requiring complex persistence mechanisms.

Tradeoffs of Stateless MCP Servers

  • No session-dependent features: Unsolicited server-to-client messages and client sampling are unsupported.
  • Root capabilities and other advanced features disabled: Since the server cannot maintain state, some Copilot Studio features reliant on session continuity are unavailable.
  • Simplicity versus full feature usage: For many scenarios, stateless mode covers typical conversational extensions without added complexity.

Quick Tips & Tricks

  1. Enable Stateless Early While Prototyping
    Start with stateless MCP Servers to avoid session headaches, especially during early development or when using serverless hosting.

  2. Monitor for Session-Related Errors
    Track logs for JSON-RPC error code -32001 with message "Session not found" to diagnose session expiration problems.

  3. Use Persistent Storage If State Is Required
    If your application needs sessions, consider external persistence (e.g., Azure Cosmos DB) to store session IDs and context.

  4. Test Agent Behavior Without Sessions
    Verify your Copilot Agents function correctly when sessions are disabled, ensuring limitations are acceptable.

  5. Check SDK Documentation Regularly
    The MCP SDK evolves rapidly; refer to the official HttpServerTransportOptions documentation for the latest features.

  6. Consider Container Hosting for Stateful Needs
    If you require sessions but want stable environments, deploy MCP Servers on stateful container hosts or Azure Kubernetes Service to avoid serverless volatility.

Conclusion

Managing MCP Server state in Microsoft 365 Copilot integrations can be challenging due to the ephemeral nature of serverless hosting platforms. Session expiration errors frustrate both users and developers but stem from the inherent difficulty of maintaining session persistence in these environments.

The recommended pragmatic solution today is to build your MCP Servers as stateless by enabling the Stateless option in your .NET MCP SDK configuration. This approach effectively sidesteps session ID expiration issues, delivers improved robustness, and simplifies deployment to serverless platforms. While it limits some advanced server-to-client messaging capabilities, it addresses the most disruptive errors seen in Copilot Studio integrations today.

As MCP Server implementations and tooling mature, we can anticipate better native support for session persistence and scalable stateful hosting. Until then, stateless MCP Servers offer a straightforward, practical path to building more reliable Copilot Agents with the Microsoft 365 Copilot extensibility ecosystem.

References

  1. Errors with Copilot Studio and MCP? – Are you Stateless? | Doy's Microsoft 365 and Azure Dev Blog — Original source explaining session errors and stateless workaround
  2. My Adventures in Building and Understanding MCP for Microsoft 365 Copilot — Foundational MCP server development post by Simon Doy
  3. How to: Build a Custom MCP Server with the .NET MCP SDK, Host as an Azure Container and Connect to Copilot Studio — Detailed tutorial on MCP server deployment
  4. ModelContextProtocol.AspNetCore.HttpServerTransportOptions Documentation — Official .NET SDK documentation on transport options
  5. Microsoft 365 Copilot Extensibility Overview — Other insights and posts tagged with Copilot on Simon Doy’s blog