-
Notifications
You must be signed in to change notification settings - Fork 9
MCP - update_artist_socials #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sweetmantech
merged 2 commits into
test
from
sweetmantech/myc-3737-mcp-update_artist_socials
Dec 13, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { getSocialPlatformByLink } from "@/lib/artists/getSocialPlatformByLink"; | ||
| import { getUsernameFromProfileUrl } from "@/lib/socials/getUsernameFromProfileUrl"; | ||
| import { selectAccountSocials } from "@/lib/supabase/account_socials/selectAccountSocials"; | ||
| import { deleteAccountSocial } from "@/lib/supabase/account_socials/deleteAccountSocial"; | ||
| import { insertAccountSocial } from "@/lib/supabase/account_socials/insertAccountSocial"; | ||
| import { selectSocials } from "@/lib/supabase/socials/selectSocials"; | ||
| import { insertSocials } from "@/lib/supabase/socials/insertSocials"; | ||
| import type { AccountSocialWithSocial } from "@/lib/supabase/account_socials/selectAccountSocials"; | ||
|
|
||
| /** | ||
| * Updates artist socials by replacing existing socials for each platform type. | ||
| * | ||
| * @param artistId - The artist account ID | ||
| * @param profileUrls - Record mapping platform types to profile URLs | ||
| * @returns Array of updated account socials with joined social data | ||
| */ | ||
| export async function updateArtistSocials( | ||
| artistId: string, | ||
| profileUrls: Record<string, string>, | ||
| ): Promise<AccountSocialWithSocial[]> { | ||
| // Get current account socials (with no limit to get all) | ||
| const accountSocials = await selectAccountSocials(artistId, 0, 10000); | ||
|
|
||
| // Process each platform type | ||
| const profilePromises = Object.entries(profileUrls).map(async ([type, value]) => { | ||
| const socials = value ? await selectSocials({ profile_url: value }) : null; | ||
| const social = socials && socials.length > 0 ? socials[0] : null; | ||
| const existingSocial = (accountSocials || []).find( | ||
| (account_social: AccountSocialWithSocial) => | ||
| getSocialPlatformByLink(account_social.social?.profile_url || "") === type, | ||
| ); | ||
|
|
||
| // Delete existing social for this platform type if it exists | ||
| if (existingSocial && existingSocial.social?.id) { | ||
| await deleteAccountSocial(artistId, existingSocial.social.id); | ||
| } | ||
|
|
||
| // Insert new social if URL provided | ||
| if (value) { | ||
| if (social) { | ||
| // Social already exists, check if account_social relationship exists | ||
| const existing = (accountSocials || []).find( | ||
| (as: AccountSocialWithSocial) => as.social_id === social.id, | ||
| ); | ||
| if (!existing) { | ||
| await insertAccountSocial(artistId, social.id); | ||
| } | ||
| } else { | ||
| // Create new social record | ||
| const newSocials = await insertSocials([ | ||
| { | ||
| username: getUsernameFromProfileUrl(value), | ||
| profile_url: value, | ||
| }, | ||
| ]); | ||
| if (newSocials.length > 0) { | ||
| await insertAccountSocial(artistId, newSocials[0].id); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| await Promise.all(profilePromises); | ||
|
|
||
| // Return the updated account socials | ||
| const updated = await selectAccountSocials(artistId, 0, 10000); | ||
| return updated || []; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
| import { registerGetArtistSocialsTool } from "./registerGetArtistSocialsTool"; | ||
| import { registerUpdateArtistSocialsTool } from "./registerUpdateArtistSocialsTool"; | ||
|
|
||
| /** | ||
| * Registers all artist socials-related MCP tools on the server. | ||
| * | ||
| * @param server - The MCP server instance to register tools on. | ||
| */ | ||
| export const registerAllArtistSocialsTools = (server: McpServer): void => { | ||
| registerGetArtistSocialsTool(server); | ||
| registerUpdateArtistSocialsTool(server); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,3 +26,4 @@ export function registerGetArtistSocialsTool(server: McpServer): void { | |
| }, | ||
| ); | ||
| } | ||
|
|
||
66 changes: 66 additions & 0 deletions
66
lib/mcp/tools/artistSocials/registerUpdateArtistSocialsTool.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
| import { z } from "zod"; | ||
| import { updateArtistSocials } from "@/lib/artist/updateArtistSocials"; | ||
| import { getSocialPlatformByLink } from "@/lib/artists/getSocialPlatformByLink"; | ||
| import { getToolResultSuccess } from "@/lib/mcp/getToolResultSuccess"; | ||
| import { getToolResultError } from "@/lib/mcp/getToolResultError"; | ||
|
|
||
| const updateArtistSocialsSchema = z.object({ | ||
| artistId: z | ||
| .string() | ||
| .min(1, "Artist account ID is required") | ||
| .describe("The artist's account ID to update socials for."), | ||
| urls: z | ||
| .array(z.string()) | ||
| .describe( | ||
| "An array of social profile URLs to associate with the artist. The platform will be inferred automatically.", | ||
| ), | ||
| }); | ||
|
|
||
| type UpdateArtistSocialsArgs = z.infer<typeof updateArtistSocialsSchema>; | ||
|
|
||
| /** | ||
| * Registers the "update_artist_socials" tool on the MCP server. | ||
| * Updates the artist_socials records for an artist. | ||
| * | ||
| * @param server - The MCP server instance to register the tool on. | ||
| */ | ||
| export function registerUpdateArtistSocialsTool(server: McpServer): void { | ||
| server.registerTool( | ||
| "update_artist_socials", | ||
| { | ||
| description: `Update the artist_socials records for an artist. Provide the artistId and an array of social profile URLs. The tool will infer the platform for each URL and update the artist's socials accordingly.`, | ||
| inputSchema: updateArtistSocialsSchema, | ||
| }, | ||
| async (args: UpdateArtistSocialsArgs) => { | ||
| try { | ||
| // Map each URL to its platform type | ||
| const profileUrls: Record<string, string> = {}; | ||
| for (const url of args.urls) { | ||
| const platform = getSocialPlatformByLink(url); | ||
| if (platform && platform !== "NONE") { | ||
| profileUrls[platform] = url; | ||
| } | ||
| } | ||
|
|
||
| const socials = await updateArtistSocials(args.artistId, profileUrls); | ||
|
|
||
| const response = { | ||
| success: true, | ||
| message: "Artist socials updated successfully.", | ||
| socials, | ||
| }; | ||
|
|
||
| return getToolResultSuccess(response); | ||
| } catch (error) { | ||
| console.error("Error updating artist socials:", error); | ||
| const errorMessage = | ||
| error instanceof Error | ||
| ? error.message | ||
| : "Failed to update artist socials."; | ||
| return getToolResultError(errorMessage); | ||
| } | ||
| }, | ||
| ); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import supabase from "../serverClient"; | ||
|
|
||
| /** | ||
| * Deletes an account_social record by account ID and social ID. | ||
| * | ||
| * @param accountId - The account ID | ||
| * @param socialId - The social ID | ||
| * @returns True if successful, false otherwise | ||
| */ | ||
| export async function deleteAccountSocial(accountId: string, socialId: string): Promise<boolean> { | ||
| const { error } = await supabase | ||
| .from("account_socials") | ||
| .delete() | ||
| .eq("account_id", accountId) | ||
| .eq("social_id", socialId); | ||
|
|
||
| if (error) { | ||
| console.error("[ERROR] deleteAccountSocial:", error); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import supabase from "../serverClient"; | ||
| import type { Tables } from "@/types/database.types"; | ||
|
|
||
| /** | ||
| * Inserts a new account_social record. | ||
| * | ||
| * @param accountId - The account ID | ||
| * @param socialId - The social ID | ||
| * @returns The inserted account_social record, or null if failed | ||
| */ | ||
| export async function insertAccountSocial( | ||
| accountId: string, | ||
| socialId: string, | ||
| ): Promise<Tables<"account_socials"> | null> { | ||
| const { data, error } = await supabase | ||
| .from("account_socials") | ||
| .insert({ account_id: accountId, social_id: socialId }) | ||
| .select("*") | ||
| .single(); | ||
|
|
||
| if (error) { | ||
| console.error("[ERROR] insertAccountSocial:", error); | ||
| return null; | ||
| } | ||
|
|
||
| return data || null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import supabase from "../serverClient"; | ||
| import type { Tables, TablesInsert } from "@/types/database.types"; | ||
|
|
||
| /** | ||
| * Inserts one or more social records. | ||
| * | ||
| * @param socials - Array of social data to insert | ||
| * @returns Array of inserted social records | ||
| */ | ||
| export async function insertSocials( | ||
| socials: TablesInsert<"socials">[], | ||
| ): Promise<Tables<"socials">[]> { | ||
| const { data, error } = await supabase.from("socials").insert(socials).select("*"); | ||
|
|
||
| if (error) { | ||
| console.error("[ERROR] insertSocials:", error); | ||
| return []; | ||
| } | ||
|
|
||
| return data || []; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.