webscope-mcp 0.2.0__tar.gz
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.
- webscope_mcp-0.2.0/LICENSE +21 -0
- webscope_mcp-0.2.0/PKG-INFO +249 -0
- webscope_mcp-0.2.0/README.md +238 -0
- webscope_mcp-0.2.0/pyproject.toml +25 -0
- webscope_mcp-0.2.0/setup.cfg +4 -0
- webscope_mcp-0.2.0/webscope.py +695 -0
- webscope_mcp-0.2.0/webscope_adaptadores/__init__.py +1 -0
- webscope_mcp-0.2.0/webscope_adaptadores/costo_sesion.py +187 -0
- webscope_mcp-0.2.0/webscope_adaptadores/e2e_chrome.py +259 -0
- webscope_mcp-0.2.0/webscope_adaptadores/laravel.py +215 -0
- webscope_mcp-0.2.0/webscope_adaptadores/limpiar_zz.py +176 -0
- webscope_mcp-0.2.0/webscope_adaptadores/payload_check.py +272 -0
- webscope_mcp-0.2.0/webscope_adaptadores/proyecto.py +62 -0
- webscope_mcp-0.2.0/webscope_adaptadores/uso_agentes.py +68 -0
- webscope_mcp-0.2.0/webscope_adaptadores/uso_webscope.py +85 -0
- webscope_mcp-0.2.0/webscope_adaptadores/vue_ts.py +207 -0
- webscope_mcp-0.2.0/webscope_adaptadores/web/chequeo-ui.js +45 -0
- webscope_mcp-0.2.0/webscope_adaptadores/web/e2e-rutas.js +124 -0
- webscope_mcp-0.2.0/webscope_adaptadores/web/form.js +333 -0
- webscope_mcp-0.2.0/webscope_mcp.egg-info/PKG-INFO +249 -0
- webscope_mcp-0.2.0/webscope_mcp.egg-info/SOURCES.txt +22 -0
- webscope_mcp-0.2.0/webscope_mcp.egg-info/dependency_links.txt +1 -0
- webscope_mcp-0.2.0/webscope_mcp.egg-info/entry_points.txt +2 -0
- webscope_mcp-0.2.0/webscope_mcp.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 partprogramming09
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webscope-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MCP server (stdio, standard library only) that gives a coding agent short answers about a project
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/partprogramming09/webscope
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Webscope
|
|
13
|
+
|
|
14
|
+
<!-- mcp-name: io.github.partprogramming09/webscope -->
|
|
15
|
+
|
|
16
|
+
A small MCP server (stdio, JSON-RPC 2.0, Python standard library only) that gives a coding agent short answers about a
|
|
17
|
+
project: grouped search hits, one symbol instead of a whole file, and the output of the project's own read-only scripts,
|
|
18
|
+
trimmed to head and tail. The goal is fewer tokens per question.
|
|
19
|
+
|
|
20
|
+
Tool names, parameters and messages are in Spanish.
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- Python 3.9 or newer (no third-party packages)
|
|
25
|
+
- Optional: [uv](https://docs.astral.sh/uv/), to run it with `uvx` without cloning
|
|
26
|
+
- `grep` on `PATH` (used by `buscar`)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
1. In your project's root, create its manifest and list the folders and scripts it may use
|
|
31
|
+
(see [Configuration](#configuration-webscopejson) and [`webscope.example.json`](webscope.example.json)).
|
|
32
|
+
|
|
33
|
+
2. Register the server. With Claude Code, from the project's root, pick one:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# with uv, no clone needed (like npx)
|
|
37
|
+
claude mcp add --scope project webscope -- uvx --from git+https://github.com/partprogramming09/webscope webscope-mcp --manifest "$PWD/webscope.json"
|
|
38
|
+
|
|
39
|
+
# with a clone and plain Python
|
|
40
|
+
git clone https://github.com/partprogramming09/webscope.git ~/webscope
|
|
41
|
+
claude mcp add --scope project webscope -- python3 -I ~/webscope/webscope.py --manifest "$PWD/webscope.json"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`--scope project` writes `.mcp.json` so the whole team gets it; use `--scope user` for all your projects. Add
|
|
45
|
+
`-e WEBSCOPE_ESCRITURA=1` before `--` only if a script declares `escribe` and you want to allow it.
|
|
46
|
+
|
|
47
|
+
3. Start `claude` in the project, approve the server, and check it with `/mcp`: `webscope` should show as connected
|
|
48
|
+
with the tools `buscar`, `leer` and `correr`.
|
|
49
|
+
|
|
50
|
+
Other MCP clients: add the same command to their configuration, for example a `.mcp.json`:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"webscope": {
|
|
56
|
+
"command": "python3",
|
|
57
|
+
"args": ["-I", "/path/to/webscope/webscope.py", "--manifest", "/path/to/your/project/webscope.json"]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Instead of `--manifest` you can set the environment variable `WEBSCOPE_MANIFEST`. Without either, the server uses
|
|
64
|
+
`./webscope.json` if it exists; otherwise it serves the current folder with `buscar` and `leer` and no scripts.
|
|
65
|
+
|
|
66
|
+
### Docker
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
docker build -t webscope .
|
|
70
|
+
docker run -i --rm -v "$PWD:/project:ro" -e WEBSCOPE_MANIFEST=/project/webscope.json webscope
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Without `WEBSCOPE_MANIFEST` the image serves the bundled `webscope.example.json`.
|
|
74
|
+
|
|
75
|
+
## Tools
|
|
76
|
+
|
|
77
|
+
| Tool | What it does |
|
|
78
|
+
| :--- | :--- |
|
|
79
|
+
| `buscar(texto, donde?, tope?, formato?, contexto?, regex?)` | Case-insensitive search, literal unless `regex=true` (extended regex). Hits grouped by file, most-referenced files first, capped at `tope` lines. `donde` limits it to a folder or file; `contexto` (0-5) adds lines around each hit. `formato="conciso"` returns only the top 5 files with counts. |
|
|
80
|
+
| `leer(archivo, simbolo?, lineas?, max_lineas?, cola?, contiene?, formato?)` | Returns only one function, method or class (PHP, TS, JS, Vue, Python) — or several, if `simbolo` is a list —, one Markdown section by heading, a line range (`lineas="120-180"`), or for `.log`/`.txt`/`.out` files the last `cola` lines and/or the lines containing `contiene`. Without `simbolo` or `lineas` it returns the file's index: headings or definitions with their line numbers. |
|
|
81
|
+
| `correr(nombre?, args?, detalle?)` | Runs a script declared in the manifest and returns `exit N` plus trimmed output. Without `nombre` it lists the scripts; `detalle="esquema"` shows one script's usage. Read-only. |
|
|
82
|
+
| `correr_escritura(nombre, args)` | Only listed when a script declares `escribe`. Runs a write argument; requires `WEBSCOPE_ESCRITURA=1` in the server environment and is marked `destructiveHint` and `anthropic/requiresUserInteraction`. |
|
|
83
|
+
|
|
84
|
+
Every answer starts with one short line saying what it is and what to do next, and is capped at `tope_tokens`
|
|
85
|
+
(about 4 characters per token).
|
|
86
|
+
|
|
87
|
+
A malformed request, a non-UTF-8 script output or an unexpected error comes back as an error message; the server keeps
|
|
88
|
+
running. `buscar` skips files that are not valid UTF-8 when the locale is UTF-8 (grep treats them as binary).
|
|
89
|
+
|
|
90
|
+
## Security model
|
|
91
|
+
|
|
92
|
+
- **Project root only.** `buscar` and `leer` resolve paths against the manifest's `root` and reject anything outside it.
|
|
93
|
+
- **Secret files are invisible.** `buscar` and `leer` skip `.env`, `.env.*`, `*.pem`, `*.key`, `*.p12`, `id_rsa*`,
|
|
94
|
+
`id_ed25519*`, `auth.json` and `credentials*` (templates ending in `.example` stay visible).
|
|
95
|
+
- **Fixed commands, no shell.** Scripts run as a fixed argument list from the manifest. Arguments that are absolute paths
|
|
96
|
+
or contain `..` are rejected (unless the script sets `acepta_barra`, which allows URL-like `/a/b` but still not `..`).
|
|
97
|
+
Flags listed in `rechaza` are rejected.
|
|
98
|
+
- **Read-only by default.** `correr` refuses any argument listed in a script's `escribe`. Those go through
|
|
99
|
+
`correr_escritura`, which only exists when declared and only runs when the user sets `WEBSCOPE_ESCRITURA=1`.
|
|
100
|
+
- **Minimal environment.** Scripts do not inherit the server's environment. They receive only `PATH`, `HOME`, `LANG`,
|
|
101
|
+
`LC_ALL`, `TMPDIR`, the variables named in the manifest's `env_permitidas`, plus `WEBSCOPE_RAIZ` (project root) and
|
|
102
|
+
`WEBSCOPE_MANIFIESTO` (manifest path).
|
|
103
|
+
- **Bounded output.** Script output is trimmed to head and tail lines, and each response to `tope_tokens`.
|
|
104
|
+
|
|
105
|
+
The scripts themselves are trusted code: Webscope limits how they are called, not what they do. Only list scripts you
|
|
106
|
+
would run yourself.
|
|
107
|
+
|
|
108
|
+
## Configuration (`webscope.json`)
|
|
109
|
+
|
|
110
|
+
See [`webscope.example.json`](webscope.example.json).
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"root": ".",
|
|
115
|
+
"recorte": { "cabeza": 10, "cola": 70 },
|
|
116
|
+
"tope_tokens": 5000,
|
|
117
|
+
"buscar": { "dirs": ["src"], "extensiones": ["py", "ts"] },
|
|
118
|
+
"env_permitidas": ["DATABASE_URL"],
|
|
119
|
+
"scripts": {
|
|
120
|
+
"report": {
|
|
121
|
+
"cmd": ["python3", "-I", "scripts/report.py"],
|
|
122
|
+
"descripcion": "Summarises a table",
|
|
123
|
+
"uso": "<table>",
|
|
124
|
+
"rechaza": ["--out"],
|
|
125
|
+
"escribe": ["--fix"],
|
|
126
|
+
"timeout": 120
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
| Key | Meaning |
|
|
133
|
+
| :--- | :--- |
|
|
134
|
+
| `root` | Project root, relative to the manifest's folder. |
|
|
135
|
+
| `recorte` | Default head (`cabeza`) and tail (`cola`) lines kept from script output. |
|
|
136
|
+
| `tope_tokens` | Maximum size of any response, in approximate tokens. |
|
|
137
|
+
| `buscar.dirs`, `buscar.extensiones` | Folders and file extensions searched by default. |
|
|
138
|
+
| `env_permitidas` | Extra environment variables passed to scripts. |
|
|
139
|
+
| `scripts.<name>.cmd` | Fixed command as a list; `python3` is replaced by the server's interpreter. |
|
|
140
|
+
| `descripcion`, `uso` | Shown by `correr()` listings. |
|
|
141
|
+
| `rechaza` | Flags that would write files; always refused. |
|
|
142
|
+
| `escribe` | Arguments that write data; only via `correr_escritura` with `WEBSCOPE_ESCRITURA=1`. |
|
|
143
|
+
| `acepta_barra` | Allow arguments starting with `/` (URL paths). |
|
|
144
|
+
| `timeout`, `cabeza`, `cola` | Per-script overrides. |
|
|
145
|
+
|
|
146
|
+
## Included scripts
|
|
147
|
+
|
|
148
|
+
The package ships ready-made scripts in `webscope_adaptadores/`. A manifest names them with `{adaptadores}` in `cmd`
|
|
149
|
+
(see [`webscope.example.json`](webscope.example.json)); copy the entries you need and adjust the folders.
|
|
150
|
+
|
|
151
|
+
| Script | What it answers | Stack |
|
|
152
|
+
| :--- | :--- | :--- |
|
|
153
|
+
| `vue_ts.py` (`mapa`) | Routes, views, API calls, composables and stores of a frontend module; `--recorrido` lists what can be clicked (actions with their `v-if` and permission, links, tabs with their API, form fields); `--cobertura` says which calls an e2e capture exercised | Vue 3 + TS |
|
|
154
|
+
| `laravel.py` (`mapa_back`) | Endpoint, controller, service, model and table behind a frontend module or API path | Laravel |
|
|
155
|
+
| `e2e_chrome.py` | JavaScript for **one** `javascript_tool` call of Claude in Chrome: walks routes and returns per route time, rows, failed requests, console errors and UI problems, without screenshots. `--llamar` reuses the walk already installed in the page; `--captura`/`--detalle` record what the page sends and receives; `--form` installs `__f` to fill a form by label, press Save and read it back, plus screen helpers that replace screenshots and coordinate clicks: `estado()` (the screen as short text), `clic(text)` (click by visible text, then wait until the page settles), `esperar`, `ir(route)` (router navigation without reload) and `pasos([...])` (several steps in one call). With a local receiver: `--servir [port folder]` starts it, `--cargar [port]` installs capture and `__f` from it, `--guardar <name> [port]` sends the whole capture to `<folder>/<name>.txt` (with one `ms <ms> <method> <status> <path>` line per API call; the receiver answers with the 5 slowest) and the steps `__f` recorded to `.claude/webscope/recorridos/<name>.json`, and `--repetir <name>` replays those steps in one call (with a fresh stamp on `ZZ_E2E` values) while the frontend does not change; `--exportar <capture> <url>` writes a Playwright test with the same steps | Any SPA with a router |
|
|
156
|
+
| `payload_check.py` | Checks a capture against the FormRequest rules, the Resource and the table columns; flags keys without a rule, values outside `in:`, `''` sent to a nullable column | Laravel |
|
|
157
|
+
| `limpiar_zz.py` | Lists, and with `--borrar` deletes after a backup, test rows whose code starts with `ZZ_` | Laravel |
|
|
158
|
+
| `costo_sesion.py` | Cost of the latest (or a given) Claude Code session in the project: USD per model at list prices (subagents and advisor included), calls and re-read context per tool, large outputs, repeated calls, and which tool loops would have been cheaper in a subagent | Claude Code |
|
|
159
|
+
| `uso_agentes.py` | Subagent usage: turns, context, models, agents over the turn limit | Claude Code |
|
|
160
|
+
| `uso_webscope.py` | Share of file reads and searches that went through `leer` and `buscar` in sessions where Webscope was available, and the `Read`/`sed`/`grep` calls used instead | Claude Code |
|
|
161
|
+
|
|
162
|
+
Project-specific settings go in the manifest's `proyecto` section:
|
|
163
|
+
|
|
164
|
+
| Key | Used by | Meaning |
|
|
165
|
+
| :--- | :--- | :--- |
|
|
166
|
+
| `modulos` | `payload_check` | Backend modules folder (default `app/Modules`) |
|
|
167
|
+
| `prefijo_rutas` | `e2e_chrome` | Prefix the app lives under, e.g. `/demo`, so routes work with or without it |
|
|
168
|
+
| `contenedor` | `mapa_back` | Docker container where `php artisan route:list --json` runs; empty reads the route files |
|
|
169
|
+
| `sql` | `payload_check`, `limpiar_zz` | Script that runs a read-only SQL query and prints TSV with a header |
|
|
170
|
+
| `tinker` | `limpiar_zz` | Script that runs a PHP file against the database (`<script> <file.php> --commit`) |
|
|
171
|
+
| `php_db` | `limpiar_zz` | PHP expression for the connection (default `DB::connection()`) |
|
|
172
|
+
| `capturas` | MCP resources | Captures folder (the one given to `--servir`); its `.txt` files are listed as `webscope://capturas/<file>` next to the saved walks `webscope://recorridos/<file>` |
|
|
173
|
+
|
|
174
|
+
The Vue index cache and `limpiar_zz` backups go to `~/.cache/webscope/`. The `e2e_chrome` receiver writes captures to the
|
|
175
|
+
folder given to `--servir` (default `capturas`, relative to where it starts). `--servir` does not return: start it from a
|
|
176
|
+
shell in the background (the example manifest lists it in `rechaza`, so `correr` refuses it).
|
|
177
|
+
|
|
178
|
+
### Using the scripts from a subagent
|
|
179
|
+
|
|
180
|
+
A subagent sees Webscope only if its definition lists the tools, for example in Claude Code's `.claude/agents/<name>.md`:
|
|
181
|
+
|
|
182
|
+
```yaml
|
|
183
|
+
tools: Read, Grep, Glob, Bash, mcp__webscope__buscar, mcp__webscope__leer, mcp__webscope__correr
|
|
184
|
+
model: sonnet
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Add `mcp__webscope__correr_escritura` only if the agent must run write arguments, plus the browser tools it needs.
|
|
188
|
+
[`agents/recorrido.example.md`](agents/recorrido.example.md) is a ready-made agent that walks one frontend module in
|
|
189
|
+
Chrome with `mapa`, `e2e_chrome` and `limpiar_zz` and returns a summary of at most 25 lines: copy it to
|
|
190
|
+
`.claude/agents/recorrido.md` and replace `<webscope>` (the clone's folder; the receiver runs from the clone, not from
|
|
191
|
+
`uvx`) and the captures folder.
|
|
192
|
+
|
|
193
|
+
One measurement (a browser walk of one module, one project, one run per condition) found:
|
|
194
|
+
|
|
195
|
+
- With the walk in the main session, Webscope did not change the cost (+7 % and −5 % in two runs). It changed accuracy:
|
|
196
|
+
the order of steps (`mapa --recorrido`), the fields that were not saved (`__f.verificar`) and the measured coverage.
|
|
197
|
+
- The same walk in a sonnet subagent that returns a summary of at most 25 lines cost 1.05 USD instead of 6.40, with the
|
|
198
|
+
same coverage. About 2× came from isolating the context; the rest from the sonnet price.
|
|
199
|
+
- Page reads and screenshots were about 80 % of the re-read context, so the agent reads state with `javascript_tool` and
|
|
200
|
+
takes screenshots only to understand an error.
|
|
201
|
+
- Subagents that ran for more than about 40 turns grew their context like a main session. Give one module or one bounded
|
|
202
|
+
task per agent, and tell it to stop at about 40 tool calls and return what is done and what is pending.
|
|
203
|
+
|
|
204
|
+
`costo_sesion.py --raiz <project>` and `uso_agentes.py --raiz <project>` measure the same in another project. The USD
|
|
205
|
+
come from the price table at the top of `costo_sesion.py` (list prices, October 2026), which only lists models checked
|
|
206
|
+
against the cost reported by `claude -p` (Opus 5.5, Sonnet 5.5, Fable 5.1: within 0.01 USD on three runs); any other
|
|
207
|
+
model is shown as `sin precio` until it is added.
|
|
208
|
+
|
|
209
|
+
## Hook: suggest Webscope
|
|
210
|
+
|
|
211
|
+
Agents often keep using `Read`, `cat`, `sed -n` and `grep` even when Webscope is available. `hooks/sugerir_webscope.py`
|
|
212
|
+
is a Claude Code `PostToolUse` hook that, after such a call, adds one line to the model's context with the equivalent
|
|
213
|
+
Webscope call (for example `leer(archivo, lineas="120-180")`). It never blocks and speaks at most 3 times per session.
|
|
214
|
+
Add it to the project's `.claude/settings.json` or `.claude/settings.local.json`:
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{"hooks": {"PostToolUse": [{"matcher": "Read|Bash", "hooks": [{"type": "command",
|
|
218
|
+
"command": "python3 -I /path/to/webscope/hooks/sugerir_webscope.py"}]}]}}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`uso_webscope.py` measures whether it works: the share of reads and searches that go through Webscope.
|
|
222
|
+
|
|
223
|
+
## Browser UI check
|
|
224
|
+
|
|
225
|
+
`webscope_adaptadores/web/chequeo-ui.js` is a standalone snippet for a browser automation tool (`page.evaluate` in Playwright, or a
|
|
226
|
+
JavaScript tool in a browser extension). It returns only the problems on the current page: horizontal overflow, empty
|
|
227
|
+
chips or badges, untranslated i18n keys, raw values (`undefined`, `NaN`…), overlapping text and unnamed buttons.
|
|
228
|
+
|
|
229
|
+
```sh
|
|
230
|
+
PLAYWRIGHT_DIR=<folder containing node_modules/playwright> node webscope_adaptadores/web/test_chequeo_ui.mjs
|
|
231
|
+
PLAYWRIGHT_DIR=<folder containing node_modules/playwright> PW_CHANNEL=chrome node webscope_adaptadores/web/test_form.mjs
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`PW_CHANNEL=chrome` uses the installed Chrome when Playwright's own browser is missing.
|
|
235
|
+
|
|
236
|
+
## Tests
|
|
237
|
+
|
|
238
|
+
```sh
|
|
239
|
+
python3 -I test_webscope.py
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Out of scope
|
|
243
|
+
|
|
244
|
+
Webscope does not replace a language server or a browser automation server, does not run code written by the agent, and
|
|
245
|
+
is not a test framework.
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Webscope
|
|
2
|
+
|
|
3
|
+
<!-- mcp-name: io.github.partprogramming09/webscope -->
|
|
4
|
+
|
|
5
|
+
A small MCP server (stdio, JSON-RPC 2.0, Python standard library only) that gives a coding agent short answers about a
|
|
6
|
+
project: grouped search hits, one symbol instead of a whole file, and the output of the project's own read-only scripts,
|
|
7
|
+
trimmed to head and tail. The goal is fewer tokens per question.
|
|
8
|
+
|
|
9
|
+
Tool names, parameters and messages are in Spanish.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Python 3.9 or newer (no third-party packages)
|
|
14
|
+
- Optional: [uv](https://docs.astral.sh/uv/), to run it with `uvx` without cloning
|
|
15
|
+
- `grep` on `PATH` (used by `buscar`)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
1. In your project's root, create its manifest and list the folders and scripts it may use
|
|
20
|
+
(see [Configuration](#configuration-webscopejson) and [`webscope.example.json`](webscope.example.json)).
|
|
21
|
+
|
|
22
|
+
2. Register the server. With Claude Code, from the project's root, pick one:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
# with uv, no clone needed (like npx)
|
|
26
|
+
claude mcp add --scope project webscope -- uvx --from git+https://github.com/partprogramming09/webscope webscope-mcp --manifest "$PWD/webscope.json"
|
|
27
|
+
|
|
28
|
+
# with a clone and plain Python
|
|
29
|
+
git clone https://github.com/partprogramming09/webscope.git ~/webscope
|
|
30
|
+
claude mcp add --scope project webscope -- python3 -I ~/webscope/webscope.py --manifest "$PWD/webscope.json"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`--scope project` writes `.mcp.json` so the whole team gets it; use `--scope user` for all your projects. Add
|
|
34
|
+
`-e WEBSCOPE_ESCRITURA=1` before `--` only if a script declares `escribe` and you want to allow it.
|
|
35
|
+
|
|
36
|
+
3. Start `claude` in the project, approve the server, and check it with `/mcp`: `webscope` should show as connected
|
|
37
|
+
with the tools `buscar`, `leer` and `correr`.
|
|
38
|
+
|
|
39
|
+
Other MCP clients: add the same command to their configuration, for example a `.mcp.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"webscope": {
|
|
45
|
+
"command": "python3",
|
|
46
|
+
"args": ["-I", "/path/to/webscope/webscope.py", "--manifest", "/path/to/your/project/webscope.json"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Instead of `--manifest` you can set the environment variable `WEBSCOPE_MANIFEST`. Without either, the server uses
|
|
53
|
+
`./webscope.json` if it exists; otherwise it serves the current folder with `buscar` and `leer` and no scripts.
|
|
54
|
+
|
|
55
|
+
### Docker
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
docker build -t webscope .
|
|
59
|
+
docker run -i --rm -v "$PWD:/project:ro" -e WEBSCOPE_MANIFEST=/project/webscope.json webscope
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Without `WEBSCOPE_MANIFEST` the image serves the bundled `webscope.example.json`.
|
|
63
|
+
|
|
64
|
+
## Tools
|
|
65
|
+
|
|
66
|
+
| Tool | What it does |
|
|
67
|
+
| :--- | :--- |
|
|
68
|
+
| `buscar(texto, donde?, tope?, formato?, contexto?, regex?)` | Case-insensitive search, literal unless `regex=true` (extended regex). Hits grouped by file, most-referenced files first, capped at `tope` lines. `donde` limits it to a folder or file; `contexto` (0-5) adds lines around each hit. `formato="conciso"` returns only the top 5 files with counts. |
|
|
69
|
+
| `leer(archivo, simbolo?, lineas?, max_lineas?, cola?, contiene?, formato?)` | Returns only one function, method or class (PHP, TS, JS, Vue, Python) — or several, if `simbolo` is a list —, one Markdown section by heading, a line range (`lineas="120-180"`), or for `.log`/`.txt`/`.out` files the last `cola` lines and/or the lines containing `contiene`. Without `simbolo` or `lineas` it returns the file's index: headings or definitions with their line numbers. |
|
|
70
|
+
| `correr(nombre?, args?, detalle?)` | Runs a script declared in the manifest and returns `exit N` plus trimmed output. Without `nombre` it lists the scripts; `detalle="esquema"` shows one script's usage. Read-only. |
|
|
71
|
+
| `correr_escritura(nombre, args)` | Only listed when a script declares `escribe`. Runs a write argument; requires `WEBSCOPE_ESCRITURA=1` in the server environment and is marked `destructiveHint` and `anthropic/requiresUserInteraction`. |
|
|
72
|
+
|
|
73
|
+
Every answer starts with one short line saying what it is and what to do next, and is capped at `tope_tokens`
|
|
74
|
+
(about 4 characters per token).
|
|
75
|
+
|
|
76
|
+
A malformed request, a non-UTF-8 script output or an unexpected error comes back as an error message; the server keeps
|
|
77
|
+
running. `buscar` skips files that are not valid UTF-8 when the locale is UTF-8 (grep treats them as binary).
|
|
78
|
+
|
|
79
|
+
## Security model
|
|
80
|
+
|
|
81
|
+
- **Project root only.** `buscar` and `leer` resolve paths against the manifest's `root` and reject anything outside it.
|
|
82
|
+
- **Secret files are invisible.** `buscar` and `leer` skip `.env`, `.env.*`, `*.pem`, `*.key`, `*.p12`, `id_rsa*`,
|
|
83
|
+
`id_ed25519*`, `auth.json` and `credentials*` (templates ending in `.example` stay visible).
|
|
84
|
+
- **Fixed commands, no shell.** Scripts run as a fixed argument list from the manifest. Arguments that are absolute paths
|
|
85
|
+
or contain `..` are rejected (unless the script sets `acepta_barra`, which allows URL-like `/a/b` but still not `..`).
|
|
86
|
+
Flags listed in `rechaza` are rejected.
|
|
87
|
+
- **Read-only by default.** `correr` refuses any argument listed in a script's `escribe`. Those go through
|
|
88
|
+
`correr_escritura`, which only exists when declared and only runs when the user sets `WEBSCOPE_ESCRITURA=1`.
|
|
89
|
+
- **Minimal environment.** Scripts do not inherit the server's environment. They receive only `PATH`, `HOME`, `LANG`,
|
|
90
|
+
`LC_ALL`, `TMPDIR`, the variables named in the manifest's `env_permitidas`, plus `WEBSCOPE_RAIZ` (project root) and
|
|
91
|
+
`WEBSCOPE_MANIFIESTO` (manifest path).
|
|
92
|
+
- **Bounded output.** Script output is trimmed to head and tail lines, and each response to `tope_tokens`.
|
|
93
|
+
|
|
94
|
+
The scripts themselves are trusted code: Webscope limits how they are called, not what they do. Only list scripts you
|
|
95
|
+
would run yourself.
|
|
96
|
+
|
|
97
|
+
## Configuration (`webscope.json`)
|
|
98
|
+
|
|
99
|
+
See [`webscope.example.json`](webscope.example.json).
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"root": ".",
|
|
104
|
+
"recorte": { "cabeza": 10, "cola": 70 },
|
|
105
|
+
"tope_tokens": 5000,
|
|
106
|
+
"buscar": { "dirs": ["src"], "extensiones": ["py", "ts"] },
|
|
107
|
+
"env_permitidas": ["DATABASE_URL"],
|
|
108
|
+
"scripts": {
|
|
109
|
+
"report": {
|
|
110
|
+
"cmd": ["python3", "-I", "scripts/report.py"],
|
|
111
|
+
"descripcion": "Summarises a table",
|
|
112
|
+
"uso": "<table>",
|
|
113
|
+
"rechaza": ["--out"],
|
|
114
|
+
"escribe": ["--fix"],
|
|
115
|
+
"timeout": 120
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| Key | Meaning |
|
|
122
|
+
| :--- | :--- |
|
|
123
|
+
| `root` | Project root, relative to the manifest's folder. |
|
|
124
|
+
| `recorte` | Default head (`cabeza`) and tail (`cola`) lines kept from script output. |
|
|
125
|
+
| `tope_tokens` | Maximum size of any response, in approximate tokens. |
|
|
126
|
+
| `buscar.dirs`, `buscar.extensiones` | Folders and file extensions searched by default. |
|
|
127
|
+
| `env_permitidas` | Extra environment variables passed to scripts. |
|
|
128
|
+
| `scripts.<name>.cmd` | Fixed command as a list; `python3` is replaced by the server's interpreter. |
|
|
129
|
+
| `descripcion`, `uso` | Shown by `correr()` listings. |
|
|
130
|
+
| `rechaza` | Flags that would write files; always refused. |
|
|
131
|
+
| `escribe` | Arguments that write data; only via `correr_escritura` with `WEBSCOPE_ESCRITURA=1`. |
|
|
132
|
+
| `acepta_barra` | Allow arguments starting with `/` (URL paths). |
|
|
133
|
+
| `timeout`, `cabeza`, `cola` | Per-script overrides. |
|
|
134
|
+
|
|
135
|
+
## Included scripts
|
|
136
|
+
|
|
137
|
+
The package ships ready-made scripts in `webscope_adaptadores/`. A manifest names them with `{adaptadores}` in `cmd`
|
|
138
|
+
(see [`webscope.example.json`](webscope.example.json)); copy the entries you need and adjust the folders.
|
|
139
|
+
|
|
140
|
+
| Script | What it answers | Stack |
|
|
141
|
+
| :--- | :--- | :--- |
|
|
142
|
+
| `vue_ts.py` (`mapa`) | Routes, views, API calls, composables and stores of a frontend module; `--recorrido` lists what can be clicked (actions with their `v-if` and permission, links, tabs with their API, form fields); `--cobertura` says which calls an e2e capture exercised | Vue 3 + TS |
|
|
143
|
+
| `laravel.py` (`mapa_back`) | Endpoint, controller, service, model and table behind a frontend module or API path | Laravel |
|
|
144
|
+
| `e2e_chrome.py` | JavaScript for **one** `javascript_tool` call of Claude in Chrome: walks routes and returns per route time, rows, failed requests, console errors and UI problems, without screenshots. `--llamar` reuses the walk already installed in the page; `--captura`/`--detalle` record what the page sends and receives; `--form` installs `__f` to fill a form by label, press Save and read it back, plus screen helpers that replace screenshots and coordinate clicks: `estado()` (the screen as short text), `clic(text)` (click by visible text, then wait until the page settles), `esperar`, `ir(route)` (router navigation without reload) and `pasos([...])` (several steps in one call). With a local receiver: `--servir [port folder]` starts it, `--cargar [port]` installs capture and `__f` from it, `--guardar <name> [port]` sends the whole capture to `<folder>/<name>.txt` (with one `ms <ms> <method> <status> <path>` line per API call; the receiver answers with the 5 slowest) and the steps `__f` recorded to `.claude/webscope/recorridos/<name>.json`, and `--repetir <name>` replays those steps in one call (with a fresh stamp on `ZZ_E2E` values) while the frontend does not change; `--exportar <capture> <url>` writes a Playwright test with the same steps | Any SPA with a router |
|
|
145
|
+
| `payload_check.py` | Checks a capture against the FormRequest rules, the Resource and the table columns; flags keys without a rule, values outside `in:`, `''` sent to a nullable column | Laravel |
|
|
146
|
+
| `limpiar_zz.py` | Lists, and with `--borrar` deletes after a backup, test rows whose code starts with `ZZ_` | Laravel |
|
|
147
|
+
| `costo_sesion.py` | Cost of the latest (or a given) Claude Code session in the project: USD per model at list prices (subagents and advisor included), calls and re-read context per tool, large outputs, repeated calls, and which tool loops would have been cheaper in a subagent | Claude Code |
|
|
148
|
+
| `uso_agentes.py` | Subagent usage: turns, context, models, agents over the turn limit | Claude Code |
|
|
149
|
+
| `uso_webscope.py` | Share of file reads and searches that went through `leer` and `buscar` in sessions where Webscope was available, and the `Read`/`sed`/`grep` calls used instead | Claude Code |
|
|
150
|
+
|
|
151
|
+
Project-specific settings go in the manifest's `proyecto` section:
|
|
152
|
+
|
|
153
|
+
| Key | Used by | Meaning |
|
|
154
|
+
| :--- | :--- | :--- |
|
|
155
|
+
| `modulos` | `payload_check` | Backend modules folder (default `app/Modules`) |
|
|
156
|
+
| `prefijo_rutas` | `e2e_chrome` | Prefix the app lives under, e.g. `/demo`, so routes work with or without it |
|
|
157
|
+
| `contenedor` | `mapa_back` | Docker container where `php artisan route:list --json` runs; empty reads the route files |
|
|
158
|
+
| `sql` | `payload_check`, `limpiar_zz` | Script that runs a read-only SQL query and prints TSV with a header |
|
|
159
|
+
| `tinker` | `limpiar_zz` | Script that runs a PHP file against the database (`<script> <file.php> --commit`) |
|
|
160
|
+
| `php_db` | `limpiar_zz` | PHP expression for the connection (default `DB::connection()`) |
|
|
161
|
+
| `capturas` | MCP resources | Captures folder (the one given to `--servir`); its `.txt` files are listed as `webscope://capturas/<file>` next to the saved walks `webscope://recorridos/<file>` |
|
|
162
|
+
|
|
163
|
+
The Vue index cache and `limpiar_zz` backups go to `~/.cache/webscope/`. The `e2e_chrome` receiver writes captures to the
|
|
164
|
+
folder given to `--servir` (default `capturas`, relative to where it starts). `--servir` does not return: start it from a
|
|
165
|
+
shell in the background (the example manifest lists it in `rechaza`, so `correr` refuses it).
|
|
166
|
+
|
|
167
|
+
### Using the scripts from a subagent
|
|
168
|
+
|
|
169
|
+
A subagent sees Webscope only if its definition lists the tools, for example in Claude Code's `.claude/agents/<name>.md`:
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
tools: Read, Grep, Glob, Bash, mcp__webscope__buscar, mcp__webscope__leer, mcp__webscope__correr
|
|
173
|
+
model: sonnet
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Add `mcp__webscope__correr_escritura` only if the agent must run write arguments, plus the browser tools it needs.
|
|
177
|
+
[`agents/recorrido.example.md`](agents/recorrido.example.md) is a ready-made agent that walks one frontend module in
|
|
178
|
+
Chrome with `mapa`, `e2e_chrome` and `limpiar_zz` and returns a summary of at most 25 lines: copy it to
|
|
179
|
+
`.claude/agents/recorrido.md` and replace `<webscope>` (the clone's folder; the receiver runs from the clone, not from
|
|
180
|
+
`uvx`) and the captures folder.
|
|
181
|
+
|
|
182
|
+
One measurement (a browser walk of one module, one project, one run per condition) found:
|
|
183
|
+
|
|
184
|
+
- With the walk in the main session, Webscope did not change the cost (+7 % and −5 % in two runs). It changed accuracy:
|
|
185
|
+
the order of steps (`mapa --recorrido`), the fields that were not saved (`__f.verificar`) and the measured coverage.
|
|
186
|
+
- The same walk in a sonnet subagent that returns a summary of at most 25 lines cost 1.05 USD instead of 6.40, with the
|
|
187
|
+
same coverage. About 2× came from isolating the context; the rest from the sonnet price.
|
|
188
|
+
- Page reads and screenshots were about 80 % of the re-read context, so the agent reads state with `javascript_tool` and
|
|
189
|
+
takes screenshots only to understand an error.
|
|
190
|
+
- Subagents that ran for more than about 40 turns grew their context like a main session. Give one module or one bounded
|
|
191
|
+
task per agent, and tell it to stop at about 40 tool calls and return what is done and what is pending.
|
|
192
|
+
|
|
193
|
+
`costo_sesion.py --raiz <project>` and `uso_agentes.py --raiz <project>` measure the same in another project. The USD
|
|
194
|
+
come from the price table at the top of `costo_sesion.py` (list prices, October 2026), which only lists models checked
|
|
195
|
+
against the cost reported by `claude -p` (Opus 5.5, Sonnet 5.5, Fable 5.1: within 0.01 USD on three runs); any other
|
|
196
|
+
model is shown as `sin precio` until it is added.
|
|
197
|
+
|
|
198
|
+
## Hook: suggest Webscope
|
|
199
|
+
|
|
200
|
+
Agents often keep using `Read`, `cat`, `sed -n` and `grep` even when Webscope is available. `hooks/sugerir_webscope.py`
|
|
201
|
+
is a Claude Code `PostToolUse` hook that, after such a call, adds one line to the model's context with the equivalent
|
|
202
|
+
Webscope call (for example `leer(archivo, lineas="120-180")`). It never blocks and speaks at most 3 times per session.
|
|
203
|
+
Add it to the project's `.claude/settings.json` or `.claude/settings.local.json`:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{"hooks": {"PostToolUse": [{"matcher": "Read|Bash", "hooks": [{"type": "command",
|
|
207
|
+
"command": "python3 -I /path/to/webscope/hooks/sugerir_webscope.py"}]}]}}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`uso_webscope.py` measures whether it works: the share of reads and searches that go through Webscope.
|
|
211
|
+
|
|
212
|
+
## Browser UI check
|
|
213
|
+
|
|
214
|
+
`webscope_adaptadores/web/chequeo-ui.js` is a standalone snippet for a browser automation tool (`page.evaluate` in Playwright, or a
|
|
215
|
+
JavaScript tool in a browser extension). It returns only the problems on the current page: horizontal overflow, empty
|
|
216
|
+
chips or badges, untranslated i18n keys, raw values (`undefined`, `NaN`…), overlapping text and unnamed buttons.
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
PLAYWRIGHT_DIR=<folder containing node_modules/playwright> node webscope_adaptadores/web/test_chequeo_ui.mjs
|
|
220
|
+
PLAYWRIGHT_DIR=<folder containing node_modules/playwright> PW_CHANNEL=chrome node webscope_adaptadores/web/test_form.mjs
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`PW_CHANNEL=chrome` uses the installed Chrome when Playwright's own browser is missing.
|
|
224
|
+
|
|
225
|
+
## Tests
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
python3 -I test_webscope.py
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Out of scope
|
|
232
|
+
|
|
233
|
+
Webscope does not replace a language server or a browser automation server, does not run code written by the agent, and
|
|
234
|
+
is not a test framework.
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "webscope-mcp"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "MCP server (stdio, standard library only) that gives a coding agent short answers about a project"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
dependencies = []
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Repository = "https://github.com/partprogramming09/webscope"
|
|
16
|
+
|
|
17
|
+
[project.scripts]
|
|
18
|
+
webscope-mcp = "webscope:main"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools]
|
|
21
|
+
py-modules = ["webscope"]
|
|
22
|
+
packages = ["webscope_adaptadores"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.package-data]
|
|
25
|
+
webscope_adaptadores = ["web/*.js"]
|