Is there a way to run multiple stateful MCP servers?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp, redis
- Domain
- api, backend, distributed-systems
Research direction
Start with StatefulSessionManager and the ISessionStorage, SessionMiddleware, and MapMcp entry points shown in the issue. Trace how session IDs are stored and retrieved across multiple server instances, then determine what shared storage behavior is needed so multiple stateful MCP servers no longer produce "Session id not found" errors.
Written by the indexing model from the issue text.
Description
As the title says, is there anyway to operate multiple stateful MCP servers without running into "Session id not found" errors?
It looks like the "session id not found" error stems from caching session ids in an in-memory dictionary in StatefulSessionManager. Is there a way in the API to, may be, swap that with Redis or use AspNetCore's default session management with a shared cache with the MCP server?
Something along the lines of (which is not working at the moment)
class Program
{
static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<SessionSettings>(
builder.Configuration.GetSection(SessionSettings.SectionName));
var sessionConfig = builder.Configuration
.GetSection(SessionSettings.SectionName)
.Get<SessionSettings>() ?? new SessionSettings();
if (sessionConfig.StorageType.Equals("Redis", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(sessionConfig.RedisConnectionString))
throw new InvalidOperationException("Redis connection string is required");
builder.Services.AddSingleton<ISessionStorage>(_ =>
new RedisSessionStorage(sessionConfig.RedisConnectionString));
}
builder.Services.AddMcpServer()
.WithHttpTransport()
.WithToolsFromAssembly();
var app = builder.Build();
app.UseMiddleware<SessionMiddleware>();
app.MapMcp();
app.Run("http://localhost:3000");
}
}
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/csharp-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelcontextprotocol/csharp-sdk#1867 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
modelcontextprotocol/csharp-sdk#1840 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelcontextprotocol/csharp-sdk#1836 ·
-
enhancement needs confirmation
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
modelcontextprotocol/csharp-sdk#678 · 1 comment ·
-
enhancement needs confirmation P3 ready for work
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
modelcontextprotocol/csharp-sdk#515 · 6 comments · 3 reactions ·
All issues in modelcontextprotocol/csharp-sdk
Similar issues
-
effort:S P3 refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nightscout/nocturne#1532 ·
-
core dependencies
Difficulty 1/5 Under an hour Newbie friendliness 80/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
C#/.NET Roslyn LSP Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
DotNetNext/SqlSugar#1458 ·