Lean Mathlib Docs MCP (Criticalline)

MCP搜索检索

提供方 未标注

搜索检索 HTTP · 远程 未标注 社区 / 第三方

全面解析Lean Mathlib Docs MCPMCP Server的核心功能、安装配置和实用案例。作为顶级Model Context Protocol服务器,Lean Mathlib Docs MCP能让AI助手访问实时数据、执行操作,为您提供更智能的工作体验和自动化解决方案。

一句话选型结论

按资料字段整理

Lean Mathlib Docs MCP (Criticalline) 属于搜索检索类 MCP 服务器,HTTP · 远程,鉴权方式未标注,没有现成安装命令,需按官方文档接入。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类搜索检索 传输方式HTTP · 远程 鉴权未标注 部署方式远程部署
GitHub 星标 未标注 仓库热度,无公开仓库时显示未标注
工具数 未标注 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

搜索检索
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量未标注暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

安装与配置

HTTP · 远程 未标注
连远程 HTTPS 端点,通常为 Streamable HTTP
  1. 1
    准备运行环境

    确认你的客户端支持远程端点,并拿到服务地址。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后随便调一个只读工具,确认能返回结果,再接入正式流程。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
联网搜索取证

让模型查最新资料并给出出处。

资料聚合

把一个主题的网页、文档集中抓回来整理。

情报与竞品检索

按关键词持续检索行业动态和竞品信息。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 基础信息齐全,可以先按官方文档接入试跑。

先想清楚的地方

  • 远程端点依赖网络与服务方可用性,注意密钥与调用额度。
  • 没有现成安装命令,需要按官方文档自己填启动命令和参数。
  • 资料没标注工具数量,实际能力要装好后确认。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在搜索检索场景里让模型直接调用外部能力的人。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
Lean Mathlib Docs MCP (Criticalline)当前 未标注 HTTP · 远程 远程部署 无 2026-05-17
Brave Search 433812ff 2 未标注 未标注 无 2026-05-17
Sequentialthinking 1 SSE · 服务端推送 远程部署 有 2026-05-18
Baidu Netdisk 未标注 未标注 未标注 无 2026-05-17
ragflow 未标注 stdio · 本地进程 本地部署 有 2026-04-11
mindsdb (430e18) 未标注 未标注 未标注 有 2026-05-17

服务器档案

搜索检索
字段来自项目仓库与公开索引,中文说明由本站标注
提供方未标注上游标注的维护方 未标注
分类搜索检索本站按上游分类展示
连接方式HTTP · 远程连远程 HTTPS 端点,通常为 Streamable HTTP
鉴权方式未标注远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时未标注 · 未标注本地安装时用到的包标识与运行时
部署类型远程部署上游给出的部署形态
最近核验2026-05-17上游最后核验时间

详细介绍

14.9 KB
来自项目仓库与上游目录的原文,未做删改

lean-mathlib-mcp

A machine-first MCP server for structured, low-ambiguity search over the
Lean Mathlib 4 knowledge base (definitions, theorems, lemmas, notations,
modules, instances, typeclasses, axioms).

It is a ground-up rewrite of the reference implementation
CriticalLine/lean-mathlib-docs-mcp,
re-targeted from "string search for humans" to "structured semantic retrieval
for LLM agents".

Design principles

  • Machine-first. Every tool returns a single JSON string with a stable
    schema — directly parseable, no prose dumps.
  • Precision over fuzzy semantics. Exact qualified name > short name +
    namespace > signature/conclusion structure > domain + intent.
  • Complete metadata. A unified entity model covers definitions / theorems /
    lemmas / notations / modules / instances / typeclasses / axioms, with source,
    dependencies, status, and a stable id.
  • Controllable granularity. Per-call terse · summary · complete · expanded,
    plus max_results, cursor pagination, and a soft token_budget.
  • Read-only, structured errors. No write/exec path. Failures return an error
    code + corrective suggestions + negative-result feedback.

Architecture```txt

docgen master index declaration-data.bmp ──► MasterIndexSource.load()
│ (neutral SourceBundle)
▼
MathlibIndex (compact secondary index + lazy entity materialization)
│
┌───────────────┬───────────────┬───────┴────┬──────────────────┐
▼ ▼ ▼ ▼ ▼
search/identity search/semantic search/context search/scoring sources/
(exact identity) (semantic feats) (graph context) (relevance rank) docgen_detail
│ │ │ (optional enrichment)
└───────────────┴───────────────┴──────────────────────────────┘
▼
output.assemble() → SearchResult (JSON)
▼
MCPServer (stdio) → 15 @server.tool


- **`sources/`** — `SourceBundle` is a neutral data contract. `MasterIndexSource`
  parses the official master index; `DocgenDetailProvider` optionally supplies
  type signatures / docs / true dependency graphs (graceful degradation if absent).
- **`index.py`** — the production master index has 425k+ declarations. To avoid
  hundreds of MB of startup cost, a compact `DeclMeta` is kept per declaration for
  filtering, and the rich entity object is materialized lazily, only for returned results.
- **`search/`** — `identity` (exact identity) / `semantic` (semantic features) /
  `context` (graph context) + `scoring` (weighted ranking).
- **`output.py`** — granularity projection + cursor pagination + token-budget
  truncation + reuse params + negative feedback.
- **`server.py`** — `MCPServer("lean-mathlib-mcp")` registers 15 tools via
  `@server.tool`; `_dispatch` routes all calls (sync request/response; the batch
  tool shares the same path).

### Data sources & enrichment

The master index `declaration-data.bmp` (official docgen export) contains the
`declarations / modules / instances / instancesFor` sections, but **not** type
signatures, docs, or true dependency graphs. Those *rich features* come from an
optional docgen4 JSON export:

- Without `docgen_detail_path`, `search_by_signature` / `search_by_conclusion` /
  `search_hypothesis` / `search_proof_complexity` and the "true dependencies" of
  `expand_dependencies` return an `enrichment_unavailable` error code with a fix
  suggestion instead of garbage.
- `search_by_domain_use` / `search_declaration` / `search_by_notation` /
  `module_snapshot` and the topology fallback (module import graph) are always available.

## Installation

Requires **Python 3.11+** (`mcp>=2`, `pydantic>=2`, `pydantic-settings`).```bash
# from a clone of this repo
python -m pip install -e .          # installs the `lean-mathlib-mcp` console script
python -m pip install -r requirements.txt   # or pin manually

An offline sample index (data/sample_index.json, ~3.4k declarations / 115
modules) ships with the repo so the tests and a quick smoke run work without
downloading anything.

Running (stdio)```bash

via the installed console script

lean-mathlib-mcp

or, without installing, via the module

LEAN_MATHLIB_DATA_SOURCE=sample python -m lean_mathlib_mcp

or via the bundled launcher (adds src/ to sys.path automatically)

LEAN_MATHLIB_DATA_SOURCE=sample python run_server.py


- `LEAN_MATHLIB_DATA_SOURCE=auto` (default): use the local sample/cache if present,
  otherwise download the production index.
- `LEAN_MATHLIB_DATA_SOURCE=remote`: force-download the full production index (network required).
- `LEAN_MATHLIB_DATA_SOURCE=sample`: force the committed offline fixture (deterministic).

### Connecting from an MCP client (e.g. WorkBuddy)

Copy `mcp.example.json` to `mcp.json`, set `command` to your Python interpreter,
and trust the server in your connector manager. Example:```json
{
  "servers": {
    "lean_mathlib_mcp": {
      "command": "python",
      "args": ["run_server.py"],
      "env": { "LEAN_MATHLIB_DATA_SOURCE": "auto" }
    }
  }
}

If the package is published to PyPI, uvx lean-mathlib-mcp works as the command.

Configuration

All knobs are environment-overridable (prefix LEAN_MATHLIB_), so the server
deploys read-only with zero code changes.

Variable Default Description
LEAN_MATHLIB_DATA_SOURCE auto auto / sample / remote
LEAN_MATHLIB_DATA_URL docgen official URL Production master index URL
LEAN_MATHLIB_CACHE_DIR data/cache Index cache directory
LEAN_MATHLIB_RAW_DIR data/raw Where declaration-data.bmp is stored
LEAN_MATHLIB_SAMPLE data/sample_index.json Offline sample path
LEAN_MATHLIB_BUILT_INDEX_PATH data/cache/index.json Built index cache
LEAN_MATHLIB_DEFAULT_GRANULARITY summary Default output granularity
LEAN_MATHLIB_DEFAULT_MAX_RESULTS 20 Max hits per call
LEAN_MATHLIB_DEFAULT_TOKEN_BUDGET 6000 Soft token cap (results truncated to fit)
LEAN_MATHLIB_MAX_DEPENDENCY_DEPTH 3 Dependency expansion cap
LEAN_MATHLIB_MATHLIB_ONLY false true excludes Init.* core-library basics
LEAN_MATHLIB_DOCGEN_DETAIL_PATH (empty) Optional docgen4 JSON export for rich features

Tools (15, all read-only)

> Tools marked ⚡ enrichment return enrichment_unavailable when
> LEAN_MATHLIB_DOCGEN_DETAIL_PATH is unset.
> Shared output controls (most tools): granularity ∈ {terse,summary,complete,expanded},
> max_results, min_score, token_budget, scope_modules, exclude_modules,
> mathlib_only, exclude_deprecated, only_stable, cursor.

3.1 Exact-identity search

Tool Key params Description
search_declaration query, entity_types?, domain?, use_tags? Exact qualified-name resolution, else ranked by name precision + domain closeness + usage. Empty result carries negative_feedback.
get_entity full_name, granularity=complete One entity by exact name or stable id decl:*. On name collision returns ambiguous_match with disambiguation candidates.
search_by_notation symbol, latex? Resolve a notation by Unicode or LaTeX (e.g. ≤ / \le / \sum): precedence, associativity, bound entity, conflicting forms.

3.2 Semantic-feature search

Tool Key params Description
search_by_signature ⚡ arity?, return_type?, param_types? (_/* wildcards) Type-signature structural match, ranked exact-unify > unifiable > structural.
search_by_conclusion ⚡ pattern, symmetric?, monotonic? Match by conclusion structure (variable names ignored, operator tokens matched), e.g. x + y = y + x.
search_by_domain_use domain?, subdomain?, use_tags?, entity_types? Domain + subdomain + intent tags + entity type; core/high-frequency first. Always available.
search_hypothesis ⚡ required_typeclasses?, required_axioms?, constructive_only?, exclude_classical?, no_axiom? Filter theorems by premise (hypothesis) outline.
search_proof_complexity ⚡ max_dep_depth?, technique?, has_short_version?, exclude_axiom? Filter by proof structure / dependency depth; recommends proof-entry lemmas.

3.3 Association & context search

Tool Key params Description
expand_dependencies full_name, depth=2, exclude_stdlib?, only_mathlib=true, as_tree=true Recursive dependency expansion (tree/flat); enriched deps preferred, else module import-graph fallback.
find_usages full_name, direct_only?, transitive=true Impact analysis: direct/indirect dependents + modules importing its module.
recommend_related full_name, limit=15 "What to read next": same-module core pairings, equivalents/duals, generalizations/specializations, other instances of its typeclass.
module_snapshot module Layered module overview: domain, priority tier, imports, imported-by count, intro/core/advanced exports, key instances. Suggests similar modules when not found.

3.4 Service & batch

Tool Key params Description
search_modules query, scope_modules?, max_results=50 Find modules/namespaces by substring.
index_info — Index health: declaration/module counts, enrichment status, data source.
batch_query queries: [{tool, args}, ...] Run multiple queries in one round-trip; per-item errors isolated.

Output schema

SearchResult```jsonc

{
"query": { / echoed query params / },
"total_matches": 326,
"returned": 5,
"next_cursor": "5", // pagination cursor; null when exhausted
"truncated_low_relevance": false,
"hits": [ / SearchHit[] / ],
"reuse_params": { "full_name": "...", "id": "decl:..." },
"negative_feedback": { // present only when hits is empty
"reason": "no matching entity for the given query",
"relax_suggestions": [ "..." ]
}
}


### SearchHit```jsonc
{
  "entity": { /* MathlibEntity projection (per granularity) */ },
  "score": 0.95,                 // 0..1 relevance
  "tier": "exact",               // exact | structural | semantic | domain | usage
  "match_dimensions": [ { "dimension": "exact_name", "score": 1.0, "tier": "exact" } ],
  "truncated": false,
  "reuse_params": { "full_name": "...", "id": "decl:..." }
}

MathlibEntity (field names are stable across Mathlib versions)

id · entity_type · raw_kind · full_name · short_name · namespace ·
module · type_signature · statement · doc · domain · subdomain ·
use_tags · doc_link · relations (dependencies/dependents/equivalents/
generalizes/specializes/related) · status (deprecated/maintenance/
cache_key) · is_core · usage_frequency · enrichment_source.

granularity projection:

  • terse: id / full_name / entity_type / module / domain
  • summary: + short_name / doc_link / use_tags / is_core / usage_frequency
  • complete: + type_signature / statement / subdomain / relations (light)
  • expanded: + doc / full relations / status

Structured error```jsonc

{
"code": "enrichment_unavailable", // see table below
"message": "this search needs the docgen detail export",
"fixable": true,
"suggested_params": { "docgen_detail_path": "<path to docgen JSON>" },
"disambiguation": [ / on ambiguous_match / ],
"negative_feedback": { / on no_match / }
}


| Error code | Trigger | Caller action |
| ------------ | --------- | --------------- |
| `unknown_tool` | Unknown tool name (`fixable:false`) | Check tool name |
| `invalid_argument` | Missing required arg | Add `full_name` / `query` |
| `ambiguous_match` | Name collision | Disambiguate via `namespace`/module (see `disambiguation`) |
| `no_match` | No notation/query match | See `negative_feedback.relax_suggestions` |
| `not_found` | Entity/module missing | Use `search_declaration` |
| `index_unavailable` | Index build failed | Switch `data_source=sample` |
| `enrichment_unavailable` | Rich feature missing | Provide `docgen_detail_path` |
| `out_of_scope` | Out of range/filtered | Adjust `scope_modules` |
| `internal` | Server exception (`fixable:false`) | Report |

### Relevance ranking

`score = 0.45·name + 0.20·structure + 0.15·domain + 0.10·usage + 0.10·stability`;
tier order `exact &gt; structural &gt; semantic &gt; domain &gt; usage`. Collisions and
ambiguity are surfaced explicitly via `ambiguous_match` rather than guessed.

## Extending

- **New data source:** implement the `DataSource` / `DetailProvider` protocols in
  `sources/__init__.py`, produce a `SourceBundle`, and wire it into
  `server.build_index()`.
- **New detail provider:** subclass `DocgenDetailProvider` and feed an external
  export (signatures / proof terms) into `bundle.enriched[name]`.
- **New tool:** add an `@server.tool` function in `server.py` (prefix the function
  name with `tool_` to avoid clashing with same-named `search.*` helpers), add a
  branch in `_dispatch`, and reuse `assemble` / `make_error`.

## Testing```bash
# unit tests (20): index, search, server wiring
python -m pytest tests/ -q

# real MCP stdio end-to-end (spawns the server subprocess over the protocol)
python tests/e2e_stdio.py

Build / rebuild fixtures and cache:bash python -m lean_mathlib_mcp.builder sample # slice multi-domain sample from the real master index python -m lean_mathlib_mcp.builder build # build the index cache python -m lean_mathlib_mcp.builder info # index statistics

Known limitations

  • Rich features (signatures / conclusions / true dependencies / proof structure)
    depend on the optional docgen4 export; without it the relevant tools return
    enrichment_unavailable and degrade gracefully.
  • In the master index, declaration names have no Mathlib. prefix (e.g. Add,
    Nat.add); mathlib_only is decided by whether the owning module is under
    Mathlib.* (default false, i.e. core library is not filtered out).
  • The production index has 425k+ declarations; the first build downloads and parses
    declaration-data.bmp (~67 MB), then reuses data/cache afterward.

Credits

Refactored from
CriticalLine/lean-mathlib-docs-mcp.
Data is sourced from the Lean community's
Mathlib 4 docgen.

License

MIT — see LICENSE.

常见问题

7 问
答案由本站依据条目字段整理,不引用上游原文
Lean Mathlib Docs MCP (Criticalline) 怎么安装?

资料没有给出安装命令,请到官方仓库或文档按说明接入;这类条目多数是生态应用,或尚未发布可安装包。

Lean Mathlib Docs MCP (Criticalline) 怎么在客户端里配置?

它的传输方式未标注,在客户端 MCP 配置里按官方文档填写启动命令和参数,保存后重启客户端生效。

Lean Mathlib Docs MCP (Criticalline) 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

Lean Mathlib Docs MCP (Criticalline) 需要 API Key 吗?

资料没有标注鉴权方式,是否需要密钥取决于服务本身,接入前按官方文档确认。

Lean Mathlib Docs MCP (Criticalline) 能提供哪些能力?

资料显示能力标签包括 本地处理、文档处理、HTTP。具体工具清单以官方文档为准。

Lean Mathlib Docs MCP (Criticalline) 需要什么运行环境?

属于远程端点,不需要在本地装运行时。

Lean Mathlib Docs MCP (Criticalline) 是本地还是远程?

它是远程端点,连服务地址即可。传输方式为HTTP · 远程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-05-17。