Library Query
library_queryRun read-only SQL against the local literature library to filter, rank, and screen collected papers, extract evidence, and explore the schema.
Instructions
Query the local literature library with read-only SQL.
TRIGGER after any search to screen, filter, or rank the collected papers (从已检索文献库中筛选/排序, e.g. top-N by citations, year/journal/author filters, substr(fulltext,1,N) evidence extraction).
This is the universal query tool — freely explore schema and run ad-hoc queries:
Explore schema:
SELECT name FROM sqlite_master WHERE type='table';PRAGMA table_info(<table>)Count / filter:
SELECT count(*) FROM works WHERE ...Plain queries: read-only SQLite SELECT / WITH / EXPLAIN queries — joins, aggregations, window functions, etc.
Keyword relevance: FTS5
bm25()ranking over title, abstract, and full text (see below).
Schema:
works — id, doi, title, publication_year,
publication_date, type, cited_by_count, is_oa, oa_status,
has_content, abstract, language, source_id, source_name,
authors_json, concepts_json, keywords_json, referenced_works,
related_works, raw_json.
sources — id, display_name, host_organization, issn_l,
issn, type, alternate_titles, abbreviated_title, homepage,
works_count, cited_by_count, is_oa, is_in_doaj, topic.
Work ids are OpenAlex ids (W...) or, for hits that OpenAlex does
not index, source-prefixed ids from search_multi (arxiv:...,
pmid:..., doi:...).
Full-text search: the works_fts FTS5 index covers title,
abstract, and fulltext. Use MATCH with bm25() ranking
(lower is better):
SELECT w.id, w.title, bm25(works_fts) AS rank FROM works_fts JOIN works w ON w.rowid = works_fts.rowid WHERE works_fts MATCH 'sensor AND fusion' ORDER BY rank LIMIT 20
Chinese full-text search: CJK text is indexed as character
bigrams, so wrap Chinese keywords with cjk_fts instead of
quoting them (中文关键词必须用 cjk_fts 包裹):
... WHERE works_fts MATCH cjk_fts('锂电池 极耳') ORDER BY rank
WAL mode allows concurrent reads + writes — library_query
does not block search_keyword / search_ids and vice versa.
Database-level read-only enforcement rejects mutations even when they
are hidden inside a CTE. WITH RECURSIVE is rejected (an
unterminated recursion would starve the shared read connection), and
any single statement is interrupted after 30 seconds. Use LIMIT and
bounded substr() expressions when selecting large columns such as
fulltext or raw_json.
Output is capped: BLOB columns render as <BLOB N bytes>, very
long text values are cut with an in-band <truncated: ...> marker,
and results over 200 rows or 200,000 chars are trimmed. A
trimmed result is returned as an object with rows, truncated,
and notes instead of a bare array. Project only the columns you
need.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sql": "<sql>"
},
"name": "library_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQLite SQL (read-only). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |