@houtini/better-search-console 1.0.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 (71) hide show
  1. package/LICENSE +189 -0
  2. package/README.md +334 -0
  3. package/better-search-console.jpg +0 -0
  4. package/dist/core/DataRetention.d.ts +49 -0
  5. package/dist/core/DataRetention.d.ts.map +1 -0
  6. package/dist/core/DataRetention.js +165 -0
  7. package/dist/core/DataRetention.js.map +1 -0
  8. package/dist/core/DataSync.d.ts +24 -0
  9. package/dist/core/DataSync.d.ts.map +1 -0
  10. package/dist/core/DataSync.js +247 -0
  11. package/dist/core/DataSync.js.map +1 -0
  12. package/dist/core/Database.d.ts +29 -0
  13. package/dist/core/Database.d.ts.map +1 -0
  14. package/dist/core/Database.js +205 -0
  15. package/dist/core/Database.js.map +1 -0
  16. package/dist/core/GscClient.d.ts +23 -0
  17. package/dist/core/GscClient.d.ts.map +1 -0
  18. package/dist/core/GscClient.js +92 -0
  19. package/dist/core/GscClient.js.map +1 -0
  20. package/dist/core/SyncManager.d.ts +66 -0
  21. package/dist/core/SyncManager.d.ts.map +1 -0
  22. package/dist/core/SyncManager.js +368 -0
  23. package/dist/core/SyncManager.js.map +1 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +14 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/overview/src/ui/overview.html +185 -0
  29. package/dist/server.d.ts +6 -0
  30. package/dist/server.d.ts.map +1 -0
  31. package/dist/server.js +441 -0
  32. package/dist/server.js.map +1 -0
  33. package/dist/src/ui/dashboard.html +437 -0
  34. package/dist/sync-progress/src/ui/sync-progress.html +147 -0
  35. package/dist/tools/compare-periods.d.ts +3 -0
  36. package/dist/tools/compare-periods.d.ts.map +1 -0
  37. package/dist/tools/compare-periods.js +127 -0
  38. package/dist/tools/compare-periods.js.map +1 -0
  39. package/dist/tools/get-dashboard.d.ts +10 -0
  40. package/dist/tools/get-dashboard.d.ts.map +1 -0
  41. package/dist/tools/get-dashboard.js +310 -0
  42. package/dist/tools/get-dashboard.js.map +1 -0
  43. package/dist/tools/get-insights.d.ts +3 -0
  44. package/dist/tools/get-insights.d.ts.map +1 -0
  45. package/dist/tools/get-insights.js +509 -0
  46. package/dist/tools/get-insights.js.map +1 -0
  47. package/dist/tools/get-overview.d.ts +36 -0
  48. package/dist/tools/get-overview.d.ts.map +1 -0
  49. package/dist/tools/get-overview.js +111 -0
  50. package/dist/tools/get-overview.js.map +1 -0
  51. package/dist/tools/helpers.d.ts +67 -0
  52. package/dist/tools/helpers.d.ts.map +1 -0
  53. package/dist/tools/helpers.js +239 -0
  54. package/dist/tools/helpers.js.map +1 -0
  55. package/dist/tools/list-properties.d.ts +4 -0
  56. package/dist/tools/list-properties.d.ts.map +1 -0
  57. package/dist/tools/list-properties.js +35 -0
  58. package/dist/tools/list-properties.js.map +1 -0
  59. package/dist/tools/query-data.d.ts +12 -0
  60. package/dist/tools/query-data.d.ts.map +1 -0
  61. package/dist/tools/query-data.js +20 -0
  62. package/dist/tools/query-data.js.map +1 -0
  63. package/dist/tools/sync-data.d.ts +11 -0
  64. package/dist/tools/sync-data.d.ts.map +1 -0
  65. package/dist/tools/sync-data.js +62 -0
  66. package/dist/tools/sync-data.js.map +1 -0
  67. package/dist/types/index.d.ts +101 -0
  68. package/dist/types/index.d.ts.map +1 -0
  69. package/dist/types/index.js +3 -0
  70. package/dist/types/index.js.map +1 -0
  71. package/package.json +57 -0
package/LICENSE ADDED
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including
48
+ the original version of the Work and any modifications or additions
49
+ to that Work or Derivative Works thereof, that is intentionally
50
+ submitted to the Licensor for inclusion in the Work by the copyright owner
51
+ or by an individual or Legal Entity authorized to submit on behalf of
52
+ the copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity
62
+ on behalf of whom a Contribution has been received by the Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
83
+ or a Contribution incorporated within the Work constitutes direct
84
+ or contributory patent infringement, then any patent licenses
85
+ granted to You under this License for that Work shall terminate
86
+ as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or
94
+ Derivative Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works
100
+ that You distribute, all copyright, patent, trademark, and
101
+ attribution notices from the Source form of the Work,
102
+ excluding those notices that do not pertain to any part of
103
+ the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, then any Derivative Works that You distribute must
107
+ include a readable copy of the attribution notices contained
108
+ within such NOTICE file, excluding any notices that do not
109
+ pertain to any part of the Derivative Works, in at least one
110
+ of the following places: within a NOTICE text file distributed
111
+ as part of the Derivative Works; within the Source form or
112
+ documentation, if provided along with the Derivative Works; or,
113
+ within a display generated by the Derivative Works, if and
114
+ wherever such third-party notices normally appear. The contents
115
+ of the NOTICE file are for informational purposes only and
116
+ do not modify the License. You may add Your own attribution
117
+ notices within Derivative Works that You distribute, alongside
118
+ or as an addendum to the NOTICE text from the Work, provided
119
+ that such additional attribution notices cannot be construed
120
+ as modifying the License.
121
+
122
+ You may add Your own copyright statement to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement you may have executed
135
+ with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and customary use in describing the
140
+ origin of the Work and reproducing the content of the NOTICE file.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or
143
+ agreed to in writing, Licensor provides the Work (and each
144
+ Contributor provides its Contributions) on an "AS IS" BASIS,
145
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
146
+ implied, including, without limitation, any warranties or conditions
147
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
148
+ PARTICULAR PURPOSE. You are solely responsible for determining the
149
+ appropriateness of using or redistributing the Work and assume any
150
+ risks associated with Your exercise of permissions under this License.
151
+
152
+ 8. Limitation of Liability. In no event and under no legal theory,
153
+ whether in tort (including negligence), contract, or otherwise,
154
+ unless required by applicable law (such as deliberate and grossly
155
+ negligent acts) or agreed to in writing, shall any Contributor be
156
+ liable to You for damages, including any direct, indirect, special,
157
+ incidental, or consequential damages of any character arising as a
158
+ result of this License or out of the use or inability to use the
159
+ Work (including but not limited to damages for loss of goodwill,
160
+ work stoppage, computer failure or malfunction, or any and all
161
+ other commercial damages or losses), even if such Contributor
162
+ has been advised of the possibility of such damages.
163
+
164
+ 9. Accepting Warranty or Additional Liability. While redistributing
165
+ the Work or Derivative Works thereof, You may choose to offer,
166
+ and charge a fee for, acceptance of support, warranty, indemnity,
167
+ or other liability obligations and/or rights consistent with this
168
+ License. However, in accepting such obligations, You may act only
169
+ on Your own behalf and on Your sole responsibility, not on behalf
170
+ of any other Contributor, and only if You agree to indemnify,
171
+ defend, and hold each Contributor harmless for any liability
172
+ incurred by, or claims asserted against, such Contributor by reason
173
+ of your accepting any such warranty or additional liability.
174
+
175
+ END OF TERMS AND CONDITIONS
176
+
177
+ Copyright 2025 Houtini Ltd
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,334 @@
1
+ # Better Search Console
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@houtini/better-search-console.svg?style=flat-square)](https://www.npmjs.com/package/@houtini/better-search-console)
4
+ [![Known Vulnerabilities](https://snyk.io/test/github/houtini-ai/better-search-console/badge.svg)](https://snyk.io/test/github/houtini-ai/better-search-console)
5
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
7
+ [![MCP](https://img.shields.io/badge/MCP-Compatible-green?style=flat-square)](https://modelcontextprotocol.io)
8
+
9
+ ![Better Search Console](better-search-console.jpg)
10
+
11
+ ## Why This Exists
12
+
13
+ Every SEO tool that connects to an LLM has the same problem: the Google Search Console API returns 1,000 rows per request, your context window fills up fast, and you end up asking the model to reason about a tiny fraction of your data. The answers sound plausible but they're built on incomplete information.
14
+
15
+ This MCP server takes a different approach. It downloads your entire Search Console dataset into a local SQLite database, then gives Claude pre-built SQL queries for every standard SEO analysis type. Claude never sees the raw data. It sees query results: the top 50 declining pages, the queries ranking 5-20 with high impressions, the device breakdown for a specific URL pattern. Precise answers from complete data, using a few hundred tokens instead of tens of thousands.
16
+
17
+ The experiment started with ext-apps, the MCP specification's support for interactive UI components. The dashboard, overview grid, and sync progress views all render as iframes inside Claude Desktop. Whether this represents the future of MCP tooling or a novelty is still an open question. But the core architecture of local SQLite plus structured SQL queries works well regardless.
18
+
19
+ ### What you get
20
+
21
+ One database per GSC property, synced in the background with full pagination (no row limits). Sixteen pre-built insight queries covering the things SEOs check repeatedly. Custom SQL for everything else. Automatic data retention that prunes low-value rows after each sync to keep databases from growing without bound. The data stays on your machine and the queries run in milliseconds.
22
+
23
+ ## Quick Start
24
+
25
+ ### Prerequisites
26
+
27
+ You'll need three things before this works:
28
+
29
+ 1. **A Google Cloud service account** with the Search Console API enabled
30
+ 2. **The service account email added as a user** on each GSC property you want to access (Settings > Users and permissions in Search Console)
31
+ 3. **Node.js 18+**
32
+
33
+ If you haven't created a service account before: go to the [Google Cloud Console](https://console.cloud.google.com/), create a project, enable the "Google Search Console API", create a service account, and download the JSON key file. The whole process takes about five minutes.
34
+
35
+ ### Claude Desktop Configuration
36
+
37
+ Add this to your Claude Desktop config file:
38
+
39
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
40
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
41
+
42
+ #### Using npx (recommended)
43
+
44
+ ```json
45
+ {
46
+ "mcpServers": {
47
+ "better-search-console": {
48
+ "command": "npx",
49
+ "args": ["@houtini/better-search-console"],
50
+ "env": {
51
+ "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json"
52
+ }
53
+ }
54
+ }
55
+ }
56
+ ```
57
+
58
+ #### Using a local build
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "better-search-console": {
64
+ "command": "node",
65
+ "args": ["C:\\MCP\\better-search-console\\dist\\index.js"],
66
+ "env": {
67
+ "GOOGLE_APPLICATION_CREDENTIALS": "C:\\path\\to\\service-account.json",
68
+ "BSC_DATA_DIR": "C:\\seo-audits\\better-search-console"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ ### Environment Variables
76
+
77
+ | Variable | Required | Default | What it does |
78
+ |----------|----------|---------|--------------|
79
+ | `GOOGLE_APPLICATION_CREDENTIALS` | Yes | - | Path to the service account JSON key file |
80
+ | `BSC_DATA_DIR` | No | `~/seo-audits/better-search-console` | Where SQLite databases are stored |
81
+
82
+ ### First Run
83
+
84
+ Tell Claude: *"Show me my search console data"*
85
+
86
+ The `setup` tool handles the rest: discovers your properties, syncs them all in the background, and shows an overview grid with sparkline trends. Depending on how much data you have, initial sync takes anywhere from 30 seconds to a few minutes.
87
+
88
+ ## Tools
89
+
90
+ ### Setup and Sync
91
+
92
+ | Tool | What it does |
93
+ |------|-------------|
94
+ | `setup` | First-run experience. Lists properties, syncs all, returns overview |
95
+ | `sync_gsc_data` | Sync a single property. Returns a job ID for progress tracking |
96
+ | `sync_all_properties` | Sync every accessible property. Runs up to 2 in parallel |
97
+ | `check_sync_status` | Poll a sync job for progress. Omit the job ID to see all jobs |
98
+ | `cancel_sync` | Stop a running sync gracefully |
99
+
100
+ ### Analysis
101
+
102
+ | Tool | What it does |
103
+ |------|-------------|
104
+ | `get_overview` | All properties at a glance with clicks, impressions, CTR, position, and sparkline trends |
105
+ | `get_dashboard` | Deep dive into one property. Hero metrics, trend chart, top queries, top pages, country breakdown, ranking distribution, new/lost queries, branded split |
106
+ | `get_insights` | Sixteen pre-built analytical queries (see below) |
107
+ | `compare_periods` | Side-by-side comparison of two arbitrary date ranges across any dimension |
108
+ | `query_gsc_data` | Run any SELECT query against the `search_analytics` table |
109
+ | `prune_database` | Apply data retention policy manually. Preview mode available |
110
+
111
+ ### Insight Types
112
+
113
+ The `get_insights` tool supports these report types:
114
+
115
+ | Insight | What it shows |
116
+ |---------|--------------|
117
+ | `summary` | Aggregate metrics with period-over-period changes |
118
+ | `top_queries` | Highest-traffic queries |
119
+ | `top_pages` | Highest-traffic pages |
120
+ | `growing_queries` | Queries gaining clicks |
121
+ | `declining_queries` | Queries losing clicks |
122
+ | `growing_pages` | Pages gaining clicks |
123
+ | `declining_pages` | Pages losing clicks |
124
+ | `opportunities` | Queries ranking 5-20 with high impressions. Your quick wins |
125
+ | `device_breakdown` | Desktop vs mobile vs tablet split |
126
+ | `country_breakdown` | Traffic by country |
127
+ | `page_queries` | All queries driving traffic to a specific page |
128
+ | `query_pages` | All pages ranking for a specific query |
129
+ | `daily_trend` | Day-by-day metrics for the period |
130
+ | `new_queries` | Queries that appeared in the current period but not the previous |
131
+ | `lost_queries` | Queries that disappeared |
132
+ | `branded_split` | Branded vs non-branded traffic (pass your brand terms) |
133
+
134
+ ## Data Retention
135
+
136
+ Large GSC properties generate millions of rows. A site with 50,000 pages indexed across 200+ countries accumulates data fast, and most of it is noise: zero-click impressions from countries you don't target, queries that appeared once and never again.
137
+
138
+ The retention system prunes this automatically after each sync. Recent data (last 90 days by default) is never touched. Older data is filtered by two rules:
139
+
140
+ **Target countries** (US, UK, EU, Australia, Canada): rows with zero clicks are kept only if they have 5+ impressions. This preserves queries with visibility potential whilst removing the long tail of single-impression noise.
141
+
142
+ **Non-target countries**: rows with zero clicks are deleted entirely. If nobody in Uzbekistan has ever clicked through on one of your results, that row isn't informing any decision.
143
+
144
+ Rows with clicks are never deleted regardless of age or country.
145
+
146
+ After deletion, the database is vacuumed to reclaim disk space and ANALYZE is run to update the query planner.
147
+
148
+ ### Manual Pruning
149
+
150
+ You can trigger this yourself with the `prune_database` tool. Preview mode shows what would be deleted without touching anything:
151
+
152
+ ```
153
+ prune_database siteUrl="sc-domain:example.com" preview=true
154
+ ```
155
+
156
+ Then run for real:
157
+
158
+ ```
159
+ prune_database siteUrl="sc-domain:example.com"
160
+ ```
161
+
162
+ Both `recentDays` (default: 90) and `targetMinImpressions` (default: 5) are configurable per run.
163
+
164
+ ### Results
165
+
166
+ On a site with 9.8 million rows and a 6GB database, the initial prune deleted 6.3 million rows (64%), reduced the database to 2.2GB, and preserved every single click. All impressions data for actionable queries remained intact. Subsequent syncs prune incrementally, so the database never bloats again.
167
+
168
+ ## Custom SQL
169
+
170
+ The `query_gsc_data` tool accepts any SELECT query against the `search_analytics` table. INSERT, UPDATE, DELETE, DROP, ALTER, and CREATE are blocked.
171
+
172
+ ### Schema
173
+
174
+ ```sql
175
+ search_analytics (
176
+ date TEXT, -- YYYY-MM-DD
177
+ query TEXT,
178
+ page TEXT,
179
+ device TEXT, -- DESKTOP, MOBILE, TABLET
180
+ country TEXT, -- ISO 3166-1 alpha-3 lowercase
181
+ clicks INTEGER,
182
+ impressions INTEGER,
183
+ ctr REAL,
184
+ position REAL
185
+ )
186
+ ```
187
+
188
+ ### Example Queries
189
+
190
+ Find cannibalisation (multiple pages ranking for the same query):
191
+
192
+ ```sql
193
+ SELECT query, COUNT(DISTINCT page) as pages, SUM(clicks) as clicks
194
+ FROM search_analytics
195
+ WHERE date >= '2025-01-01'
196
+ GROUP BY query
197
+ HAVING pages > 1
198
+ ORDER BY clicks DESC
199
+ LIMIT 20
200
+ ```
201
+
202
+ Content decay detection:
203
+
204
+ ```sql
205
+ SELECT page,
206
+ SUM(CASE WHEN date >= date('now', '-28 days') THEN clicks END) as recent,
207
+ SUM(CASE WHEN date BETWEEN date('now', '-56 days') AND date('now', '-29 days') THEN clicks END) as prior
208
+ FROM search_analytics
209
+ GROUP BY page
210
+ HAVING prior > 10
211
+ ORDER BY (recent * 1.0 / NULLIF(prior, 0)) ASC
212
+ LIMIT 20
213
+ ```
214
+
215
+ Mobile vs desktop performance gap:
216
+
217
+ ```sql
218
+ SELECT page, device,
219
+ SUM(clicks) as clicks,
220
+ AVG(position) as avg_position
221
+ FROM search_analytics
222
+ WHERE date >= date('now', '-28 days')
223
+ GROUP BY page, device
224
+ HAVING clicks > 5
225
+ ORDER BY page, device
226
+ ```
227
+
228
+ ## Architecture
229
+
230
+ ### How Sync Works
231
+
232
+ The GSC API paginates at 25,000 rows per request. For large properties with millions of rows across 16 months of data, that means hundreds of API calls. The sync system handles this:
233
+
234
+ 1. Date ranges are chunked into 30-day windows
235
+ 2. Chunks run in parallel (concurrency of 3 by default)
236
+ 3. Each chunk paginates until the API returns fewer than 25,000 rows
237
+ 4. Rows are batch-inserted into SQLite with UPSERT semantics
238
+ 5. After all chunks complete, the data retention policy runs automatically
239
+
240
+ Sync jobs run in the background. The `setup` tool blocks until completion for the first-run experience, but `sync_gsc_data` and `sync_all_properties` return immediately with a job ID.
241
+
242
+ ### ext-apps UI
243
+
244
+ Three interactive views are built with Vite and `vite-plugin-singlefile`, producing self-contained HTML files served as MCP resources:
245
+
246
+ - **Dashboard**: trend chart (Chart.js), hero metrics, top queries/pages tables, ranking distribution, country breakdown, new/lost queries, branded split
247
+ - **Overview**: grid of property cards with sparklines and period-over-period changes
248
+ - **Sync progress**: real-time progress bar with row counts and ETA
249
+
250
+ Client-side code uses `@modelcontextprotocol/ext-apps` for bidirectional communication with the server. Data flows as `structuredContent` alongside the text response.
251
+
252
+ ### Project Structure
253
+
254
+ ```
255
+ src/
256
+ core/
257
+ Database.ts SQLite wrapper with schema, UPSERT, sync logging
258
+ DataRetention.ts Prune/preview logic with configurable retention policy
259
+ GscClient.ts Google Search Console API client with pagination
260
+ SyncManager.ts Background sync orchestration with job tracking
261
+ tools/
262
+ compare-periods.ts Period comparison across dimensions
263
+ get-dashboard.ts Dashboard data assembly
264
+ get-insights.ts 16 pre-built analytical queries
265
+ get-overview.ts Multi-property overview with sparklines
266
+ helpers.ts Date ranges, DB paths, formatting
267
+ list-properties.ts Property discovery with sync status
268
+ query-data.ts Custom SQL execution with safety checks
269
+ types/
270
+ index.ts Shared TypeScript interfaces
271
+ ui/
272
+ dashboard.html/ts Dashboard ext-apps UI
273
+ overview.html/ts Overview grid ext-apps UI
274
+ sync-progress.html/ts Sync progress ext-apps UI
275
+ index.ts Entry point
276
+ server.ts MCP server, tool registration, resource serving
277
+ ```
278
+
279
+ ## Development
280
+
281
+ ### Building from Source
282
+
283
+ ```bash
284
+ git clone https://github.com/houtini-ai/better-search-console.git
285
+ cd better-search-console
286
+ npm install
287
+ npm run build
288
+ ```
289
+
290
+ ### Scripts
291
+
292
+ | Command | What it does |
293
+ |---------|-------------|
294
+ | `npm run build` | Build everything (server TypeScript + UI bundles) |
295
+ | `npm run build:server` | TypeScript compilation only |
296
+ | `npm run build:ui` | Vite builds for all three UI views |
297
+ | `npm run dev` | Watch mode for server TypeScript |
298
+ | `npm start` | Run the compiled server |
299
+
300
+ ### Adding Insight Queries
301
+
302
+ New insights go in `src/tools/get-insights.ts`. Each insight is a function that takes the standard params (siteUrl, dateRange, filters) and returns a SQL result. The pattern is consistent: calculate date ranges, build parameterised SQL, execute against the property database, return structured results.
303
+
304
+ ## Troubleshooting
305
+
306
+ ### "No Google Search Console properties found"
307
+
308
+ The service account needs to be added as a user on each property. Go to Search Console > Settings > Users and permissions > Add user. Use the service account email from your JSON key file (it looks like `name@project.iam.gserviceaccount.com`). Grant "Full" permission level.
309
+
310
+ ### Sync takes a long time
311
+
312
+ Large properties with years of data and many countries can have millions of rows. Initial sync for a property with 10 million rows takes 5-10 minutes. Subsequent syncs are incremental (only fetching new dates) and complete in seconds.
313
+
314
+ ### Database files are large
315
+
316
+ Run `prune_database` with `preview=true` to see how much can be cleaned up. The default retention policy typically removes 50-70% of rows from properties with international traffic. The auto-prune after each sync prevents future bloat.
317
+
318
+ ### ext-apps UI not rendering
319
+
320
+ The interactive dashboards require Claude Desktop with ext-apps support. If you're using an older version or a different MCP client, the text-based fallback responses still contain all the data.
321
+
322
+ ## Licence
323
+
324
+ Apache-2.0. See [LICENSE](LICENSE) for details.
325
+
326
+ ## Disclaimer
327
+
328
+ This software is provided as-is. Your GSC data is stored locally in SQLite databases on your machine. The server communicates with Google's Search Console API using your service account credentials. Review Google's API terms of service and ensure your usage complies.
329
+
330
+ API keys and service account credentials are sensitive. Keep them out of version control, rotate them if exposed, and restrict service account permissions to the Search Console API only.
331
+
332
+ ---
333
+
334
+ Built by [Houtini](https://houtini.ai) for the Model Context Protocol community.
Binary file
@@ -0,0 +1,49 @@
1
+ export interface RetentionPolicy {
2
+ /** Days of recent data to keep in full (all rows). Default: 90 */
3
+ recentDays: number;
4
+ /** For older target-country rows: minimum impressions to keep when clicks=0. Default: 5 */
5
+ targetMinImpressions: number;
6
+ /** For older non-target-country rows: only keep rows with clicks > 0. */
7
+ pruneNonTargetZeroClicks: boolean;
8
+ /** ISO alpha-3 country codes considered "target". */
9
+ targetCountries: string[];
10
+ }
11
+ export interface PruneResult {
12
+ siteUrl: string;
13
+ rowsBefore: number;
14
+ rowsDeleted: number;
15
+ rowsAfter: number;
16
+ dbSizeBefore: number;
17
+ dbSizeAfter: number;
18
+ vacuumed: boolean;
19
+ durationMs: number;
20
+ }
21
+ export declare class DataRetention {
22
+ /**
23
+ * Apply retention policy to a site's database.
24
+ *
25
+ * Rules applied to rows OLDER than recentDays:
26
+ * 1. Target countries: delete rows where clicks=0 AND impressions < targetMinImpressions
27
+ * 2. Non-target countries: delete rows where clicks=0
28
+ *
29
+ * Recent data (last recentDays) is never touched.
30
+ * Rows with clicks > 0 are never deleted regardless of age or country.
31
+ */
32
+ static prune(siteUrl: string, policy?: Partial<RetentionPolicy>, onProgress?: (message: string) => void): PruneResult;
33
+ /**
34
+ * Preview what a prune would delete without actually deleting anything.
35
+ */
36
+ static preview(siteUrl: string, policy?: Partial<RetentionPolicy>): {
37
+ siteUrl: string;
38
+ totalRows: number;
39
+ wouldDelete: number;
40
+ wouldKeep: number;
41
+ reductionPct: number;
42
+ breakdown: {
43
+ targetLowValue: number;
44
+ nonTargetZeroClick: number;
45
+ recentProtected: number;
46
+ };
47
+ };
48
+ }
49
+ //# sourceMappingURL=DataRetention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataRetention.d.ts","sourceRoot":"","sources":["../../src/core/DataRetention.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,2FAA2F;IAC3F,oBAAoB,EAAE,MAAM,CAAC;IAC7B,yEAAyE;IACzE,wBAAwB,EAAE,OAAO,CAAC;IAClC,qDAAqD;IACrD,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AASD,qBAAa,aAAa;IAExB;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,CACV,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM,EACrC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACrC,WAAW;IAuGd;;OAEG;IACH,MAAM,CAAC,OAAO,CACZ,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM,GACpC;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE;YACT,cAAc,EAAE,MAAM,CAAC;YACvB,kBAAkB,EAAE,MAAM,CAAC;YAC3B,eAAe,EAAE,MAAM,CAAC;SACzB,CAAC;KACH;CAiDF"}