Skip to content

Allow MCP to use ADC - #8735

Merged
joehan merged 6 commits into
masterfrom
jh-mcp-adc
Jun 10, 2025
Merged

joehan merged 6 commits into
masterfrom
jh-mcp-adc

Conversation

@joehan

@joehan joehan commented Jun 10, 2025

Copy link
Copy Markdown
Member

Description

Fixes #8671.

Scenarios Tested

Ran firebase logout, gcloud auth application-default login, and then tested a tool that required auth and confirmed that it did not error out.

Comment thread src/mcp/index.ts Outdated
return mcpAuthError();
if (tool.mcp._meta?.requiresAuth) {
try {
await requireAuth(await this.resolveOptions());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How it is different then calling getAuthenticatedUser()?

  async getAuthenticatedUser(): Promise<string | null> {
    try {
      return await requireAuth(await this.resolveOptions());
    } catch (e) {
      return null;
    }
  }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correct me if I am wrong

It sounds like getAuthenticatedUser() currently returns:

  • string for firebase login
  • null for gcloud auth application-default login
  • Throw error if there is neither

Should we document that clearly in requireAuth().

Maybe change this.getAuthenticatedUser() to encode that information property

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

requireAuth can return null when you are authenticated via a service account, but it errors when the user is not authenticated. getAuthenticated catches those errors and returns null. Under the previous logic, this triggered the conditional that returned mcpAuthError()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call - refactored this. Now, getAuthenticatedUser() returns:
email for firebase login
'Application default credentials when using ADC
null for gcloud auth application-default login

and we skip the redundant requireAuth call.

@joehan
joehan requested a review from fredzqm June 10, 2025 18:33
Comment thread src/mcp/index.ts Outdated
try {
return await requireAuth(await this.resolveOptions());
const email = await requireAuth(await this.resolveOptions());
return email ?? "Application default credentials";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: "Application Default Credentials"

Could you also update the tsdoc on requireAuth? It wasn't obvious what null means reading it.

Thanks!

@fredzqm fredzqm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@joehan
joehan enabled auto-merge (squash) June 10, 2025 21:15
@joehan
joehan merged commit 8b8b9ca into master Jun 10, 2025
@joehan
joehan deleted the jh-mcp-adc branch June 10, 2025 22:13
@github-project-automation github-project-automation Bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Jun 10, 2025
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.

[MCP] MCP server not auth with Application Default Credentials (ADC)

2 participants