diff --git a/lib/mcp/oauth/__tests__/registerFullOAuthTools.test.ts b/lib/mcp/oauth/__tests__/registerFullOAuthTools.test.ts index 9dc49300e..6cc36fc49 100644 --- a/lib/mcp/oauth/__tests__/registerFullOAuthTools.test.ts +++ b/lib/mcp/oauth/__tests__/registerFullOAuthTools.test.ts @@ -2,6 +2,15 @@ import { describe, it, expect, vi } from "vitest"; import { z } from "zod"; import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { registerFullOAuthTools } from "../registerFullOAuthTools"; +import { registerGetArtistSocialsTool } from "../../tools/artistSocials/registerGetArtistSocialsTool"; + +const socials = vi.hoisted(() => { + process.env.PRIVY_PROJECT_SECRET = "test"; + return vi.fn(); +}); +vi.mock("@/lib/auth/validateAuthContext", () => ({ validateAuthContext: vi.fn() })); +vi.mock("@/lib/artist/getArtistSocials", () => ({ getArtistSocials: socials })); +vi.mock("@/lib/supabase/serverClient", () => ({ default: {} })); const operation = vi.fn(async (args: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(args) }], @@ -50,8 +59,8 @@ vi.mock("../../tools", () => ({ { inputSchema: z.object({ active: z.boolean() }) }, operation, ); + registerGetArtistSocialsTool(server); for (const name of [ - "get_artist_socials", "artist_deep_research", "spotify_deep_research", "get_catalog_playcount_history", @@ -120,6 +129,37 @@ describe("full OAuth registry", () => { expect(registered.has("spotify_deep_research")).toBe(false); expect(registered.has("ingestion")).toBe(false); }); + it("reads artist socials through the real tool registration with OAuth-bound access", async () => { + const { registered, prepare } = setup(); + const tool = registered.get("get_artist_socials")!; + const artist_account_id = "artist-listed-for-owner"; + const profile = { + status: "success", + socials: [{ username: "saved-profile", follower_count: 42 }], + pagination: { page: 1, limit: 20, total_count: 1, total_pages: 1 }, + }; + socials.mockResolvedValue(profile); + + const result = await tool.run({ artist_account_id }, extra); + expect(result.isError).toBeFalsy(); + const expectedArgs = { artist_account_id, page: 1, limit: 20 }; + expect(prepare).toHaveBeenCalledExactlyOnceWith("get_artist_socials", expectedArgs, "owner"); + expect(socials).toHaveBeenCalledExactlyOnceWith(expectedArgs); + expect(JSON.parse(result.content[0].text)).toEqual(profile); + + socials.mockClear(); + const custom = { artist_account_id, page: 2, limit: 5, history: 14 }; + expect((await tool.run(custom, extra)).isError).toBeFalsy(); + expect(socials).toHaveBeenCalledExactlyOnceWith(custom); + + socials.mockClear(); + prepare.mockRejectedValueOnce(new Error("Artist access denied")); + expect((await tool.run({ artist_account_id: "outside-workspace" }, extra)).isError).toBe(true); + expect( + (await tool.run({ artist_account_id, account_id: "different-owner" }, extra)).isError, + ).toBe(true); + expect(socials).not.toHaveBeenCalled(); + }); it.each([ undefined, { ...access, scopes: ["mcp:read", "mcp:write"] }, diff --git a/lib/mcp/oauth/fullOAuthToolPolicy.ts b/lib/mcp/oauth/fullOAuthToolPolicy.ts index af20320ac..775ba57e4 100644 --- a/lib/mcp/oauth/fullOAuthToolPolicy.ts +++ b/lib/mcp/oauth/fullOAuthToolPolicy.ts @@ -40,7 +40,12 @@ export const fullOAuthToolPolicy: Record = { get_artist_posts: { readOnly: true, destructive: false, openWorld: false }, get_scraper_results: { readOnly: true, destructive: false, openWorld: false }, scrape_artist_socials: { readOnly: false, destructive: true, openWorld: true }, - get_artist_socials: { readOnly: true, destructive: false, openWorld: false }, + get_artist_socials: { + readOnly: true, + destructive: false, + openWorld: false, + notice: "Use the artist account_id returned by list_artists as artist_account_id.", + }, artist_deep_research: { readOnly: true, destructive: false, openWorld: false }, spotify_deep_research: { readOnly: true, destructive: false, openWorld: false }, get_spotify_album: { readOnly: true, destructive: false, openWorld: true }, diff --git a/lib/mcp/oauth/registerFullOAuthTools.ts b/lib/mcp/oauth/registerFullOAuthTools.ts index 61056589e..206230d4b 100644 --- a/lib/mcp/oauth/registerFullOAuthTools.ts +++ b/lib/mcp/oauth/registerFullOAuthTools.ts @@ -36,7 +36,11 @@ export function registerFullOAuthTools( ) { const register = ( name: string, - config: { description?: string; inputSchema: z.ZodType; annotations?: Record }, + config: { + description?: string; + inputSchema: z.ZodType | z.ZodRawShape; + annotations?: Record; + }, handler: (args: Args, extra: Extra) => Promise, operation?: { name: string; @@ -102,13 +106,15 @@ export function registerFullOAuthTools( } : fullOAuthToolPolicy[name]; if (!policy) throw new Error(`Missing delegated policy for ${name}`); - const originalObject = - config.inputSchema instanceof z.ZodObject ? config.inputSchema : undefined; + // The MCP SDK accepts raw Zod shapes. The OAuth adapter also parses them itself. + const registeredSchema = + config.inputSchema instanceof z.ZodType ? config.inputSchema : z.object(config.inputSchema); + const originalObject = registeredSchema instanceof z.ZodObject ? registeredSchema : undefined; // External agents need not create a Recoup chat merely to send an email. const sourceSchema = name === "send_email" && originalObject ? originalObject.extend({ room_id: originalObject.shape.room_id.optional() }) - : config.inputSchema; + : registeredSchema; const object = sourceSchema instanceof z.ZodObject ? sourceSchema : undefined; const hasOwner = !!object && "account_id" in object.shape; const inputSchema = object