modelcontextprotocol / modelcontextprotocol/csharp-sdk
Not able to customize the url '.well-known/oauth-protected-resource' behind AKS/nginx ingress
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 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
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.
Research direction
Start with the AddMcp ResourceMetadata configuration and app.MapMcp("/api/mcp") entry points, then trace how the WWW-Authenticate resource_metadata URL is produced when deployed behind an AKS/nginx ingress path. Reproduce the /sanjayd/api/mcp flow and verify that clients can retrieve metadata with the base route preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, kubernetes, nginx
- Domain
- api, authentication, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100