Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/server/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
updateProjectContextTool,
} from "@/server/mcp/tools/project-context";
import { listSavedKeywordsTool } from "@/server/mcp/tools/list-saved-keywords";
import { removeSavedKeywordsTool } from "@/server/mcp/tools/remove-saved-keywords";
import {
findSerpCompetitorsTool,
getGoogleBusinessQuestionsTool,
Expand Down Expand Up @@ -165,6 +166,7 @@ export function createOpenSeoMcpServer(authProps: McpProps) {
register(listSavedKeywordsTool);
register(researchKeywordsTool);
register(saveKeywordsTool);
register(removeSavedKeywordsTool);
register(getDomainOverviewTool);
register(getDomainKeywordSuggestionsTool);
register(getBacklinksOverviewTool);
Expand Down
2 changes: 1 addition & 1 deletion src/server/mcp/tools/list-saved-keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const listSavedKeywordsTool = {
row.tags.length > 0
? ` tags:${row.tags.map((tag) => tag.name).join(",")}`
: "";
return `- ${row.keyword} vol:${row.searchVolume ?? "?"} kd:${row.keywordDifficulty ?? "?"} cpc:${row.cpc != null ? `$${row.cpc.toFixed(2)}` : "?"}${tagText}`;
return `- ${row.keyword} id:${row.id} vol:${row.searchVolume ?? "?"} kd:${row.keywordDifficulty ?? "?"} cpc:${row.cpc != null ? `$${row.cpc.toFixed(2)}` : "?"}${tagText}`;
})
.join("\n");
return mcpResponse({
Expand Down
63 changes: 63 additions & 0 deletions src/server/mcp/tools/remove-saved-keywords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { z } from "zod";
import { KeywordResearchService } from "@/server/features/keywords/services/KeywordResearchService";
import { buildProjectMeta } from "@/server/mcp/context";
import { mcpResponse } from "@/server/mcp/formatters";
import { optionalMetaOutputSchema } from "@/server/mcp/output-schemas";
import { withMcpProjectAuth } from "@/server/mcp/project-auth";
import { projectIdSchema } from "@/server/mcp/schemas";

const inputSchema = {
projectId: projectIdSchema,
savedKeywordIds: z
.array(z.string().min(1))
.min(1)
.max(2000)
.describe(
"Saved-keyword row IDs to delete. Use the `id` values returned by list_saved_keywords.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expose the required saved-keyword IDs in text output

When an MCP client surfaces only text content, it cannot supply this parameter: list_saved_keywords renders keyword, metrics, and tags at src/server/mcp/tools/list-saved-keywords.ts:65-73, but leaves each row's id only in structuredContent. The repository explicitly supports text-only MCP clients, so following this instruction still leaves those clients unable to use the new removal flow; include the row ID in list_saved_keywords's text output or accept an identifier already shown there.

Useful? React with 👍 / 👎.

),
} as const;

type Args = z.infer<z.ZodObject<typeof inputSchema>>;

export const removeSavedKeywordsTool = {
name: "remove_saved_keywords",
config: {
title: "Remove saved keywords",
description:
"Permanently deletes keywords from a project's saved-keywords list by their row ID. Uses no credits — does not call DataForSEO. This does not affect Rank Tracking; use remove_rank_tracking_keywords for that list separately.",
inputSchema,
outputSchema: z
.object({
projectId: z.string(),
requested: z.number(),
deletedCount: z.number(),
...optionalMetaOutputSchema,
})
.passthrough(),
annotations: {
readOnlyHint: false,
openWorldHint: false,
destructiveHint: true,
},
},
handler: withMcpProjectAuth(async (args: Args, context) => {
const requested = args.savedKeywordIds.length;
const result = await KeywordResearchService.removeSavedKeywords(
args.projectId,
{ projectId: args.projectId, savedKeywordIds: args.savedKeywordIds },
);
return mcpResponse({
text: `Deleted ${result.deletedCount} of ${requested} requested saved keyword${requested === 1 ? "" : "s"}.`,
meta: buildProjectMeta(
context,
args.projectId,
`/p/${args.projectId}/saved`,
),
structuredContent: {
projectId: args.projectId,
requested,
deletedCount: result.deletedCount,
},
});
}),
};