From 148b62826ccb6c58fa2a7d36b24be339ea756082 Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Sat, 13 Dec 2025 13:01:41 -0500 Subject: [PATCH] MCP - spotify_deep_research --- lib/mcp/tools/spotify/index.ts | 2 + .../registerGetSpotifyDeepResearchTool.ts | 77 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 lib/mcp/tools/spotify/registerGetSpotifyDeepResearchTool.ts diff --git a/lib/mcp/tools/spotify/index.ts b/lib/mcp/tools/spotify/index.ts index dabfe128e..d103f753a 100644 --- a/lib/mcp/tools/spotify/index.ts +++ b/lib/mcp/tools/spotify/index.ts @@ -3,6 +3,7 @@ import { registerGetSpotifySearchTool } from "./registerGetSpotifySearchTool"; import { registerGetSpotifyArtistTopTracksTool } from "./registerGetSpotifyArtistTopTracksTool"; import { registerGetSpotifyArtistAlbumsTool } from "./registerGetSpotifyArtistAlbumsTool"; import { registerGetSpotifyAlbumTool } from "./registerGetSpotifyAlbumTool"; +import { registerGetSpotifyDeepResearchTool } from "./registerGetSpotifyDeepResearchTool"; /** * Registers all Spotify-related MCP tools on the server. @@ -14,4 +15,5 @@ export const registerAllSpotifyTools = (server: McpServer): void => { registerGetSpotifyArtistTopTracksTool(server); registerGetSpotifyArtistAlbumsTool(server); registerGetSpotifyAlbumTool(server); + registerGetSpotifyDeepResearchTool(server); }; diff --git a/lib/mcp/tools/spotify/registerGetSpotifyDeepResearchTool.ts b/lib/mcp/tools/spotify/registerGetSpotifyDeepResearchTool.ts new file mode 100644 index 000000000..8264a4baa --- /dev/null +++ b/lib/mcp/tools/spotify/registerGetSpotifyDeepResearchTool.ts @@ -0,0 +1,77 @@ +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import { z } from "zod"; +import { getArtistSocials } from "@/lib/artist/getArtistSocials"; +import { getToolResultSuccess } from "@/lib/mcp/getToolResultSuccess"; +import { getToolResultError } from "@/lib/mcp/getToolResultError"; + +const SPOTIFY_DEEP_RESEARCH_REQUIREMENTS = ` + - popularity info (MANDATORY): + * Track popularity scores (0-100) for all tracks + * Average popularity across all tracks + * Most popular tracks ranked by popularity + * Popularity trends over time (if available) + - Spotify follower metrics (MANDATORY): + * Current total follower count for the artist on Spotify + - engagement info + - tracklist + - collaborators + - album art + - album name +`; + +// Zod schema for the MCP tool - matches the original tool interface +const getSpotifyDeepResearchSchema = z.object({ + artist_account_id: z.string().min(1, "Artist account ID is required"), +}); + +type GetSpotifyDeepResearchArgs = z.infer; + +/** + * Registers the "spotify_deep_research" tool on the MCP server. + * Performs deep research on an artist using a Spotify ID. + * + * @param server - The MCP server instance to register the tool on. + */ +export function registerGetSpotifyDeepResearchTool(server: McpServer): void { + server.registerTool( + "spotify_deep_research", + { + description: `Performs deep research on an artist using a Spotify ID. + + Required items in deep research document: + ${SPOTIFY_DEEP_RESEARCH_REQUIREMENTS}`, + inputSchema: getSpotifyDeepResearchSchema, + }, + async (args: GetSpotifyDeepResearchArgs) => { + try { + // Call getArtistSocials with default pagination (page 1, limit 20) + const result = await getArtistSocials({ + artist_account_id: args.artist_account_id, + page: 1, + limit: 20, + }); + + if (result.status === "error") { + return getToolResultError(result.message || "Failed to fetch artist socials"); + } + + // Format response to match the original tool's expected structure + const response = { + success: true, + artistSocials: { + socials: result.socials, + }, + artist_account_id: args.artist_account_id, + pagination: result.pagination, + }; + + return getToolResultSuccess(response); + } catch (error) { + console.error("Error performing Spotify deep research:", error); + return getToolResultError( + error instanceof Error ? error.message : "Failed to perform Spotify deep research", + ); + } + }, + ); +}