Skip to content

Add optional OAuth protection for the MCP endpoint - #22

Merged
stphnwlsh merged 30 commits into
mainfrom
feature/mcp-auth
Oct 28, 2026
Merged

stphnwlsh merged 30 commits into
mainfrom
feature/mcp-auth

Conversation

@stphnwlsh

@stphnwlsh stphnwlsh commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Built on #21. Lets the template protect /mcp with OAuth, following the MCP authorization spec. It stays off by default.

  • New Authentication settings (Authority, Audience, Scopes). When Authority is set the server adds JWT bearer validation plus the SDK's MCP authentication handler, and /mcp requires authorization.
  • Unauthenticated calls get a 401 whose WWW-Authenticate header points at /.well-known/oauth-protected-resource/mcp, which publishes the authorization server, resource and scopes so clients can sign in.
  • Template options --authority and --audience write the values into appsettings.json when a solution is created. Leaving them out gives the same open server as today.
  • Integration tests sign their own tokens to cover the 401, the metadata document, a wrong audience and an authenticated tool list.
  • README explains how to turn it on.

docker compose up now also starts the official MCP Inspector on
localhost:6274, already configured for the server over Streamable HTTP, so
the tools, their descriptions and input schemas can be browsed and run
without installing anything.
Rename the tools by resource (authors_list, movies_get, reviews_create
and so on), add titles and the read-only, destructive, idempotent and
open-world hints, and rewrite the descriptions and parameter names for
agents. The server instructions now describe the domain instead of
output formatting, the server info has a proper title and an absolute
icon URL, and not-found and validation errors tell the agent how to
recover.

The server now runs stateless at /mcp, and a tools/list test pins the
names, titles and hints.
Tools now return Application entities instead of JSON strings, with
UseStructuredContent so the SDK publishes an output schema and returns
structuredContent alongside the JSON text. The tool serializer uses
camelCase and the source-generated context, which was registered but
never used. reviews_update returns the updated review, reviews_delete
returns a small result object, and server_get_version returns an
object instead of a markdown table.
SearchMovies, SearchAuthors and SearchReviews return one page of results
with a total count and an opaque cursor for the next page. Movies and
authors match a case-insensitive search term, and reviews filter by
movie and author. Limits run from 1 to 50 with a default of 10, and
invalid cursors fail validation with a message that explains how to
get a valid one.
Replace the ten CRUD tools with six: movies_search, movies_get,
authors_search, reviews_list, reviews_write and reviews_delete. Searches
page through results ten at a time with a total count and a cursor,
return review counts and average stars instead of every nested review
unless asked, and put movie titles and author names next to their ids.
reviews_write creates a review, or replaces one when given its id, and
reviews_list can fetch a single review by id.
…tools

# Conflicts:
#	src/Presentation/Errors/ToolErrorFilter.cs
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.97%. Comparing base (18d1cd4) to head (d356153).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #22   +/-   ##
=======================================
  Coverage   98.97%   98.97%           
=======================================
  Files          67       68    +1     
  Lines         681      686    +5     
  Branches       40       41    +1     
=======================================
+ Hits          674      679    +5     
  Partials        7        7           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Conflicts:
#	tests/Presentation.Tests.Integration/ModelContextProtocolApplication.cs
# Conflicts:
#	src/Presentation/Serialization/AppJsonSerializerContext.cs
#	src/Presentation/Tools/AuthorTools.cs
#	src/Presentation/Tools/MovieTools.cs
#	src/Presentation/Tools/ReviewTools.cs
#	tests/Presentation.Tests.Integration/Tools/ReviewToolTests.cs
#	tests/Presentation.Tests.Unit/Tools/AuthorToolTests.cs
#	tests/Presentation.Tests.Unit/Tools/MovieToolTests.cs
#	tests/Presentation.Tests.Unit/Tools/ReviewToolTests.cs
# Conflicts:
#	src/Presentation/Extensions/WebApplicationBuilderExtensions.cs
@stphnwlsh
stphnwlsh merged commit b169bfc into main Oct 28, 2026
12 checks passed
@stphnwlsh
stphnwlsh deleted the feature/mcp-auth branch October 28, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants