modelcontextprotocol / modelcontextprotocol/csharp-sdk

Alternative to `RunSessionHandler` for accessing MCP servers

Open
#1,416 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

blocked enhancement needs confirmation P2
Dominant language
C#
Stars
4.5k
Forks
814
Avg merge
9d 19h
Merged PRs (30d)
4

Description

Now that RunSessionHandler has been marked as experimental, what is the correct way to access the MCP servers in order to send notifications at a later time?

We currently have:

var mcpServers = new ConcurrentDictionary<string, McpServer>();

options.RunSessionHandler = async (_, mcpServer, token) =>
{
    if (mcpServer.SessionId == null)
    {
        // There is no sessionId if serverOptions.Stateless is true.
        await mcpServer.RunAsync(token);
        return;
    }

    try
    {
        mcpServers[mcpServer.SessionId] = mcpServer;
        await mcpServer.RunAsync(token);
    }
    finally
    {
        // This code runs when the session ends.
        mcpServers.TryRemove(mcpServer.SessionId, out var _);
    }
};

We are then able to send notifications to the active servers.

(initially posted here)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the RunSessionHandler and McpServer APIs, especially McpServer.SessionId and RunAsync, and compare them with the discussion linked from issue 1382. Determine the supported way to retain access to active MCP servers and send later notifications, including how stateless servers should be handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.