Hide Analytics section when GA4 OAuth app is pending (#475)
This commit is contained in:
parent
75aec8424f
commit
72eaa09c32
@ -28,10 +28,12 @@ export function GoogleAnalyticsConnectionCard({
|
|||||||
projectId,
|
projectId,
|
||||||
onDismiss,
|
onDismiss,
|
||||||
dismissing = false,
|
dismissing = false,
|
||||||
|
heading,
|
||||||
}: {
|
}: {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
onDismiss?: () => void;
|
onDismiss?: () => void;
|
||||||
dismissing?: boolean;
|
dismissing?: boolean;
|
||||||
|
heading?: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const hosted = isHostedClientAuthMode();
|
const hosted = isHostedClientAuthMode();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@ -115,6 +117,8 @@ export function GoogleAnalyticsConnectionCard({
|
|||||||
if (hiddenPendingApproval) return null;
|
if (hiddenPendingApproval) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{heading}
|
||||||
<IntegrationConnectionCard
|
<IntegrationConnectionCard
|
||||||
title="Google Analytics"
|
title="Google Analytics"
|
||||||
icon={<GoogleAnalyticsLogo className="size-5" />}
|
icon={<GoogleAnalyticsLogo className="size-5" />}
|
||||||
@ -206,6 +210,7 @@ export function GoogleAnalyticsConnectionCard({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</IntegrationConnectionCard>
|
</IntegrationConnectionCard>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -63,8 +63,14 @@ export function ProjectSettings({ projectId }: { projectId: string }) {
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="google-analytics" className="space-y-3 scroll-mt-6">
|
<section id="google-analytics" className="space-y-3 scroll-mt-6">
|
||||||
<h2 className="text-sm font-medium text-base-content/50">Analytics</h2>
|
<GoogleAnalyticsConnectionCard
|
||||||
<GoogleAnalyticsConnectionCard projectId={projectId} />
|
projectId={projectId}
|
||||||
|
heading={
|
||||||
|
<h2 className="text-sm font-medium text-base-content/50">
|
||||||
|
Analytics
|
||||||
|
</h2>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<DangerSection project={project} canArchive={projects.length > 1} />
|
<DangerSection project={project} canArchive={projects.length > 1} />
|
||||||
|
|||||||
80
src/server/mcp/server.test.ts
Normal file
80
src/server/mcp/server.test.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { createOpenSeoMcpServer } from "./server";
|
||||||
|
|
||||||
|
const mcpServerMocks = vi.hoisted(() => ({
|
||||||
|
registerTool: vi.fn<(name: string, ...args: unknown[]) => void>(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("@modelcontextprotocol/server", () => ({
|
||||||
|
McpServer: class {
|
||||||
|
registerTool(name: string, ...args: unknown[]) {
|
||||||
|
mcpServerMocks.registerTool(name, ...args);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("cloudflare:workers", () => ({
|
||||||
|
DurableObject: vi.fn(),
|
||||||
|
env: {},
|
||||||
|
waitUntil: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("@/server/mcp/instrumentation", () => ({
|
||||||
|
instrumentMcpToolHandler: (
|
||||||
|
_name: string,
|
||||||
|
_outputSchema: unknown,
|
||||||
|
handler: unknown,
|
||||||
|
) => handler,
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("createOpenSeoMcpServer", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mcpServerMocks.registerTool.mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not expose GA4-backed tools while OAuth approval is pending", () => {
|
||||||
|
createOpenSeoMcpServer({
|
||||||
|
openSeoAuth: {
|
||||||
|
userId: "user-1",
|
||||||
|
userEmail: "user@example.com",
|
||||||
|
organizationId: "org-1",
|
||||||
|
baseUrl: "https://example.com",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const registeredToolNames = mcpServerMocks.registerTool.mock.calls.map(
|
||||||
|
([name]) => name,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(registeredToolNames).toContain("whoami");
|
||||||
|
expect(registeredToolNames).toContain("get_search_console_performance");
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_organic_landing_pages",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_page_performance",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_key_events",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain("get_search_opportunities");
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_organic_overview",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_traffic_acquisition",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_measurement_health",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_ecommerce_performance",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_site_search",
|
||||||
|
);
|
||||||
|
expect(registeredToolNames).not.toContain(
|
||||||
|
"get_google_analytics_audience_breakdown",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -51,6 +51,7 @@ import {
|
|||||||
getSearchConsolePerformanceTool,
|
getSearchConsolePerformanceTool,
|
||||||
inspectUrlsTool,
|
inspectUrlsTool,
|
||||||
} from "@/server/mcp/tools/search-console-tools";
|
} from "@/server/mcp/tools/search-console-tools";
|
||||||
|
import { GA4_OAUTH_APP_PENDING } from "@/shared/ga4";
|
||||||
import {
|
import {
|
||||||
getAuditIssuesTool,
|
getAuditIssuesTool,
|
||||||
getAuditPagesTool,
|
getAuditPagesTool,
|
||||||
@ -166,6 +167,7 @@ export function createOpenSeoMcpServer(authProps: McpProps) {
|
|||||||
register(getKeywordMetricsTool);
|
register(getKeywordMetricsTool);
|
||||||
register(getSearchConsolePerformanceTool);
|
register(getSearchConsolePerformanceTool);
|
||||||
register(inspectUrlsTool);
|
register(inspectUrlsTool);
|
||||||
|
if (!GA4_OAUTH_APP_PENDING) {
|
||||||
register(getGoogleAnalyticsOrganicLandingPagesTool);
|
register(getGoogleAnalyticsOrganicLandingPagesTool);
|
||||||
register(getGoogleAnalyticsPagePerformanceTool);
|
register(getGoogleAnalyticsPagePerformanceTool);
|
||||||
register(getGoogleAnalyticsKeyEventsTool);
|
register(getGoogleAnalyticsKeyEventsTool);
|
||||||
@ -176,6 +178,7 @@ export function createOpenSeoMcpServer(authProps: McpProps) {
|
|||||||
register(getGoogleAnalyticsEcommercePerformanceTool);
|
register(getGoogleAnalyticsEcommercePerformanceTool);
|
||||||
register(getGoogleAnalyticsSiteSearchTool);
|
register(getGoogleAnalyticsSiteSearchTool);
|
||||||
register(getGoogleAnalyticsAudienceBreakdownTool);
|
register(getGoogleAnalyticsAudienceBreakdownTool);
|
||||||
|
}
|
||||||
register(runSiteAuditTool);
|
register(runSiteAuditTool);
|
||||||
register(getAuditStatusTool);
|
register(getAuditStatusTool);
|
||||||
register(getAuditIssuesTool);
|
register(getAuditIssuesTool);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user