Skip to main content
Glama

TRM MCP

本地、离线优先的超长 datasheet/TRM PDF 检索服务。它将页面级结构化解析、 BM25、Qwen3 dense embedding、Qwen3 reranker 和页面视觉 embedding 融合, 通过 MCP 提供 searchgrepreadrendercompare

快速开始

docker compose up -d
python -m venv .venv
.venv/bin/pip install -e '.[dev]'
.venv/bin/trm init
.venv/bin/trm models download
# 默认:只建立文本索引
.venv/bin/trm ingest /path/to/manual.pdf
# 也可递归导入目录及其所有子目录中的 PDF
.venv/bin/trm ingest /path/to/manuals/
# 可选:同时建立页面视觉索引
.venv/bin/trm ingest --visual /path/to/manual.pdf
# HTTP 服务必须设置一个固定 Bearer key
export TRM_MCP_API_KEY="$(openssl rand -hex 32)"
.venv/bin/trm serve --transport http

直接运行时服务默认监听 http://127.0.0.1:8765/mcp。HTTP 请求必须携带 Authorization: Bearer <TRM_MCP_API_KEY>;stdio 不需要网络认证。所有文档内容和查询均留在本机。 默认数据目录是 ${XDG_DATA_HOME:-~/.local/share}/trm-mcp,可通过 TRM_DATA_DIR 覆盖。

生成数据包括:

  • trm.sqlite3:文档、页面、布局 JSON、Markdown、切块和 FTS5/BM25;

  • documents/:按内容哈希保存的只读 PDF 副本;

  • images/:用于视觉索引的 144 DPI 页面图;

  • .trm-data/qdrant/:Qdrant 文本和视觉向量,可用 TRM_QDRANT_STORAGE 覆盖。

Related MCP server: pdf-context

MCP 客户端

export TRM_MCP_API_KEY="...与服务端相同的值..."
codex mcp add trm --url http://127.0.0.1:8765/mcp \
  --bearer-token-env-var TRM_MCP_API_KEY

--bearer-token-env-var 不会把密钥写进 Codex 配置。使用 systemd 部署时, 在启动 Codex 前加载同一私有环境文件:

set -a; . ~/.config/trm-mcp.env; set +a
codex

Claude Code 2.1.77 在本机使用 stdio(该版本的 HTTP 健康检查与当前 Streamable HTTP SDK 不兼容):

claude mcp add-json --scope user trm \
  '{"type":"stdio","command":"/absolute/path/to/trm-mcp/.venv/bin/trm",
  "args":["serve","--transport","stdio"],
  "env":{"TRM_DATA_DIR":"/absolute/path/to/trm-data",
  "TRM_QDRANT_URL":"http://127.0.0.1:6333","HF_HUB_OFFLINE":"1",
  "TRANSFORMERS_OFFLINE":"1",
  "TESSDATA_PREFIX":"/absolute/path/to/trm-data/tessdata"}}'

把示例中的绝对路径替换为本机仓库和数据目录;Claude Code 的 JSON 配置不会通过 shell 展开 $HOME

服务本身同时支持 HTTP 与 stdio;较新的 Claude Code 可直接改用 HTTP URL。

管理命令

trm list
trm status
trm reindex DOCUMENT_ID
trm remove DOCUMENT_ID
trm eval evals/golden_queries.json -o eval-report.json

MCP 接口是只读的。导入、重建、删除只能由本地 CLI 显式执行。

默认混合检索分别召回 BM25、Qwen3 文本向量和 Qwen3-VL 页面向量, 先用 RRF 合并文本候选,再经 Qwen3 reranker 重排,最后以 0.7/0.3 权重融合文本与视觉页排名。所有结果均带稳定文档 ID 和一基页码。

模型在第一次搜索时按需加载,服务启动和纯 list_documentsgrepreadrender 调用不会占用模型显存。reranker 默认使用 batch 1,可通过 TRM_RERANK_BATCH_SIZE 调整。每次查询结束后会归还未使用的 CUDA allocator 缓存;连续 600 秒没有模型查询时会卸载全部模型,可通过 TRM_MODEL_IDLE_TIMEOUT_SECONDS 调整,设为 0 可关闭自动卸载。默认搜索模式 仍为 hybrid,因此首次搜索及空闲卸载后的首次搜索需要重新加载三个模型。

解析器会先检查每页的原生文字、坏字符、已有 OCR 文字层和图像覆盖,只对 确实需要识别的页面启用 OCR。视觉编码默认从 batch 8 开始;如果出现 CUDA 显存不足,会自动按 8 → 4 → 2 → 1 退避,并在当前进程中保持已验证的大小。 可通过 TRM_VISUAL_BATCH_SIZE 设置起始上限,通过 TRM_VISUAL_BATCH_MIN 设置退避下限。

导入默认只建立文本索引,不渲染页面。显式传入 --visual 时,页面渲染使用 与可用逻辑 CPU 数相同的独立 spawn 进程;每个进程独立 打开 PDF,并使用原子文件替换写入 JPEG。SQLite 路径每 25 页批量提交,因此 并行 worker 不会共享数据库连接。本机可通过 TRM_RENDER_WORKERS 指定固定 进程数,0 表示自动;用 TRM_RENDER_PIN_CPUS=0/1 控制 CPU 绑定。 之后可用 trm ingest --visualreindex 补建图片与视觉索引。

PDF 结构化解析默认使用 8 个独立的 spawn 进程;每个进程独立打开 PDF、 绑定自己的 CPU 核集合,并将 ONNX Runtime intra-op 线程限制为 2。子进程 只返回页面结果,SQLite 写入和 Docling fallback 仍由主进程串行完成。可通过 TRM_PARSE_WORKERSTRM_PARSE_ORT_THREADSTRM_PARSE_PIN_CPUS=0/1 调整。

常驻服务与严格离线

仓库提供 deploy/trm-mcp.service,默认假定仓库位于 ~/trm-mcp。如果 安装位置不同,先修改其中的路径。安装并启动:

mkdir -p ~/.config/systemd/user
cp deploy/trm-mcp.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now trm-mcp.service

该服务将 Hugging Face 和 Transformers 设置为离线模式,默认同时绑定 IPv6 [::]:8765 和 IPv4 0.0.0.0:8765。安装前创建仅当前用户可读的密钥文件:

install -m 600 /dev/null ~/.config/trm-mcp.env
openssl rand -hex 32 | sed 's/^/TRM_MCP_API_KEY=/' >> ~/.config/trm-mcp.env

本机 Codex 使用 IPv6 loopback 时,URL 写作 http://[::1]:8765/mcp。 访问其他主机时必须使用其实际 IPv6 地址,并在 URL 中加方括号。此内置认证是 固定 Bearer key,未提供 TLS;若流量会经过不可信网络,请在反向代理上启用 HTTPS。 首次运行前必须执行一次 trm models download

Available Tools

6 tools
compareA

Retrieve matching passages from two documents and return aligned unified diffs.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYes
top_kNo
left_document_idYes
right_document_idYes

TDQS

A3.5/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It discloses that the tool retrieves matching passages and produces unified diffs, which indicates a read-oriented operation, but it does not mention side effects, permission requirements, or how it handles missing documents or edge cases. The disclosure is useful but minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single compact sentence that conveys the core functionality with zero unnecessary words. It is well-structured and front-loaded, earning a perfect score for conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has four parameters, no annotations, and no output schema, the description is too sparse. It lacks usage context, parameter explanations, output structure details, and how it differs from sibling tools. For an agent to invoke the tool correctly, significantly more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description should compensate by explaining parameters. It only alludes to 'two documents' without defining query, top_k, or how left_document_id and right_document_id map. The parameter names in the schema are somewhat self-explanatory, but the description adds little semantic value beyond what the schema already implies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool compares two documents by retrieving matching passages and returning aligned unified diffs. This specific verb+resource combination distinguishes it from siblings like search, grep, and read, which focus on searching or reading rather than multi-document comparison.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is used for comparing two documents, but it does not explicitly state when to choose it over alternatives such as search or grep, nor does it provide exclusions or context about when not to use it. The intended use is clear but not strongly differentiated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

grepC

Find exact register, field, signal, address, or regex occurrences by page.

ParametersJSON Schema
NameRequiredDescriptionDefault
regexNo
patternYes
max_resultsNo
document_idsNo
case_sensitiveNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of disclosing behavior. It adds only 'by page' and 'exact' context, but does not mention read-only nature, pagination, result format, case sensitivity, or document filtering. This is insufficient for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no redundant words. It front-loads the action ('Find') and specifies scope ('by page'), earning its place without excess.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 5 parameters, no schema descriptions, and no annotations, the description is drastically incomplete. It omits key behavioral details like case sensitivity, result limits, document scoping, and return structure. The presence of an output schema does not compensate for this missing invocation guidance.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must explain parameters. It only references 'regex' and indirectly 'pattern', leaving the other three parameters (max_results, document_ids, case_sensitive) unexplained. No parameter-level semantics are provided beyond what the schema titles show.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool finds exact occurrences of registers, fields, signals, addresses, or regex matches by page, using the specific verb 'Find' with named resource types. It does not explicitly differentiate from the sibling tool 'search', but the 'exact' and 'regex' qualifiers provide enough distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance is given on when to use grep versus alternatives like 'search'. The description implies exact/regex searching but lacks exclusions or comparisons to sibling tools, leaving the agent to infer appropriate usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_documentsB

List indexed documents and their stable IDs, titles, page counts, and status.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
queryNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the burden of behavioral disclosure. It states it lists documents and specifies output fields, but does not disclose pagination behavior, the effect of the query parameter, or whether it retrieves all documents by default. This provides partial transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that front-loads the verb and core purpose without extraneous detail. It effectively communicates the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple with optional parameters and an output schema. The description covers the returned fields but omits parameter semantics and usage context, making the description only partially complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, and the description does not explain the 'limit' or 'query' parameters. While the schema provides types and defaults, the description adds no semantic meaning, leaving the agent to guess how filtering and pagination work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses the specific verb 'List' with the resource 'indexed documents' and enumerates the returned fields (stable IDs, titles, page counts, status). This clearly differentiates it from sibling tools like search or grep, which focus on content retrieval.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description simply lists what it does without mentioning any exclusions or preferred contexts, leaving the agent to infer usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

readB

Read up to 20 indexed pages as Markdown, text, HTML, or layout JSON.

ParametersJSON Schema
NameRequiredDescriptionDefault
formatNomarkdown
page_endNo
page_startYes
document_idYes

TDQS

B3.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

While annotations are absent, the description adds a useful constraint (up to 20 pages) and lists formats. However, it does not explain indexing, error behavior, or whether results are always read-only (though implied by the name).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence with no filler words, efficiently conveying the core action and options.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations, no output schema, and no parameter descriptions, this terse description is insufficient. An agent cannot determine how to specify page ranges or understand return structure, making the tool harder to invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions the format options and a page limit, which loosely maps to format and page range parameters, but it does not explain document_id, page_start, or page_end semantics. With 0% schema description coverage, this leaves gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool reads pages and lists supported output formats, using a specific verb and resource. It does not explicitly distinguish it from sibling tools like render, but its function is reasonably clear.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like search, grep, or render. It does not state prerequisites or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

renderA

Render one to four PDF pages as images for visual inspection.

ParametersJSON Schema
NameRequiredDescriptionDefault
dpiNo
pagesYes
formatNojpeg
document_idYes

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the burden of behavioral disclosure. It notes a constraint ('one to four PDF pages') and the output type ('images'), but does not mention side effects, permissions, or return format beyond what the schema implies.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single, front-loaded sentence communicates the key information without redundancy. It is concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With 4 parameters, no output schema, and no annotations, the description provides essential purpose and a page limit, but lacks detail on output structure and parameter semantics. It is adequate but not comprehensive for the tool's complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, yet the description barely addresses parameters. It hints at the pages parameter via 'one to four', but does not explain document_id, dpi, or format, leaving the agent to rely on schema structure alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Render') and resource ('PDF pages as images'), stating a clear intended purpose 'for visual inspection'. This distinguishes it from sibling tools like read (text extraction) and compare (comparison).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies when to use the tool ('for visual inspection'), providing clear context. However, it does not explicitly mention when not to use it or name alternative tools for other scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv0.1.0
    • First observedcompare
    • First observedgrep
    • First observedlist_documents
    • First observedread
    • First observedrender
    • First observedsearch

TDQS

B3.4/5.0

Scored across 6 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: listing documents, searching with ranking, exact pattern matching, reading page content, rendering images, and comparing documents. There is no ambiguity about which tool to use for a given task.

Naming Consistency4/5

Most tool names are single-word imperative verbs (search, grep, read, render, compare), which is consistent. However, list_documents deviates by using a verb_noun pattern, creating a minor inconsistency.

Tool Count5/5

With 6 tools, the server is well-scoped for document retrieval and inspection. Each tool addresses a distinct aspect of the workflow, and the count feels appropriate for the domain.

Completeness4/5

The toolset covers listing, searching, grep-style extraction, reading, visual rendering, and comparison, which are the core operations for document analysis. Minor gaps might include a dedicated tool for fetching a single document's metadata, but list_documents already provides this.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Local-first RAG indexing and semantic search MCP server. Enables document retrieval and context-aware queries using local embedding models.
    3
    6 npm
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    A local-first MCP server that ingests PDFs, extracts structure, and provides semantic search and sequential navigation tools for AI clients to query and learn from documents.
    10
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    MCP server for local RAG over personal notes, PDFs, and documents, enabling plain-English querying and hybrid search with multi-hop context expansion.
    MIT