Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Alternative to `RunSessionHandler` for accessing MCP servers

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

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.

Description

blocked enhancement needs confirmation P2

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)

Dominant language
C#
Stars
4.6k
Forks
817
Avg merge
8d 7h
Merged PRs (30d)
3

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from modelcontextprotocol/csharp-sdk

All issues in modelcontextprotocol/csharp-sdk

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.