modelcontextprotocol / modelcontextprotocol/csharp-sdk

Not able to customize the url '.well-known/oauth-protected-resource' behind AKS/nginx ingress

Ouverte
#643 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

area-auth bug help wanted needs confirmation P3
Langage dominant
C#
Étoiles
4.5k
Forks
814
Merge moyen
9 j 19 h
PR mergées (30 j)
4

Description

Describe the bug
When we enable OAuth (using Entra) for the MCP server it produces the well known resource url through '/.well-known/oauth-protected-resource'.

.AddMcp(options =>
{
    var metadata = new ModelContextProtocol.Authentication.ProtectedResourceMetadata()
    {
        Resource = new Uri(serverAddress + "api/mcp"),
        AuthorizationServers = { new Uri($"{instance}/{tenantId}/v2.0") },
        ScopesSupported = [$"{apiAppName}/Mcp.Access"],
    };

    options.ResourceMetadata = metadata;
});
...
...
app.MapMcp("/api/mcp").RequireAuthorization();

Now when we deploy this behind an ingress controller with path redirects, the MCP client doesn't have a way to know the modified resource url that it needs to connect.

E.g. if I deploy the server from this base route 'https://abc.azure.com/sanjayd' with ingress redirects, we can ideally reach the mcp server at 'https://abc.azure.com/sanjayd/api/mcp', and that will throw 401. But all clients including VS Code etc. now tries to connect to 'https://abc.azure.com/.well-known/oauth-protected-resource' to download the metadata. Ideally there should be a way to mention the base route for metadata while using ingress.

1st call from client: POST https://abc.azure.com/sanjayd/api/mcp -> returns 401 with 'www-authenticate' header like 'Bearer realm="McpAuth", resource_metadata="http://10.10.1.40/.well-known/oauth-protected-resource"'

2nd call from client: GET https://abc.azure.com/.well-known/oauth-protected-resource -> missing the 'sanjayd' part.

This works locally though as there is no ingress/re-route.

Any help is appreciated on how this will work with ingress.

Below are from a web client
Image

Image

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la configuration AddMcp ResourceMetadata et les points d’entrée app.MapMcp("/api/mcp"), puis suivez la manière dont l’URL resource_metadata de WWW-Authenticate est produite lorsque l’application est déployée derrière un chemin d’ingress AKS/nginx. Reproduisez le flux /sanjayd/api/mcp et vérifiez que les clients peuvent récupérer les métadonnées en conservant la route de base.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
azure, csharp, kubernetes, nginx
Domaine
api, authentication, cloud
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.