Skip to content

feat: support oauth#214

Merged
shruti-mantri merged 7 commits intomainfrom
add-oauth-authz
Feb 4, 2026
Merged

feat: support oauth#214
shruti-mantri merged 7 commits intomainfrom
add-oauth-authz

Conversation

@shruti-mantri
Copy link
Collaborator

No description provided.

@husainhirani
Copy link
Collaborator

My main point here is that we currently have to pass accessToken everywhere so the client can retrieve it. We may want to find a way to avoid 'prop drilling.'

One idea is to create a context for every request using AsyncLocalStorage and just insert the accessToken there.

Ex.
const authContext = new AsyncLocalStorage();

function runWithAccessToken(accessToken, callback) {
return authContext.run(accessToken, callback);
}

This would have to be inserted in mcp-server somewhere.
Then, clients would be able to get the access token directly by calling:

export function getAccessToken() {
const store = authContext.getStore();
return store !== undefined ? store : GCLOUD_AUTH;
}

This would require a decent amount of changes. Maybe there's a better approach out there, so I'll leave it up to you to decide whether to fix the 'prop drilling' here or handle it as an action item later.

throw new Error(`Invalid audience: expected ${audience}`);
}

console.log('Access token verified successfully.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to https://github.com/GoogleCloudPlatform/cloud-run-mcp/pull/214/changes#r2764520428. I think we can get rid of all consoles for this function.

export const oauthMiddleware = async (req, res, next) => {
//If OAUTH_ENABLED is not true or the request is not a tools/call, skip the middleware
if (
process.env.OAUTH_ENABLED !== 'true' ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: Will OAUTH_ENABLED will always be a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its coming from env file. GCP_STDIO is also being checked in a similar fashion.

mcp-server.js Outdated
import { extractAccessToken } from './lib/util/helpers.js';
import { oauthMiddleware } from './lib/middleware/oauth.js';
import { config } from '@dotenvx/dotenvx';
config({ quiet: true, ignore: ['MISSING_ENV_FILE'] });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we format this code? i.e.
It can be placed after all imports. And a comment can be added above its use to dictate its use.

@shruti-mantri shruti-mantri merged commit eb34ece into main Feb 4, 2026
6 checks passed
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.

3 participants