Skip to content

Conversation

@joehan
Copy link
Contributor

@joehan joehan commented Jul 28, 2025

Description

Builds on #8900 , which added some tests which highlighted that we are doing a weird mix of ESM and CJS style imports in MCP server. To get the new tests working correctly, I've moved all these imports to CJS style. I also added a CHANGELOG entry.

platinumazure and others added 4 commits July 27, 2025 22:49
Add parentheses to ensure skipAutoAuth check happens before fallback to
"Application Default Credentials" string.

Also add unit tests to cover this logic and ensure correct behavior.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @joehan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on enhancing the robustness and consistency of the MCP server by standardizing its module import styles. It includes a critical bug fix for handling Application Default Credentials during user authentication and introduces new tests to validate this improved behavior, alongside minor documentation and changelog updates.

Highlights

  • Import Style Consistency: Standardized import paths across numerous MCP server files by removing the .js extension for local module imports (e.g., import { foo } from './bar.js' became import { foo } from './bar'). This change aims to resolve a mixed ESM/CJS import style issue.
  • Authentication Logic Fix: Corrected a logical error in src/mcp/index.ts within the FirebaseMcpServer.getAuthenticatedUser method. The fix addresses an operator precedence issue that prevented the MCP server from correctly identifying 'Application Default Credentials' when no explicit user was authenticated.
  • New Test Coverage: Added a new test file, src/mcp/index.spec.ts, to provide comprehensive unit test coverage for the FirebaseMcpServer.getAuthenticatedUser method, ensuring the corrected authentication logic functions as expected under various scenarios.
  • Documentation and Changelog Updates: Updated src/mcp/CONTRIBUTING.md to reflect the new import style in code examples. A new entry was also added to CHANGELOG.md to document the fix for the Application Default Credentials issue.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to standardize import styles to resolve issues highlighted by new tests. The changes primarily involve removing the .js extension from relative imports, which aligns with CJS conventions. However, for imports from @modelcontextprotocol/sdk/types, the .js extension is being added. This creates an inconsistent import pattern. My review includes suggestions to address this for better code clarity and maintainability. Additionally, I've noted a potential typo in the CHANGELOG.md issue reference. The bug fix for operator precedence in getAuthenticatedUser is a good catch and is well-tested by the new unit tests.

@@ -1,4 +1,4 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The PR description states the goal is to move all imports to CJS style, which typically means removing file extensions like .js. However, this change adds the .js extension to the import from @modelcontextprotocol/sdk/types. This appears to contradict the stated goal and introduces an inconsistency in import styles throughout the project.

Could you clarify why this change is needed? If it's not strictly necessary for CJS compatibility, please consider removing the extension to maintain a consistent style.

Suggested change
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";

@@ -1,4 +1,4 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to other files in this PR, the .js extension is being added to this import path. The PR description mentions a move to CJS-style imports, which usually don't include file extensions. This change appears inconsistent with that goal.

To maintain a uniform import style, please consider removing the .js extension if it's not strictly required.

Suggested change
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";

isGraphQLResponse,
} from "../../../dataconnect/types";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change adds a .js extension to the import, which is inconsistent with the PR's goal of standardizing on CJS-style imports (which typically omit file extensions). For consistency with the other changes in this PR that remove the extension, could you remove it here as well, unless it's required for a specific reason?

Suggested change
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";

@@ -1,4 +1,4 @@
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The addition of the .js extension here is inconsistent with the PR's stated goal of moving to CJS-style imports. Most other changes in this PR remove this extension from relative imports. To ensure consistency, please remove the extension from this import path as well.

Suggested change
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types";

Copy link
Contributor

@fredzqm fredzqm left a comment

Choose a reason for hiding this comment

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

Looks pretty low risk

@joehan joehan enabled auto-merge (squash) July 28, 2025 18:36
@joehan joehan merged commit 226c375 into master Jul 28, 2025
77 of 81 checks passed
@joehan joehan deleted the jh-esm-auth-fix branch July 28, 2025 18:41
@github-project-automation github-project-automation bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Jul 28, 2025
@platinumazure
Copy link
Contributor

@joehan Thanks for this!

Should this PR have closed #8896?

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