-
Notifications
You must be signed in to change notification settings - Fork 9
MCP - update_account_info #52
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 1 commit into
test
from
sweetmantech/myc-3736-mcp-update_account_info
Dec 13, 2025
Merged
Changes from all commits
Commits
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,98 @@ | ||
| import { selectAccounts } from "@/lib/supabase/accounts/selectAccounts"; | ||
| import { updateAccount } from "@/lib/supabase/accounts/updateAccount"; | ||
| import { selectAccountInfo } from "@/lib/supabase/account_info/selectAccountInfo"; | ||
| import { updateAccountInfo } from "@/lib/supabase/account_info/updateAccountInfo"; | ||
| import { insertAccountInfo } from "@/lib/supabase/account_info/insertAccountInfo"; | ||
| import type { Tables } from "@/types/database.types"; | ||
|
|
||
| export type Knowledge = { | ||
| url: string; | ||
| name: string; | ||
| type: string; | ||
| }; | ||
|
|
||
| export type ArtistProfile = Tables<"accounts"> & Tables<"account_info">; | ||
|
|
||
| /** | ||
| * Updates an artist profile (account and account_info). | ||
| * All fields are optional except artistId. | ||
| * | ||
| * @param artistId - The artist account ID | ||
| * @param image - Optional profile image URL | ||
| * @param name - Optional display name | ||
| * @param instruction - Optional custom instructions | ||
| * @param label - Optional label/role | ||
| * @param knowledges - Optional array of knowledge objects | ||
| * @returns The updated artist profile | ||
| */ | ||
| export async function updateArtistProfile( | ||
| artistId: string, | ||
| image: string, | ||
| name: string, | ||
| instruction: string, | ||
| label: string, | ||
| knowledges: Knowledge[] | null, | ||
| ): Promise<ArtistProfile> { | ||
| // Fetch current account | ||
| const currentAccounts = await selectAccounts(artistId); | ||
| const currentAccount = currentAccounts[0]; | ||
| if (!currentAccount) { | ||
| throw new Error("Artist does not exist"); | ||
| } | ||
|
|
||
| // Update account name if provided | ||
| if (name) { | ||
| const accountUpdate = { name }; | ||
| const updatedAccount = await updateAccount(artistId, accountUpdate); | ||
| if (!updatedAccount) { | ||
| throw new Error("Failed to update account"); | ||
| } | ||
| } | ||
|
|
||
| // Get or create account_info | ||
| const accountInfo = await selectAccountInfo(artistId); | ||
|
|
||
| if (accountInfo) { | ||
| // Update existing account_info | ||
| const infoUpdate: Partial<typeof accountInfo> = {}; | ||
| if (image) infoUpdate.image = image; | ||
| if (instruction) infoUpdate.instruction = instruction; | ||
|
|
||
| if (knowledges !== null && knowledges !== undefined) { | ||
| // Deduplicate knowledges by URL | ||
| const uniqueMap = new Map(knowledges.map(k => [k.url, k])); | ||
| infoUpdate.knowledges = Array.from(uniqueMap.values()); | ||
| } | ||
|
|
||
| if (label !== undefined) { | ||
| infoUpdate.label = label === "" ? null : label; | ||
| } | ||
|
|
||
| await updateAccountInfo(artistId, infoUpdate); | ||
| } else { | ||
| // Create new account_info | ||
| await insertAccountInfo({ | ||
| image: image || null, | ||
| instruction: instruction || null, | ||
| knowledges: knowledges || null, | ||
| label: label === "" ? null : label || null, | ||
| account_id: artistId, | ||
| }); | ||
| } | ||
|
|
||
| // Fetch and return the latest account and account_info | ||
| const [updatedAccounts, updatedAccountInfo] = await Promise.all([ | ||
| selectAccounts(artistId), | ||
| selectAccountInfo(artistId), | ||
| ]); | ||
|
|
||
| const account = updatedAccounts[0]; | ||
| if (!account || !updatedAccountInfo) { | ||
| throw new Error("Failed to fetch updated artist profile"); | ||
| } | ||
|
|
||
| return { | ||
| ...updatedAccountInfo, | ||
| ...account, | ||
| }; | ||
| } | ||
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,80 @@ | ||
| import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
| import { z } from "zod"; | ||
| import { updateArtistProfile } from "@/lib/artist/updateArtistProfile"; | ||
| import { getToolResultSuccess } from "@/lib/mcp/getToolResultSuccess"; | ||
| import { getToolResultError } from "@/lib/mcp/getToolResultError"; | ||
|
|
||
| const updateAccountInfoSchema = z.object({ | ||
| artistId: z | ||
| .string() | ||
| .min(1, "Artist account ID is required") | ||
| .describe( | ||
| "The artist_account_id to update. If not provided, check system prompt for the active artist_account_id.", | ||
| ), | ||
| image: z.string().optional().describe("(Optional) The new profile image URL for the artist."), | ||
| name: z.string().optional().describe("(Optional) The display name for the artist."), | ||
| instruction: z | ||
| .string() | ||
| .optional() | ||
| .describe("(Optional) Custom instructions for the artist's account."), | ||
| label: z.string().optional().describe("(Optional) The label or role for the artist."), | ||
| knowledges: z | ||
| .array( | ||
| z.object({ | ||
| url: z.string(), | ||
| name: z.string(), | ||
| type: z | ||
| .string() | ||
| .describe( | ||
| 'MIME type of the file, e.g., "text/plain" for TXT files, "application/pdf" for PDFs', | ||
| ), | ||
| }), | ||
| ) | ||
| .optional() | ||
| .describe( | ||
| "(Optional) Array of knowledge objects ({ url, name, type }) to be stored as the knowledge base or notes for the artist. The 'type' field must be a valid MIME type (e.g., 'text/plain' for TXT files).", | ||
| ), | ||
| }); | ||
|
|
||
| type UpdateAccountInfoArgs = z.infer<typeof updateAccountInfoSchema>; | ||
|
|
||
| /** | ||
| * Registers the "update_account_info" tool on the MCP server. | ||
| * Updates the account_info record for an artist. | ||
| * | ||
| * @param server - The MCP server instance to register the tool on. | ||
| */ | ||
| export function registerUpdateAccountInfoTool(server: McpServer): void { | ||
| server.registerTool( | ||
| "update_account_info", | ||
| { | ||
| description: `Update the account_info record for an artist. All fields are optional except for artistId. This tool is used to update the artist's profile image, name, instructions, label, and knowledge base. If artistId is not provided, use the active artist_account_id from the system prompt.`, | ||
| inputSchema: updateAccountInfoSchema, | ||
| }, | ||
| async (args: UpdateAccountInfoArgs) => { | ||
| try { | ||
| const artistProfile = await updateArtistProfile( | ||
| args.artistId, | ||
| args.image || "", | ||
| args.name || "", | ||
| args.instruction || "", | ||
| args.label || "", | ||
| args.knowledges || null, | ||
| ); | ||
|
|
||
| const response = { | ||
| success: true, | ||
| artistProfile, | ||
| message: `Account info updated successfully for account_id: ${artistProfile.id}`, | ||
| }; | ||
|
|
||
| return getToolResultSuccess(response); | ||
| } catch (error) { | ||
| console.error("Error updating account info:", error); | ||
| const errorMessage = | ||
| error instanceof Error ? error.message : "Failed to update account info"; | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import supabase from "../serverClient"; | ||
| import type { Tables } from "@/types/database.types"; | ||
|
|
||
| /** | ||
| * Retrieves account_info by account_id. | ||
| * | ||
| * @param accountId - The account ID | ||
| * @returns The account_info record, or null if not found | ||
| */ | ||
| export async function selectAccountInfo(accountId: string): Promise<Tables<"account_info"> | null> { | ||
| const { data, error } = await supabase | ||
| .from("account_info") | ||
| .select("*") | ||
| .eq("account_id", accountId) | ||
| .single(); | ||
|
|
||
| if (error || !data) { | ||
| return null; | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import supabase from "../serverClient"; | ||
| import type { Tables, TablesUpdate } from "@/types/database.types"; | ||
|
|
||
| /** | ||
| * Updates an account_info record. | ||
| * | ||
| * @param accountId - The account ID | ||
| * @param updates - Partial account_info data to update | ||
| * @returns The updated account_info record, or null if failed | ||
| */ | ||
| export async function updateAccountInfo( | ||
| accountId: string, | ||
| updates: TablesUpdate<"account_info">, | ||
| ): Promise<Tables<"account_info"> | null> { | ||
| const { data, error } = await supabase | ||
| .from("account_info") | ||
| .update(updates) | ||
| .eq("account_id", accountId) | ||
| .select("*") | ||
| .single(); | ||
|
|
||
| if (error) { | ||
| console.error("[ERROR] updateAccountInfo:", 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,18 @@ | ||
| import supabase from "../serverClient"; | ||
| import type { Tables } from "@/types/database.types"; | ||
|
|
||
| /** | ||
| * Retrieves accounts by ID. | ||
| * | ||
| * @param accountId - The account ID | ||
| * @returns Array of account records (empty array if not found) | ||
| */ | ||
| export async function selectAccounts(accountId: string): Promise<Tables<"accounts">[]> { | ||
| const { data, error } = await supabase.from("accounts").select("*").eq("id", accountId); | ||
|
|
||
| if (error || !data) { | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import supabase from "../serverClient"; | ||
| import type { Tables, TablesUpdate } from "@/types/database.types"; | ||
|
|
||
| /** | ||
| * Updates an account record. | ||
| * | ||
| * @param accountId - The account ID | ||
| * @param updates - Partial account data to update | ||
| * @returns The updated account record, or null if failed | ||
| */ | ||
| export async function updateAccount( | ||
| accountId: string, | ||
| updates: TablesUpdate<"accounts">, | ||
| ): Promise<Tables<"accounts"> | null> { | ||
| const { data, error } = await supabase | ||
| .from("accounts") | ||
| .update(updates) | ||
| .eq("id", accountId) | ||
| .select("*") | ||
| .single(); | ||
|
|
||
| if (error) { | ||
| console.error("[ERROR] updateAccount:", error); | ||
| return null; | ||
| } | ||
|
|
||
| return data || null; | ||
| } |
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.