modelcontextprotocol / modelcontextprotocol/csharp-sdk

Expose OAuth metadata, pass token to API without validation

Offen
#893 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

area-auth enhancement P2 ready for work
Vorherrschende Sprache
C#
Sterne
4.5k
Forks
814
Ø Merge
9 T. 19 Std.
Gemergte PRs (30 T.)
4

Beschreibung

I'm trying to create an MCP server that is simply a wrapper on top of an existing API, for example some Google API. I want the MCP server to expose corresponding authorization metadata (authorization server URL etc.) so the clients using this MCP can prompt the user to authenticate. However, I do not want to validate the Google token myself, and instead I just want to pass it as is to the corresponding Google API, which can do all the necessary validation on its side.

I tried following the ProtectedMcpServer example and was able to expose the authorization metadata, which seems to work pretty well, and my MCP client is able to authenticate and obtain a valid Google access token and send a valid Authorization header to the MCP.

But the issue was that the sample app also tries to validate the token, which fails because the token Google generates is not a valid JWT token (has only one dot in it). I was able to work around that by providing my own TokenHandler which always returns success, then I hit another issue when the framework tries to create an AuthenticationTicket, for which I had to set a Principal object and Success result in the OnMessageReceived event. But now I'm still getting 403 since some authorization is still taking place, and I'm not sure how to disable it, while still keeping OAuth metadata for MCP clients.

Is there any way to get this to work and just let the access token be passed to the underlying API without any additional validation? Or am I doing something completely wrong that I shouldn't be doing, which is not supported and is intentionally made hard to work around?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem Beispiel samples/ProtectedMcpServer und verfolge den Token-Validierungs- und Autorisierungsablauf rund um den benutzerdefinierten TokenHandler und das OnMessageReceived-Ereignis. Reproduziere das Verhalten mit dem Nicht-JWT-Google-Zugriffstoken und ermittle, ob der Server OAuth-Metadaten beibehalten kann, während er das Token ohne lokale Validierung weiterleitet. Als erledigt gilt, wenn das unterstützte Verhalten oder die Einschränkung demonstriert und dokumentiert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
api, authentication
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.