Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@
return {};
});

this.detectProjectRoot();

Check warning on line 149 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
this.detectActiveFeatures();

Check warning on line 150 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

/** Wait until initialization has finished. */
ready() {

Check warning on line 154 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
if (this._ready) return Promise.resolve();
return new Promise((resolve, reject) => {
this._readyPromises.push({ resolve: resolve as () => void, reject });
Expand All @@ -162,19 +162,19 @@
return this.clientInfo?.name ?? (isFirebaseStudio() ? "Firebase Studio" : "<unknown-client>");
}

private get clientConfigKey() {

Check warning on line 165 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
return `mcp.clientConfigs.${this.clientName}:${this.startupRoot || process.cwd()}`;
}

getStoredClientConfig(): ClientConfig {
return configstore.get(this.clientConfigKey) || {};

Check warning on line 170 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
}

updateStoredClientConfig(update: Partial<ClientConfig>) {

Check warning on line 173 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
const config = configstore.get(this.clientConfigKey) || {};

Check warning on line 174 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const newConfig = { ...config, ...update };

Check warning on line 175 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
configstore.set(this.clientConfigKey, newConfig);
return newConfig;

Check warning on line 177 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
}

async detectProjectRoot(): Promise<string> {
Expand Down Expand Up @@ -274,7 +274,7 @@
return getProjectId(await this.resolveOptions());
}

async getAuthenticatedUser(skipAutoAuth: boolean = false): Promise<string | null> {

Check warning on line 277 in src/mcp/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Type boolean trivially inferred from a boolean literal, remove type annotation
try {
this.log("debug", `calling requireAuth`);
const email = await requireAuth(await this.resolveOptions(), skipAutoAuth);
Expand Down Expand Up @@ -424,6 +424,7 @@
}

async mcpListResources(): Promise<ListResourcesResult> {
await trackGA4("mcp_read_resource", { resource_name: "__list__" });
return {
resources: resources.map((r) => r.mcp),
};
Expand Down
6 changes: 5 additions & 1 deletion src/mcp/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { init_firestore_rules } from "./guides/init_firestore_rules";
import { init_hosting } from "./guides/init_hosting";
import { init_rtdb } from "./guides/init_rtdb";
import { ServerResource, ServerResourceTemplate } from "../resource";
import { trackGA4 } from "../../track";

export const resources = [
init_backend,
Expand All @@ -27,6 +28,7 @@ export const resourceTemplates = [docs];
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

): Promise<
| ({
result: ReadResourceResult;
Expand All @@ -39,16 +41,18 @@ export async function resolveResource(
// check if an exact resource name matches first
const resource = resources.find((r) => r.mcp.uri === uri);
if (resource) {
if (track) void trackGA4("mcp_read_resource", { resource_name: uri });
const result = await resource.fn(uri, ctx);
return { type: "resource", mcp: resource.mcp, result };
}

// then check if any templates match
const template = resourceTemplates.find((rt) => rt.match(uri));
if (template) {
if (track) void trackGA4("mcp_read_resource", { resource_name: uri });
const result = await template.fn(uri, ctx);
return { type: "template", mcp: template.mcp, result };
}

if (track) void trackGA4("mcp_read_resource", { resource_name: uri, not_found: "true" });
return null;
}
2 changes: 2 additions & 0 deletions src/mcp/tools/core/read_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod";
import { tool } from "../../tool";
import { resolveResource, resources } from "../../resources";
import { toContent } from "../../util";
import { trackGA4 } from "../../../track";

export const read_resources = tool(
{
Expand All @@ -24,6 +25,7 @@ export const read_resources = tool(
},
async ({ uris }, ctx) => {
if (!uris?.length) {
void trackGA4("mcp_read_resource", { resource_name: "__list__" });
return toContent(
resources
.map(
Expand Down
3 changes: 2 additions & 1 deletion src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type cliEventNames =
| "mcp_list_tools"
| "mcp_client_connected"
| "mcp_list_prompts"
| "mcp_get_prompt";
| "mcp_get_prompt"
| "mcp_read_resource";
type GA4Property = "cli" | "emulator" | "vscode";
interface GA4Info {
measurementId: string;
Expand Down
Loading