A remote MCP server that gives Claude (and other MCP clients) direct read-only access to the LMFDB PostgreSQL mirror.
Once deployed and connected, users can make natural-language requests like:
"Create a scatter plot of number of rational points vs analytic rank for genus 2 curves in the LMFDB with Sato-Tate group USp(4)."
…and Claude will query the database, analyze results, and produce plots — all within the chat interface, no code to run.
The code in this repository was written entirely by Claude Opus 4.6.
┌──────────────┐ HTTPS ┌──────────────────┐ PostgreSQL ┌──────────────────┐
│ Claude.ai │ ──────────────►│ lmfdb-mcp │ ──────────────►│ devmirror │
│ (any user) │ MCP protocol │ (Cloud Run) │ read-only │ .lmfdb.xyz:5432 │
└──────────────┘ └──────────────────┘ └──────────────────┘
| Tool | Description |
|---|---|
overview |
Overview of LMFDB sections and tables |
list_tables |
Curated list of tables, optionally filtered by prefix |
describe_table |
Show column names and types for a table |
search_knowls |
Search table/column knowls using keywords |
sample_rows |
Return a small sample from a table |
run_sql |
Run an arbitrary SELECT query (max 100,000 rows) |
count_rows |
Count rows with optional WHERE clause |
table_stats |
Compute min/max/avg/stddev for a numeric column |
export_query |
Bulk download (CSV or JSONL) via short-lived URL |
All Claude models (Haiku/Sonnet/Opus) can use tools via MCP servers.
- In the claude.ai sidebar, click Customize → Connectors
- Click Add custom connector
- Enter:
- Name:
LMFDB - URL:
https://mcp.lmfdb.org/mcp
- Name:
- Click Add
- Set Read-only tools to Always allow (optional, lets Claude use the tool without asking permission).
- In any conversation, click + → Connectors → enable LMFDB
An organization Owner adds the connector once in Organization Settings → Connectors, and all members can then enable it per-conversation.
The export_query tool returns a URL on https://mcp.lmfdb.org/ instead
of streaming rows through the MCP conversation. For Claude to actually
fetch that URL inside its code-execution sandbox — where pandas, numpy,
and plotting happen — the domain needs to be on the sandbox's
network-egress allowlist. The other eight tools return data directly
through the MCP conversation and are unaffected; this setup is only
needed if you (or your users) want to use export_query.
- Go to claude.ai → Settings → Capabilities.
- Under Code execution and file creation, make sure the feature is enabled and turn on Allow network egress.
- Set the domain allowlist to Package managers and specific domains
and add
mcp.lmfdb.orgto Additional allowed domains.
Allowlist changes are copied into the sandbox when a conversation starts. Toggling settings mid-conversation has no effect on the current chat — start a fresh conversation after updating.
In ChatGPT MCP connectors are treated as "apps". Custom apps (including the LMFDB MCP server) are not available on the Free/Go plan, as you need to enable Developer mode in order to install them.
Apps cannot be used in Pro models (but they can be used in all other models available under the Pro plan).
- Go to chatgpt.com → Settings → Apps → Advanced settings
- Enable Developer mode.
- Go to Settings → Apps and click Create app.
- Enter the app details:
- Name:
LMFDB - MCP server URL:
https://mcp.lmfdb.org/mcp - Authentication:
NoAuth - I understand and want to continue: tick the box (OpenAI has not reviewed this MCP server).
- Name:
- Click Create.
- In any chat, use + → More to add the LMFDB app.
An administrator needs to enable developer mode and create a new app for the LMFDB connector, all members can then enable it per-conversation.
The instructions below assume you are an administrator of the lmfdb-mirror project on Google Cloud.
# 1. Set your project
gcloud config set project YOUR_PROJECT_ID
# 2. Build and push the container
gcloud builds submit --tag us-central1-docker.pkg.dev/lmfdbmirror/lmfdb-mcp/lmfdb-mcp
# 3. Deploy to Cloud Run
gcloud run deploy lmfdb-mcp \
--image us-central1-docker.pkg.dev/lmfdbmirror/lmfdb-mcp/lmfdb-mcp \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--port 8080 \
--memory 512Mi \
--timeout 300 \
--min-instances=1# Install dependencies
pip install -r requirements.txt
# Run locally
python server.py
# Test with MCP Inspector
npx @modelcontextprotocol/inspector http://localhost:8000/mcp| Variable | Default | Description |
|---|---|---|
LMFDB_HOST |
devmirror.lmfdb.xyz |
PostgreSQL host |
LMFDB_PORT |
5432 |
PostgreSQL port |
LMFDB_DBNAME |
lmfdb |
Database name |
LMFDB_USER |
lmfdb |
Database user |
LMFDB_PASSWORD |
lmfdb |
Database password |
LMFDB_MAX_ROWS |
100000 |
Hard limit on returned rows |
LMFDB_DEFAULT_LIMIT |
100 |
Default LIMIT if not specified |
PORT |
8000 |
HTTP port (Cloud Run sets this) |
- The server only allows
SELECT,WITH, andEXPLAINqueries. - A 120-second statement timeout prevents runaway queries.
- Row results are capped at 100,000.
- The underlying LMFDB mirror is read-only; writes will fail at the database level regardless of what SQL is sent.
- The default config is auth-less, which is appropriate since the LMFDB mirror credentials are public.
GPL-3.0 (matching lmfdb-lite)