@itsaakashpatel/seo-webmaster-mcp 0.0.0-stage → 1.1.0

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 (213) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +21 -0
  3. package/README.md +380 -2
  4. package/build/approvals/format.d.ts +29 -0
  5. package/build/approvals/format.js +88 -0
  6. package/build/approvals/gate.d.ts +23 -0
  7. package/build/approvals/gate.js +102 -0
  8. package/build/approvals/groups.d.ts +14 -0
  9. package/build/approvals/groups.js +113 -0
  10. package/build/approvals/session.d.ts +8 -0
  11. package/build/approvals/session.js +23 -0
  12. package/build/cli/args.d.ts +18 -0
  13. package/build/cli/args.js +41 -0
  14. package/build/cli/commands.d.ts +8 -0
  15. package/build/cli/commands.js +64 -0
  16. package/build/cli/engines.d.ts +1 -0
  17. package/build/cli/engines.js +6 -0
  18. package/build/cli/help.d.ts +2 -0
  19. package/build/cli/help.js +29 -0
  20. package/build/cli/install/clients.d.ts +18 -0
  21. package/build/cli/install/clients.js +46 -0
  22. package/build/cli/install/command.d.ts +21 -0
  23. package/build/cli/install/command.js +44 -0
  24. package/build/cli/install/exec.d.ts +3 -0
  25. package/build/cli/install/exec.js +14 -0
  26. package/build/cli/install/flow.d.ts +14 -0
  27. package/build/cli/install/flow.js +114 -0
  28. package/build/cli/install/json-config.d.ts +24 -0
  29. package/build/cli/install/json-config.js +70 -0
  30. package/build/cli/prompter.d.ts +21 -0
  31. package/build/cli/prompter.js +15 -0
  32. package/build/cli/run.d.ts +17 -0
  33. package/build/cli/run.js +48 -0
  34. package/build/cli/screens.d.ts +45 -0
  35. package/build/cli/screens.js +83 -0
  36. package/build/cli/setup/approvals.d.ts +2 -0
  37. package/build/cli/setup/approvals.js +59 -0
  38. package/build/cli/setup/bing.d.ts +2 -0
  39. package/build/cli/setup/bing.js +35 -0
  40. package/build/cli/setup/flow.d.ts +8 -0
  41. package/build/cli/setup/flow.js +91 -0
  42. package/build/cli/setup/google.d.ts +2 -0
  43. package/build/cli/setup/google.js +94 -0
  44. package/build/cli/setup/helpers.d.ts +13 -0
  45. package/build/cli/setup/helpers.js +38 -0
  46. package/build/cli/setup/indexnow.d.ts +3 -0
  47. package/build/cli/setup/indexnow.js +89 -0
  48. package/build/cli/setup/services.d.ts +5 -0
  49. package/build/cli/setup/services.js +62 -0
  50. package/build/cli/setup/text.d.ts +10 -0
  51. package/build/cli/setup/text.js +40 -0
  52. package/build/cli/setup/types.d.ts +35 -0
  53. package/build/cli/setup/types.js +1 -0
  54. package/build/cli/status.d.ts +14 -0
  55. package/build/cli/status.js +54 -0
  56. package/build/cli/terminal.d.ts +6 -0
  57. package/build/cli/terminal.js +134 -0
  58. package/build/config/file.d.ts +29 -0
  59. package/build/config/file.js +58 -0
  60. package/build/config/index.d.ts +24 -0
  61. package/build/config/index.js +72 -0
  62. package/build/config/paths.d.ts +11 -0
  63. package/build/config/paths.js +19 -0
  64. package/build/core/analytics.d.ts +5 -0
  65. package/build/core/analytics.js +18 -0
  66. package/build/core/constants.d.ts +9 -0
  67. package/build/core/constants.js +9 -0
  68. package/build/core/errors.d.ts +18 -0
  69. package/build/core/errors.js +53 -0
  70. package/build/core/filters.d.ts +14 -0
  71. package/build/core/filters.js +42 -0
  72. package/build/core/guards.d.ts +11 -0
  73. package/build/core/guards.js +32 -0
  74. package/build/core/http.d.ts +17 -0
  75. package/build/core/http.js +51 -0
  76. package/build/core/insights/compare.d.ts +32 -0
  77. package/build/core/insights/compare.js +56 -0
  78. package/build/core/insights/crawl.d.ts +9 -0
  79. package/build/core/insights/crawl.js +61 -0
  80. package/build/core/insights/links.d.ts +5 -0
  81. package/build/core/insights/links.js +20 -0
  82. package/build/core/insights/metrics.d.ts +8 -0
  83. package/build/core/insights/metrics.js +15 -0
  84. package/build/core/insights/opportunities.d.ts +15 -0
  85. package/build/core/insights/opportunities.js +40 -0
  86. package/build/core/insights/periods.d.ts +12 -0
  87. package/build/core/insights/periods.js +38 -0
  88. package/build/core/insights/types.d.ts +31 -0
  89. package/build/core/insights/types.js +1 -0
  90. package/build/core/markdown.d.ts +14 -0
  91. package/build/core/markdown.js +28 -0
  92. package/build/core/paging.d.ts +11 -0
  93. package/build/core/paging.js +5 -0
  94. package/build/core/provider.d.ts +15 -0
  95. package/build/core/provider.js +1 -0
  96. package/build/core/rate-limit.d.ts +8 -0
  97. package/build/core/rate-limit.js +19 -0
  98. package/build/core/registry.d.ts +11 -0
  99. package/build/core/registry.js +16 -0
  100. package/build/core/responses.d.ts +13 -0
  101. package/build/core/responses.js +9 -0
  102. package/build/core/secrets.d.ts +2 -0
  103. package/build/core/secrets.js +9 -0
  104. package/build/core/types.d.ts +137 -0
  105. package/build/core/types.js +13 -0
  106. package/build/core/untrusted.d.ts +11 -0
  107. package/build/core/untrusted.js +34 -0
  108. package/build/core/urls.d.ts +16 -0
  109. package/build/core/urls.js +80 -0
  110. package/build/core/validation.d.ts +23 -0
  111. package/build/core/validation.js +100 -0
  112. package/build/index.d.ts +2 -0
  113. package/build/index.js +30 -0
  114. package/build/providers/bing/auth.d.ts +11 -0
  115. package/build/providers/bing/auth.js +87 -0
  116. package/build/providers/bing/mappers.d.ts +18 -0
  117. package/build/providers/bing/mappers.js +87 -0
  118. package/build/providers/bing/operations.d.ts +8 -0
  119. package/build/providers/bing/operations.js +40 -0
  120. package/build/providers/bing/provider.d.ts +16 -0
  121. package/build/providers/bing/provider.js +132 -0
  122. package/build/providers/bing/records.d.ts +11 -0
  123. package/build/providers/bing/records.js +47 -0
  124. package/build/providers/bing/wire.d.ts +86 -0
  125. package/build/providers/bing/wire.js +38 -0
  126. package/build/providers/bing/writes.d.ts +9 -0
  127. package/build/providers/bing/writes.js +31 -0
  128. package/build/providers/google/auth.d.ts +13 -0
  129. package/build/providers/google/auth.js +174 -0
  130. package/build/providers/google/indexing.d.ts +14 -0
  131. package/build/providers/google/indexing.js +89 -0
  132. package/build/providers/google/mappers.d.ts +6 -0
  133. package/build/providers/google/mappers.js +96 -0
  134. package/build/providers/google/probe.d.ts +9 -0
  135. package/build/providers/google/probe.js +42 -0
  136. package/build/providers/google/provider.d.ts +15 -0
  137. package/build/providers/google/provider.js +118 -0
  138. package/build/providers/index.d.ts +4 -0
  139. package/build/providers/index.js +7 -0
  140. package/build/providers/indexnow/probe.d.ts +8 -0
  141. package/build/providers/indexnow/probe.js +17 -0
  142. package/build/providers/indexnow/provider.d.ts +21 -0
  143. package/build/providers/indexnow/provider.js +96 -0
  144. package/build/providers/insights/bing.d.ts +2 -0
  145. package/build/providers/insights/bing.js +73 -0
  146. package/build/providers/insights/google.d.ts +2 -0
  147. package/build/providers/insights/google.js +67 -0
  148. package/build/providers/insights/index.d.ts +5 -0
  149. package/build/providers/insights/index.js +15 -0
  150. package/build/providers/insights/source.d.ts +14 -0
  151. package/build/providers/insights/source.js +1 -0
  152. package/build/server.d.ts +2 -0
  153. package/build/server.js +14 -0
  154. package/build/tools/bing/catalog-crawl.d.ts +2 -0
  155. package/build/tools/bing/catalog-crawl.js +125 -0
  156. package/build/tools/bing/catalog-settings.d.ts +2 -0
  157. package/build/tools/bing/catalog-settings.js +51 -0
  158. package/build/tools/bing/catalog-site.d.ts +2 -0
  159. package/build/tools/bing/catalog-site.js +70 -0
  160. package/build/tools/bing/catalog-traffic.d.ts +2 -0
  161. package/build/tools/bing/catalog-traffic.js +88 -0
  162. package/build/tools/bing/index.d.ts +6 -0
  163. package/build/tools/bing/index.js +26 -0
  164. package/build/tools/bing/inputs.d.ts +21 -0
  165. package/build/tools/bing/inputs.js +34 -0
  166. package/build/tools/bing/read-tool.d.ts +23 -0
  167. package/build/tools/bing/read-tool.js +71 -0
  168. package/build/tools/bing/render.d.ts +8 -0
  169. package/build/tools/bing/render.js +50 -0
  170. package/build/tools/bing/write-tool.d.ts +25 -0
  171. package/build/tools/bing/write-tool.js +127 -0
  172. package/build/tools/bing/writes-settings.d.ts +2 -0
  173. package/build/tools/bing/writes-settings.js +227 -0
  174. package/build/tools/bing/writes-sites.d.ts +2 -0
  175. package/build/tools/bing/writes-sites.js +172 -0
  176. package/build/tools/engine-status.d.ts +14 -0
  177. package/build/tools/engine-status.js +81 -0
  178. package/build/tools/get-sitemap.d.ts +4 -0
  179. package/build/tools/get-sitemap.js +46 -0
  180. package/build/tools/index.d.ts +6 -0
  181. package/build/tools/index.js +43 -0
  182. package/build/tools/insights/bing-crawl-overview.d.ts +2 -0
  183. package/build/tools/insights/bing-crawl-overview.js +46 -0
  184. package/build/tools/insights/bing-link-evidence.d.ts +2 -0
  185. package/build/tools/insights/bing-link-evidence.js +65 -0
  186. package/build/tools/insights/declining-pages.d.ts +2 -0
  187. package/build/tools/insights/declining-pages.js +59 -0
  188. package/build/tools/insights/performance-overview.d.ts +2 -0
  189. package/build/tools/insights/performance-overview.js +39 -0
  190. package/build/tools/insights/report.d.ts +50 -0
  191. package/build/tools/insights/report.js +86 -0
  192. package/build/tools/insights/search-opportunities.d.ts +2 -0
  193. package/build/tools/insights/search-opportunities.js +30 -0
  194. package/build/tools/insights/shared.d.ts +44 -0
  195. package/build/tools/insights/shared.js +90 -0
  196. package/build/tools/inspect-url.d.ts +4 -0
  197. package/build/tools/inspect-url.js +104 -0
  198. package/build/tools/list-sitemaps.d.ts +4 -0
  199. package/build/tools/list-sitemaps.js +37 -0
  200. package/build/tools/list-sites.d.ts +4 -0
  201. package/build/tools/list-sites.js +56 -0
  202. package/build/tools/search-analytics.d.ts +4 -0
  203. package/build/tools/search-analytics.js +108 -0
  204. package/build/tools/shared.d.ts +29 -0
  205. package/build/tools/shared.js +63 -0
  206. package/build/tools/sitemaps.d.ts +2 -0
  207. package/build/tools/sitemaps.js +140 -0
  208. package/build/tools/submit-google.d.ts +4 -0
  209. package/build/tools/submit-google.js +68 -0
  210. package/build/tools/submit-urls.d.ts +4 -0
  211. package/build/tools/submit-urls.js +65 -0
  212. package/package.json +66 -4
  213. package/server.json +58 -0
@@ -0,0 +1,94 @@
1
+ import { runTest, sayEnvNote } from "./helpers.js";
2
+ import { GOOGLE_ADC_STEPS, GOOGLE_ADD_USER_STEP, GOOGLE_KEY_STEPS, INDEXING_INTRO, INDEXING_STEPS, } from "./text.js";
3
+ function withKeyFile(ctx, keyFile) {
4
+ const { google: _old, ...rest } = ctx.draft.config;
5
+ ctx.draft.config = keyFile === undefined ? rest : { ...rest, google: { keyFile } };
6
+ }
7
+ async function testSearchConsole(ctx, keyFile) {
8
+ const outcome = await runTest(ctx, async () => {
9
+ const count = await ctx.services.countGoogleSites(keyFile);
10
+ const zero = count === 0 ? `\n${GOOGLE_ADD_USER_STEP}` : "";
11
+ return `Google accepted the credentials. Search Console lists ${count} site(s).${zero}`;
12
+ });
13
+ return outcome;
14
+ }
15
+ async function askKeyFile(ctx) {
16
+ const { prompt, services } = ctx;
17
+ const path = (await prompt.line("Path to the service account key file: ")).trim();
18
+ if (path === "") {
19
+ return undefined;
20
+ }
21
+ try {
22
+ const account = services.readServiceAccount(path);
23
+ prompt.say(`Service account email: ${account.email}\n${GOOGLE_ADD_USER_STEP}`);
24
+ // The server needs an absolute path, because it does not expand `~`.
25
+ return account.path;
26
+ }
27
+ catch (err) {
28
+ prompt.say(err instanceof Error ? err.message : "The file is not a service account key.");
29
+ return undefined;
30
+ }
31
+ }
32
+ /** Optional. A read call that gets the notification state of one URL checks the access. */
33
+ async function setupIndexing(ctx, keyFile) {
34
+ const { prompt, services } = ctx;
35
+ prompt.say(INDEXING_INTRO);
36
+ if (!(await prompt.confirm("Configure the Google Indexing API now?"))) {
37
+ return;
38
+ }
39
+ prompt.say(INDEXING_STEPS);
40
+ const siteUrl = (await prompt.line("A URL on a property that you own, to test the access: ")).trim();
41
+ if (siteUrl === "") {
42
+ return;
43
+ }
44
+ await runTest(ctx, async () => {
45
+ const access = await services.testGoogleIndexing(keyFile, siteUrl);
46
+ return access === "ok"
47
+ ? "The Indexing API access works."
48
+ : "Google answered 403. Enable the Indexing API, and make the service account an Owner of the property.";
49
+ });
50
+ }
51
+ async function useKeyFile(ctx) {
52
+ ctx.prompt.say(GOOGLE_KEY_STEPS);
53
+ const keyFile = await askKeyFile(ctx);
54
+ if (keyFile === undefined) {
55
+ return "back";
56
+ }
57
+ if ((await testSearchConsole(ctx, keyFile)) === "back") {
58
+ return "back";
59
+ }
60
+ withKeyFile(ctx, keyFile);
61
+ sayEnvNote(ctx, "googleKeyFile");
62
+ await setupIndexing(ctx, keyFile);
63
+ return "done";
64
+ }
65
+ async function useAdc(ctx) {
66
+ ctx.prompt.say(GOOGLE_ADC_STEPS);
67
+ await ctx.prompt.line("Press Enter when you finish the sign-in. ");
68
+ if ((await testSearchConsole(ctx, undefined)) === "back") {
69
+ return "back";
70
+ }
71
+ // Application Default Credentials need no stored value.
72
+ withKeyFile(ctx, undefined);
73
+ return "done";
74
+ }
75
+ export async function setupGoogle(ctx) {
76
+ const choice = await ctx.prompt.choose("Google", [
77
+ { value: "keyFile", label: "Service account key file (recommended)" },
78
+ { value: "adc", label: "Application Default Credentials" },
79
+ { value: "remove", label: "Remove" },
80
+ { value: "back", label: "Back" },
81
+ ]);
82
+ if (choice === "keyFile") {
83
+ return useKeyFile(ctx);
84
+ }
85
+ if (choice === "adc") {
86
+ return useAdc(ctx);
87
+ }
88
+ if (choice === "remove") {
89
+ withKeyFile(ctx, undefined);
90
+ ctx.prompt.say("The Google key file path will be removed when you save.");
91
+ return "done";
92
+ }
93
+ return "back";
94
+ }
@@ -0,0 +1,13 @@
1
+ import { type SettingName } from "../../config/index.js";
2
+ import type { SetupContext } from "./types.js";
3
+ export type TestOutcome = "ok" | "keep" | "back";
4
+ /** The last 4 characters of a key at most. The setup never shows more. */
5
+ export declare function maskKey(key: string): string;
6
+ /** The note about an environment variable that has priority over the file. */
7
+ export declare function envNote(name: SettingName): string | undefined;
8
+ export declare function sayEnvNote(ctx: SetupContext, name: SettingName): void;
9
+ /**
10
+ * Runs a test. If it fails, the user can try again, keep the value anyway, or go back. The
11
+ * message never contains a secret.
12
+ */
13
+ export declare function runTest(ctx: SetupContext, action: () => Promise<string>, secrets?: readonly string[]): Promise<TestOutcome>;
@@ -0,0 +1,38 @@
1
+ import { describeSource, resolveSetting } from "../../config/index.js";
2
+ import { getErrorMessage } from "../../core/errors.js";
3
+ import { redactSecret } from "../../core/secrets.js";
4
+ /** The last 4 characters of a key at most. The setup never shows more. */
5
+ export function maskKey(key) {
6
+ return key.length > 8 ? `ends with ${key.slice(-4)}` : "set";
7
+ }
8
+ /** The note about an environment variable that has priority over the file. */
9
+ export function envNote(name) {
10
+ const setting = resolveSetting(name);
11
+ return setting.source === "environment" ? describeSource(setting) : undefined;
12
+ }
13
+ export function sayEnvNote(ctx, name) {
14
+ const note = envNote(name);
15
+ if (note) {
16
+ ctx.prompt.say(`Note: ${note}.`);
17
+ }
18
+ }
19
+ /**
20
+ * Runs a test. If it fails, the user can try again, keep the value anyway, or go back. The
21
+ * message never contains a secret.
22
+ */
23
+ export async function runTest(ctx, action, secrets = []) {
24
+ try {
25
+ ctx.prompt.say(await action());
26
+ return "ok";
27
+ }
28
+ catch (err) {
29
+ const message = secrets.reduce(redactSecret, getErrorMessage(err));
30
+ ctx.prompt.say(`The test failed: ${message}`);
31
+ const next = await ctx.prompt.choose("What now?", [
32
+ { value: "retry", label: "Try again" },
33
+ { value: "keep", label: "Keep it anyway" },
34
+ { value: "back", label: "Go back" },
35
+ ]);
36
+ return next === "retry" ? runTest(ctx, action, secrets) : next;
37
+ }
38
+ }
@@ -0,0 +1,3 @@
1
+ import type { SetupContext, Step } from "./types.js";
2
+ export declare function isValidIndexNowKey(key: string): boolean;
3
+ export declare function setupIndexNow(ctx: SetupContext): Promise<Step>;
@@ -0,0 +1,89 @@
1
+ import { parseHttpUrl } from "../../core/urls.js";
2
+ import { runTest } from "./helpers.js";
3
+ import { INDEXNOW_NEW_KEY_NOTE } from "./text.js";
4
+ const KEY_RE = /^[A-Za-z0-9-]{8,128}$/;
5
+ export function isValidIndexNowKey(key) {
6
+ return KEY_RE.test(key);
7
+ }
8
+ async function askExistingKey(ctx) {
9
+ const key = await ctx.prompt.secret("Paste the IndexNow key (the input is hidden): ");
10
+ if (!isValidIndexNowKey(key)) {
11
+ ctx.prompt.say("The key must have 8 to 128 letters, digits or - characters. Nothing changed.");
12
+ return undefined;
13
+ }
14
+ return key;
15
+ }
16
+ /** Creates a key and writes its file. Without the file, the key is lost, so it is not saved. */
17
+ async function createKey(ctx) {
18
+ const { prompt, services } = ctx;
19
+ prompt.say(INDEXNOW_NEW_KEY_NOTE);
20
+ const folder = (await prompt.line("Folder for the key file: ")).trim();
21
+ if (folder === "") {
22
+ prompt.say("No folder was given. The setup did not create a key.");
23
+ return undefined;
24
+ }
25
+ const key = services.newIndexNowKey();
26
+ if (services.writeIndexNowKeyFile(folder, key) === "exists") {
27
+ prompt.say("A file with this name already exists. The setup did not overwrite it. Try again.");
28
+ return undefined;
29
+ }
30
+ prompt.say(`The key file is in ${folder}. Upload it to the root of your site.`);
31
+ return key;
32
+ }
33
+ async function askKeyLocation(ctx) {
34
+ const text = (await ctx.prompt.line("Key file URL, if it is not at the site root (optional): ")).trim();
35
+ if (text === "") {
36
+ return undefined;
37
+ }
38
+ if (!parseHttpUrl(text)) {
39
+ ctx.prompt.say("This is not a full http(s) URL. The setup ignores it.");
40
+ return undefined;
41
+ }
42
+ return text;
43
+ }
44
+ async function checkSite(ctx, key, keyLocation) {
45
+ const siteUrl = (await ctx.prompt.line("Site URL to check the key file (optional): ")).trim();
46
+ if (siteUrl === "") {
47
+ return;
48
+ }
49
+ await runTest(ctx, async () => {
50
+ const state = await ctx.services.checkIndexNowKeyFile({ siteUrl, key, keyLocation });
51
+ if (state === "match") {
52
+ return "The key file is on the site, and its content is correct.";
53
+ }
54
+ return state === "missing"
55
+ ? "The key file is not on the site yet. The setup keeps the key. Upload the file named <key>.txt to the site root."
56
+ : "A file exists, but its content is not the key. Fix the file on the site.";
57
+ }, [key]);
58
+ }
59
+ async function setKey(ctx, choice) {
60
+ const key = choice === "existing" ? await askExistingKey(ctx) : await createKey(ctx);
61
+ if (key === undefined) {
62
+ return "back";
63
+ }
64
+ const keyLocation = await askKeyLocation(ctx);
65
+ await checkSite(ctx, key, keyLocation);
66
+ ctx.draft.config = {
67
+ ...ctx.draft.config,
68
+ indexnow: { key, ...(keyLocation && { keyLocation }) },
69
+ };
70
+ return "done";
71
+ }
72
+ export async function setupIndexNow(ctx) {
73
+ const choice = await ctx.prompt.choose("IndexNow", [
74
+ { value: "existing", label: "Use an existing key" },
75
+ { value: "create", label: "Create a new key" },
76
+ { value: "remove", label: "Remove" },
77
+ { value: "back", label: "Back" },
78
+ ]);
79
+ if (choice === "existing" || choice === "create") {
80
+ return setKey(ctx, choice);
81
+ }
82
+ if (choice === "remove") {
83
+ const { indexnow: _removed, ...rest } = ctx.draft.config;
84
+ ctx.draft.config = rest;
85
+ ctx.prompt.say("The IndexNow key will be removed when you save.");
86
+ return "done";
87
+ }
88
+ return "back";
89
+ }
@@ -0,0 +1,5 @@
1
+ import type { SetupServices } from "./types.js";
2
+ /** Expands a leading `~` and makes the path absolute. */
3
+ export declare function expandPath(path: string): string;
4
+ /** The services of a real setup. They only read from the search engines. */
5
+ export declare function createSetupServices(): SetupServices;
@@ -0,0 +1,62 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { readFileSync, writeFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { basename, join, resolve } from "node:path";
5
+ import { writeConfigFile } from "../../config/file.js";
6
+ import { configFilePath } from "../../config/paths.js";
7
+ import { isRecord } from "../../core/guards.js";
8
+ import { countBingSitesForKey } from "../../providers/bing/auth.js";
9
+ import { countSearchConsoleSites, testIndexingAccess } from "../../providers/google/probe.js";
10
+ import { checkIndexNowKeyFile } from "../../providers/indexnow/probe.js";
11
+ /** Expands a leading `~` and makes the path absolute. */
12
+ export function expandPath(path) {
13
+ const expanded = path.startsWith("~") ? join(homedir(), path.slice(1)) : path;
14
+ return resolve(expanded);
15
+ }
16
+ function readServiceAccount(path) {
17
+ const full = expandPath(path);
18
+ const name = basename(full);
19
+ let json;
20
+ try {
21
+ json = JSON.parse(readFileSync(full, "utf8"));
22
+ }
23
+ catch {
24
+ // The error text of the parser can quote the file. The message shows the base name only.
25
+ throw new Error(`The setup cannot read "${name}" as a JSON file.`);
26
+ }
27
+ if (!isRecord(json) || json.type !== "service_account" || typeof json.client_email !== "string") {
28
+ throw new Error(`"${name}" is not a service account key file.`);
29
+ }
30
+ return { email: json.client_email, path: full };
31
+ }
32
+ function writeIndexNowKeyFile(folder, key) {
33
+ const file = join(expandPath(folder), `${key}.txt`);
34
+ try {
35
+ // The `wx` flag fails when the file exists, so the setup never overwrites a file.
36
+ writeFileSync(file, key, { flag: "wx" });
37
+ return "written";
38
+ }
39
+ catch (err) {
40
+ if (isRecord(err) && err.code === "EEXIST") {
41
+ return "exists";
42
+ }
43
+ throw new Error(`The setup cannot write the key file in "${basename(folder)}".`, {
44
+ cause: err,
45
+ });
46
+ }
47
+ }
48
+ /** The services of a real setup. They only read from the search engines. */
49
+ export function createSetupServices() {
50
+ return {
51
+ readServiceAccount,
52
+ countGoogleSites: countSearchConsoleSites,
53
+ testGoogleIndexing: testIndexingAccess,
54
+ countBingSites: countBingSitesForKey,
55
+ checkIndexNowKeyFile,
56
+ writeIndexNowKeyFile,
57
+ newIndexNowKey: () => randomBytes(16).toString("hex"),
58
+ saveConfig: (config) => {
59
+ writeConfigFile(configFilePath(), config);
60
+ },
61
+ };
62
+ }
@@ -0,0 +1,10 @@
1
+ export declare const GOOGLE_KEY_STEPS: string;
2
+ export declare const GOOGLE_ADD_USER_STEP = "Add this email as a user of each Search Console property: Search Console, Settings, Users and permissions.";
3
+ export declare const GOOGLE_ADC_STEPS: string;
4
+ export declare const INDEXING_INTRO: string;
5
+ export declare const INDEXING_STEPS: string;
6
+ export declare const BING_STEPS: string;
7
+ export declare const INDEXNOW_NEW_KEY_NOTE: string;
8
+ export declare const APPROVAL_NOTE: string;
9
+ export declare const PLAIN_TEXT_NOTE = "The keys are stored as plain text. The file has mode 600, so only your user can read it.";
10
+ export declare const RESTART_NOTE = "Restart your MCP client so that the server reads the new file.";
@@ -0,0 +1,40 @@
1
+ export const GOOGLE_KEY_STEPS = [
2
+ "To use a service account key file:",
3
+ " 1. Open the Google Cloud Console. Create or select a project.",
4
+ " 2. Enable the Google Search Console API for the project.",
5
+ " 3. Create a service account. Create a JSON key for it and download the key file.",
6
+ ].join("\n");
7
+ export const GOOGLE_ADD_USER_STEP = "Add this email as a user of each Search Console property: Search Console, Settings, Users and permissions.";
8
+ export const GOOGLE_ADC_STEPS = [
9
+ "Run this command in another terminal:",
10
+ " gcloud auth application-default login --scopes=https://www.googleapis.com/auth/webmasters.readonly,https://www.googleapis.com/auth/cloud-platform",
11
+ "Google can block this sign-in for these scopes. If it fails, use a service account key file.",
12
+ "The setup does not run this command.",
13
+ ].join("\n");
14
+ export const INDEXING_INTRO = [
15
+ "The Google Indexing API is optional.",
16
+ "Google allows it only for JobPosting and BroadcastEvent pages.",
17
+ ].join("\n");
18
+ export const INDEXING_STEPS = [
19
+ "To use the Indexing API:",
20
+ " 1. Enable the Indexing API in the same Google Cloud project.",
21
+ " 2. Add the service account email as Owner of each property in Search Console.",
22
+ "Use a key file for this. Google can block Application Default Credentials for this scope.",
23
+ ].join("\n");
24
+ export const BING_STEPS = [
25
+ "To create a Bing API key:",
26
+ " 1. Sign in to Bing Webmaster Tools: https://www.bing.com/webmasters",
27
+ " 2. Open Settings, then API Access, then API Key.",
28
+ " 3. Create a key and copy it.",
29
+ ].join("\n");
30
+ export const INDEXNOW_NEW_KEY_NOTE = [
31
+ "A new key needs a key file on your site.",
32
+ "The setup writes the file for you. The file name is the key plus .txt.",
33
+ "Without the file, the setup does not save the new key.",
34
+ ].join("\n");
35
+ export const APPROVAL_NOTE = [
36
+ "Clients without approval dialogs: the call runs, and the tool prompt of the client is the approval.",
37
+ "If you set that client to approve tools automatically, the agent decides.",
38
+ ].join("\n");
39
+ export const PLAIN_TEXT_NOTE = "The keys are stored as plain text. The file has mode 600, so only your user can read it.";
40
+ export const RESTART_NOTE = "Restart your MCP client so that the server reads the new file.";
@@ -0,0 +1,35 @@
1
+ import type { ConfigFile } from "../../config/file.js";
2
+ import type { IndexingAccess } from "../../providers/google/probe.js";
3
+ import type { KeyFileCheck, KeyFileState } from "../../providers/indexnow/probe.js";
4
+ import type { Prompter } from "../prompter.js";
5
+ /** Every call to a search engine or to the disk. Tests replace it with stubs. */
6
+ export interface SetupServices {
7
+ /**
8
+ * Reads a service account key file. It returns the email and the absolute path. The error never
9
+ * shows the content of the file.
10
+ */
11
+ readServiceAccount(path: string): {
12
+ readonly email: string;
13
+ readonly path: string;
14
+ };
15
+ countGoogleSites(keyFile: string | undefined): Promise<number>;
16
+ testGoogleIndexing(keyFile: string | undefined, siteUrl: string): Promise<IndexingAccess>;
17
+ countBingSites(apiKey: string): Promise<number>;
18
+ checkIndexNowKeyFile(check: KeyFileCheck): Promise<KeyFileState>;
19
+ /** Never overwrites a file. */
20
+ writeIndexNowKeyFile(folder: string, key: string): "written" | "exists";
21
+ newIndexNowKey(): string;
22
+ saveConfig(config: ConfigFile): void;
23
+ }
24
+ export interface SetupContext {
25
+ readonly prompt: Prompter;
26
+ readonly services: SetupServices;
27
+ /** The choices in memory. Nothing reaches the disk until Save and exit. */
28
+ readonly draft: {
29
+ config: ConfigFile;
30
+ };
31
+ readonly configPath: string;
32
+ /** Runs after the save, when no client has the server yet. */
33
+ readonly offerInstall?: () => Promise<void>;
34
+ }
35
+ export type Step = "done" | "back";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { type ConfigurableGroup } from "../config/file.js";
2
+ export interface EngineLine {
3
+ readonly name: string;
4
+ readonly configured: boolean;
5
+ readonly source: string;
6
+ }
7
+ export interface StatusReport {
8
+ readonly configPath: string;
9
+ readonly engines: readonly EngineLine[];
10
+ readonly approvals: Readonly<Record<ConfigurableGroup, string>>;
11
+ }
12
+ export declare function collectStatus(): StatusReport;
13
+ /** The text of `status`. It never shows a key. */
14
+ export declare function renderStatus(report: StatusReport): string;
@@ -0,0 +1,54 @@
1
+ import { describeSource, getApprovalChoice, resolveSetting, } from "../config/index.js";
2
+ import { CONFIGURABLE_GROUPS } from "../config/file.js";
3
+ import { configFilePath } from "../config/paths.js";
4
+ import { isBingConfigured } from "../providers/bing/auth.js";
5
+ import { isGoogleConfigured } from "../providers/google/auth.js";
6
+ import { isIndexNowConfigured } from "../providers/indexnow/provider.js";
7
+ const GROUP_LABELS = {
8
+ submit: "Submit URLs and sitemaps",
9
+ visibility: "Change visibility",
10
+ access: "Manage site access",
11
+ };
12
+ function describeChoice(group) {
13
+ return getApprovalChoice(group) === "run" ? "run without asking" : "ask first";
14
+ }
15
+ function describeGoogleSource() {
16
+ const raw = resolveSetting("googleServiceAccountKey");
17
+ const file = resolveSetting("googleKeyFile");
18
+ const first = [raw, file].find((setting) => setting.source !== "none");
19
+ return first ? describeSource(first) : "Application Default Credentials, if the file exists";
20
+ }
21
+ function line(name, configured, setting) {
22
+ const source = setting === "google" ? describeGoogleSource() : describeSource(resolveSetting(setting));
23
+ return { name, configured, source };
24
+ }
25
+ export function collectStatus() {
26
+ const google = isGoogleConfigured();
27
+ return {
28
+ configPath: configFilePath(),
29
+ engines: [
30
+ line("Google Search Console", google, "google"),
31
+ line("Google Indexing API", google, "google"),
32
+ line("Bing Webmaster Tools", isBingConfigured(), "bingApiKey"),
33
+ line("IndexNow", isIndexNowConfigured(), "indexNowKey"),
34
+ ],
35
+ approvals: {
36
+ submit: describeChoice("submit"),
37
+ visibility: describeChoice("visibility"),
38
+ access: describeChoice("access"),
39
+ },
40
+ };
41
+ }
42
+ /** The text of `status`. It never shows a key. */
43
+ export function renderStatus(report) {
44
+ return [
45
+ "Engines:",
46
+ ...report.engines.map((engine) => ` ${engine.name.padEnd(26)}${engine.configured ? "configured " : "not configured"} ${engine.source}`),
47
+ "",
48
+ "Approvals:",
49
+ ` ${"Read reports and data".padEnd(26)}always runs`,
50
+ ...CONFIGURABLE_GROUPS.map((group) => ` ${GROUP_LABELS[group].padEnd(26)}${report.approvals[group]}`),
51
+ "",
52
+ `Configuration file: ${report.configPath}`,
53
+ ].join("\n");
54
+ }
@@ -0,0 +1,6 @@
1
+ import { type Prompter } from "./prompter.js";
2
+ type Input = NodeJS.ReadStream;
3
+ type Output = NodeJS.WriteStream;
4
+ /** The real prompter. It needs a terminal on stdin and stdout. */
5
+ export declare function createTerminalPrompter(input?: Input, output?: Output): Prompter;
6
+ export {};
@@ -0,0 +1,134 @@
1
+ import { emitKeypressEvents } from "node:readline";
2
+ import { createInterface } from "node:readline/promises";
3
+ import { parseYesNo, SetupCancelled } from "./prompter.js";
4
+ import { applyHiddenInput, renderCheckbox, renderMenu, stepCheckbox, stepMenu, toKeyName, } from "./screens.js";
5
+ function enterRawMode(input) {
6
+ emitKeypressEvents(input);
7
+ input.setRawMode(true);
8
+ input.resume();
9
+ return () => {
10
+ input.setRawMode(false);
11
+ input.pause();
12
+ };
13
+ }
14
+ /** Draws a screen again in place: it moves up over the old lines and clears them. */
15
+ function draw(output, lines, previous) {
16
+ output.write(previous > 0 ? `\u001b[${previous}A\u001b[0J` : "");
17
+ output.write(`${lines.join("\n")}\n`);
18
+ }
19
+ function runScreen(input, output, screen) {
20
+ return new Promise((resolve, reject) => {
21
+ const leave = enterRawMode(input);
22
+ let state = screen.initial;
23
+ let height = 0;
24
+ const show = () => {
25
+ const lines = screen.render(state);
26
+ draw(output, lines, height);
27
+ height = lines.length;
28
+ };
29
+ const onKey = (_text, key) => {
30
+ if (key.ctrl && key.name === "c") {
31
+ finish(() => reject(new SetupCancelled()));
32
+ return;
33
+ }
34
+ const next = screen.step(state, toKeyName(key));
35
+ state = next.state;
36
+ if (next.result === undefined) {
37
+ show();
38
+ return;
39
+ }
40
+ const { result } = next;
41
+ finish(() => resolve(result));
42
+ };
43
+ const finish = (settle) => {
44
+ input.off("keypress", onKey);
45
+ leave();
46
+ settle();
47
+ };
48
+ input.on("keypress", onKey);
49
+ show();
50
+ });
51
+ }
52
+ async function readLine(input, output, question) {
53
+ const rl = createInterface({ input, output });
54
+ const abort = new AbortController();
55
+ rl.once("SIGINT", () => abort.abort());
56
+ try {
57
+ return await rl.question(question, { signal: abort.signal });
58
+ }
59
+ catch (err) {
60
+ // Ctrl+C aborts the question. Other read errors also end the setup.
61
+ throw new SetupCancelled({ cause: err });
62
+ }
63
+ finally {
64
+ rl.close();
65
+ }
66
+ }
67
+ function readSecret(input, output, question) {
68
+ return new Promise((resolve, reject) => {
69
+ output.write(question);
70
+ const leave = enterRawMode(input);
71
+ let buffer = "";
72
+ const onData = (chunk) => {
73
+ const next = applyHiddenInput(buffer, chunk.toString("utf8"));
74
+ buffer = next.buffer;
75
+ if (!next.done && !next.cancelled) {
76
+ return;
77
+ }
78
+ input.off("data", onData);
79
+ leave();
80
+ output.write("\n");
81
+ if (next.cancelled) {
82
+ reject(new SetupCancelled());
83
+ }
84
+ else {
85
+ resolve(buffer.trim());
86
+ }
87
+ };
88
+ input.on("data", onData);
89
+ });
90
+ }
91
+ /** The real prompter. It needs a terminal on stdin and stdout. */
92
+ export function createTerminalPrompter(input = process.stdin, output = process.stdout) {
93
+ return {
94
+ say: (text) => {
95
+ output.write(`${text}\n`);
96
+ },
97
+ line: (question) => readLine(input, output, question),
98
+ secret: (question) => readSecret(input, output, question),
99
+ confirm: async (question, defaultYes = false) => parseYesNo(await readLine(input, output, `${question} ${defaultYes ? "(Y/n)" : "(y/N)"} `), defaultYes),
100
+ async choose(title, options) {
101
+ const labels = options.map((option) => option.label);
102
+ const chosen = await runScreen(input, output, {
103
+ initial: 0,
104
+ step: (cursor, key) => {
105
+ const next = stepMenu(cursor, labels.length, key);
106
+ return { state: next.cursor, result: next.chosen };
107
+ },
108
+ render: (cursor) => renderMenu(title, labels, cursor),
109
+ });
110
+ const option = options[chosen];
111
+ if (!option) {
112
+ throw new Error("The menu returned a row that does not exist.");
113
+ }
114
+ return option.value;
115
+ },
116
+ async checkbox(title, items) {
117
+ const final = await runScreen(input, output, {
118
+ initial: { items, cursor: 0 },
119
+ step: (state, key) => {
120
+ const next = stepCheckbox(state, key);
121
+ return {
122
+ state: next.state,
123
+ result: next.outcome ? { state: next.state, outcome: next.outcome } : undefined,
124
+ };
125
+ },
126
+ render: (state) => renderCheckbox(title, state),
127
+ });
128
+ return {
129
+ outcome: final.outcome,
130
+ checked: Object.fromEntries(final.state.items.map((item) => [item.id, item.checked])),
131
+ };
132
+ },
133
+ };
134
+ }
@@ -0,0 +1,29 @@
1
+ export declare const APPROVAL_CHOICES: readonly ["ask", "run"];
2
+ export type ApprovalChoice = (typeof APPROVAL_CHOICES)[number];
3
+ /** The groups that the user can set to "run without asking". `read` never asks. */
4
+ export declare const CONFIGURABLE_GROUPS: readonly ["submit", "visibility", "access"];
5
+ export type ConfigurableGroup = (typeof CONFIGURABLE_GROUPS)[number];
6
+ export interface ConfigFile {
7
+ readonly bing?: {
8
+ readonly apiKey: string;
9
+ };
10
+ readonly google?: {
11
+ readonly keyFile: string;
12
+ };
13
+ readonly indexnow?: {
14
+ readonly key: string;
15
+ readonly keyLocation?: string;
16
+ };
17
+ readonly approvals?: Readonly<Partial<Record<ConfigurableGroup, ApprovalChoice>>>;
18
+ }
19
+ /** A configuration problem. The message never shows the content of the file. */
20
+ export declare class ConfigError extends Error {
21
+ constructor(message: string, options?: ErrorOptions);
22
+ }
23
+ /** Reads and checks the file. A missing file gives an empty configuration. */
24
+ export declare function readConfigFile(path: string): ConfigFile;
25
+ /**
26
+ * Writes the file with mode 600 in a folder with mode 700. It writes a temporary file first and
27
+ * then renames it, so a reader never sees a half-written file.
28
+ */
29
+ export declare function writeConfigFile(path: string, config: ConfigFile): void;