mcp: add client-side OAuth flow (#544)

This is a preliminary implementation of OAuth 2.1 for the client.

When a StreamableClientTransport encounters a 401 Unauthorized response
from the server, it initiates the OAuth flow described in thec
authorization section of the MCP spec

(https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization).
On success, the transport obtains an access token which it passes
to all subsequent requests.

Much remains to be done here:

* Resource Indicators, as described in section 2.5.1 of the MCP spec.

* All of this is unexported, so it is available only to our own
StreamingClientTransport. We should add API so people can use it
with their own transports.

* And, of course, tests. We should test against fake implementations
but also, if we can find any, real reference implementations.

For #19
Co-authored-by: Jonathan Amsterdam <jba@google.com>

---------

Co-authored-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Sam Thanawalla 2025-09-30 16:16:30 -04:00 • committed by GitHub
commit 069aae16df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

1
go.mod
View file

@ -7,5 +7,6 @@ require (
github.com/google/go-cmp v0.7.0
github.com/google/jsonschema-go v0.3.0
github.com/yosida95/uritemplate/v3 v3.0.2
golang.org/x/oauth2 v0.30.0
golang.org/x/tools v0.34.0
)