mcp-google-search-console 0.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.
- package/LICENSE +21 -0
- package/README.md +246 -0
- package/dist/client.js +290 -0
- package/dist/config.js +54 -0
- package/dist/index.js +69 -0
- package/dist/telemetry.js +120 -0
- package/dist/tools/analytics.js +123 -0
- package/dist/tools/inspection.js +31 -0
- package/dist/tools/raw.js +30 -0
- package/dist/tools/sitemaps.js +62 -0
- package/dist/tools/sites.js +55 -0
- package/dist/tools/util.js +65 -0
- package/dist/types.js +50 -0
- package/package.json +62 -0
- package/test/dist-smoke.test.js +129 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
7
|
+
|
|
8
|
+
import { GoogleSearchConsoleClient } from "../dist/client.js";
|
|
9
|
+
import { registerSiteTools } from "../dist/tools/sites.js";
|
|
10
|
+
import { registerSitemapTools } from "../dist/tools/sitemaps.js";
|
|
11
|
+
import { registerAnalyticsTools } from "../dist/tools/analytics.js";
|
|
12
|
+
import { registerInspectionTools } from "../dist/tools/inspection.js";
|
|
13
|
+
import { registerRawTool } from "../dist/tools/raw.js";
|
|
14
|
+
|
|
15
|
+
const ALL_TOOLS = [
|
|
16
|
+
"add_site",
|
|
17
|
+
"delete_site",
|
|
18
|
+
"delete_sitemap",
|
|
19
|
+
"get_site",
|
|
20
|
+
"get_sitemap",
|
|
21
|
+
"get_top_queries",
|
|
22
|
+
"inspect_url",
|
|
23
|
+
"list_sitemaps",
|
|
24
|
+
"list_sites",
|
|
25
|
+
"raw_request",
|
|
26
|
+
"search_analytics",
|
|
27
|
+
"submit_sitemap",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
test("dist client rejects foreign-origin paths before sending the Bearer token", async () => {
|
|
31
|
+
const original = globalThis.fetch;
|
|
32
|
+
let called = false;
|
|
33
|
+
globalThis.fetch = async () => {
|
|
34
|
+
called = true;
|
|
35
|
+
return new Response("{}", { status: 200 });
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const client = new GoogleSearchConsoleClient({
|
|
39
|
+
accessToken: "SECRET",
|
|
40
|
+
apiBase: "https://searchconsole.googleapis.com",
|
|
41
|
+
timeoutMs: 1000,
|
|
42
|
+
maxRetries: 0,
|
|
43
|
+
});
|
|
44
|
+
await assert.rejects(() => client.request("GET", "https://example.invalid/steal"), /foreign origin/);
|
|
45
|
+
assert.equal(called, false);
|
|
46
|
+
} finally {
|
|
47
|
+
globalThis.fetch = original;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("dist client sends the Bearer token, URL-encodes the property and posts JSON", async () => {
|
|
52
|
+
const original = globalThis.fetch;
|
|
53
|
+
let seen;
|
|
54
|
+
globalThis.fetch = async (url, init) => {
|
|
55
|
+
seen = { url: String(url), auth: init.headers.Authorization, body: JSON.parse(init.body) };
|
|
56
|
+
return new Response('{"rows":[]}', { status: 200 });
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
const client = new GoogleSearchConsoleClient({
|
|
60
|
+
accessToken: "SECRET",
|
|
61
|
+
apiBase: "https://searchconsole.googleapis.com",
|
|
62
|
+
timeoutMs: 1000,
|
|
63
|
+
maxRetries: 0,
|
|
64
|
+
});
|
|
65
|
+
await client.searchAnalytics({
|
|
66
|
+
siteUrl: "sc-domain:example.com",
|
|
67
|
+
startDate: "2026-08-01",
|
|
68
|
+
endDate: "2026-08-07",
|
|
69
|
+
});
|
|
70
|
+
assert.equal(
|
|
71
|
+
seen.url,
|
|
72
|
+
"https://searchconsole.googleapis.com/webmasters/v3/sites/sc-domain%3Aexample.com/searchAnalytics/query",
|
|
73
|
+
);
|
|
74
|
+
assert.equal(seen.auth, "Bearer SECRET");
|
|
75
|
+
assert.deepEqual(seen.body, { startDate: "2026-08-01", endDate: "2026-08-07" });
|
|
76
|
+
} finally {
|
|
77
|
+
globalThis.fetch = original;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("dist registers the expected tools", () => {
|
|
82
|
+
const names = [];
|
|
83
|
+
const server = {
|
|
84
|
+
registerTool(name) {
|
|
85
|
+
names.push(name);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const client = {};
|
|
89
|
+
|
|
90
|
+
registerSiteTools(server, client);
|
|
91
|
+
registerSitemapTools(server, client);
|
|
92
|
+
registerAnalyticsTools(server, client);
|
|
93
|
+
registerInspectionTools(server, client);
|
|
94
|
+
registerRawTool(server, client);
|
|
95
|
+
|
|
96
|
+
assert.deepEqual(names.sort(), ALL_TOOLS);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("dist binary completes a real MCP handshake over stdio and lists every tool", async () => {
|
|
100
|
+
const transport = new StdioClientTransport({
|
|
101
|
+
command: process.execPath,
|
|
102
|
+
args: [fileURLToPath(new URL("../dist/index.js", import.meta.url))],
|
|
103
|
+
env: {
|
|
104
|
+
...process.env,
|
|
105
|
+
GOOGLE_SEARCH_CONSOLE_ACCESS_TOKEN: "test-token",
|
|
106
|
+
ASKADS_TELEMETRY: "0", // keep the suite offline
|
|
107
|
+
},
|
|
108
|
+
stderr: "pipe",
|
|
109
|
+
});
|
|
110
|
+
const client = new Client({ name: "dist-smoke", version: "0.0.0" });
|
|
111
|
+
await client.connect(transport);
|
|
112
|
+
try {
|
|
113
|
+
const server = client.getServerVersion();
|
|
114
|
+
assert.equal(server?.name, "mcp-google-search-console");
|
|
115
|
+
assert.match(String(server?.version), /^\d+\.\d+\.\d+$/);
|
|
116
|
+
|
|
117
|
+
const { tools } = await client.listTools();
|
|
118
|
+
assert.deepEqual(tools.map((t) => t.name).sort(), ALL_TOOLS);
|
|
119
|
+
|
|
120
|
+
const analytics = tools.find((t) => t.name === "search_analytics");
|
|
121
|
+
assert.equal(analytics.annotations?.readOnlyHint, true);
|
|
122
|
+
assert.ok(analytics.inputSchema?.properties?.site_url, "input schema must reach the client");
|
|
123
|
+
|
|
124
|
+
const deleteSite = tools.find((t) => t.name === "delete_site");
|
|
125
|
+
assert.equal(deleteSite.annotations?.destructiveHint, true);
|
|
126
|
+
} finally {
|
|
127
|
+
await client.close();
|
|
128
|
+
}
|
|
129
|
+
});
|