fpl-context-mcp 0.4.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.
- fpl_context_mcp-0.4.0/LICENSE +21 -0
- fpl_context_mcp-0.4.0/PKG-INFO +538 -0
- fpl_context_mcp-0.4.0/README.md +506 -0
- fpl_context_mcp-0.4.0/config.py +91 -0
- fpl_context_mcp-0.4.0/fpl_context_mcp.egg-info/PKG-INFO +538 -0
- fpl_context_mcp-0.4.0/fpl_context_mcp.egg-info/SOURCES.txt +22 -0
- fpl_context_mcp-0.4.0/fpl_context_mcp.egg-info/dependency_links.txt +1 -0
- fpl_context_mcp-0.4.0/fpl_context_mcp.egg-info/entry_points.txt +4 -0
- fpl_context_mcp-0.4.0/fpl_context_mcp.egg-info/requires.txt +11 -0
- fpl_context_mcp-0.4.0/fpl_context_mcp.egg-info/top_level.txt +4 -0
- fpl_context_mcp-0.4.0/jobs/__init__.py +0 -0
- fpl_context_mcp-0.4.0/jobs/ingest_match_data.py +776 -0
- fpl_context_mcp-0.4.0/jobs/ingest_press_content.py +791 -0
- fpl_context_mcp-0.4.0/pyproject.toml +75 -0
- fpl_context_mcp-0.4.0/server.py +269 -0
- fpl_context_mcp-0.4.0/setup.cfg +4 -0
- fpl_context_mcp-0.4.0/tests/test_config.py +87 -0
- fpl_context_mcp-0.4.0/tests/test_ingest_match_data.py +317 -0
- fpl_context_mcp-0.4.0/tests/test_ingest_press_content.py +627 -0
- fpl_context_mcp-0.4.0/tests/test_tools_press.py +152 -0
- fpl_context_mcp-0.4.0/tests/test_tools_stats.py +215 -0
- fpl_context_mcp-0.4.0/tools/__init__.py +0 -0
- fpl_context_mcp-0.4.0/tools/query_historical_stats.py +178 -0
- fpl_context_mcp-0.4.0/tools/query_press_conferences.py +160 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shubham Banthia
|
|
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,538 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fpl-context-mcp
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: MCP server that gives Claude Fantasy Premier League stats and press/injury news search, with ingestion jobs that keep PostgreSQL and Pinecone up to date.
|
|
5
|
+
Author-email: Shubham Banthia <sbanthia92@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sbanthia92/fpl-context-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/sbanthia92/fpl-context-mcp
|
|
9
|
+
Project-URL: Changelog, https://github.com/sbanthia92/fpl-context-mcp/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/sbanthia92/fpl-context-mcp/issues
|
|
11
|
+
Keywords: mcp,model-context-protocol,fantasy-premier-league,fpl,sports,rag
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: mcp<2.0.0,>=1.0.0
|
|
22
|
+
Requires-Dist: pinecone>=5.0.0
|
|
23
|
+
Requires-Dist: asyncpg>=0.29.0
|
|
24
|
+
Requires-Dist: psycopg2-binary>=2.9.9
|
|
25
|
+
Requires-Dist: requests>=2.32.0
|
|
26
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# fpl-context-mcp
|
|
34
|
+
|
|
35
|
+
An [MCP](https://modelcontextprotocol.io) server that gives Claude (or any MCP client) two tools for answering Fantasy Premier League (FPL) and Premier League football questions:
|
|
36
|
+
|
|
37
|
+
| Tool | What it does |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `query_historical_stats` | Runs a read-only SQL SELECT against a PostgreSQL database of FPL player, fixture and gameweek stats (whatever seasons you've ingested) |
|
|
40
|
+
| `query_press_conferences` | Semantic search over BBC Sport and The Guardian press-conference summaries and injury updates stored in Pinecone |
|
|
41
|
+
|
|
42
|
+
Two ingestion jobs keep that data populated and current:
|
|
43
|
+
|
|
44
|
+
| Job | What it does |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `ingest_press_content` | Fetches articles from BBC Sport RSS and The Guardian API, embeds them, and upserts into Pinecone |
|
|
47
|
+
| `ingest_match_data` | Fetches fixture and player-stat data from the FPL API, and delta-writes to PostgreSQL |
|
|
48
|
+
|
|
49
|
+
> **This server does not fetch live data per-question.** The two tools above only read whatever is already sitting in *your* PostgreSQL database and Pinecone index. Those stores start out **empty** — you must run the ingestion jobs once to seed them, and then keep running them **on a recurring schedule forever**, or answers will silently go stale (press results) or stay empty (stats results). This is not a one-time setup step. See [Keeping data fresh (ongoing)](#keeping-data-fresh-ongoing) — it's the single most important thing to get right before handing this to anyone.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Contents
|
|
54
|
+
|
|
55
|
+
- [Quickstart](#quickstart)
|
|
56
|
+
- [Prerequisites](#prerequisites)
|
|
57
|
+
- [Installation](#installation)
|
|
58
|
+
- [Configuration](#configuration)
|
|
59
|
+
- [Provisioning your own database (standalone only)](#provisioning-your-own-database-standalone-only)
|
|
60
|
+
- [Seeding data (required before first use)](#seeding-data-required-before-first-use)
|
|
61
|
+
- [Keeping data fresh (ongoing)](#keeping-data-fresh-ongoing)
|
|
62
|
+
- [Registering with Claude Desktop](#registering-with-claude-desktop)
|
|
63
|
+
- [Running the server standalone](#running-the-server-standalone)
|
|
64
|
+
- [Verifying connectivity (--check)](#verifying-connectivity---check)
|
|
65
|
+
- [Dry-run mode](#dry-run-mode)
|
|
66
|
+
- [MCP tools reference](#mcp-tools-reference)
|
|
67
|
+
- [Database schema](#database-schema)
|
|
68
|
+
- [Running tests](#running-tests)
|
|
69
|
+
- [Extending with new press sources](#extending-with-new-press-sources)
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Quickstart
|
|
74
|
+
|
|
75
|
+
The full path from zero to a working MCP tool, in order. Each step links to details further down.
|
|
76
|
+
|
|
77
|
+
1. **Install**: `pip install fpl-context-mcp` — see [Installation](#installation).
|
|
78
|
+
2. **Provision storage**: a PostgreSQL database and a Pinecone index. If you're not reusing [The Gaffer](https://github.com/sbanthia92/Gaffer)'s existing storage, run [`db/schema.sql`](db/schema.sql) against a fresh Postgres database and create a Pinecone index named `the-gaffer` (or your own name) using the `multilingual-e5-large` model — see [Provisioning your own database](#provisioning-your-own-database-standalone-only).
|
|
79
|
+
3. **Configure**: copy [`.env.example`](.env.example) to `.env` and fill in your `DATABASE_URL`, `DATABASE_ETL_URL`, and `PINECONE_API_KEY` — see [Configuration](#configuration).
|
|
80
|
+
4. **Verify connectivity**: `fpl-context-mcp --check` — confirms every credential works before you go further.
|
|
81
|
+
5. **Seed data**: run both ingestion commands once so there's actually something to query — see [Seeding data](#seeding-data-required-before-first-use).
|
|
82
|
+
6. **Schedule ongoing ingestion**: set up cron (or equivalent) to keep re-running those same two commands indefinitely — see [Keeping data fresh](#keeping-data-fresh-ongoing). Skipping this is the #1 cause of "the tool returns nothing" reports.
|
|
83
|
+
7. **Register with Claude Desktop**: add the server to `claude_desktop_config.json` and restart Claude — see [Registering with Claude Desktop](#registering-with-claude-desktop).
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Prerequisites
|
|
88
|
+
|
|
89
|
+
| Requirement | Version |
|
|
90
|
+
|---|---|
|
|
91
|
+
| Python | 3.11+ |
|
|
92
|
+
| PostgreSQL | Any recent version, with a read-only role (e.g. `gaffer_readonly`) and a read/write role (e.g. `gaffer_etl`) |
|
|
93
|
+
| Pinecone | An index using the `multilingual-e5-large` model (1024 dims) — free tier works |
|
|
94
|
+
|
|
95
|
+
You can point this server at [The Gaffer](https://github.com/sbanthia92/Gaffer)'s existing PostgreSQL database and Pinecone index if you already run that app, or provision your own — see the next two sections either way.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Installation
|
|
100
|
+
|
|
101
|
+
### From PyPI (recommended)
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install fpl-context-mcp
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
This installs three CLI commands: `fpl-context-mcp` (the MCP server), `fpl-context-ingest-press`, and `fpl-context-ingest-match` (the two ingestion jobs — see [Seeding data](#seeding-data-required-before-first-use)).
|
|
108
|
+
|
|
109
|
+
### With uv
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
git clone https://github.com/sbanthia92/fpl-context-mcp
|
|
113
|
+
cd fpl-context-mcp
|
|
114
|
+
uv sync
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### With pip (from source)
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
git clone https://github.com/sbanthia92/fpl-context-mcp
|
|
121
|
+
cd fpl-context-mcp
|
|
122
|
+
pip install -e ".[dev]"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### As a dependency of another project
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
fpl-context-mcp @ git+https://github.com/sbanthia92/fpl-context-mcp.git
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
134
|
+
|
|
135
|
+
The server reads all secrets from environment variables. Copy [`.env.example`](.env.example) to `.env` in your working directory (it's gitignored) and fill in your own values:
|
|
136
|
+
|
|
137
|
+
```dotenv
|
|
138
|
+
# PostgreSQL — read-only connection for the query_historical_stats tool
|
|
139
|
+
DATABASE_URL=postgresql://gaffer_readonly:password@localhost:5432/gaffer
|
|
140
|
+
|
|
141
|
+
# PostgreSQL — read/write connection for the ingest_match_data job
|
|
142
|
+
# Falls back to DATABASE_URL if not set
|
|
143
|
+
DATABASE_ETL_URL=postgresql://gaffer_etl:password@localhost:5432/gaffer
|
|
144
|
+
|
|
145
|
+
# Pinecone — required for both the press tool and the ingest_press_content job
|
|
146
|
+
PINECONE_API_KEY=pcsk_...
|
|
147
|
+
PINECONE_INDEX_NAME=the-gaffer # optional, defaults to 'the-gaffer'
|
|
148
|
+
|
|
149
|
+
# The Guardian open platform API key
|
|
150
|
+
# Register free at https://open-platform.theguardian.com/access/
|
|
151
|
+
# Recommended: without a key the Guardian source is skipped (BBC Sport only) —
|
|
152
|
+
# the old public 'test' key is rejected by the API.
|
|
153
|
+
GUARDIAN_API_KEY=your-key-here
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Which variables does each component need?
|
|
157
|
+
|
|
158
|
+
| Component | Variables required |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `query_historical_stats` tool | `DATABASE_URL` |
|
|
161
|
+
| `query_press_conferences` tool | `PINECONE_API_KEY` |
|
|
162
|
+
| `ingest_press_content` job | `PINECONE_API_KEY` (plus `GUARDIAN_API_KEY` for Guardian articles) |
|
|
163
|
+
| `ingest_match_data` job | `DATABASE_ETL_URL` (or `DATABASE_URL`) |
|
|
164
|
+
|
|
165
|
+
Run `fpl-context-mcp --check` any time to confirm all of the above are set correctly and reachable — see [Verifying connectivity](#verifying-connectivity---check).
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Provisioning your own database (standalone only)
|
|
170
|
+
|
|
171
|
+
Skip this section if you're pointing at an existing [The Gaffer](https://github.com/sbanthia92/Gaffer) database and Pinecone index — they're already set up.
|
|
172
|
+
|
|
173
|
+
**PostgreSQL:**
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
createdb gaffer # or whatever database name you'll use in DATABASE_URL
|
|
177
|
+
psql gaffer -f db/schema.sql
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
[`db/schema.sql`](db/schema.sql) creates the six tables `query_historical_stats` expects (`seasons`, `teams`, `gameweeks`, `players`, `fixtures`, `gw_player_stats`, plus the `player_xpts` materialized view) and includes example `CREATE ROLE` statements for the read-only and read/write roles referenced in `.env.example`. It's a starting schema, not a full migration tool — adjust types/constraints as needed.
|
|
181
|
+
|
|
182
|
+
**Pinecone:**
|
|
183
|
+
|
|
184
|
+
1. Create a free account at [pinecone.io](https://www.pinecone.io/) if you don't have one.
|
|
185
|
+
2. Create an index named `the-gaffer` (or any name — just set `PINECONE_INDEX_NAME` to match) configured for the `multilingual-e5-large` **integrated embedding model** (1024 dimensions, cosine metric). No separate embedding step needed — the ingestion job and the query tool both call Pinecone's built-in inference.
|
|
186
|
+
3. Grab an API key from the Pinecone console and set `PINECONE_API_KEY`.
|
|
187
|
+
|
|
188
|
+
Both tables and the index start **completely empty**. Continue to [Seeding data](#seeding-data-required-before-first-use).
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Seeding data (required before first use)
|
|
193
|
+
|
|
194
|
+
Both ingestion jobs are plain functions you run directly — nothing runs automatically on `pip install` or on MCP server startup.
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# If installed from PyPI
|
|
198
|
+
fpl-context-ingest-press
|
|
199
|
+
fpl-context-ingest-match
|
|
200
|
+
|
|
201
|
+
# If running from source
|
|
202
|
+
python -m jobs.ingest_press_content
|
|
203
|
+
python -m jobs.ingest_match_data
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Run both **once, right after configuring your `.env`**, before registering the server with Claude Desktop. Until you do:
|
|
207
|
+
|
|
208
|
+
- `query_press_conferences` will return a message telling you the namespace is unseeded, instead of any article content.
|
|
209
|
+
- `query_historical_stats` will return `Query returned no results.` for any query, since the tables are empty.
|
|
210
|
+
|
|
211
|
+
`ingest_match_data` loads the **current season** on first run — every team, player and fixture, plus per-player stats for matches already played (the first run can take a while mid-season, since it fetches stats one player at a time). The FPL API only serves the current season, so past seasons aren't backfilled: history builds up over time as you keep the job running, or you can load older seasons into the same tables yourself. The `gameweeks` table is not written by this job, so it stays empty unless you fill it. `ingest_press_content` only pulls currently-live articles (BBC/Guardian don't offer deep history), so the press index will be thin until it's had a few days of scheduled runs — that's expected, not a bug.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Keeping data fresh (ongoing)
|
|
216
|
+
|
|
217
|
+
**This is not a one-time step.** Fixtures change weekly, player stats update after every match, press articles are deleted from the index after 14 days, and injury/availability news is rewritten on every run so it reflects what FPL currently says (`ingest_press_content` prunes stale docs each time). If you seed once and never run these jobs again, a query a month later will hit a Pinecone namespace with **zero documents** (everything aged out) and a Postgres database that's **missing every fixture since your last run**.
|
|
218
|
+
|
|
219
|
+
You need something to invoke `fpl-context-ingest-press` and `fpl-context-ingest-match` on a recurring schedule, indefinitely, for as long as the MCP server is in use. Pick whichever fits your setup:
|
|
220
|
+
|
|
221
|
+
### Option A — cron (simplest, any Linux/macOS host)
|
|
222
|
+
|
|
223
|
+
```cron
|
|
224
|
+
# Press content: nightly at midnight UTC
|
|
225
|
+
0 0 * * * /path/to/venv/bin/fpl-context-ingest-press >> /var/log/fpl-context-ingest-press.log 2>&1
|
|
226
|
+
|
|
227
|
+
# Match data: twice daily during the season (06:00 + 22:00 UTC)
|
|
228
|
+
0 6,22 * * * /path/to/venv/bin/fpl-context-ingest-match >> /var/log/fpl-context-ingest-match.log 2>&1
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Adjust the match-data cadence to the calendar:
|
|
232
|
+
|
|
233
|
+
| Period | Recommended cadence |
|
|
234
|
+
|---|---|
|
|
235
|
+
| PL season (Aug–May) | Twice daily, `0 6,22 * * *` |
|
|
236
|
+
| World Cup / tournament group stage | Hourly, `0 * * * *` |
|
|
237
|
+
| World Cup / tournament knockout | Every 6 hours, `0 */6 * * *` |
|
|
238
|
+
| Off-season | Once daily, `0 8 * * *` |
|
|
239
|
+
|
|
240
|
+
### Option B — GitHub Actions in your own private repo (free, no server needed)
|
|
241
|
+
|
|
242
|
+
Best if you don't have a machine that's always on. You don't fork this project — you create a tiny repo of your own with one file that installs the package from PyPI and runs the two commands on a schedule.
|
|
243
|
+
|
|
244
|
+
1. Create a new **private** GitHub repository (any name).
|
|
245
|
+
2. Add this file as `.github/workflows/ingest.yml`:
|
|
246
|
+
|
|
247
|
+
```yaml
|
|
248
|
+
name: Ingest sports data
|
|
249
|
+
|
|
250
|
+
on:
|
|
251
|
+
schedule:
|
|
252
|
+
- cron: "0 6,22 * * *" # twice daily, UTC
|
|
253
|
+
workflow_dispatch: {} # lets you run it by hand from the Actions tab
|
|
254
|
+
|
|
255
|
+
jobs:
|
|
256
|
+
ingest:
|
|
257
|
+
runs-on: ubuntu-latest
|
|
258
|
+
steps:
|
|
259
|
+
- uses: actions/setup-python@v5
|
|
260
|
+
with:
|
|
261
|
+
python-version: "3.11"
|
|
262
|
+
- run: pip install fpl-context-mcp
|
|
263
|
+
- name: Ingest press content
|
|
264
|
+
run: fpl-context-ingest-press
|
|
265
|
+
env:
|
|
266
|
+
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
|
|
267
|
+
PINECONE_INDEX_NAME: ${{ secrets.PINECONE_INDEX_NAME }}
|
|
268
|
+
GUARDIAN_API_KEY: ${{ secrets.GUARDIAN_API_KEY }}
|
|
269
|
+
- name: Ingest match data
|
|
270
|
+
run: fpl-context-ingest-match
|
|
271
|
+
env:
|
|
272
|
+
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
|
273
|
+
DATABASE_ETL_URL: ${{ secrets.DATABASE_ETL_URL }}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
3. In that repo: **Settings → Secrets and variables → Actions → New repository secret**, and add `PINECONE_API_KEY`, `DATABASE_URL`, and `DATABASE_ETL_URL`. `GUARDIAN_API_KEY` is strongly recommended — without it the Guardian source is skipped and only BBC Sport articles are ingested (register a free key at [open-platform.theguardian.com](https://open-platform.theguardian.com/access/)). `PINECONE_INDEX_NAME` is optional and defaults to `the-gaffer`.
|
|
277
|
+
4. Open the **Actions** tab, pick "Ingest sports data", and click **Run workflow** once to seed your data. From then on it runs by itself on the schedule.
|
|
278
|
+
|
|
279
|
+
Notes:
|
|
280
|
+
|
|
281
|
+
- **A failed run turns red** and GitHub emails you (missing credentials, a database that's unreachable, an API outage), so you'll know if data stops flowing.
|
|
282
|
+
- **Updates:** `pip install fpl-context-mcp` grabs the latest release on every run, so fixes arrive automatically. Pin a version (`fpl-context-mcp==0.3.0`) if you'd rather upgrade on purpose.
|
|
283
|
+
- **Cost:** each run takes about a minute or two, so a twice-daily schedule stays well inside GitHub's free monthly minutes for private repos.
|
|
284
|
+
- **Why private:** GitHub automatically pauses scheduled workflows in *public* repos after 60 days without a commit. Private repos aren't paused.
|
|
285
|
+
|
|
286
|
+
### Option C — any other scheduler
|
|
287
|
+
|
|
288
|
+
Managed cron (Render, Railway, Fly.io machines, GCP Cloud Scheduler + Cloud Run Jobs, AWS EventBridge + Lambda/Fargate, systemd timers, Airflow, Dagster, etc.) all work the same way — point it at `fpl-context-ingest-press` and `fpl-context-ingest-match` (or the `python -m jobs.*` equivalents) with the cadence table above and the environment variables from [Configuration](#configuration).
|
|
289
|
+
|
|
290
|
+
Whichever option you pick, re-run `fpl-context-mcp --check` afterward to confirm the scheduled job's credentials actually work in that environment — a job that silently fails every night is worse than no job, since nothing tells you the data's gone stale.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Registering with Claude Desktop
|
|
295
|
+
|
|
296
|
+
Add the server to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows).
|
|
297
|
+
|
|
298
|
+
### If installed from PyPI (recommended)
|
|
299
|
+
|
|
300
|
+
```json
|
|
301
|
+
{
|
|
302
|
+
"mcpServers": {
|
|
303
|
+
"fpl-context": {
|
|
304
|
+
"command": "fpl-context-mcp",
|
|
305
|
+
"env": {
|
|
306
|
+
"DATABASE_URL": "postgresql://gaffer_readonly:password@localhost:5432/gaffer",
|
|
307
|
+
"PINECONE_API_KEY": "pcsk_..."
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### If running from source
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"mcpServers": {
|
|
319
|
+
"fpl-context": {
|
|
320
|
+
"command": "python",
|
|
321
|
+
"args": ["/absolute/path/to/fpl-context-mcp/server.py"],
|
|
322
|
+
"env": {
|
|
323
|
+
"DATABASE_URL": "postgresql://gaffer_readonly:password@localhost:5432/gaffer",
|
|
324
|
+
"PINECONE_API_KEY": "pcsk_..."
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
> **Tip:** If you use `uv`, replace `"python"` with `"uv"` and prepend `"run"` to `args`:
|
|
332
|
+
> ```json
|
|
333
|
+
> "command": "uv",
|
|
334
|
+
> "args": ["run", "/absolute/path/to/fpl-context-mcp/server.py"]
|
|
335
|
+
> ```
|
|
336
|
+
|
|
337
|
+
Restart Claude Desktop. You should see `fpl-context` appear in the tools panel. If either tool returns nothing useful, re-check [Seeding data](#seeding-data-required-before-first-use) and [Keeping data fresh](#keeping-data-fresh-ongoing) before assuming the server itself is broken.
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Running the server standalone
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# If installed from PyPI
|
|
345
|
+
fpl-context-mcp
|
|
346
|
+
|
|
347
|
+
# If running from source
|
|
348
|
+
python server.py
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
The server communicates over stdio — it is designed to be launched by an MCP client, not run as a persistent HTTP service. Running it directly is mainly useful for smoke-testing startup and environment variable loading.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Verifying connectivity (--check)
|
|
356
|
+
|
|
357
|
+
Before registering the server with a client — and any time something seems off — verify that your environment variables are correct and all backends are reachable:
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# If installed from PyPI
|
|
361
|
+
fpl-context-mcp --check
|
|
362
|
+
|
|
363
|
+
# If running from source
|
|
364
|
+
python server.py --check
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Output example:
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
=== fpl-context-mcp configuration check ===
|
|
371
|
+
|
|
372
|
+
✅ Pinecone connected (index: 'the-gaffer')
|
|
373
|
+
✅ PostgreSQL (RO) connected (localhost:5432/gaffer)
|
|
374
|
+
✅ PostgreSQL (ETL) connected (localhost:5432/gaffer)
|
|
375
|
+
✅ Guardian API registered key configured
|
|
376
|
+
|
|
377
|
+
✅ All required components OK
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
The command exits with code `0` if all required components pass, or `1` if any required component fails. Optional components (Guardian API) emit warnings but do not cause a non-zero exit — a missing `GUARDIAN_API_KEY` just means Guardian articles are skipped. Note that `--check` only verifies *connectivity* — it doesn't tell you whether your tables/index actually have data in them; for that, see [Seeding data](#seeding-data-required-before-first-use).
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## Dry-run mode
|
|
385
|
+
|
|
386
|
+
Set `DRY_RUN=true` to fetch data and verify routing without writing anything to Pinecone or PostgreSQL:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
DRY_RUN=true fpl-context-mcp
|
|
390
|
+
DRY_RUN=true fpl-context-ingest-press
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
In dry-run mode:
|
|
394
|
+
|
|
395
|
+
- **Tools** return a human-readable description of the call that *would* have been made — the SQL with host, or the Pinecone index/namespace/params — without opening any connection.
|
|
396
|
+
- **Ingestion jobs** still call all external APIs (verifying connectivity) but skip every Pinecone and PostgreSQL write. Log output shows how many documents would have been upserted.
|
|
397
|
+
- The server logs a `DRY RUN MODE` warning at startup so it is obvious from the logs.
|
|
398
|
+
|
|
399
|
+
Accepted values for `DRY_RUN`: `true`, `1`, `yes` (case-insensitive). Any other value (or absent) disables dry-run.
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## MCP tools reference
|
|
404
|
+
|
|
405
|
+
### `query_historical_stats`
|
|
406
|
+
|
|
407
|
+
Executes a read-only SQL `SELECT` against the historical stats database.
|
|
408
|
+
|
|
409
|
+
**Parameters**
|
|
410
|
+
|
|
411
|
+
| Parameter | Type | Description |
|
|
412
|
+
|---|---|---|
|
|
413
|
+
| `sql` | string | A `SELECT` statement. Mutations are rejected before reaching the database. `LIMIT` is injected automatically if omitted (capped at 100 rows). |
|
|
414
|
+
|
|
415
|
+
**Example prompts**
|
|
416
|
+
|
|
417
|
+
- *"Who are the top 10 midfielders by total points this season?"*
|
|
418
|
+
- *"How many goals has Salah scored this season?"*
|
|
419
|
+
- *"Which teams have the best defensive record at home in 2024/25?"*
|
|
420
|
+
|
|
421
|
+
**Safety**
|
|
422
|
+
|
|
423
|
+
The tool enforces two layers of protection: a keyword blocklist rejects `INSERT`, `UPDATE`, `DELETE`, `DROP`, and similar statements before any database call is made, and the database connection uses a read-only role with no write grants.
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
### `query_press_conferences`
|
|
428
|
+
|
|
429
|
+
Semantic search over Premier League press coverage ingested from BBC Sport and The Guardian.
|
|
430
|
+
|
|
431
|
+
**Parameters**
|
|
432
|
+
|
|
433
|
+
| Parameter | Type | Default | Description |
|
|
434
|
+
|---|---|---|---|
|
|
435
|
+
| `query` | string | — | Natural-language question or topic |
|
|
436
|
+
| `top_k` | integer | 5 | Number of documents to return |
|
|
437
|
+
| `recency_weight` | float | 0.3 | Recency boost: `0.0` = pure semantic similarity, `1.0` = heavy recency bias |
|
|
438
|
+
|
|
439
|
+
**Ranking formula**
|
|
440
|
+
|
|
441
|
+
Results are re-ranked after retrieval:
|
|
442
|
+
|
|
443
|
+
```
|
|
444
|
+
final_score = semantic_score × (1 + recency_weight × recency_score)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
`recency_score` is 1.0 for an article published today and decays toward 0.1 over 14 days.
|
|
448
|
+
|
|
449
|
+
**Example prompts**
|
|
450
|
+
|
|
451
|
+
- *"Any injury concerns for Saka this week?"*
|
|
452
|
+
- *"What did Slot say about Salah's contract situation?"*
|
|
453
|
+
- *"Who is doubtful for Arsenal's next match?"*
|
|
454
|
+
|
|
455
|
+
**No results?** If the `press` namespace hasn't been seeded yet, or everything in it has aged out past 14 days, this tool returns a message explaining that instead of an empty response — see [Keeping data fresh](#keeping-data-fresh-ongoing).
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## Database schema
|
|
460
|
+
|
|
461
|
+
The `query_historical_stats` tool has access to these tables (see [`db/schema.sql`](db/schema.sql) for the full DDL if provisioning standalone):
|
|
462
|
+
|
|
463
|
+
```
|
|
464
|
+
seasons id, label (e.g. '2025/26'), start_year, is_current
|
|
465
|
+
|
|
466
|
+
teams season_id, fpl_id, name, short_name, strength,
|
|
467
|
+
strength_attack_home/away, strength_defence_home/away
|
|
468
|
+
|
|
469
|
+
gameweeks season_id, gw_number (1–38), deadline_time, is_current,
|
|
470
|
+
is_next, is_finished, average_entry_score, highest_score
|
|
471
|
+
|
|
472
|
+
players season_id, fpl_id, team_fpl_id, first_name, second_name,
|
|
473
|
+
web_name, position (GKP/DEF/MID/FWD), now_cost, form,
|
|
474
|
+
total_points, minutes, goals_scored, assists, clean_sheets,
|
|
475
|
+
expected_goals, expected_assists, ict_index, status, news
|
|
476
|
+
|
|
477
|
+
fixtures season_id, fpl_id, gw_number, kickoff_time,
|
|
478
|
+
home_team_fpl_id, away_team_fpl_id, home_score, away_score,
|
|
479
|
+
finished, home_team_difficulty, away_team_difficulty
|
|
480
|
+
|
|
481
|
+
gw_player_stats season_id, player_fpl_id, gw_number, fixture_fpl_id,
|
|
482
|
+
opponent_team_fpl_id, was_home, minutes, goals_scored,
|
|
483
|
+
assists, clean_sheets, bonus, total_points,
|
|
484
|
+
expected_goals, expected_assists, ict_index, starts
|
|
485
|
+
|
|
486
|
+
player_xpts materialized view: player_fpl_id, web_name, team_name,
|
|
487
|
+
position, now_cost, expected_points (next GW projection)
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Join hint:** `teams.fpl_id = players.team_fpl_id` (within the same `season_id`).
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
## Running tests
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
# Install dev dependencies if you haven't already
|
|
498
|
+
pip install -e ".[dev]"
|
|
499
|
+
|
|
500
|
+
# Run the full suite (all mocked — no real DB or API calls)
|
|
501
|
+
pytest tests/ -v
|
|
502
|
+
|
|
503
|
+
# Lint and format
|
|
504
|
+
ruff check . && ruff format .
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
The test suite covers:
|
|
508
|
+
|
|
509
|
+
| File | What's tested |
|
|
510
|
+
|---|---|
|
|
511
|
+
| `tests/test_config.py` | Env var reading, defaults, dotenv loading, dry-run flag |
|
|
512
|
+
| `tests/test_tools_stats.py` | Mutation guard, row formatter, async DB path, dry-run |
|
|
513
|
+
| `tests/test_tools_press.py` | Pinecone query, recency re-ranking, degradation, dry-run |
|
|
514
|
+
| `tests/test_ingest_press_content.py` | BBC/Guardian fetchers, deduplication, orchestration, dry-run |
|
|
515
|
+
| `tests/test_ingest_match_data.py` | Delta filtering, thread coordination, rollback, dry-run |
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
## Extending with new press sources
|
|
520
|
+
|
|
521
|
+
To add a new press source, subclass `_BaseFetcher` in `jobs/ingest_press_content.py` and add an instance to the `FETCHERS` list. The orchestrator picks it up automatically — no other changes needed.
|
|
522
|
+
|
|
523
|
+
```python
|
|
524
|
+
class MySportsFetcher(_BaseFetcher):
|
|
525
|
+
source_name = "My Sports Site"
|
|
526
|
+
|
|
527
|
+
def fetch(self) -> list[tuple[str, str, dict]]:
|
|
528
|
+
# return a list of (doc_id, text, metadata) tuples
|
|
529
|
+
...
|
|
530
|
+
|
|
531
|
+
FETCHERS: list[_BaseFetcher] = [BBCSportFetcher(), GuardianAPIFetcher(), MySportsFetcher()]
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
Each tuple is `(doc_id, text, metadata)` where:
|
|
535
|
+
|
|
536
|
+
- `doc_id` — a stable 32-char hex ID (use `_doc_id(source + url)`)
|
|
537
|
+
- `text` — the full text to embed, prefixed with the source name
|
|
538
|
+
- `metadata` — must include `type`, `source`, `recency_score`, and `pub_timestamp`
|