Static resources whose URIs differ only in the fragment or user info collapse into one

Aperta Adatta ai principianti
#1,970 4 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@halter73 ci sta già lavorando.

Dal 11/11/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Inizia con UriTemplateComparer in UriTemplate.cs intorno alle righe 502-519 e ai suoi test esistenti sulla distinzione tra maiuscole e minuscole dell'host; la modifica proposta aggiunge il confronto di fragment e user-info. Poi controlla il percorso di registrazione resource in McpServerOptionsSetup.cs:63 e gli usi downstream del comparatore in AIFunctionMcpServerResource.cs:325 e McpClient.Methods.cs:832. Aggiungi un test di regressione in McpServerResourceTests con due risorse che differiscono solo per il fragment e una lettura della seconda; fatto quando entrambe sono elencate e ogni lettura restituisce il proprio body.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

P2

Two static resources whose URIs differ only in the fragment collapse into one. WithResources silently drops the second, and reading it returns the first.

Repro at 5221939, in-process over two Pipes:

services.AddMcpServer().WithResources([
    McpServerResource.Create(() => "intro text", new() { UriTemplate = "docs://guide#intro", Name = "intro" }),
    McpServerResource.Create(() => "setup text", new() { UriTemplate = "docs://guide#setup", Name = "setup" }),
]);
// ...McpServer.Create over StreamServerTransport, McpClient.CreateAsync over StreamClientTransport
foreach (var r in await client.ListResourcesAsync()) Console.WriteLine($"listed: {r.Uri}");
var read = await client.ReadResourceAsync("docs://guide#setup");
$ dotnet run -c Release      # net10.0, SDK 10.0.403, ProjectReference to src/ModelContextProtocol at 5221939
listed: docs://guide#intro
read docs://guide#setup -> intro text

Expected: both listed, and the read returns setup text. A server exposing one resource per heading anchor loses every section after the first, with no error. The spec says each resource "is uniquely identified by a URI" (server/resources), and RFC 3986 section 3 puts the fragment in it. Section 3.5 strips it for dereference, not for two entries a server registered.

UriTemplateComparer (UriTemplate.cs:502) says it uses "regular System.Uri equality comparison (host name is case insensitive)", and its tests cover host case only. Uri.Equals also ignores UserInfo and Fragment, so docs://alice@host/x and docs://bob@host/x collide too. McpServerOptionsSetup.cs:63 uses TryAdd, so nothing throws.

I'd keep System.Uri and add && uri1.UserInfo == uri2.UserInfo && uri1.Fragment == uri2.Fragment at line 519:

$ dotnet run -c Release      # same app, with that change at UriTemplate.cs:519
listed: docs://guide#intro
listed: docs://guide#setup
read docs://guide#setup -> setup text
# not run: test suite with the change

The comparer also backs IsMatch (AIFunctionMcpServerResource.cs:325) and the SubscribeToResourceAsync filter (McpClient.Methods.cs:832), so a read or update for docs://guide#x would stop matching a static docs://guide. That fits the spec but changes behavior for clients sending fragments today. Shall I open that pull request with a test in McpServerResourceTests?

Lingua principale
C#
Stelle
4.6k
Fork
849
Merge medio
1g 16h
PR unite (30g)
24

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/csharp-sdk

Tutte le issue di modelcontextprotocol/csharp-sdk

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.