fix: validate tag names in update_forum_post

Return an error listing the invalid tag names and available tags
instead of silently ignoring unrecognized tags.
This commit is contained in:
Claude 2026-02-26 16:02:04 -05:00 committed by Warren
parent 6b9dde03e9
commit b7e0098987
1 changed files with 15 additions and 7 deletions

View File

@ -376,15 +376,23 @@ export const updateForumPostHandler: ToolHandler = async (args, { client }) => {
if (parent && parent.type === ChannelType.GuildForum) { if (parent && parent.type === ChannelType.GuildForum) {
const forumChannel = parent as ForumChannel; const forumChannel = parent as ForumChannel;
const availableTags = forumChannel.availableTags; const availableTags = forumChannel.availableTags;
const tagIds = tags.map(tagInput => { const resolved: string[] = [];
// Accept either tag name or tag ID const invalid: string[] = [];
for (const tagInput of tags) {
const byName = availableTags.find(t => t.name === tagInput); const byName = availableTags.find(t => t.name === tagInput);
if (byName) return byName.id; if (byName) { resolved.push(byName.id); continue; }
const byId = availableTags.find(t => t.id === tagInput); const byId = availableTags.find(t => t.id === tagInput);
if (byId) return byId.id; if (byId) { resolved.push(byId.id); continue; }
return null; invalid.push(tagInput);
}).filter((id): id is string => id !== null); }
editOptions.appliedTags = tagIds; if (invalid.length > 0) {
const validNames = availableTags.map(t => t.name).join(', ');
return {
content: [{ type: "text", text: `Unknown tag(s): ${invalid.join(', ')}. Available tags: ${validNames}` }],
isError: true
};
}
editOptions.appliedTags = resolved;
} else { } else {
return { return {
content: [{ type: "text", text: `Thread's parent channel is not a forum channel. Tags can only be applied to forum posts.` }], content: [{ type: "text", text: `Thread's parent channel is not a forum channel. Tags can only be applied to forum posts.` }],