football-docs 0.13.0 → 0.15.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/README.md +33 -11
- package/bin/serve.js +10 -0
- package/data/docs.db +0 -0
- package/dist/data-format.d.ts +4 -4
- package/dist/data-format.js +8 -8
- package/dist/data-signing.d.ts +30 -0
- package/dist/data-signing.js +55 -0
- package/dist/data-update.d.ts +9 -1
- package/dist/data-update.js +18 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -6
- package/dist/ingest.js +6 -7
- package/dist/opta-truth.d.ts +44 -0
- package/dist/opta-truth.js +158 -0
- package/dist/sportmonks-truth.d.ts +37 -0
- package/dist/sportmonks-truth.js +87 -0
- package/dist/sqlite.d.ts +18 -0
- package/dist/sqlite.js +31 -0
- package/dist/statsbomb-truth.d.ts +48 -0
- package/dist/statsbomb-truth.js +193 -0
- package/dist/tools.d.ts +8 -8
- package/dist/tools.js +61 -9
- package/docs/kloppy/event-derived-metrics.md +2 -2
- package/docs/opta/charting-game-state.md +7 -5
- package/docs/opta/charting-passmaps.md +3 -2
- package/docs/opta/charting-shot-placement.md +14 -12
- package/docs/opta/coordinate-system.md +9 -2
- package/docs/opta/event-types.md +46 -40
- package/docs/opta/qualifiers.md +7 -5
- package/docs/sportmonks/charting-season-stories.md +3 -3
- package/docs/sportmonks/data-model.md +9 -9
- package/docs/sportmonks/event-types.md +81 -59
- package/docs/statsbomb/event-types.md +83 -4
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -29,6 +29,9 @@ MCP ([Model Context Protocol](https://modelcontextprotocol.io)) is a standard fo
|
|
|
29
29
|
|
|
30
30
|
## Quick start
|
|
31
31
|
|
|
32
|
+
The server needs Node.js 22.13 or newer. It uses Node's built-in SQLite, so no
|
|
33
|
+
native module is compiled at install time.
|
|
34
|
+
|
|
32
35
|
### Claude Code
|
|
33
36
|
|
|
34
37
|
```bash
|
|
@@ -84,7 +87,7 @@ Add to `claude_desktop_config.json`:
|
|
|
84
87
|
|
|
85
88
|
| Tool | Description |
|
|
86
89
|
|------|-------------|
|
|
87
|
-
| `search_docs` | Full-text search across all provider docs. Filter by provider. Results include provenance (source URL, version). |
|
|
90
|
+
| `search_docs` | Full-text search across all provider docs. Filter by provider. Results include provenance (source URL, version), mark partial matches, and name query terms that no indexed doc mentions. |
|
|
88
91
|
| `resolve_provider_id` | Resolve provider names and aliases to canonical indexed provider keys before searching. |
|
|
89
92
|
| `get_provider_docs` | Retrieve docs for a resolved provider, optionally filtered by topic or category. |
|
|
90
93
|
| `list_providers` | List all indexed providers and their doc coverage. |
|
|
@@ -101,8 +104,11 @@ version. Once a day at most, the server checks the
|
|
|
101
104
|
[`data-latest`](https://github.com/withqwerty/football-docs/releases/tag/data-latest)
|
|
102
105
|
release of this repository for a newer index built from `main`:
|
|
103
106
|
|
|
104
|
-
- It reads a small manifest (`manifest-v1.json`) and, only when that
|
|
105
|
-
newer build, downloads the index (about 6 MB).
|
|
107
|
+
- It reads a small signed manifest (`manifest-v1-signed.json`) and, only when that
|
|
108
|
+
names a newer build, downloads the index (about 6 MB).
|
|
109
|
+
- It accepts the manifest only if its ed25519 signature verifies against a public
|
|
110
|
+
key shipped in the package (`src/data-signing.ts`). The manifest carries the
|
|
111
|
+
index's size and SHA-256, so the signature covers the index too.
|
|
106
112
|
- It checks the download's size and SHA-256, its SQLite integrity, its exact
|
|
107
113
|
schema and its metadata before using it, and keeps the one it had on any failure.
|
|
108
114
|
- It stores downloads in `$XDG_DATA_HOME/football-docs/data/` (by default
|
|
@@ -132,7 +138,7 @@ development and tests always use the working tree's docs.
|
|
|
132
138
|
|
|
133
139
|
## Example queries
|
|
134
140
|
|
|
135
|
-
- "What is Opta qualifier
|
|
141
|
+
- "What is Opta qualifier 214?" (big chance)
|
|
136
142
|
- "How does StatsBomb represent shot events?"
|
|
137
143
|
- "Compare Opta and Wyscout coordinate systems"
|
|
138
144
|
- "What player ID fields does Transfermarkt expose?"
|
|
@@ -145,12 +151,12 @@ development and tests always use the working tree's docs.
|
|
|
145
151
|
| Provider | Chunks | Categories |
|
|
146
152
|
|----------|--------|------------|
|
|
147
153
|
| fast-forward | 250 | overview, getting-started, data-model, coordinate-system, orientations, layouts, transformations, distributed-compute, api-reference, 12 provider format pages |
|
|
148
|
-
| StatsBomb |
|
|
154
|
+
| StatsBomb | 244 | event-types, data-model, coordinate-system, api-access, api-endpoints, charting-lineups, xg-model, iq-metrics, player/team stats, player-mapping, identity-surfaces, data-provenance |
|
|
149
155
|
| unravelsports | 202 | overview, installation, quickstart, concepts, graph converters, pressing intensity, formation detection, models, utils, american-football |
|
|
150
156
|
| Wyscout | 165 | event-types, data-model, coordinate-system, api-access, api-endpoints, charting-analysis-metrics, glossary, identity-surfaces, data-provenance |
|
|
151
157
|
| kloppy | 126 | data-model, usage, provider-mapping, tracking-rendering, event-derived-metrics |
|
|
152
158
|
| floodlight | 144 | core data objects, io parsers (Tracab, DFL, Kinexon, Opta, SkillCorner, StatsBomb, StatsPerform, Second Spectrum), transforms, metrics, models, visualisation, guides |
|
|
153
|
-
| SportMonks |
|
|
159
|
+
| SportMonks | 568 | full v3 endpoint reference (fixtures, livescores, leagues, seasons, states, types, statistics, brackets), syntax and includes, filtering, rate limits, error codes, changelog, plus curated event-types, data-model, api-access, charting-season-stories, identity-surfaces, data-provenance |
|
|
154
160
|
| databallpy | 63 | data-model, overview, usage |
|
|
155
161
|
| mplsoccer | 65 | overview, pitch-types, visualizations |
|
|
156
162
|
| Impect | 79 | overview, data-model, event-types, coordinate-system, concepts, kpi-definitions, identity-surfaces, data-provenance |
|
|
@@ -171,7 +177,7 @@ development and tests always use the working tree's docs.
|
|
|
171
177
|
| Soccerdonna | 5 | identity-surfaces, data-provenance |
|
|
172
178
|
| Transfermarkt | 5 | identity-surfaces, data-provenance |
|
|
173
179
|
|
|
174
|
-
**2,
|
|
180
|
+
**2,860 searchable chunks** across 26 providers and tools.
|
|
175
181
|
|
|
176
182
|
ESPN coverage consists of curated, dated observations of ESPN-hosted soccer
|
|
177
183
|
endpoints, checked for eng.1 and esp.1. These observations are not an official API
|
|
@@ -202,6 +208,9 @@ trusting them.
|
|
|
202
208
|
| BeSoccer | The vendor's published Postman collection — request vocabulary and parameters | `src/__tests__/provider-truth.test.ts` |
|
|
203
209
|
| Driblab | The vendor's published API guide — endpoint paths and methods. Field and group names are not in CI: the guide disagrees with the live API on them, so the docs follow the live API, checked by hand on 2026-09-22 | `src/__tests__/provider-truth.test.ts` |
|
|
204
210
|
| Impect | The public [open-data](https://github.com/ImpectAPI/open-data) repository | `src/__tests__/impect-open-data-validation.test.ts` |
|
|
211
|
+
| StatsBomb | ID and name pairs observed in a sample of the public [open data](https://github.com/statsbomb/open-data) (three matches per competition-season, at a pinned commit). IDs the sample lacks must be listed in both the Open Data Events specification and kloppy's parser. Regenerate with `pnpm statsbomb:truth` | `src/__tests__/statsbomb-truth.test.ts` |
|
|
212
|
+
| Opta | Stats Perform's F24 appendices, which have no machine-readable form. `data/opta-truth.json` holds each ID the docs use, with its label, checked by hand. The test also rejects the wrong meanings earlier docs gave some IDs (`WRONG_MEANINGS` in `src/opta-truth.ts`) | `src/__tests__/opta-truth.test.ts` |
|
|
213
|
+
| SportMonks | Type and state IDs as SportMonks publishes them on its definitions pages and in the types spreadsheet linked from its Types page (`data/sportmonks-types-truth.json`, fetched 2026-09-30). Not the full list: the complete one needs an API key | `src/__tests__/sportmonks-truth.test.ts` |
|
|
205
214
|
| Reep | The public OpenAPI spec (endpoint paths and methods), and one release's manifest and column schema (CSV table list, columns used in the SQL examples, licence and exclusions) | `src/__tests__/provider-truth.test.ts`, `src/__tests__/reep.test.ts` |
|
|
206
215
|
|
|
207
216
|
ESPN has a separate observation check in `src/__tests__/espn.test.ts`. It validates
|
|
@@ -295,6 +304,21 @@ every six hours, at most once a day). Merging a doc PR is therefore also shippin
|
|
|
295
304
|
which to stop it. To undo a bad doc change, revert it on `main`, which publishes a
|
|
296
305
|
newer build.
|
|
297
306
|
|
|
307
|
+
**What the signature guarantees.** The publish job signs the manifest with a key
|
|
308
|
+
held only in the `data-publish` environment, whose deployment policy allows only
|
|
309
|
+
`main`. A manifest that verifies was therefore produced by `data.yml` running on
|
|
310
|
+
`main`. Replacing release assets by hand, or from a workflow on another branch,
|
|
311
|
+
cannot produce one. It does **not** mean anyone reviewed the change: `main`
|
|
312
|
+
accepts a PR with no approvals, so anyone who can merge to `main` can still ship
|
|
313
|
+
data. Requiring approvals on `main`, or required reviewers on the `data-publish`
|
|
314
|
+
environment (which makes every doc publish wait for a person), would close that
|
|
315
|
+
too.
|
|
316
|
+
|
|
317
|
+
**Rotating the key:** generate a new ed25519 pair, add its public key to
|
|
318
|
+
`TRUSTED_KEYS` in `src/data-signing.ts`, release, then replace the
|
|
319
|
+
`DATA_SIGNING_KEY` environment secret and `DATA_SIGNING_PUBLIC_KEY` in `data.yml`.
|
|
320
|
+
Drop the old key in a later release. A lost private key is handled the same way.
|
|
321
|
+
|
|
298
322
|
The index carries its own metadata (`meta` table, `src/data-format.ts`): a schema
|
|
299
323
|
version, the oldest server version that can read it, the build stamp and the
|
|
300
324
|
provider registry. Two rules follow:
|
|
@@ -375,10 +399,8 @@ workflow run without the workflow asking for it.
|
|
|
375
399
|
Two consequences worth knowing:
|
|
376
400
|
|
|
377
401
|
- **The release job runs on Node 24.** Trusted publishing needs npm >= 11.5.1 and
|
|
378
|
-
Node 22 still ships npm 10.
|
|
379
|
-
|
|
380
|
-
wrong ABI and `pnpm ingest` would fail on it. Node 24 is in the CI matrix for
|
|
381
|
-
the same reason: a release must not be the first time the suite meets it.
|
|
402
|
+
Node 22 still ships npm 10. Node 24 is in the CI matrix so that a release is
|
|
403
|
+
not the first time the suite meets it.
|
|
382
404
|
- **The release job does not cache dependencies.** This is the tree that gets
|
|
383
405
|
published, so it is resolved fresh from the lockfile rather than rehydrated
|
|
384
406
|
from a cache that earlier runs could have poisoned.
|
package/bin/serve.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
import { resolve, dirname } from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
|
|
5
|
+
// node:sqlite prints an ExperimentalWarning on Node 22 and 24. It is expected
|
|
6
|
+
// here, and MCP clients show a server's stderr to users, so drop that one warning.
|
|
7
|
+
const emitWarning = process.emitWarning;
|
|
8
|
+
process.emitWarning = (warning, ...args) => {
|
|
9
|
+
const type = typeof args[0] === "string" ? args[0] : args[0]?.type;
|
|
10
|
+
const message = typeof warning === "string" ? warning : warning?.message;
|
|
11
|
+
if (type === "ExperimentalWarning" && message?.includes("SQLite")) return;
|
|
12
|
+
return emitWarning.call(process, warning, ...args);
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
16
|
const { main } = await import(pathToFileURL(resolve(__dirname, "..", "dist", "index.js")).href);
|
|
7
17
|
|
package/data/docs.db
CHANGED
|
Binary file
|
package/dist/data-format.d.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* on what a usable file looks like, so the schema, the metadata keys and the
|
|
7
7
|
* validation all live here.
|
|
8
8
|
*/
|
|
9
|
-
import Database from "better-sqlite3";
|
|
10
9
|
import { z } from "zod";
|
|
10
|
+
import { type Database } from "./sqlite.js";
|
|
11
11
|
/** Bump when the table layout changes. Servers only use data with their own version. */
|
|
12
12
|
export declare const DATA_SCHEMA_VERSION = 1;
|
|
13
13
|
/**
|
|
@@ -67,16 +67,16 @@ export declare function compareVersions(a: string, b: string): number;
|
|
|
67
67
|
* Read and check the meta table. Returns null when the file predates the table
|
|
68
68
|
* (older releases, and the in-memory databases some tests build).
|
|
69
69
|
*/
|
|
70
|
-
export declare function readMeta(db: Database
|
|
70
|
+
export declare function readMeta(db: Database): DataMeta | null;
|
|
71
71
|
export interface MetaInput {
|
|
72
72
|
dataStamp: string;
|
|
73
73
|
commit: string | null;
|
|
74
74
|
providersJson: string;
|
|
75
75
|
}
|
|
76
76
|
/** Replace the meta table's contents. Used by ingest. */
|
|
77
|
-
export declare function writeMeta(db: Database
|
|
77
|
+
export declare function writeMeta(db: Database, input: MetaInput): void;
|
|
78
78
|
/** Settings for any docs database this process opens, bundled or downloaded. */
|
|
79
|
-
export declare function hardenConnection(db: Database
|
|
79
|
+
export declare function hardenConnection(db: Database): void;
|
|
80
80
|
export type ValidationResult = {
|
|
81
81
|
ok: true;
|
|
82
82
|
meta: DataMeta;
|
package/dist/data-format.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* on what a usable file looks like, so the schema, the metadata keys and the
|
|
7
7
|
* validation all live here.
|
|
8
8
|
*/
|
|
9
|
-
import Database from "better-sqlite3";
|
|
10
9
|
import { z } from "zod";
|
|
10
|
+
import { openDatabase, pragmaValue, transaction } from "./sqlite.js";
|
|
11
11
|
/** Bump when the table layout changes. Servers only use data with their own version. */
|
|
12
12
|
export const DATA_SCHEMA_VERSION = 1;
|
|
13
13
|
/**
|
|
@@ -126,7 +126,7 @@ export function readMeta(db) {
|
|
|
126
126
|
/** Replace the meta table's contents. Used by ingest. */
|
|
127
127
|
export function writeMeta(db, input) {
|
|
128
128
|
const insert = db.prepare("INSERT OR REPLACE INTO meta (key, value) VALUES (?, ?)");
|
|
129
|
-
|
|
129
|
+
transaction(db, () => {
|
|
130
130
|
db.prepare("DELETE FROM meta").run();
|
|
131
131
|
insert.run("schema_version", String(DATA_SCHEMA_VERSION));
|
|
132
132
|
insert.run("min_server_version", MIN_SERVER_VERSION);
|
|
@@ -134,7 +134,7 @@ export function writeMeta(db, input) {
|
|
|
134
134
|
if (input.commit)
|
|
135
135
|
insert.run("commit", input.commit);
|
|
136
136
|
insert.run("providers_json", input.providersJson);
|
|
137
|
-
})
|
|
137
|
+
});
|
|
138
138
|
}
|
|
139
139
|
/** FTS5's internal tables. Their SQL is written by SQLite, not by us. */
|
|
140
140
|
const FTS_SHADOW_TABLE = /^docs_fts_(data|idx|content|docsize|config)$/;
|
|
@@ -154,7 +154,7 @@ let referenceSchema;
|
|
|
154
154
|
/** The exact sqlite_master rows a database built from SCHEMA_SQL has. */
|
|
155
155
|
function expectedSchema() {
|
|
156
156
|
if (!referenceSchema) {
|
|
157
|
-
const reference =
|
|
157
|
+
const reference = openDatabase(":memory:");
|
|
158
158
|
reference.exec(SCHEMA_SQL);
|
|
159
159
|
referenceSchema = JSON.stringify(schemaRows(reference));
|
|
160
160
|
reference.close();
|
|
@@ -163,8 +163,8 @@ function expectedSchema() {
|
|
|
163
163
|
}
|
|
164
164
|
/** Settings for any docs database this process opens, bundled or downloaded. */
|
|
165
165
|
export function hardenConnection(db) {
|
|
166
|
-
db.
|
|
167
|
-
db.
|
|
166
|
+
db.exec("PRAGMA trusted_schema = OFF");
|
|
167
|
+
db.exec("PRAGMA cell_size_check = ON");
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
170
|
* Decide whether a file is a docs index this server can use: the exact schema,
|
|
@@ -175,10 +175,10 @@ export function hardenConnection(db) {
|
|
|
175
175
|
export function validateDatabase(path, serverVersion, options = {}) {
|
|
176
176
|
let db;
|
|
177
177
|
try {
|
|
178
|
-
db =
|
|
178
|
+
db = openDatabase(path, { readonly: true });
|
|
179
179
|
hardenConnection(db);
|
|
180
180
|
if (options.integrity) {
|
|
181
|
-
const check = db
|
|
181
|
+
const check = pragmaValue(db, "quick_check");
|
|
182
182
|
if (check !== "ok")
|
|
183
183
|
return { ok: false, reason: `integrity check failed (${String(check)})` };
|
|
184
184
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signatures on data-latest manifests.
|
|
3
|
+
*
|
|
4
|
+
* The publish job in .github/workflows/data.yml signs each manifest with an
|
|
5
|
+
* ed25519 key held only in the data-publish environment, which only workflows
|
|
6
|
+
* running on main can use. Servers accept a manifest only if a key listed here
|
|
7
|
+
* verifies it. Replacing release assets by hand, or from a workflow on another
|
|
8
|
+
* branch, therefore cannot put an index on users' machines: without the key it
|
|
9
|
+
* cannot produce a manifest they accept, and the manifest carries the index's
|
|
10
|
+
* size and SHA-256.
|
|
11
|
+
*
|
|
12
|
+
* To rotate: generate a new key pair, add its public key here, release, then
|
|
13
|
+
* replace the DATA_SIGNING_KEY secret and DATA_SIGNING_PUBLIC_KEY in data.yml.
|
|
14
|
+
* Remove the old key in a later release.
|
|
15
|
+
*/
|
|
16
|
+
export interface TrustedKey {
|
|
17
|
+
/** First 16 hex characters of the SHA-256 of the raw public key. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** The raw 32-byte ed25519 public key, base64. */
|
|
20
|
+
publicKey: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const TRUSTED_KEYS: readonly TrustedKey[];
|
|
23
|
+
export declare function keyIdFor(publicKey: string): string;
|
|
24
|
+
export declare class SignatureError extends Error {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check a signed manifest and return the manifest JSON it carries. The payload
|
|
28
|
+
* is verified as the exact string that was signed, before anything parses it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function verifySignedManifest(envelope: unknown, keys?: readonly TrustedKey[]): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signatures on data-latest manifests.
|
|
3
|
+
*
|
|
4
|
+
* The publish job in .github/workflows/data.yml signs each manifest with an
|
|
5
|
+
* ed25519 key held only in the data-publish environment, which only workflows
|
|
6
|
+
* running on main can use. Servers accept a manifest only if a key listed here
|
|
7
|
+
* verifies it. Replacing release assets by hand, or from a workflow on another
|
|
8
|
+
* branch, therefore cannot put an index on users' machines: without the key it
|
|
9
|
+
* cannot produce a manifest they accept, and the manifest carries the index's
|
|
10
|
+
* size and SHA-256.
|
|
11
|
+
*
|
|
12
|
+
* To rotate: generate a new key pair, add its public key here, release, then
|
|
13
|
+
* replace the DATA_SIGNING_KEY secret and DATA_SIGNING_PUBLIC_KEY in data.yml.
|
|
14
|
+
* Remove the old key in a later release.
|
|
15
|
+
*/
|
|
16
|
+
import { createHash, createPublicKey, verify } from "node:crypto";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
export const TRUSTED_KEYS = [
|
|
19
|
+
{ id: "e5a0dcbb72a87e45", publicKey: "1FjljvdILY3mrvrUeK4FqO8KbyYL4iDbTO0nIoNJuO8=" },
|
|
20
|
+
];
|
|
21
|
+
/** DER prefix that wraps a raw ed25519 public key as SubjectPublicKeyInfo. */
|
|
22
|
+
const ED25519_SPKI_PREFIX = Buffer.from("302a300506032b6570032100", "hex");
|
|
23
|
+
export function keyIdFor(publicKey) {
|
|
24
|
+
return createHash("sha256").update(Buffer.from(publicKey, "base64")).digest("hex").slice(0, 16);
|
|
25
|
+
}
|
|
26
|
+
const envelopeSchema = z.object({
|
|
27
|
+
/** The manifest JSON, exactly as signed. */
|
|
28
|
+
payload: z.string(),
|
|
29
|
+
/** Base64 ed25519 signature over the payload's UTF-8 bytes. */
|
|
30
|
+
signature: z.string(),
|
|
31
|
+
key_id: z.string(),
|
|
32
|
+
});
|
|
33
|
+
export class SignatureError extends Error {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check a signed manifest and return the manifest JSON it carries. The payload
|
|
37
|
+
* is verified as the exact string that was signed, before anything parses it.
|
|
38
|
+
*/
|
|
39
|
+
export function verifySignedManifest(envelope, keys = TRUSTED_KEYS) {
|
|
40
|
+
const parsed = envelopeSchema.safeParse(envelope);
|
|
41
|
+
if (!parsed.success)
|
|
42
|
+
throw new SignatureError("signed manifest is malformed");
|
|
43
|
+
const key = keys.find((candidate) => candidate.id === parsed.data.key_id);
|
|
44
|
+
if (!key)
|
|
45
|
+
throw new SignatureError(`manifest is signed with unknown key ${parsed.data.key_id}`);
|
|
46
|
+
const publicKey = createPublicKey({
|
|
47
|
+
key: Buffer.concat([ED25519_SPKI_PREFIX, Buffer.from(key.publicKey, "base64")]),
|
|
48
|
+
format: "der",
|
|
49
|
+
type: "spki",
|
|
50
|
+
});
|
|
51
|
+
const valid = verify(null, Buffer.from(parsed.data.payload, "utf-8"), publicKey, Buffer.from(parsed.data.signature, "base64"));
|
|
52
|
+
if (!valid)
|
|
53
|
+
throw new SignatureError("manifest signature does not verify");
|
|
54
|
+
return parsed.data.payload;
|
|
55
|
+
}
|
package/dist/data-update.d.ts
CHANGED
|
@@ -11,8 +11,14 @@
|
|
|
11
11
|
* which is the MCP channel.
|
|
12
12
|
*/
|
|
13
13
|
import { z } from "zod";
|
|
14
|
+
import { type TrustedKey } from "./data-signing.js";
|
|
14
15
|
export declare const DEFAULT_DATA_BASE_URL = "https://github.com/withqwerty/football-docs/releases/download/data-latest/";
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The signed manifest servers read. Its payload is the manifest-v<schema>.json
|
|
18
|
+
* that data.yml builds; the unsigned file is not published, and a server never
|
|
19
|
+
* falls back to it, so deleting the signed file cannot downgrade the check.
|
|
20
|
+
*/
|
|
21
|
+
export declare const MANIFEST_NAME = "manifest-v1-signed.json";
|
|
16
22
|
export declare const MAX_DOWNLOAD_BYTES: number;
|
|
17
23
|
declare const manifestSchema: z.ZodObject<{
|
|
18
24
|
schema_version: z.ZodNumber;
|
|
@@ -36,6 +42,8 @@ export interface UpdateOptions {
|
|
|
36
42
|
now?: () => number;
|
|
37
43
|
signal?: AbortSignal;
|
|
38
44
|
maxBytes?: number;
|
|
45
|
+
/** Keys that may sign manifests; defaults to the keys shipped in the package. */
|
|
46
|
+
trustedKeys?: readonly TrustedKey[];
|
|
39
47
|
log?: (message: string) => void;
|
|
40
48
|
}
|
|
41
49
|
export interface UpdateResult {
|
package/dist/data-update.js
CHANGED
|
@@ -16,9 +16,15 @@ import { open } from "node:fs/promises";
|
|
|
16
16
|
import { join } from "node:path";
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { compareVersions, DATA_SCHEMA_VERSION, validateDatabase } from "./data-format.js";
|
|
19
|
+
import { SignatureError, TRUSTED_KEYS, verifySignedManifest } from "./data-signing.js";
|
|
19
20
|
import { cachedFileName } from "./data-source.js";
|
|
20
21
|
export const DEFAULT_DATA_BASE_URL = "https://github.com/withqwerty/football-docs/releases/download/data-latest/";
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The signed manifest servers read. Its payload is the manifest-v<schema>.json
|
|
24
|
+
* that data.yml builds; the unsigned file is not published, and a server never
|
|
25
|
+
* falls back to it, so deleting the signed file cannot downgrade the check.
|
|
26
|
+
*/
|
|
27
|
+
export const MANIFEST_NAME = `manifest-v${DATA_SCHEMA_VERSION}-signed.json`;
|
|
22
28
|
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
23
29
|
const MANIFEST_TIMEOUT_MS = 10_000;
|
|
24
30
|
const DOWNLOAD_TIMEOUT_MS = 60_000;
|
|
@@ -76,7 +82,7 @@ class NotPublished extends Error {
|
|
|
76
82
|
}
|
|
77
83
|
class Rejected extends Error {
|
|
78
84
|
}
|
|
79
|
-
async function fetchManifest(fetchImpl, url, parent) {
|
|
85
|
+
async function fetchManifest(fetchImpl, url, keys, parent) {
|
|
80
86
|
requireHttps(url);
|
|
81
87
|
const timeout = timeoutSignal(MANIFEST_TIMEOUT_MS, parent);
|
|
82
88
|
try {
|
|
@@ -87,7 +93,9 @@ async function fetchManifest(fetchImpl, url, parent) {
|
|
|
87
93
|
throw new NotPublished(`no ${MANIFEST_NAME} published`);
|
|
88
94
|
if (!response.ok)
|
|
89
95
|
throw new Error(`manifest request returned HTTP ${response.status}`);
|
|
90
|
-
|
|
96
|
+
// Verify the signature over the exact signed text before parsing any of it.
|
|
97
|
+
const payload = verifySignedManifest(await response.json(), keys);
|
|
98
|
+
return manifestSchema.parse(JSON.parse(payload));
|
|
91
99
|
}
|
|
92
100
|
finally {
|
|
93
101
|
timeout.done();
|
|
@@ -165,7 +173,7 @@ export async function checkForUpdate(options) {
|
|
|
165
173
|
const base = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
166
174
|
let manifest;
|
|
167
175
|
try {
|
|
168
|
-
manifest = await fetchManifest(fetchImpl, new URL(MANIFEST_NAME, base).toString(), options.signal);
|
|
176
|
+
manifest = await fetchManifest(fetchImpl, new URL(MANIFEST_NAME, base).toString(), options.trustedKeys ?? TRUSTED_KEYS, options.signal);
|
|
169
177
|
}
|
|
170
178
|
catch (error) {
|
|
171
179
|
if (error instanceof NotPublished) {
|
|
@@ -174,7 +182,12 @@ export async function checkForUpdate(options) {
|
|
|
174
182
|
}
|
|
175
183
|
const detail = error instanceof Error ? error.message : String(error);
|
|
176
184
|
// A malformed manifest is a completed check; a network failure is not.
|
|
177
|
-
if (error instanceof
|
|
185
|
+
if (error instanceof SignatureError) {
|
|
186
|
+
recordCheck(options.dataDir, now());
|
|
187
|
+
log(`football-docs: data manifest rejected: ${detail}`);
|
|
188
|
+
return { outcome: "rejected", detail };
|
|
189
|
+
}
|
|
190
|
+
if (error instanceof z.ZodError || error instanceof SyntaxError) {
|
|
178
191
|
recordCheck(options.dataDir, now());
|
|
179
192
|
log(`football-docs: data manifest rejected: ${detail}`);
|
|
180
193
|
return { outcome: "rejected", detail: "malformed manifest" };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* location (XDG_DATA_HOME or ~/.local/share).
|
|
11
11
|
*/
|
|
12
12
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
13
|
-
import Database from "
|
|
13
|
+
import { type Database } from "./sqlite.js";
|
|
14
14
|
export { sanitiseFtsQuery } from "./tools.js";
|
|
15
|
-
export declare function openDb(): Database
|
|
16
|
-
export declare function openQueueDb(): Database
|
|
15
|
+
export declare function openDb(): Database;
|
|
16
|
+
export declare function openQueueDb(): Database;
|
|
17
17
|
export declare function createFootballDocsServer(): McpServer;
|
|
18
18
|
export declare function main(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -15,12 +15,12 @@ import { dirname, resolve } from "node:path";
|
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
16
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
17
17
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
18
|
-
import Database from "better-sqlite3";
|
|
19
18
|
import { z } from "zod";
|
|
20
19
|
import { hardenConnection } from "./data-format.js";
|
|
21
20
|
import { cleanDataDir, dataModeFor, defaultDataDir, IndexChooser } from "./data-source.js";
|
|
22
21
|
import { checkForUpdate } from "./data-update.js";
|
|
23
22
|
import { ENTITY_TYPES } from "./reep.js";
|
|
23
|
+
import { openDatabase } from "./sqlite.js";
|
|
24
24
|
import { compareProviders, getProviderDocs, listProviders, requestUpdate, resolveEntity, resolveProviderId, searchDocs, } from "./tools.js";
|
|
25
25
|
export { sanitiseFtsQuery } from "./tools.js";
|
|
26
26
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -51,9 +51,9 @@ export function openDb() {
|
|
|
51
51
|
if (!existsSync(path)) {
|
|
52
52
|
throw new Error(`Docs database not found at ${path}. Run 'npm run ingest' first to build the index.`);
|
|
53
53
|
}
|
|
54
|
-
const db =
|
|
54
|
+
const db = openDatabase(path, { readonly: true });
|
|
55
55
|
hardenConnection(db);
|
|
56
|
-
const columns = db.
|
|
56
|
+
const columns = db.prepare("PRAGMA table_info(docs)").all();
|
|
57
57
|
const hasProvenance = columns.some((column) => column.name === "source_type");
|
|
58
58
|
if (!hasProvenance) {
|
|
59
59
|
db.close();
|
|
@@ -63,8 +63,8 @@ export function openDb() {
|
|
|
63
63
|
}
|
|
64
64
|
export function openQueueDb() {
|
|
65
65
|
mkdirSync(QUEUE_DB_DIR, { recursive: true });
|
|
66
|
-
const db =
|
|
67
|
-
db.
|
|
66
|
+
const db = openDatabase(QUEUE_DB_PATH);
|
|
67
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
68
68
|
db.exec(`
|
|
69
69
|
CREATE TABLE IF NOT EXISTS requests (
|
|
70
70
|
id TEXT PRIMARY KEY,
|
|
@@ -101,7 +101,7 @@ export function createFootballDocsServer() {
|
|
|
101
101
|
name: "nutmeg-football-docs",
|
|
102
102
|
version: PKG_VERSION,
|
|
103
103
|
});
|
|
104
|
-
server.tool("search_docs", "Search football data provider documentation. Use for finding event types, qualifier IDs, API endpoints, coordinate systems, data models, and cross-provider mappings. Returns the most relevant documentation chunks.", {
|
|
104
|
+
server.tool("search_docs", "Search football data provider documentation. Use for finding event types, qualifier IDs, API endpoints, coordinate systems, data models, and cross-provider mappings. Returns the most relevant documentation chunks. Results that do not contain every query term are marked \"partial\", and the reply names any query term that no indexed doc mentions: if the question is about that term, it is not indexed.", {
|
|
105
105
|
query: z.string().describe("Search query. Examples: 'Opta goal qualifier', 'StatsBomb shot event type', 'coordinate system differences', 'xG qualifier ID', 'SportMonks fixture endpoint', 'FMDB Pro players endpoint'"),
|
|
106
106
|
provider: z
|
|
107
107
|
.string()
|
package/dist/ingest.js
CHANGED
|
@@ -22,8 +22,8 @@ import { execFileSync } from "node:child_process";
|
|
|
22
22
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
23
23
|
import { basename, dirname, resolve } from "node:path";
|
|
24
24
|
import { fileURLToPath } from "node:url";
|
|
25
|
-
import Database from "better-sqlite3";
|
|
26
25
|
import { SCHEMA_SQL, writeMeta } from "./data-format.js";
|
|
26
|
+
import { openDatabase, transaction } from "./sqlite.js";
|
|
27
27
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
28
28
|
const DOCS_DIR = resolve(__dirname, "..", "docs");
|
|
29
29
|
const DB_DIR = resolve(__dirname, "..", "data");
|
|
@@ -158,14 +158,14 @@ function main() {
|
|
|
158
158
|
const providerArg = process.argv.indexOf("--provider");
|
|
159
159
|
const singleProvider = providerArg >= 0 ? process.argv[providerArg + 1] : undefined;
|
|
160
160
|
mkdirSync(DB_DIR, { recursive: true });
|
|
161
|
-
const db =
|
|
162
|
-
db.
|
|
161
|
+
const db = openDatabase(DB_PATH);
|
|
162
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
163
163
|
if (singleProvider) {
|
|
164
164
|
// Single-provider mode: only rebuild that provider's data
|
|
165
165
|
// Ensure tables exist (in case DB is fresh)
|
|
166
166
|
ensureSchema(db);
|
|
167
167
|
// Atomically delete existing data and re-ingest for this provider
|
|
168
|
-
|
|
168
|
+
transaction(db, () => {
|
|
169
169
|
const rows = db.prepare("SELECT id, provider, category, title, content FROM docs WHERE provider = ?").all(singleProvider);
|
|
170
170
|
const ftsDelete = db.prepare("INSERT INTO docs_fts(docs_fts, rowid, provider, category, title, content) VALUES('delete', ?, ?, ?, ?, ?)");
|
|
171
171
|
for (const row of rows) {
|
|
@@ -173,7 +173,6 @@ function main() {
|
|
|
173
173
|
}
|
|
174
174
|
db.prepare("DELETE FROM docs WHERE provider = ?").run(singleProvider);
|
|
175
175
|
});
|
|
176
|
-
deleteAndReinsert();
|
|
177
176
|
console.log(`Ingesting ${singleProvider}...\n`);
|
|
178
177
|
const count = ingestProvider(db, singleProvider);
|
|
179
178
|
console.log(`\nDone: ${count} chunks from ${singleProvider}`);
|
|
@@ -186,7 +185,7 @@ function main() {
|
|
|
186
185
|
console.log(`No docs directory at ${DOCS_DIR}`);
|
|
187
186
|
console.log("Create docs/{provider}/*.md files first.");
|
|
188
187
|
recordMeta(db);
|
|
189
|
-
db.
|
|
188
|
+
db.exec("PRAGMA journal_mode = DELETE");
|
|
190
189
|
db.close();
|
|
191
190
|
return;
|
|
192
191
|
}
|
|
@@ -207,7 +206,7 @@ function main() {
|
|
|
207
206
|
// A shipped or downloaded file must not be in WAL mode: opening it read-only
|
|
208
207
|
// would try to create -wal/-shm files next to it, which fails in a read-only
|
|
209
208
|
// install and leaves side files behind in the cache.
|
|
210
|
-
db.
|
|
209
|
+
db.exec("PRAGMA journal_mode = DELETE");
|
|
211
210
|
db.close();
|
|
212
211
|
}
|
|
213
212
|
// Only run when executed directly, not when imported for tests
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation for the Opta ID tables.
|
|
3
|
+
*
|
|
4
|
+
* Opta's reference, the Stats Perform F24 appendices, has no machine-readable
|
|
5
|
+
* form, so data/opta-truth.json is kept by hand: each ID the docs use,
|
|
6
|
+
* with the label the docs give it, checked against F24. The tests then hold the
|
|
7
|
+
* docs to that file, and reject meanings that were wrong in earlier versions of
|
|
8
|
+
* the docs (Q76 as big chance, Q213 as xG and so on) wherever they reappear.
|
|
9
|
+
*/
|
|
10
|
+
export declare const OPTA_TRUTH_PATH: string;
|
|
11
|
+
export interface OptaTruth {
|
|
12
|
+
source: {
|
|
13
|
+
reference: string;
|
|
14
|
+
url: string;
|
|
15
|
+
checked: string;
|
|
16
|
+
note: string;
|
|
17
|
+
};
|
|
18
|
+
/** typeId -> event type name. */
|
|
19
|
+
eventTypes: Record<string, string>;
|
|
20
|
+
/** qualifierId -> the label docs/opta/qualifiers.md gives it. */
|
|
21
|
+
qualifiers: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
export interface OptaDoc {
|
|
24
|
+
path: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
export interface OptaViolation {
|
|
28
|
+
path: string;
|
|
29
|
+
line: number;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function loadOptaTruth(): OptaTruth;
|
|
33
|
+
/**
|
|
34
|
+
* Meanings earlier docs gave these IDs, all wrong. The pattern matches the ID
|
|
35
|
+
* and the wrong meaning in one clause, in either order, and in a row of an Opta
|
|
36
|
+
* qualifier table. A clause that negates the claim ("Q213 is the pass angle, not
|
|
37
|
+
* xG", "Do not read qualifier 213 as xG") is allowed.
|
|
38
|
+
*/
|
|
39
|
+
export declare const WRONG_MEANINGS: Array<{
|
|
40
|
+
id: number;
|
|
41
|
+
meaning: string;
|
|
42
|
+
pattern: RegExp;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function validateOptaDocs(docs: OptaDoc[], truth: OptaTruth): OptaViolation[];
|