Skip to content

Commit b23d480

Browse files
ashwinpvgSkCQ
authored andcommitted
Use google-auth-library to make oauth requests in SSE transport in typescript client.
- The library authenticates with Google oauth, we extract the request headers and attach it to the SSE transport. Change-Id: I67039203efb71dbc4f00ceb0788ffcf1baeeab52 Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/1011262 Reviewed-by: Jeff Yoon <[email protected]> Auto-Submit: Ashwin Verleker <[email protected]> Commit-Queue: Ashwin Verleker <[email protected]>
1 parent b9b7ac4 commit b23d480

File tree

6 files changed

+494
-5
lines changed

6 files changed

+494
-5
lines changed

mcp/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
include ../make/bazel.mk
22

33
run-auth-proxy:
4-
bazelisk run //kube/cmd/auth-proxy -- \
4+
bazelisk run -c dbg //kube/cmd/auth-proxy -- \
55
--prom-port=:20003 \
66
--role=editor=google.com \
77
--port=:8000 \
88
--target_port=:8080 \
99
--local \
1010
--self_sign_localhost_tls \
11-
--passive \
11+
--authtype=oauth2 \
1212
--use_http1
1313

1414
run-perf-mcp:

mcp/client/lib/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ts_library(
88
":settings_ts_lib",
99
"//:node_modules/@google/generative-ai",
1010
"//:node_modules/@modelcontextprotocol/sdk",
11+
"//:node_modules/google-auth-library",
1112
],
1213
)
1314

mcp/client/lib/mcp-client.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
44
import { ServerConfig } from './settings';
55
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
66
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
7+
import { GoogleAuth } from 'google-auth-library';
78

89
export class MCPClient {
910
private client: Client;
@@ -69,7 +70,16 @@ export class MCPClient {
6970
e instanceof Error ? e.message : String(e)
7071
}. Falling back to SSE.`
7172
);
72-
this.transport = new SSEClientTransport(new URL(serverConfig.url));
73+
const auth = new GoogleAuth({
74+
scopes: 'https://www.googleapis.com/auth/userinfo.email',
75+
});
76+
const client = await auth.getClient();
77+
const headers = await client.getRequestHeaders();
78+
this.transport = new SSEClientTransport(new URL(serverConfig.url), {
79+
requestInit: {
80+
headers: headers,
81+
},
82+
});
7383
}
7484
} else {
7585
throw new Error(`Invalid server config for ${serverName}: No command or URL provided.`);

0 commit comments

Comments
 (0)