Metadata-Version: 2.4
Name: concept-bridge-mcp
Version: 0.1.0a1
Summary: A local-first MCP server bridging personal knowledge bases and seminal research.
Author: ConceptBridge contributors
License-Expression: MIT
Keywords: mcp,research,zotero,obsidian,knowledge-management
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx<1,>=0.27
Requires-Dist: mcp[cli]<2,>=1.0
Requires-Dist: python-dotenv<2,>=1.0
Provides-Extra: test
Requires-Dist: pytest<9,>=8; extra == "test"
Dynamic: license-file

# ConceptBridge MCP

**Connect known concepts to unfamiliar research, then build an editable lineage note.** ConceptBridge is a local-first, pure-Python MCP server for Cursor, Antigravity, Claude Desktop, and other stdio MCP clients. It retrieves papers from the free OpenAlex API and optionally scans local Markdown knowledge bases. It can run without Obsidian, a Wiki, or Zotero; a compatible MCP client and internet access for OpenAlex are the only optional-system-independent requirements for the full online research workflow. Local notes, Obsidian wikilinks, and Zotero exports add context but are not required. ConceptBridge does not read Zotero databases or PDFs directly.

README 使用说明：ConceptBridge 可独立于 Obsidian、Wiki 和 Zotero 使用（需要支持 MCP 的 Agent 工作台；联网文献检索需要互联网）。本地 Wiki 和双向链接是可选增强；Zotero 目前没有直接集成，不读取其数据库或 PDF，可先将文献条目导出为 Markdown 后纳入 Wiki。

## Highlights | 核心亮点

- **Known-to-unknown concept bridging | 已知到未知的概念桥接：** optionally match known concepts against local Markdown notes and `[[wikilinks]]`, then retrieve citation-ranked OpenAlex works.
- **Math Diff | 数学公式对比：** organize historical motivation and LaTeX-level equation comparisons in a dedicated section.
- **Iterative learning | 多轮状态迭代：** the `research_lineage_workflow` MCP prompt instructs clients to ask diagnostic questions and reread the latest file before follow-up edits.
- **One file, two-way editing | 单文件双向编辑：** YAML frontmatter, Obsidian links, Mermaid mind map, comparison table and math discussion live together. Section markers let updates preserve text outside the selected managed region.
- **Optional local setup | 本地知识库可选：** no `WIKI_ROOT_DIR` is required; missing or invalid Wiki paths simply disable local search. No Obsidian or Zotero install is required.
- **Resilient literature lookup | 文献检索容错：** OpenAlex failures trigger an arXiv search fallback. If both sources are unavailable, the one-call workflow still saves local context and records the retrieval failure instead of dropping the note.

## How the integrations fit together | 各组件的关系

- **Agent workbench / MCP client** (Cursor, Antigravity, Claude Desktop, etc.) is the user-facing host. It sends requests to this MCP server and presents the tools/prompts to the model. ConceptBridge is not itself an agent or a chat UI.
- **ConceptBridge** performs local Markdown search, OpenAlex requests, and note creation/update. It can be used on its own with the MCP client and OpenAlex; local knowledge integration is optional.
- **Wiki / LLM Wiki** is an optional folder of Markdown notes used as existing knowledge context. ConceptBridge searches files and links; it does not require a particular Wiki product or indexer.
- **Obsidian** is an optional editor for that Markdown folder. `[[wikilinks]]` and YAML frontmatter make saved notes convenient to browse in Obsidian, but ordinary Markdown editors also work.
- **Zotero** remains separate. There is currently no direct Zotero API/database/PDF integration. Export or sync Zotero item notes to Markdown in the Wiki if you want them included in local matching.

In short: **Agent workbench → MCP protocol → ConceptBridge** is the required relationship. **Wiki/Obsidian/Zotero are optional sources and destinations**, not runtime dependencies. Without a Wiki, notes are saved to the default user data folder; OpenAlex still requires network access.

## Quick start | 快速开始

Requires Python 3.10+. By default, `OUTPUT_DIR` uses a persistent user data directory (Windows: `%LOCALAPPDATA%\ConceptBridge\workspace`; macOS: `~/Library/Application Support/ConceptBridge/workspace`; Linux: `$XDG_DATA_HOME/conceptbridge/workspace` or `~/.local/share/conceptbridge/workspace`). This avoids writing into the `uvx` package cache. Set `OUTPUT_DIR` to choose another location. Set `WIKI_ROOT_DIR` only if you want local-note matching; the legacy `LOCAL_WIKI_DIR` is also accepted. Configuration is loaded from the project-root `.env` even when an MCP client launches the server from a different working directory. Missing paths are reported in the research context together with the Markdown file count and attempted keyword variants. For local development, copy `.env.example` to `.env` and set optional variables there.

### Run with `uvx` | 使用 uvx

After the package is published to PyPI, launch it without cloning the repository:

```powershell
uvx --from concept-bridge-mcp concept-bridge-mcp
```

MCP clients start the same entry point using `uvx` as the command. Configure environment variables in the client as shown below.

### Run from a local clone | 本地运行

```powershell
uv sync --extra test
uv run concept-bridge-mcp
```

Or install with pip and run `python -m pip install -e .` followed by `concept-bridge-mcp`.

### MCP client JSON | 客户端配置

Use the matching stdio configuration in Cursor, Antigravity, or Claude Desktop. `WIKI_ROOT_DIR` and `OUTPUT_DIR` are optional; remove either setting to use its default behavior. Replace placeholders with local paths and use JSON-escaped backslashes on Windows.

Published package (`uvx`; available after the first PyPI release):

```json
{
  "mcpServers": {
    "concept-bridge": {
      "command": "uvx",
      "args": ["--from", "concept-bridge-mcp", "concept-bridge-mcp"],
      "env": {
        "WIKI_ROOT_DIR": "<optional-path-to-Obsidian-or-LLM-Wiki>",
        "OUTPUT_DIR": "<optional-path-for-generated-notes>"
      }
    }
  }
}
```

Local clone with `uv` (no PyPI release required):

```json
{
  "mcpServers": {
    "concept-bridge": {
      "command": "uv",
      "args": ["run", "--directory", "<path-to-cloned-project>", "concept-bridge-mcp"],
      "env": {
        "WIKI_ROOT_DIR": "<optional-path-to-Obsidian-or-LLM-Wiki>",
        "OUTPUT_DIR": "<optional-path-for-generated-notes>"
      }
    }
  }
}
```

Local Python alternative, after installing the project dependencies with `python -m pip install .`:

```json
{
  "mcpServers": {
    "concept-bridge": {
      "command": "<path-to-python-executable>",
      "args": ["<path-to-cloned-project>/mcp_server.py"],
      "env": {
        "WIKI_ROOT_DIR": "<optional-path-to-Obsidian-or-LLM-Wiki>",
        "OUTPUT_DIR": "<optional-path-for-generated-notes>"
      }
    }
  }
}
```

For all examples, omit the `env` object or individual variables when not needed. An unset `OUTPUT_DIR` writes to the persistent user data location described above. For VS Code's MCP support, the equivalent entry belongs under `servers` with `type: "stdio"`.

### Available tools and prompt | 工具与工作流提示

- `research_and_save_lineage_doc(unknown_concept, known_concepts, filename)` — one call retrieves local notes and literature (OpenAlex, falling back to arXiv), then persists an evidence-based note and returns its path; it also saves local context when both APIs fail.
- `gather_research_context(unknown_concept, known_concepts)` — local notes if available, plus OpenAlex/arXiv results and an explicit next-action request to save a lineage document before replying.
- `create_lineage_doc(filename, mindmap_mermaid, comparison_table_md, math_diff_md, known_anchors?, seminal_papers?)` — create a standalone named Markdown note.
- `patch_lineage_section(filename, section, new_content)` — patch only `MINDMAP`, `TABLE`, or `MATH_DIFF`.
- `read_current_doc(filename)` — read the latest disk version before follow-up edits.
- `research_lineage_workflow(unknown_concept, known_concepts)` — a reusable MCP prompt that guides the evidence-first, multi-turn workflow.

Document frontmatter includes `title`, `created`, `tags`, `known_anchors`, and `seminal_papers`. Concept anchors are rendered as Obsidian `[[wikilinks]]`. Each section has outer `SECTION` markers and inner `MANAGED` markers containing a SHA-256 checksum. Put human annotations inside the section but outside `MANAGED`; patches preserve those annotations. If generated content inside a managed block was edited, the update refuses to overwrite it and asks for conflict resolution. The first patch of a legacy section without managed markers preserves all old content and appends a new generated block.

## Zotero + Obsidian + LLM Wiki | 生态联动

ConceptBridge can act as an incremental knowledge-hub compiler in an existing local research workflow, but does not depend on that ecosystem. Zotero remains your reference manager; export or sync bibliographic records and notes into Markdown files under the Wiki root if you want those records included in local matching. ConceptBridge does not ingest Zotero's database, attachments, or PDFs itself.

```mermaid
flowchart LR
    Z[Zotero library] -->|Export or sync notes| W[Obsidian / LLM Wiki<br/>Markdown + wikilinks]
    W -->|Optional local concept cards| C[ConceptBridge MCP]
    O[OpenAlex<br/>citation-ranked records] --> C
    C -->|Named lineage note<br/>Frontmatter + Mermaid + table + Math Diff| W
    W <-->|Read latest / patch one section| L[LLM client<br/>Cursor / Antigravity / Claude]
    L -->|Research workflow prompt| C
```

## Development and tests | 开发与测试

```powershell
uv sync --extra test
uv run pytest -q
```

The unit suite verifies graceful no-Wiki startup, local note matching when configured, preservation of manual annotations during repeated section-level edits, and note persistence when OpenAlex/arXiv are unavailable. The live OpenAlex integration test is network-dependent and may be skipped when the service is unreachable or rate-limits the request.

## Packaging and publishing | 打包发布

Project metadata follows PEP 621 in `pyproject.toml`; the console command is `concept-bridge-mcp`. Build and publish with uv after configuring trusted publishing or PyPI credentials:

```powershell
uv build
uv publish
```

Before the first public release, confirm the package name is available on PyPI and add repository-specific details such as the GitHub URL, maintainers, and contribution policy.
