seo360-mcp 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +151 -29
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,15 +3,41 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { z } from "zod";
5
5
 
6
- const server = new McpServer({
7
- name: "seo360-mcp",
8
- version: "1.0.1",
9
- });
10
-
11
6
  const PARAMS_DOC_URL = "https://seo360.pages.dev/dataforseo/params.json";
12
7
  const EXTENSION_STORE_URL = "https://chromewebstore.google.com/detail/seo360-dataforseo-free-no/mpphhakiifalmlkphalklimjfkhkpbmp";
8
+ const OFFICIAL_DATAFORSEO_AI_URL = "https://chat.dataforseo.com/";
9
+
10
+ const SEO360_SYSTEM_INSTRUCTIONS = `
11
+ # SEO360 MCP Server — Operational Rules & Knowledge Source
12
+
13
+ 1. **High-Coupling "Extension + MCP" Architecture**:
14
+ - **SEO360 Chrome Extension** (${EXTENSION_STORE_URL}) is the visual preset builder ("Extension Pack Generator"). Users do **NOT** need a DataForSEO account or API key to install the extension, browse endpoints, customize parameters, and export JSON presets.
15
+ - **seo360-mcp** is the zero-hallucination execution engine. It imports preset packs exported from the extension, allows safe parameter updates, and executes live DataForSEO v3 API calls using DATAFORSEO_LOGIN and DATAFORSEO_PASSWORD.
16
+
17
+ 2. **Authentic SEO360 Preset JSON Structure (STRICT — DO NOT FABRICATE OTHER SCHEMAS)**:
18
+ Every JSON preset exported by the SEO360 Chrome Extension is an array of task objects with three exact fields:
19
+ - \`note\` (string): Task name / label.
20
+ - \`api\` (string): Specific DataForSEO v3 API endpoint path (e.g., \`"serp/google/organic/live/regular"\`).
21
+ - \`payload\` (array): Parameter list as an array of \`[key, value]\` pairs preserving exact JSON types (e.g., \`[["keyword", "best running shoes"], ["location_code", 2840]]\`).
22
+ - **NEVER** invent fake JSON formats (such as \`task_name\`, \`endpoint\`, or \`parameters\` objects) and **NEVER** ask users to hand-write preset JSON. Always instruct users without a preset to install the free SEO360 Chrome Extension (${EXTENSION_STORE_URL}) to export an authentic preset pack.
23
+
24
+ 3. **Single Source of Truth for Parameter Knowledge (${PARAMS_DOC_URL})**:
25
+ - All parameter explanations, types, and default/common values MUST come strictly from the live SEO360 parameter dictionary at \`${PARAMS_DOC_URL}\` (exposed via \`seo360://params-dictionary\` and \`lookup_seo360_param\`).
26
+ - **Preset Values Convention**: In the raw dictionary descriptions, values wrapped in \`<code>...</code>\` tags (which appear inside backticks \`...\` after formatting) represent **official preset values, standard enum options, or ready-to-use example values** (such as location codes, language codes, sorting rules, or filter templates). Present these preset options clearly so users can quickly pick or apply them.
27
+ - **NEVER guess or fabricate parameter meanings or allowed values.** If a parameter is NOT found in \`${PARAMS_DOC_URL}\`, explicitly tell the user to consult the official DataForSEO AI at: **${OFFICIAL_DATAFORSEO_AI_URL}**
28
+ `.trim();
29
+
30
+ const server = new McpServer(
31
+ {
32
+ name: "seo360-mcp",
33
+ version: "1.0.2",
34
+ },
35
+ {
36
+ instructions: SEO360_SYSTEM_INSTRUCTIONS,
37
+ }
38
+ );
13
39
 
14
- // Isolated in-memory store for imported SEO360 presets (keyed by unique task name)
40
+ // Isolated in-memory store for imported SEO360 presets (keyed by unique task name derived from `note`)
15
41
  const presetStore = new Map();
16
42
 
17
43
  // Cached parameter dictionary fetched from Cloudflare
@@ -27,12 +53,12 @@ async function getParamsDictionary() {
27
53
  return cachedParamsDict;
28
54
  }
29
55
  } catch (e) {
30
- // Ignore network errors and fall back to schema-less mode
56
+ // Ignore network errors and fall back to empty dictionary
31
57
  }
32
58
  return {};
33
59
  }
34
60
 
35
- // Strip HTML tags (e.g., <code>2840</code> -> `2840`)
61
+ // Convert <code>...</code> preset value tags into Markdown backticks `...` and strip remaining HTML tags
36
62
  function cleanHtml(str) {
37
63
  if (!str) return "";
38
64
  return String(str).replace(/<\/?code>/g, "`").replace(/<[^>]+>/g, "");
@@ -69,25 +95,52 @@ function buildDataForSeoRequestBody(paramsObj) {
69
95
  return [task];
70
96
  }
71
97
 
72
- // Format parameters alongside descriptions from the Cloudflare parameter dictionary
98
+ // Format parameters strictly using the Cloudflare parameter dictionary; point unknown params to DataForSEO Official AI
73
99
  async function formatParamsWithDescriptions(paramsObj) {
74
100
  const dict = await getParamsDictionary();
75
101
  const lines = [];
76
102
  for (const [key, val] of Object.entries(paramsObj)) {
77
103
  const displayVal = JSON.stringify(val);
78
- const doc = dict[key]?.description ? ` — ${cleanHtml(dict[key].description)}` : "";
79
- lines.push(`- **${key}**: \`${displayVal}\`${doc}`);
104
+ const entry = dict[key];
105
+ if (entry && entry.description) {
106
+ const expectedType = entry.type ? ` [${entry.type}]` : "";
107
+ lines.push(`- **${key}**${expectedType}: \`${displayVal}\` — ${cleanHtml(entry.description)}`);
108
+ } else {
109
+ lines.push(`- **${key}**: \`${displayVal}\` — *(Not listed in SEO360 dictionary; please consult DataForSEO Official AI: ${OFFICIAL_DATAFORSEO_AI_URL})*`);
110
+ }
80
111
  }
81
112
  return lines.join("\n");
82
113
  }
83
114
 
115
+ // Expose the live Cloudflare params.json dictionary as a native MCP Resource so AI can read & learn all documented parameters
116
+ server.resource(
117
+ "seo360-params-dictionary",
118
+ "seo360://params-dictionary",
119
+ {
120
+ description: `Live SEO360 DataForSEO parameter dictionary fetched from ${PARAMS_DOC_URL}. Contains official types, descriptions (values inside <code> tags are preset/enum/example options), and default values. For any parameter not in this dictionary, direct users to ${OFFICIAL_DATAFORSEO_AI_URL}.`,
121
+ mimeType: "application/json",
122
+ },
123
+ async () => {
124
+ const dict = await getParamsDictionary();
125
+ return {
126
+ contents: [
127
+ {
128
+ uri: "seo360://params-dictionary",
129
+ mimeType: "application/json",
130
+ text: JSON.stringify(dict, null, 2),
131
+ },
132
+ ],
133
+ };
134
+ }
135
+ );
136
+
84
137
  // Tool 1: Import SEO360 presets (supports single-endpoint or multi-endpoint JSON arrays)
85
138
  server.tool(
86
139
  "import_seo360_preset",
87
- `Import an SEO360 JSON preset exported from the SEO360 Chrome Extension (supports single or multi-endpoint JSON arrays). Automatically enriches parameters with official descriptions from the SEO360 schema dictionary, lists all configurable parameters, and asks the user which fields they want to modify. NOTE: If the user does not have an SEO360 preset or asks how to get one, provide this official Chrome Web Store link (${EXTENSION_STORE_URL}) and emphasize that NO DataForSEO account or API key is required to use the extension to browse endpoints, customize parameters, and export JSON presets (an API key is only needed later when executing live API calls via MCP).`,
140
+ `Import an authentic SEO360 JSON preset pack exported from the SEO360 Chrome Extension. Each item in the JSON array uses: "note" (task name), "api" (specific DataForSEO endpoint), and "payload" (array of [key, value] parameter pairs). Enriches parameters strictly using ${PARAMS_DOC_URL} where backticked/<code> values are official preset options (for undocumented parameters, directs users to ${OFFICIAL_DATAFORSEO_AI_URL}). STRICT RULE: NEVER invent fake example JSON structures or ask users to hand-write presets. If the user does not have a preset, tell them to install the free SEO360 Chrome Extension (${EXTENSION_STORE_URL}) — NO DataForSEO account or API key is required in the extension to configure and export presets.`,
88
141
  {
89
- preset_json: z.string().describe("The raw JSON array string exported from the SEO360 Chrome Extension"),
90
- prefix: z.string().optional().describe("Optional prefix to namespace imported tasks and avoid naming collisions with existing presets"),
142
+ preset_json: z.string().describe('The raw JSON array string exported from the SEO360 Chrome Extension, structured as [{"note": "Task Name", "api": "endpoint/path", "payload": [["key", value], ...]}]'),
143
+ prefix: z.string().optional().describe("Optional prefix to namespace imported task names and avoid naming collisions across multiple preset files"),
91
144
  },
92
145
  async ({ preset_json, prefix }) => {
93
146
  try {
@@ -98,19 +151,23 @@ server.tool(
98
151
  content: [
99
152
  {
100
153
  type: "text",
101
- text: `Invalid format: SEO360 preset must be a non-empty JSON array. You can visually build, customize, and export valid presets for free using the SEO360 Chrome Extension (no DataForSEO account or API key required): ${EXTENSION_STORE_URL}`,
154
+ text: `Invalid format: An SEO360 preset pack must be a non-empty JSON array exported from the SEO360 Chrome Extension.\n\nInstall the free extension to visually configure endpoints, customize parameters, and export valid presets (NO DataForSEO account or API key required): ${EXTENSION_STORE_URL}`,
102
155
  },
103
156
  ],
104
157
  };
105
158
  }
106
159
 
107
160
  const importedDetails = [];
161
+ let skippedCount = 0;
108
162
 
109
163
  for (let i = 0; i < items.length; i++) {
110
164
  const item = items[i];
111
- if (!item.api || !item.payload) continue;
165
+ if (!item || typeof item.api !== "string" || !Array.isArray(item.payload)) {
166
+ skippedCount++;
167
+ continue;
168
+ }
112
169
 
113
- const baseName = item.note ? item.note.trim() : `${item.api}_${i + 1}`;
170
+ const baseName = item.note && String(item.note).trim() ? String(item.note).trim() : `${item.api}_${i + 1}`;
114
171
  const taskName = prefix ? `[${prefix}] ${baseName}` : baseName;
115
172
  const paramsObj = payloadPairsToObject(item.payload);
116
173
 
@@ -121,14 +178,30 @@ server.tool(
121
178
  });
122
179
 
123
180
  const formattedParams = await formatParamsWithDescriptions(paramsObj);
124
- importedDetails.push(`### 📦 Task Name: 【${taskName}】\n- **Endpoint**: \`${item.api}\`\n- **Current Parameters & Descriptions**:\n${formattedParams}`);
181
+ importedDetails.push(
182
+ `### 📦 Task Name (\`note\`): 【${taskName}】\n- **Endpoint (\`api\`)**: \`${item.api}\`\n- **Parameters (\`payload\`)** *(values in backticks are available preset options)*:\n${formattedParams}`
183
+ );
184
+ }
185
+
186
+ if (importedDetails.length === 0) {
187
+ return {
188
+ isError: true,
189
+ content: [
190
+ {
191
+ type: "text",
192
+ text: `No valid SEO360 preset tasks found. Authentic SEO360 presets must contain "note" (task name), "api" (endpoint), and "payload" (array of [key, value] pairs).\n\nExport an authentic preset pack using the free SEO360 Chrome Extension (no DataForSEO API key required): ${EXTENSION_STORE_URL}`,
193
+ },
194
+ ],
195
+ };
125
196
  }
126
197
 
198
+ const skippedNotice = skippedCount > 0 ? `\n*(Skipped ${skippedCount} invalid item(s) missing \`api\` or array \`payload\`.)*` : "";
199
+
127
200
  return {
128
201
  content: [
129
202
  {
130
203
  type: "text",
131
- text: `✅ Successfully imported ${importedDetails.length} SEO360 preset task(s)! Total active tasks in memory: ${presetStore.size}.\n\n${importedDetails.join("\n\n---\n\n")}\n\nPresent these parameters clearly to the user and ask which task and parameters they would like to modify before execution.`,
204
+ text: `✅ Successfully imported ${importedDetails.length} SEO360 preset task(s)! Total active tasks in memory: ${presetStore.size}.${skippedNotice}\n\n${importedDetails.join("\n\n---\n\n")}\n\nPresent these tasks, parameter descriptions, and available preset options clearly to the user, and ask which task and parameters they would like to customize before execution.`,
132
205
  },
133
206
  ],
134
207
  };
@@ -138,7 +211,7 @@ server.tool(
138
211
  content: [
139
212
  {
140
213
  type: "text",
141
- text: `Failed to parse JSON: ${err.message}\n\nNeed a valid preset? Build, customize, and export one visually with the free SEO360 Chrome Extension (no DataForSEO API key required): ${EXTENSION_STORE_URL}`,
214
+ text: `Failed to parse JSON: ${err.message}\n\nDo not hand-write preset JSON — export a valid preset pack visually with the free SEO360 Chrome Extension (no DataForSEO API key required): ${EXTENSION_STORE_URL}`,
142
215
  },
143
216
  ],
144
217
  };
@@ -149,9 +222,9 @@ server.tool(
149
222
  // Tool 2: Update any parameters of a specific imported preset task (persists in memory)
150
223
  server.tool(
151
224
  "update_seo360_preset",
152
- "Update or add parameters for a specific imported SEO360 preset task. Strictly preserves the exact JSON data types provided (string, number, boolean, array, or object). Changes persist in memory for the current session without affecting other tasks.",
225
+ `Update or add parameters for a specific imported SEO360 preset task (identified by its task name / \`note\`). Strictly preserves exact JSON data types (string, number, boolean, array, or object). Changes persist in memory for the current session without affecting other tasks. Refer to ${PARAMS_DOC_URL} for parameter usage and preset options (wrapped in <code> tags in the raw JSON); if unknown, refer the user to ${OFFICIAL_DATAFORSEO_AI_URL}.`,
153
226
  {
154
- task_name: z.string().describe("The exact task name of the imported SEO360 preset to update"),
227
+ task_name: z.string().describe("The exact task name (`note`) of the imported SEO360 preset to update"),
155
228
  updates_json: z.string().describe('A JSON object of key-value pairs to update, e.g., {"keyword": "best laptops", "location_code": 2826, "depth": 20}'),
156
229
  },
157
230
  async ({ task_name, updates_json }) => {
@@ -170,6 +243,13 @@ server.tool(
170
243
 
171
244
  try {
172
245
  const updates = JSON.parse(updates_json);
246
+ if (!updates || typeof updates !== "object" || Array.isArray(updates)) {
247
+ return {
248
+ isError: true,
249
+ content: [{ type: "text", text: "Invalid updates_json: Must be a valid JSON object of key-value pairs." }],
250
+ };
251
+ }
252
+
173
253
  for (const [key, newVal] of Object.entries(updates)) {
174
254
  target.params[key] = newVal;
175
255
  }
@@ -179,7 +259,7 @@ server.tool(
179
259
  content: [
180
260
  {
181
261
  type: "text",
182
- text: `✅ Parameters for task 【${task_name}】 have been updated and saved!\n\nUpdated Parameter State:\n${formattedParams}`,
262
+ text: `✅ Parameters for task 【${task_name}】 (\`${target.api}\`) have been updated and saved!\n\nUpdated Parameter State:\n${formattedParams}`,
183
263
  },
184
264
  ],
185
265
  };
@@ -195,7 +275,7 @@ server.tool(
195
275
  // Tool 3: List all currently loaded preset tasks and their parameter states
196
276
  server.tool(
197
277
  "list_seo360_presets",
198
- `List all currently loaded SEO360 preset tasks in memory along with their endpoints and latest parameter configurations. If no presets are loaded, guide the user to install the free SEO360 Chrome Extension (${EXTENSION_STORE_URL}) and clearly note that NO DataForSEO account or API key is needed in the extension to configure parameters and export JSON presets (an API key is only required later when executing live requests).`,
278
+ `List all currently loaded SEO360 preset tasks in memory along with their task names (\`note\`), endpoints (\`api\`), and latest parameter configurations. If no presets are loaded, guide the user to install the free SEO360 Chrome Extension (${EXTENSION_STORE_URL}) — clearly emphasize that NO DataForSEO account or API key is required in the extension to browse endpoints, customize parameters, and export JSON presets. NEVER fabricate example JSON formats.`,
199
279
  {},
200
280
  async () => {
201
281
  if (presetStore.size === 0) {
@@ -203,7 +283,7 @@ server.tool(
203
283
  content: [
204
284
  {
205
285
  type: "text",
206
- text: `No SEO360 presets have been imported yet.\n\nTo get started, install the free SEO360 Chrome Extension to visually configure DataForSEO endpoints, customize parameters, and export a JSON preset (no DataForSEO account or API key required to configure and export):\n👉 ${EXTENSION_STORE_URL}`,
286
+ text: `No SEO360 presets have been imported yet.\n\nTo get started, install the free SEO360 Chrome Extension to visually configure DataForSEO endpoints, customize parameters, and export a JSON preset pack (**no DataForSEO account or API key required** to configure and export):\n👉 ${EXTENSION_STORE_URL}`,
207
287
  },
208
288
  ],
209
289
  };
@@ -212,6 +292,7 @@ server.tool(
212
292
  for (const [name, data] of presetStore.entries()) {
213
293
  list.push({
214
294
  task_name: name,
295
+ note: data.note,
215
296
  api: data.api,
216
297
  current_params: data.params,
217
298
  });
@@ -225,9 +306,9 @@ server.tool(
225
306
  // Tool 4: Execute a specific preset task against the live DataForSEO API
226
307
  server.tool(
227
308
  "execute_seo360_preset",
228
- `Execute a specific SEO360 preset task against the live DataForSEO API using its latest saved parameters and return real-time results. If no preset has been imported yet, ask the user to import one or install the free SEO360 Chrome Extension (${EXTENSION_STORE_URL}) to configure and export presets (no API key required in the extension).`,
309
+ `Execute a specific SEO360 preset task against the live DataForSEO API using its latest saved parameters and return real-time results. Requires DATAFORSEO_LOGIN and DATAFORSEO_PASSWORD environment variables. If no preset has been imported yet, ask the user to import one exported from the free SEO360 Chrome Extension (${EXTENSION_STORE_URL}) — no API key is required in the extension.`,
229
310
  {
230
- task_name: z.string().describe("The exact task name of the SEO360 preset to execute"),
311
+ task_name: z.string().describe("The exact task name (`note`) of the SEO360 preset to execute"),
231
312
  },
232
313
  async ({ task_name }) => {
233
314
  const target = presetStore.get(task_name);
@@ -248,7 +329,12 @@ server.tool(
248
329
  if (!login || !password) {
249
330
  return {
250
331
  isError: true,
251
- content: [{ type: "text", text: "Missing DATAFORSEO_LOGIN or DATAFORSEO_PASSWORD environment variables. Please configure them in your MCP server settings." }],
332
+ content: [
333
+ {
334
+ type: "text",
335
+ text: "Missing DATAFORSEO_LOGIN or DATAFORSEO_PASSWORD environment variables. Note: You do NOT need an API key to create/export presets in the SEO360 Chrome Extension, but executing live API calls via MCP requires your DataForSEO API credentials in the MCP server configuration.",
336
+ },
337
+ ],
252
338
  };
253
339
  }
254
340
 
@@ -271,7 +357,7 @@ server.tool(
271
357
  content: [
272
358
  {
273
359
  type: "text",
274
- text: `🚀 Task 【${task_name}】 executed successfully!\n- **Endpoint**: \`${url}\`\n- **Payload Sent**: \`${JSON.stringify(requestBody)}\`\n\n### API Response:\n${JSON.stringify(resultData, null, 2)}`,
360
+ text: `🚀 Task 【${task_name}】 executed successfully!\n- **Endpoint (\`api\`)**: \`${url}\`\n- **Payload Sent**: \`${JSON.stringify(requestBody)}\`\n\n### API Response:\n${JSON.stringify(resultData, null, 2)}`,
275
361
  },
276
362
  ],
277
363
  };
@@ -284,5 +370,41 @@ server.tool(
284
370
  }
285
371
  );
286
372
 
373
+ // Tool 5: Look up official parameter documentation & preset options from SEO360's live Cloudflare dictionary
374
+ server.tool(
375
+ "lookup_seo360_param",
376
+ `Look up the official type, description, default value, and available preset options (values wrapped in <code> tags in the raw JSON) for one or more DataForSEO parameters from SEO360's live parameter dictionary (${PARAMS_DOC_URL}). If a parameter is not found in the dictionary, instructs the user to consult the official DataForSEO AI at ${OFFICIAL_DATAFORSEO_AI_URL}.`,
377
+ {
378
+ param_names: z.array(z.string()).describe('List of parameter keys to look up, e.g. ["location_code", "filters", "depth"]'),
379
+ },
380
+ async ({ param_names }) => {
381
+ const dict = await getParamsDictionary();
382
+ const results = [];
383
+
384
+ for (const rawKey of param_names) {
385
+ const key = rawKey.trim();
386
+ const entry = dict[key];
387
+ if (entry) {
388
+ results.push(
389
+ `### 🔹 \`${key}\`\n- **Type**: \`${entry.type || "unknown"}\`\n- **Default**: \`${JSON.stringify(entry.default)}\`\n- **Description & Preset Options** *(backticked values are ready-to-use presets)*: ${cleanHtml(entry.description)}`
390
+ );
391
+ } else {
392
+ results.push(
393
+ `### ❓ \`${key}\`\n- Not found in the SEO360 common parameter dictionary (\`${PARAMS_DOC_URL}\`).\n- Please ask the **DataForSEO Official AI** for exact specification: 👉 ${OFFICIAL_DATAFORSEO_AI_URL}`
394
+ );
395
+ }
396
+ }
397
+
398
+ return {
399
+ content: [
400
+ {
401
+ type: "text",
402
+ text: results.join("\n\n---\n\n"),
403
+ },
404
+ ],
405
+ };
406
+ }
407
+ );
408
+
287
409
  const transport = new StdioServerTransport();
288
410
  await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seo360-mcp",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "SEO360 MCP: Import extension presets, customize parameters, and call DataForSEO APIs with zero hallucination.",
5
5
  "homepage": "https://seo360.pages.dev",
6
6
  "type": "module",