@itsaakashpatel/seo-webmaster-mcp 0.0.0-stage → 1.1.1
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.
- package/CHANGELOG.md +44 -0
- package/LICENSE +21 -0
- package/README.md +441 -2
- package/build/approvals/format.d.ts +29 -0
- package/build/approvals/format.js +88 -0
- package/build/approvals/gate.d.ts +23 -0
- package/build/approvals/gate.js +102 -0
- package/build/approvals/groups.d.ts +14 -0
- package/build/approvals/groups.js +113 -0
- package/build/approvals/session.d.ts +8 -0
- package/build/approvals/session.js +23 -0
- package/build/cli/args.d.ts +18 -0
- package/build/cli/args.js +41 -0
- package/build/cli/commands.d.ts +8 -0
- package/build/cli/commands.js +64 -0
- package/build/cli/engines.d.ts +1 -0
- package/build/cli/engines.js +6 -0
- package/build/cli/help.d.ts +2 -0
- package/build/cli/help.js +29 -0
- package/build/cli/install/clients.d.ts +18 -0
- package/build/cli/install/clients.js +46 -0
- package/build/cli/install/command.d.ts +21 -0
- package/build/cli/install/command.js +44 -0
- package/build/cli/install/exec.d.ts +3 -0
- package/build/cli/install/exec.js +14 -0
- package/build/cli/install/flow.d.ts +14 -0
- package/build/cli/install/flow.js +114 -0
- package/build/cli/install/json-config.d.ts +24 -0
- package/build/cli/install/json-config.js +70 -0
- package/build/cli/prompter.d.ts +21 -0
- package/build/cli/prompter.js +15 -0
- package/build/cli/run.d.ts +17 -0
- package/build/cli/run.js +48 -0
- package/build/cli/screens.d.ts +45 -0
- package/build/cli/screens.js +83 -0
- package/build/cli/setup/approvals.d.ts +2 -0
- package/build/cli/setup/approvals.js +59 -0
- package/build/cli/setup/bing.d.ts +2 -0
- package/build/cli/setup/bing.js +35 -0
- package/build/cli/setup/flow.d.ts +8 -0
- package/build/cli/setup/flow.js +91 -0
- package/build/cli/setup/google.d.ts +2 -0
- package/build/cli/setup/google.js +94 -0
- package/build/cli/setup/helpers.d.ts +13 -0
- package/build/cli/setup/helpers.js +38 -0
- package/build/cli/setup/indexnow.d.ts +3 -0
- package/build/cli/setup/indexnow.js +89 -0
- package/build/cli/setup/services.d.ts +5 -0
- package/build/cli/setup/services.js +62 -0
- package/build/cli/setup/text.d.ts +10 -0
- package/build/cli/setup/text.js +40 -0
- package/build/cli/setup/types.d.ts +35 -0
- package/build/cli/setup/types.js +1 -0
- package/build/cli/status.d.ts +14 -0
- package/build/cli/status.js +54 -0
- package/build/cli/terminal.d.ts +6 -0
- package/build/cli/terminal.js +134 -0
- package/build/config/file.d.ts +29 -0
- package/build/config/file.js +58 -0
- package/build/config/index.d.ts +24 -0
- package/build/config/index.js +72 -0
- package/build/config/paths.d.ts +11 -0
- package/build/config/paths.js +19 -0
- package/build/core/analytics.d.ts +5 -0
- package/build/core/analytics.js +18 -0
- package/build/core/constants.d.ts +9 -0
- package/build/core/constants.js +9 -0
- package/build/core/errors.d.ts +18 -0
- package/build/core/errors.js +53 -0
- package/build/core/filters.d.ts +14 -0
- package/build/core/filters.js +42 -0
- package/build/core/guards.d.ts +11 -0
- package/build/core/guards.js +32 -0
- package/build/core/http.d.ts +17 -0
- package/build/core/http.js +51 -0
- package/build/core/insights/compare.d.ts +32 -0
- package/build/core/insights/compare.js +56 -0
- package/build/core/insights/crawl.d.ts +9 -0
- package/build/core/insights/crawl.js +61 -0
- package/build/core/insights/links.d.ts +5 -0
- package/build/core/insights/links.js +20 -0
- package/build/core/insights/metrics.d.ts +8 -0
- package/build/core/insights/metrics.js +15 -0
- package/build/core/insights/opportunities.d.ts +15 -0
- package/build/core/insights/opportunities.js +40 -0
- package/build/core/insights/periods.d.ts +12 -0
- package/build/core/insights/periods.js +38 -0
- package/build/core/insights/types.d.ts +31 -0
- package/build/core/insights/types.js +1 -0
- package/build/core/markdown.d.ts +14 -0
- package/build/core/markdown.js +28 -0
- package/build/core/paging.d.ts +11 -0
- package/build/core/paging.js +5 -0
- package/build/core/provider.d.ts +15 -0
- package/build/core/provider.js +1 -0
- package/build/core/rate-limit.d.ts +8 -0
- package/build/core/rate-limit.js +19 -0
- package/build/core/registry.d.ts +11 -0
- package/build/core/registry.js +16 -0
- package/build/core/responses.d.ts +13 -0
- package/build/core/responses.js +9 -0
- package/build/core/secrets.d.ts +2 -0
- package/build/core/secrets.js +9 -0
- package/build/core/types.d.ts +137 -0
- package/build/core/types.js +13 -0
- package/build/core/untrusted.d.ts +11 -0
- package/build/core/untrusted.js +34 -0
- package/build/core/urls.d.ts +16 -0
- package/build/core/urls.js +80 -0
- package/build/core/validation.d.ts +23 -0
- package/build/core/validation.js +100 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +30 -0
- package/build/providers/bing/auth.d.ts +11 -0
- package/build/providers/bing/auth.js +87 -0
- package/build/providers/bing/mappers.d.ts +18 -0
- package/build/providers/bing/mappers.js +87 -0
- package/build/providers/bing/operations.d.ts +8 -0
- package/build/providers/bing/operations.js +40 -0
- package/build/providers/bing/provider.d.ts +16 -0
- package/build/providers/bing/provider.js +132 -0
- package/build/providers/bing/records.d.ts +11 -0
- package/build/providers/bing/records.js +47 -0
- package/build/providers/bing/wire.d.ts +86 -0
- package/build/providers/bing/wire.js +38 -0
- package/build/providers/bing/writes.d.ts +9 -0
- package/build/providers/bing/writes.js +31 -0
- package/build/providers/google/auth.d.ts +13 -0
- package/build/providers/google/auth.js +174 -0
- package/build/providers/google/indexing.d.ts +14 -0
- package/build/providers/google/indexing.js +89 -0
- package/build/providers/google/mappers.d.ts +6 -0
- package/build/providers/google/mappers.js +96 -0
- package/build/providers/google/probe.d.ts +9 -0
- package/build/providers/google/probe.js +42 -0
- package/build/providers/google/provider.d.ts +15 -0
- package/build/providers/google/provider.js +118 -0
- package/build/providers/index.d.ts +4 -0
- package/build/providers/index.js +7 -0
- package/build/providers/indexnow/probe.d.ts +8 -0
- package/build/providers/indexnow/probe.js +17 -0
- package/build/providers/indexnow/provider.d.ts +21 -0
- package/build/providers/indexnow/provider.js +96 -0
- package/build/providers/insights/bing.d.ts +2 -0
- package/build/providers/insights/bing.js +73 -0
- package/build/providers/insights/google.d.ts +2 -0
- package/build/providers/insights/google.js +67 -0
- package/build/providers/insights/index.d.ts +5 -0
- package/build/providers/insights/index.js +15 -0
- package/build/providers/insights/source.d.ts +14 -0
- package/build/providers/insights/source.js +1 -0
- package/build/server.d.ts +2 -0
- package/build/server.js +14 -0
- package/build/tools/bing/catalog-crawl.d.ts +2 -0
- package/build/tools/bing/catalog-crawl.js +125 -0
- package/build/tools/bing/catalog-settings.d.ts +2 -0
- package/build/tools/bing/catalog-settings.js +51 -0
- package/build/tools/bing/catalog-site.d.ts +2 -0
- package/build/tools/bing/catalog-site.js +70 -0
- package/build/tools/bing/catalog-traffic.d.ts +2 -0
- package/build/tools/bing/catalog-traffic.js +88 -0
- package/build/tools/bing/index.d.ts +6 -0
- package/build/tools/bing/index.js +26 -0
- package/build/tools/bing/inputs.d.ts +21 -0
- package/build/tools/bing/inputs.js +34 -0
- package/build/tools/bing/read-tool.d.ts +23 -0
- package/build/tools/bing/read-tool.js +71 -0
- package/build/tools/bing/render.d.ts +8 -0
- package/build/tools/bing/render.js +50 -0
- package/build/tools/bing/write-tool.d.ts +25 -0
- package/build/tools/bing/write-tool.js +127 -0
- package/build/tools/bing/writes-settings.d.ts +2 -0
- package/build/tools/bing/writes-settings.js +227 -0
- package/build/tools/bing/writes-sites.d.ts +2 -0
- package/build/tools/bing/writes-sites.js +172 -0
- package/build/tools/engine-status.d.ts +14 -0
- package/build/tools/engine-status.js +81 -0
- package/build/tools/get-sitemap.d.ts +4 -0
- package/build/tools/get-sitemap.js +46 -0
- package/build/tools/index.d.ts +6 -0
- package/build/tools/index.js +43 -0
- package/build/tools/insights/bing-crawl-overview.d.ts +2 -0
- package/build/tools/insights/bing-crawl-overview.js +46 -0
- package/build/tools/insights/bing-link-evidence.d.ts +2 -0
- package/build/tools/insights/bing-link-evidence.js +65 -0
- package/build/tools/insights/declining-pages.d.ts +2 -0
- package/build/tools/insights/declining-pages.js +59 -0
- package/build/tools/insights/performance-overview.d.ts +2 -0
- package/build/tools/insights/performance-overview.js +39 -0
- package/build/tools/insights/report.d.ts +50 -0
- package/build/tools/insights/report.js +86 -0
- package/build/tools/insights/search-opportunities.d.ts +2 -0
- package/build/tools/insights/search-opportunities.js +30 -0
- package/build/tools/insights/shared.d.ts +44 -0
- package/build/tools/insights/shared.js +90 -0
- package/build/tools/inspect-url.d.ts +4 -0
- package/build/tools/inspect-url.js +104 -0
- package/build/tools/list-sitemaps.d.ts +4 -0
- package/build/tools/list-sitemaps.js +37 -0
- package/build/tools/list-sites.d.ts +4 -0
- package/build/tools/list-sites.js +56 -0
- package/build/tools/search-analytics.d.ts +4 -0
- package/build/tools/search-analytics.js +108 -0
- package/build/tools/shared.d.ts +29 -0
- package/build/tools/shared.js +63 -0
- package/build/tools/sitemaps.d.ts +2 -0
- package/build/tools/sitemaps.js +140 -0
- package/build/tools/submit-google.d.ts +4 -0
- package/build/tools/submit-google.js +68 -0
- package/build/tools/submit-urls.d.ts +4 -0
- package/build/tools/submit-urls.js +65 -0
- package/package.json +78 -4
- package/server.json +58 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getApprovalChoice } from "../config/index.js";
|
|
2
|
+
import { ApprovalError } from "../core/errors.js";
|
|
3
|
+
import { renderDialogMessage } from "./format.js";
|
|
4
|
+
import { addSessionApproval, isSessionApproved, takeNoDialogNotice } from "./session.js";
|
|
5
|
+
export const DIALOG_TIMEOUT_MS = 10 * 60 * 1000;
|
|
6
|
+
export const NO_DIALOG_NOTICE = "This client cannot show approval dialogs. The server did not ask you before this change.";
|
|
7
|
+
/** True when the client sent the `elicitation` capability with form mode. */
|
|
8
|
+
export function clientSupportsDialogs(server) {
|
|
9
|
+
const elicitation = server.server.getClientCapabilities()?.elicitation;
|
|
10
|
+
// An empty `elicitation` object means form mode in the first version of the protocol.
|
|
11
|
+
return (elicitation !== undefined && (elicitation.form !== undefined || elicitation.url === undefined));
|
|
12
|
+
}
|
|
13
|
+
function offersSession(request) {
|
|
14
|
+
return request.group !== "access" && request.sessionKey !== undefined;
|
|
15
|
+
}
|
|
16
|
+
const SCOPE_FIELD = {
|
|
17
|
+
type: "string",
|
|
18
|
+
title: "Scope",
|
|
19
|
+
description: "once: this call only. session: this group on this site until the server stops.",
|
|
20
|
+
enum: ["once", "session"],
|
|
21
|
+
default: "once",
|
|
22
|
+
};
|
|
23
|
+
function buildForm(request) {
|
|
24
|
+
return {
|
|
25
|
+
mode: "form",
|
|
26
|
+
message: renderDialogMessage(request),
|
|
27
|
+
requestedSchema: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: offersSession(request)
|
|
30
|
+
? { scope: { ...SCOPE_FIELD, enum: [...SCOPE_FIELD.enum] } }
|
|
31
|
+
: {},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function notApproved(tool) {
|
|
36
|
+
return new ApprovalError(`The user did not approve ${tool}.`);
|
|
37
|
+
}
|
|
38
|
+
async function askUser(server, request) {
|
|
39
|
+
try {
|
|
40
|
+
return await server.server.elicitInput(buildForm(request), {
|
|
41
|
+
timeout: DIALOG_TIMEOUT_MS,
|
|
42
|
+
signal: request.signal,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// A timeout, a client cancel or a protocol error. All of them mean no approval.
|
|
47
|
+
throw notApproved(request.tool);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function runDialog(server, request) {
|
|
51
|
+
const result = await askUser(server, request);
|
|
52
|
+
if (result.action === "decline") {
|
|
53
|
+
throw new ApprovalError(`The user rejected ${request.tool}. Do not call it again unless the user asks.`);
|
|
54
|
+
}
|
|
55
|
+
// The client can cancel the call just after the user accepts.
|
|
56
|
+
if (result.action !== "accept" || request.signal?.aborted) {
|
|
57
|
+
throw notApproved(request.tool);
|
|
58
|
+
}
|
|
59
|
+
if (result.content?.scope === "session" && offersSession(request) && request.sessionKey) {
|
|
60
|
+
addSessionApproval(request.group, request.sessionKey);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function needsNoDialog(request) {
|
|
64
|
+
const { group } = request;
|
|
65
|
+
return (group === "read" ||
|
|
66
|
+
getApprovalChoice(group) === "run" ||
|
|
67
|
+
isSessionApproved(group, request.sessionKey));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Decides before the server sends any request. It returns when the call may run. It throws an
|
|
71
|
+
* `ApprovalError` when the user declines, cancels, or does not answer in 10 minutes.
|
|
72
|
+
*/
|
|
73
|
+
export async function requireApproval(server, request) {
|
|
74
|
+
const outcome = await decide(server, request);
|
|
75
|
+
// The last check before the request: the client can cancel the call at any time.
|
|
76
|
+
if (request.signal?.aborted) {
|
|
77
|
+
throw notApproved(request.tool);
|
|
78
|
+
}
|
|
79
|
+
return outcome;
|
|
80
|
+
}
|
|
81
|
+
async function decide(server, request) {
|
|
82
|
+
if (needsNoDialog(request)) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
if (!clientSupportsDialogs(server)) {
|
|
86
|
+
// The client prompt for the tool is the only approval. The agent and the user get a warning.
|
|
87
|
+
return takeNoDialogNotice() ? { notice: NO_DIALOG_NOTICE } : {};
|
|
88
|
+
}
|
|
89
|
+
await runDialog(server, request);
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
/** Adds the notice to the first text block of a result. */
|
|
93
|
+
export function prependNotice(result, outcome) {
|
|
94
|
+
const [first, ...rest] = result.content;
|
|
95
|
+
if (!outcome.notice || !first) {
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...result,
|
|
100
|
+
content: [{ ...first, text: `${outcome.notice}\n\n${first.text}` }, ...rest],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The approval groups. `read` never asks. */
|
|
2
|
+
export declare const APPROVAL_GROUPS: readonly ["read", "submit", "visibility", "access"];
|
|
3
|
+
export type ApprovalGroup = (typeof APPROVAL_GROUPS)[number];
|
|
4
|
+
/** The one table of approval data. Each tool is in exactly one group. */
|
|
5
|
+
export declare const GROUP_TOOLS: Readonly<Record<ApprovalGroup, readonly string[]>>;
|
|
6
|
+
/** The risk text that the dialog shows. */
|
|
7
|
+
export declare const GROUP_RISK: Readonly<Record<ApprovalGroup, string>>;
|
|
8
|
+
/** Finds the group of a tool. A tool that is not in the table is a bug, so this throws. */
|
|
9
|
+
export declare function groupOf(tool: string): ApprovalGroup;
|
|
10
|
+
/**
|
|
11
|
+
* The `_meta` of a tool. Claude Code asks the user at each call of a `visibility` or `access`
|
|
12
|
+
* tool. This holds even when the client has no approval dialog.
|
|
13
|
+
*/
|
|
14
|
+
export declare function toolMeta(tool: string): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** The approval groups. `read` never asks. */
|
|
2
|
+
export const APPROVAL_GROUPS = ["read", "submit", "visibility", "access"];
|
|
3
|
+
/** The one table of approval data. Each tool is in exactly one group. */
|
|
4
|
+
export const GROUP_TOOLS = {
|
|
5
|
+
read: [
|
|
6
|
+
"engine_status",
|
|
7
|
+
"list_sites",
|
|
8
|
+
"search_analytics",
|
|
9
|
+
"inspect_url",
|
|
10
|
+
"list_sitemaps",
|
|
11
|
+
"get_sitemap",
|
|
12
|
+
"get_performance_overview",
|
|
13
|
+
"find_search_opportunities",
|
|
14
|
+
"find_declining_pages",
|
|
15
|
+
"bing_get_crawl_overview",
|
|
16
|
+
"bing_get_link_evidence",
|
|
17
|
+
"bing_get_sites",
|
|
18
|
+
"bing_get_site_roles",
|
|
19
|
+
"bing_get_site_moves",
|
|
20
|
+
"bing_get_feed_details",
|
|
21
|
+
"bing_get_url_submission_quota",
|
|
22
|
+
"bing_get_content_submission_quota",
|
|
23
|
+
"bing_get_fetched_urls",
|
|
24
|
+
"bing_get_fetched_url_details",
|
|
25
|
+
"bing_get_query_stats",
|
|
26
|
+
"bing_get_query_traffic_stats",
|
|
27
|
+
"bing_get_query_page_stats",
|
|
28
|
+
"bing_get_query_page_detail_stats",
|
|
29
|
+
"bing_get_page_stats",
|
|
30
|
+
"bing_get_page_query_stats",
|
|
31
|
+
"bing_get_rank_and_traffic_stats",
|
|
32
|
+
"bing_get_keyword",
|
|
33
|
+
"bing_get_keyword_stats",
|
|
34
|
+
"bing_get_related_keywords",
|
|
35
|
+
"bing_get_crawl_stats",
|
|
36
|
+
"bing_get_crawl_issues",
|
|
37
|
+
"bing_get_crawl_settings",
|
|
38
|
+
"bing_get_link_counts",
|
|
39
|
+
"bing_get_url_links",
|
|
40
|
+
"bing_get_connected_pages",
|
|
41
|
+
"bing_get_deep_link_blocks",
|
|
42
|
+
"bing_get_url_info",
|
|
43
|
+
"bing_get_url_traffic_info",
|
|
44
|
+
"bing_get_children_url_info",
|
|
45
|
+
"bing_get_children_url_traffic_info",
|
|
46
|
+
"bing_get_blocked_urls",
|
|
47
|
+
"bing_get_page_preview_blocks",
|
|
48
|
+
"bing_get_country_region_settings",
|
|
49
|
+
"bing_get_query_parameters",
|
|
50
|
+
"bing_get_deep_link",
|
|
51
|
+
"bing_get_deep_link_algo_urls",
|
|
52
|
+
],
|
|
53
|
+
submit: [
|
|
54
|
+
"submit_urls_indexnow",
|
|
55
|
+
"submit_urls_google",
|
|
56
|
+
"bing_submit_url",
|
|
57
|
+
"bing_submit_url_batch",
|
|
58
|
+
"bing_submit_content",
|
|
59
|
+
"bing_submit_feed",
|
|
60
|
+
"bing_fetch_url",
|
|
61
|
+
"bing_add_connected_page",
|
|
62
|
+
"bing_add_site",
|
|
63
|
+
"bing_verify_site",
|
|
64
|
+
],
|
|
65
|
+
visibility: [
|
|
66
|
+
"bing_update_crawl_settings",
|
|
67
|
+
"bing_add_deep_link_block",
|
|
68
|
+
"bing_remove_deep_link_block",
|
|
69
|
+
"bing_update_deep_link",
|
|
70
|
+
"bing_add_blocked_url",
|
|
71
|
+
"bing_remove_blocked_url",
|
|
72
|
+
"bing_add_page_preview_block",
|
|
73
|
+
"bing_remove_page_preview_block",
|
|
74
|
+
"bing_add_country_region_settings",
|
|
75
|
+
"bing_remove_country_region_settings",
|
|
76
|
+
"bing_add_query_parameter",
|
|
77
|
+
"bing_remove_query_parameter",
|
|
78
|
+
"bing_set_query_parameter_state",
|
|
79
|
+
"bing_remove_feed",
|
|
80
|
+
],
|
|
81
|
+
access: [
|
|
82
|
+
"bing_remove_site",
|
|
83
|
+
"bing_add_site_role",
|
|
84
|
+
"bing_remove_site_role",
|
|
85
|
+
"bing_submit_site_move",
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
/** The risk text that the dialog shows. */
|
|
89
|
+
export const GROUP_RISK = {
|
|
90
|
+
read: "Reads search data of your sites, including verification codes and the email addresses of site users.",
|
|
91
|
+
submit: "Sends URLs, content and sitemaps to search engines, and adds sites. Uses daily quota.",
|
|
92
|
+
visibility: "Can remove pages or the whole site from search results, and slow the crawl.",
|
|
93
|
+
access: "Can remove or move a site, or give or remove the access of other people.",
|
|
94
|
+
};
|
|
95
|
+
const GROUP_BY_TOOL = new Map(APPROVAL_GROUPS.flatMap((group) => GROUP_TOOLS[group].map((tool) => [tool, group])));
|
|
96
|
+
/** Finds the group of a tool. A tool that is not in the table is a bug, so this throws. */
|
|
97
|
+
export function groupOf(tool) {
|
|
98
|
+
const group = GROUP_BY_TOOL.get(tool);
|
|
99
|
+
if (!group) {
|
|
100
|
+
throw new Error(`The tool "${tool}" is not in an approval group. Add it to GROUP_TOOLS.`);
|
|
101
|
+
}
|
|
102
|
+
return group;
|
|
103
|
+
}
|
|
104
|
+
const INTERACTION_GROUPS = ["visibility", "access"];
|
|
105
|
+
/**
|
|
106
|
+
* The `_meta` of a tool. Claude Code asks the user at each call of a `visibility` or `access`
|
|
107
|
+
* tool. This holds even when the client has no approval dialog.
|
|
108
|
+
*/
|
|
109
|
+
export function toolMeta(tool) {
|
|
110
|
+
return INTERACTION_GROUPS.includes(groupOf(tool))
|
|
111
|
+
? { "anthropic/requiresUserInteraction": true }
|
|
112
|
+
: undefined;
|
|
113
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApprovalGroup } from "./groups.js";
|
|
2
|
+
/** A session approval is for one group and one site, until the server stops. */
|
|
3
|
+
export declare function isSessionApproved(group: ApprovalGroup, site: string | undefined): boolean;
|
|
4
|
+
export declare function addSessionApproval(group: ApprovalGroup, site: string): void;
|
|
5
|
+
/** True once. The notice for a client without dialogs shows on the first risky result only. */
|
|
6
|
+
export declare function takeNoDialogNotice(): boolean;
|
|
7
|
+
/** Clears all state. Tests use this. */
|
|
8
|
+
export declare function resetSessionState(): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const approved = new Set();
|
|
2
|
+
let noticeShown = false;
|
|
3
|
+
function keyOf(group, site) {
|
|
4
|
+
return `${group}\u0000${site}`;
|
|
5
|
+
}
|
|
6
|
+
/** A session approval is for one group and one site, until the server stops. */
|
|
7
|
+
export function isSessionApproved(group, site) {
|
|
8
|
+
return site !== undefined && approved.has(keyOf(group, site));
|
|
9
|
+
}
|
|
10
|
+
export function addSessionApproval(group, site) {
|
|
11
|
+
approved.add(keyOf(group, site));
|
|
12
|
+
}
|
|
13
|
+
/** True once. The notice for a client without dialogs shows on the first risky result only. */
|
|
14
|
+
export function takeNoDialogNotice() {
|
|
15
|
+
const first = !noticeShown;
|
|
16
|
+
noticeShown = true;
|
|
17
|
+
return first;
|
|
18
|
+
}
|
|
19
|
+
/** Clears all state. Tests use this. */
|
|
20
|
+
export function resetSessionState() {
|
|
21
|
+
approved.clear();
|
|
22
|
+
noticeShown = false;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const COMMANDS: readonly ["serve", "setup", "status", "install"];
|
|
2
|
+
export type CommandName = (typeof COMMANDS)[number];
|
|
3
|
+
/** What the user asked for. `bare` means that the user gave no command. */
|
|
4
|
+
export type CliRequest = {
|
|
5
|
+
readonly kind: "command";
|
|
6
|
+
readonly command: CommandName;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "help";
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "version";
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "bare";
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "unknown";
|
|
15
|
+
readonly input: string;
|
|
16
|
+
};
|
|
17
|
+
/** Reads the arguments. No argument and no environment variable can change an approval. */
|
|
18
|
+
export declare function parseCliArguments(argv: readonly string[]): CliRequest;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
export const COMMANDS = ["serve", "setup", "status", "install"];
|
|
3
|
+
function isCommand(value) {
|
|
4
|
+
return COMMANDS.some((command) => command === value);
|
|
5
|
+
}
|
|
6
|
+
function parseFlags(argv) {
|
|
7
|
+
try {
|
|
8
|
+
return parseArgs({
|
|
9
|
+
args: [...argv],
|
|
10
|
+
allowPositionals: true,
|
|
11
|
+
options: {
|
|
12
|
+
help: { type: "boolean", short: "h" },
|
|
13
|
+
version: { type: "boolean", short: "v" },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// An unknown option. The caller shows the usage error.
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Reads the arguments. No argument and no environment variable can change an approval. */
|
|
23
|
+
export function parseCliArguments(argv) {
|
|
24
|
+
const parsed = parseFlags(argv);
|
|
25
|
+
if (!parsed) {
|
|
26
|
+
return { kind: "unknown", input: argv.join(" ") };
|
|
27
|
+
}
|
|
28
|
+
const [first, ...rest] = parsed.positionals;
|
|
29
|
+
if (parsed.values.help) {
|
|
30
|
+
return { kind: "help" };
|
|
31
|
+
}
|
|
32
|
+
if (parsed.values.version) {
|
|
33
|
+
return { kind: "version" };
|
|
34
|
+
}
|
|
35
|
+
if (first === undefined) {
|
|
36
|
+
return { kind: "bare" };
|
|
37
|
+
}
|
|
38
|
+
return isCommand(first) && rest.length === 0
|
|
39
|
+
? { kind: "command", command: first }
|
|
40
|
+
: { kind: "unknown", input: argv.join(" ") };
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CliContext } from "./run.js";
|
|
2
|
+
export interface CommandOptions {
|
|
3
|
+
readonly out: (text: string) => void;
|
|
4
|
+
readonly err: (text: string) => void;
|
|
5
|
+
readonly stdinIsTerminal: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** The command table. */
|
|
8
|
+
export declare function createCommands(options: CommandOptions): Pick<CliContext, "commands" | "offerInstall">;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { currentConfig, loadConfig } from "../config/index.js";
|
|
3
|
+
import { configFilePath } from "../config/paths.js";
|
|
4
|
+
import { startServer } from "../server.js";
|
|
5
|
+
import { resolveServerCommand } from "./install/command.js";
|
|
6
|
+
import { runCommand } from "./install/exec.js";
|
|
7
|
+
import { offerInstall, runInstall } from "./install/flow.js";
|
|
8
|
+
import { baseCommands, EXIT_FAILURE } from "./run.js";
|
|
9
|
+
import { runSetup } from "./setup/flow.js";
|
|
10
|
+
import { createSetupServices } from "./setup/services.js";
|
|
11
|
+
import { createTerminalPrompter } from "./terminal.js";
|
|
12
|
+
function installContext() {
|
|
13
|
+
return {
|
|
14
|
+
prompt: createTerminalPrompter(),
|
|
15
|
+
install: { platform: process.platform, home: homedir(), env: process.env, run: runCommand },
|
|
16
|
+
command: resolveServerCommand({
|
|
17
|
+
scriptPath: process.argv[1],
|
|
18
|
+
execPath: process.execPath,
|
|
19
|
+
platform: process.platform,
|
|
20
|
+
env: process.env,
|
|
21
|
+
}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function needsTerminal({ err, stdinIsTerminal }, name) {
|
|
25
|
+
if (stdinIsTerminal) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
err(`The ${name} needs a terminal. Run seo-webmaster-mcp ${name} in a terminal window.`);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
function setupCommand(options) {
|
|
32
|
+
return async () => {
|
|
33
|
+
if (needsTerminal(options, "setup")) {
|
|
34
|
+
return EXIT_FAILURE;
|
|
35
|
+
}
|
|
36
|
+
loadConfig();
|
|
37
|
+
const install = installContext();
|
|
38
|
+
return runSetup({
|
|
39
|
+
prompt: install.prompt,
|
|
40
|
+
services: createSetupServices(),
|
|
41
|
+
draft: { config: currentConfig() },
|
|
42
|
+
configPath: configFilePath(),
|
|
43
|
+
offerInstall: async () => {
|
|
44
|
+
await offerInstall(install);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function installCommand(options) {
|
|
50
|
+
return () => needsTerminal(options, "install")
|
|
51
|
+
? Promise.resolve(EXIT_FAILURE)
|
|
52
|
+
: runInstall(installContext());
|
|
53
|
+
}
|
|
54
|
+
/** The command table. */
|
|
55
|
+
export function createCommands(options) {
|
|
56
|
+
return {
|
|
57
|
+
commands: {
|
|
58
|
+
...baseCommands(startServer, options.out),
|
|
59
|
+
setup: setupCommand(options),
|
|
60
|
+
install: installCommand(options),
|
|
61
|
+
},
|
|
62
|
+
offerInstall: () => offerInstall(installContext()),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isAnyEngineConfigured(): boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { isBingConfigured } from "../providers/bing/auth.js";
|
|
2
|
+
import { isGoogleConfigured } from "../providers/google/auth.js";
|
|
3
|
+
import { isIndexNowConfigured } from "../providers/indexnow/provider.js";
|
|
4
|
+
export function isAnyEngineConfigured() {
|
|
5
|
+
return isGoogleConfigured() || isBingConfigured() || isIndexNowConfigured();
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SERVER_NAME, SERVER_VERSION } from "../core/constants.js";
|
|
2
|
+
const COMMAND_LINES = [
|
|
3
|
+
["serve", "Start the MCP server. This is the default when stdin is not a terminal."],
|
|
4
|
+
["setup", "Set up Google, Bing, IndexNow and the approval choices."],
|
|
5
|
+
["status", "Show the engines, the approval choices and the configuration file path."],
|
|
6
|
+
["install", "Add this server to Claude Code, Claude Desktop or Cursor."],
|
|
7
|
+
];
|
|
8
|
+
const OPTION_LINES = [
|
|
9
|
+
["-h, --help", "Show this help text."],
|
|
10
|
+
["-v, --version", "Show the version."],
|
|
11
|
+
];
|
|
12
|
+
function lines(rows) {
|
|
13
|
+
return rows.map(([name, text]) => ` ${name.padEnd(16)}${text}`);
|
|
14
|
+
}
|
|
15
|
+
/** The help text. It points to `setup` when no engine has a key. */
|
|
16
|
+
export function renderHelp(anyEngineConfigured) {
|
|
17
|
+
return [
|
|
18
|
+
`${SERVER_NAME} ${SERVER_VERSION}`,
|
|
19
|
+
"",
|
|
20
|
+
`Usage: ${SERVER_NAME} [command]`,
|
|
21
|
+
"",
|
|
22
|
+
"Commands:",
|
|
23
|
+
...lines(COMMAND_LINES),
|
|
24
|
+
"",
|
|
25
|
+
"Options:",
|
|
26
|
+
...lines(OPTION_LINES),
|
|
27
|
+
...(anyEngineConfigured ? [] : ["", `Run ${SERVER_NAME} setup to start.`]),
|
|
28
|
+
].join("\n");
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const CLIENT_IDS: readonly ["claude-code", "claude-desktop", "cursor"];
|
|
2
|
+
export type ClientId = (typeof CLIENT_IDS)[number];
|
|
3
|
+
export declare const CLIENT_LABELS: Readonly<Record<ClientId, string>>;
|
|
4
|
+
export interface RunResult {
|
|
5
|
+
readonly code: number;
|
|
6
|
+
readonly output: string;
|
|
7
|
+
}
|
|
8
|
+
/** Everything that touches the machine. Tests give temporary folders and a fake runner. */
|
|
9
|
+
export interface InstallEnv {
|
|
10
|
+
readonly platform: NodeJS.Platform;
|
|
11
|
+
readonly home: string;
|
|
12
|
+
readonly env: NodeJS.ProcessEnv;
|
|
13
|
+
readonly run: (file: string, args: readonly string[]) => Promise<RunResult>;
|
|
14
|
+
}
|
|
15
|
+
/** The JSON file of a client, or `undefined` for Claude Code. */
|
|
16
|
+
export declare function configPathOf(client: ClientId, install: InstallEnv): string | undefined;
|
|
17
|
+
/** The clients that this machine has. A JSON client is found when its folder exists. */
|
|
18
|
+
export declare function findClients(install: InstallEnv): Promise<ClientId[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
export const CLIENT_IDS = ["claude-code", "claude-desktop", "cursor"];
|
|
4
|
+
export const CLIENT_LABELS = {
|
|
5
|
+
"claude-code": "Claude Code",
|
|
6
|
+
"claude-desktop": "Claude Desktop",
|
|
7
|
+
cursor: "Cursor",
|
|
8
|
+
};
|
|
9
|
+
function desktopBase({ platform, home, env }) {
|
|
10
|
+
if (platform === "darwin") {
|
|
11
|
+
return join(home, "Library", "Application Support");
|
|
12
|
+
}
|
|
13
|
+
if (platform === "win32") {
|
|
14
|
+
return env.APPDATA ?? join(home, "AppData", "Roaming");
|
|
15
|
+
}
|
|
16
|
+
return env.XDG_CONFIG_HOME ?? join(home, ".config");
|
|
17
|
+
}
|
|
18
|
+
/** The JSON file of a client, or `undefined` for Claude Code. */
|
|
19
|
+
export function configPathOf(client, install) {
|
|
20
|
+
if (client === "cursor") {
|
|
21
|
+
return join(install.home, ".cursor", "mcp.json");
|
|
22
|
+
}
|
|
23
|
+
return client === "claude-desktop"
|
|
24
|
+
? join(desktopBase(install), "Claude", "claude_desktop_config.json")
|
|
25
|
+
: undefined;
|
|
26
|
+
}
|
|
27
|
+
async function hasClaudeCode(install) {
|
|
28
|
+
try {
|
|
29
|
+
return (await install.run("claude", ["--version"])).code === 0;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// The command is not on the PATH. Claude Code is not installed.
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The clients that this machine has. A JSON client is found when its folder exists. */
|
|
37
|
+
export async function findClients(install) {
|
|
38
|
+
const found = await Promise.all(CLIENT_IDS.map(async (client) => {
|
|
39
|
+
if (client === "claude-code") {
|
|
40
|
+
return (await hasClaudeCode(install)) ? client : undefined;
|
|
41
|
+
}
|
|
42
|
+
const path = configPathOf(client, install);
|
|
43
|
+
return path !== undefined && existsSync(dirname(path)) ? client : undefined;
|
|
44
|
+
}));
|
|
45
|
+
return found.filter((client) => client !== undefined);
|
|
46
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME = "@itsaakashpatel/seo-webmaster-mcp";
|
|
2
|
+
export declare const SERVER_ENTRY_NAME = "seo-webmaster";
|
|
3
|
+
export interface ServerCommand {
|
|
4
|
+
readonly command: string;
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export interface CommandContext {
|
|
8
|
+
readonly scriptPath: string | undefined;
|
|
9
|
+
readonly execPath: string;
|
|
10
|
+
readonly platform: NodeJS.Platform;
|
|
11
|
+
readonly env: NodeJS.ProcessEnv;
|
|
12
|
+
}
|
|
13
|
+
/** True when npx started the CLI. The script path then points into the cache of npx. */
|
|
14
|
+
export declare function startedByNpx(context: CommandContext): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The command that a client runs. It is `npx -y <package>` when npx started the CLI. Otherwise
|
|
17
|
+
* it is the absolute path of the installed command. It is never a path in the npx cache.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveServerCommand(context: CommandContext): ServerCommand;
|
|
20
|
+
/** The line that a user can read in the confirmation. */
|
|
21
|
+
export declare function describeCommand({ command, args }: ServerCommand): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
export const PACKAGE_NAME = "@itsaakashpatel/seo-webmaster-mcp";
|
|
4
|
+
export const SERVER_ENTRY_NAME = "seo-webmaster";
|
|
5
|
+
const NPX_FORM = { command: "npx", args: ["-y", PACKAGE_NAME] };
|
|
6
|
+
function inNpxCache(path) {
|
|
7
|
+
return path !== undefined && path.split(/[\\/]/).includes("_npx");
|
|
8
|
+
}
|
|
9
|
+
/** True when npx started the CLI. The script path then points into the cache of npx. */
|
|
10
|
+
export function startedByNpx(context) {
|
|
11
|
+
return inNpxCache(context.scriptPath) || Boolean(context.env.npm_execpath);
|
|
12
|
+
}
|
|
13
|
+
function resolveScript(path) {
|
|
14
|
+
const absolute = isAbsolute(path) ? path : resolve(path);
|
|
15
|
+
try {
|
|
16
|
+
return realpathSync(absolute);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// The path cannot be resolved. The absolute form is still a stable path.
|
|
20
|
+
return absolute;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The command that a client runs. It is `npx -y <package>` when npx started the CLI. Otherwise
|
|
25
|
+
* it is the absolute path of the installed command. It is never a path in the npx cache.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveServerCommand(context) {
|
|
28
|
+
const { scriptPath, execPath, platform } = context;
|
|
29
|
+
if (!scriptPath || startedByNpx(context)) {
|
|
30
|
+
return NPX_FORM;
|
|
31
|
+
}
|
|
32
|
+
const script = resolveScript(scriptPath);
|
|
33
|
+
if (inNpxCache(script)) {
|
|
34
|
+
return NPX_FORM;
|
|
35
|
+
}
|
|
36
|
+
// Windows cannot run a script file directly, so it runs the script with Node.
|
|
37
|
+
return platform === "win32"
|
|
38
|
+
? { command: execPath, args: [script] }
|
|
39
|
+
: { command: script, args: [] };
|
|
40
|
+
}
|
|
41
|
+
/** The line that a user can read in the confirmation. */
|
|
42
|
+
export function describeCommand({ command, args }) {
|
|
43
|
+
return [command, ...args].join(" ");
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
/** Runs a command without a shell. A command that does not start gives an error. */
|
|
3
|
+
export function runCommand(file, args) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
execFile(file, [...args], { timeout: 30_000 }, (error, stdout, stderr) => {
|
|
6
|
+
if (error && !("code" in error && typeof error.code === "number")) {
|
|
7
|
+
reject(error);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const code = error && typeof error.code === "number" ? error.code : 0;
|
|
11
|
+
resolve({ code, output: `${stdout}${stderr}`.trim() });
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Prompter } from "../prompter.js";
|
|
2
|
+
import { type ClientId, type InstallEnv } from "./clients.js";
|
|
3
|
+
import { type ServerCommand } from "./command.js";
|
|
4
|
+
export interface InstallContext {
|
|
5
|
+
readonly prompt: Prompter;
|
|
6
|
+
readonly install: InstallEnv;
|
|
7
|
+
readonly command: ServerCommand;
|
|
8
|
+
}
|
|
9
|
+
/** The clients that already have the server. */
|
|
10
|
+
export declare function findInstalled(ctx: InstallContext): Promise<ClientId[]>;
|
|
11
|
+
/** Adds the server to one client that the user picks. */
|
|
12
|
+
export declare function runInstall(ctx: InstallContext): Promise<number>;
|
|
13
|
+
/** Asks to install when no found client has the server yet. */
|
|
14
|
+
export declare function offerInstall(ctx: InstallContext): Promise<number>;
|