Skip to content

Conversation

@ashleyhindle
Copy link
Collaborator

@ashleyhindle ashleyhindle commented Sep 8, 2025

What & Why

  • ReorderJsonAccept Middleware
    We need this for MCP routes so the 'authenticate' middleware returns a JSON 401, even if the JSON isn't the first preference in the 'Accept' header.
    This happens in VS Code for example where its Accept header asks for text-event-stream first, then application/json, but it still expects a JSON 401 response or it breaks.
  • AddWwwAuthenticateHeader Middleware
    We need this to signal to the MCP client where to go to be able to authenticate the user. This is an OAuth requirement, but we return it for Sanctum also with an error message to aid debugging.

How I tested

  1. Used Locket with OAuth and Sanctum

ashleyhindle and others added 10 commits September 8, 2025 16:55
We need this for MCP routes so the 'authenticate' middleware returns a JSON 401, even if the JSON isn't the first preference in the 'Accept' header.

This happens in VS Code for example where its Accept header asks for text-event-stream first, then application/json, but it still expects a JSON 401 response or it breaks.
MCP specification expects 202 status code to empty responses from pings/notifications
@ashleyhindle ashleyhindle marked this pull request as ready for review September 8, 2025 19:18
@ashleyhindle ashleyhindle changed the title feat: add reorder JSON accept middleware feat: tested Sanctum support Sep 8, 2025
@ashleyhindle ashleyhindle merged commit 83bab33 into main Sep 15, 2025
@ashleyhindle ashleyhindle deleted the ai-121-sanctum-auth-works-great branch September 15, 2025 08:11
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