Skip to content

Conversation

joehan
Copy link
Contributor

@joehan joehan commented Oct 2, 2025

Description

Instrument read_resource with what resource was read.

Copy link
Contributor

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 integrates Google Analytics 4 (GA4) tracking into the read_resources tool. The primary goal is to gain better insights into how resources are being accessed and utilized. By adding a new mcp_read_resource event, the system can now record whether users are requesting a list of available resources or reading specific resource URIs, providing valuable data for usage analysis.

Highlights

  • Instrumentation: The read_resources tool has been instrumented to track resource access using Google Analytics 4 (GA4).
  • New GA4 Event: A new GA4 event, mcp_read_resource, has been introduced to specifically log when resources are read.
  • Resource Details: The mcp_read_resource event now includes a resource_name property, indicating either 'listAvaiable' when listing resources or the specific URI of the resource being read.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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 adds analytics instrumentation to the read_resource tool. The changes are well-implemented, but I've identified a couple of areas for improvement. There is a minor typo in an analytics event parameter which could affect data consistency. Additionally, there's an opportunity to improve performance within a loop by not awaiting a non-critical tracking call, allowing for concurrent execution.


const out: string[] = [];
for (const uri of uris) {
await trackGA4("mcp_read_resource", { resource_name: uri });
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Awaiting the trackGA4 call inside this loop makes the execution for each URI sequential, which can slow down the process if there are many URIs. Since trackGA4 is a non-critical analytics call and is designed to handle errors gracefully, you can safely call it without await. This allows the tracking call to run in the background, in parallel with the resolveResource call, improving overall performance.

Suggested change
await trackGA4("mcp_read_resource", { resource_name: uri });
trackGA4("mcp_read_resource", { resource_name: uri });

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, tho you may need to do void trackGA4(...)


const out: string[] = [];
for (const uri of uris) {
await trackGA4("mcp_read_resource", { resource_name: uri });
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, tho you may need to do void trackGA4(...)

export async function resolveResource(
uri: string,
ctx: McpContext,
track: boolean = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I personally prefer options objects even if we're not sure we'll ever add more because they make the code more self-documenting, but nbd either way

// check if an exact resource name matches first
const resource = resources.find((r) => r.mcp.uri === uri);
if (resource) {
track || (await trackGA4("mcp_read_resource", { resource_name: uri }));
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be track && not track ||? (same below)

Might prefer if (track) void trackGA4(...) for readability.

Same below.

@joehan joehan enabled auto-merge (squash) October 2, 2025 17:08
@joehan joehan merged commit 4725f2e into master Oct 2, 2025
48 checks passed
@joehan joehan deleted the jh-read-resources-metrics branch October 2, 2025 17:28
@github-project-automation github-project-automation bot moved this from Approved [PR] to Done in [Cloud] Extensions + Functions Oct 2, 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.

2 participants