modelcontextprotocol / modelcontextprotocol/csharp-sdk

Expose OAuth metadata, pass token to API without validation

Aperta
#893 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

area-auth enhancement P2 ready for work
Lingua principale
C#
Stelle
4.5k
Fork
814
Merge medio
9g 19h
PR unite (30g)
4

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia con l'esempio samples/ProtectedMcpServer e traccia il flusso di convalida del token e autorizzazione relativo al TokenHandler personalizzato e all'evento OnMessageReceived. Riproduci il comportamento con il token di accesso Google non JWT e determina se il server può conservare i metadati OAuth inoltrando al contempo il token senza convalida locale. Il lavoro è completato quando il comportamento supportato o la limitazione sono dimostrati e documentati.

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

Valutazione

Stack tecnologico
csharp
Ambito
api, authentication
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.