通用源代码管理系统
一个轻量级的FastMCP服务器,用于管理文献、笔记、实体链接和读取本地SQLite数据库中的列表资源。
当前范围
此存储库提供:
- 本地SQLite支持的源代码管理
- 来源所附注释
- 源和命名概念之间的实体链接
- 只读数据库检查工具
- 用于源查找和阅读列表的MCP资源
- 具有过渡JSON缓存的标准化标识符存储
它不与MCP内存服务器或外部内存图集成。
快速开始
- 从当前架构创建数据库:
sqlite3 sources.db `
- `source://by-identifier//`
- `reading-list://unread`
- `reading-list://reading`
- `entity://`
## 架构注释
当前模式以四个表为中心:
- `sources`
- `source_identifiers`
- `source_notes`
- `source_entity_links`
`sources.identifiers` 仍然保留为过渡性JSON缓存,但标识符查找现在使用 `source_identifiers`.
支持的标识符类型:
- `semantic_scholar`
- `doi`
- `arxiv`
- `openalex`
- `pmid`
- `isbn`
- `url`
支持的实体关系类型:
- `discusses`
- `introduces`
- `extends`
- `evaluates`
- `applies`
- `critiques`
- `supports`
- `contradicts`
- `refutes`
轻量级的起源领域继续存在 `sources`:
- `provider`
- `discovered_via`
- `discovered_at`
模式现在使用 `PRAGMA user_version = 3`.
## 迁移
如果您有版本0或版本1的数据库,请应用:
sqlite3 /path/to/sources.db < migrations/2026-03-09__normalize-identifiers.sql sqlite3 /path/to/sources.db < migrations/2026-03-09__expand-entity-relation-types.sql
如果您已经迁移到版本2,请应用:
sqlite3 /path/to/sources.db < migrations/2026-03-09__expand-entity-relation-types.sql
这些迁移:
- 添加 `source_identifiers`
- 从旧JSON列中回填标识符行
- 添加来源字段
- 扩展 `source_entity_links.relation_type` 包括 `supports`, `contradicts`,以及 `refutes`
- 更新 `PRAGMA user_version` 到 `3`
服务器检查 `PRAGMA user_version` 在连接时,将拒绝旧数据库,直到它们被迁移。
## 包布局
实施按以下方式组织 `sqlite_lit_server/`:
- `app.py` 创建FastMCP实例并注册工具/资源
- `db.py` 负责连接设置和架构版本检查
- `repository.py` 将SQL繁重的查找逻辑保持在数据层附近
- `tools_admin.py`, `tools_sources.py`,以及 `tools_entities.py` 握住MCP工具
- `resources.py` 定义MCP资源
`sqlite-paper-fastmcp-server.py` 仍然是一个薄的兼容性垫片。
## 批量导入源
`add_sources` 是新来源的批量导入入口点。它接受一个名为的参数 `sources`,其中每个项目为:
[title, source_type, identifier_type, identifier_value, initial_note]
`initial_note` 必须是 `null` 或同时具有这两种功能的对象 `title` 和 `content`.
支持 `source_type` 值:
- `paper`
- `webpage`
- `book`
- `video`
- `blog`
支持 `identifier_type` 值:
- `semantic_scholar`
- `doi`
- `arxiv`
- `openalex`
- `pmid`
- `isbn`
- `url`
重复处理:
- 精确标识符与返回值匹配 `Source already exists` 以及现有的源有效载荷。
- 基于标题的模糊匹配返回 `Potential duplicates found. Please verify or use add_identifiers if these are the same source.`
- 成功的批处理写入将按与请求相同的顺序为每个输入项返回一个结果。
MCP/JSON有效载荷示例:
{ "sources": [ [ "Attention Is All You Need", "paper", "arxiv", "1706.03762", { "title": "Initial thoughts", "content": "Transformers start here." } ], [ "OpenAlex Import", "paper", "openalex", "W1234567890", null ] ] }
Python调用示例:
add_sources([ ( "Attention Is All You Need", "paper", "arxiv", "1706.03762", { "title": "Initial thoughts", "content": "Transformers start here.", }, ), ( "OpenAlex Import", "paper", "openalex", "W1234567890", None, ), ])
无论您是在本地启动服务器还是通过Docker启动服务器,都可以使用相同的工具有效负载 `docker compose run --rm sqlite-lit-mcp`.
## 批处理写入约定
多个写入工具接受列表,并以相同的顺序返回每个输入的结果列表。相关批处理工具包括:
- `add_notes`
- `add_identifiers`
- `update_status`
- `link_to_entities`
## 示例用法
添加另一个标识符:
add_identifiers([ ( "Attention Is All You Need", "paper", "arxiv", "1706.03762", "semantic_scholar", "204e3073870fae3d05bcbc2f6a8e263d9b72e776", ), ])
读取源资源:
source://by-identifier/arxiv/1706.03762
