backend: let a model ask for a line break, and read the 参考文献 list back
The paper model gained two things while the MCP layer was not looking, and both were invisible from a tool call. `paper_sentence.line_break_before` — the flag a paragraph needs so a formula, a list of items or an author line can start a line of its own — was not in `SentenceSpec`, and `sentence_inputs` dropped it on the floor: a model could write the field, watch the call succeed, and get prose back. It is now part of every write path (`paragraph_write`, `paper_write`, `sentence_add`, `sentence_update`) and of every read path (`sentence_row` reports it, so a model can see the lines before moving one). Two bugs fell out of doing it properly: * `paragraph_move` rebuilt its sentences without the flag, so moving a paragraph that carried a formula turned it into prose. It also passed the *source* sorts through, which interleaved the moved sentences with the target's own — the merged paragraph read in an order neither writer wrote. Both are fixed; the tool now appends, as its own description promised. * `document_text` printed a formula run into the sentence before it. The paper view renders `$$…$$` as a block, so the seam rules are now the same in both places, with a comment on each side naming the other. `PaperDocumentRead.references` and `reference_style` — the per-work 参考文献 list the backend now assembles and formats — were reachable over REST but not over MCP: `paper_document(format="json")` returned citations and nothing to point them at, even though docs/MCP.md already described the list. The json form now carries the entries (index, reference_id, text, missing, citations) and the style name, so a model quotes the bibliography instead of assembling a second one out of the same fields. smoke_mcp.py grows from 76 checks to 99 over two new steps — the line-break step pins the display-formula rule, the marker toggle and the moving case; the bibliography step cites one work from two sentences and checks that the text, the entry and both markers agree on one number.
This commit is contained in:
@@ -248,7 +248,7 @@ def register(server: MCPServer) -> None:
|
||||
bool, Field(description="是否带上引用标记与参考文献列表")
|
||||
] = True,
|
||||
) -> str:
|
||||
"""读整篇论文:按模板顺序输出全文(含引用编号和参考文献)。"""
|
||||
"""读整篇论文:按模板顺序输出全文(含引用编号、参考文献表与换行)。"""
|
||||
with s.session() as db:
|
||||
paper = s.paper_or_fail(db, paper_id)
|
||||
document = paper_crud.build_document(db, paper)
|
||||
@@ -270,6 +270,8 @@ def register(server: MCPServer) -> None:
|
||||
for paragraph in document.paragraphs
|
||||
if include_empty or paragraph.sentences
|
||||
]
|
||||
# One row per *place* in the text, each carrying the number of
|
||||
# the work it cites — the number the marker in the text shows.
|
||||
payload["citations"] = [
|
||||
{
|
||||
"index": item.index,
|
||||
@@ -279,6 +281,24 @@ def register(server: MCPServer) -> None:
|
||||
}
|
||||
for item in document.citations
|
||||
]
|
||||
# The 参考文献 list as it prints: one entry per work, already
|
||||
# formatted by the server, so a model quotes the bibliography
|
||||
# rather than assembling a second one out of the same fields.
|
||||
# It is reported even when it is empty, because "this paper
|
||||
# cites nothing yet" is an answer.
|
||||
payload["references"] = [
|
||||
{
|
||||
"index": entry.index,
|
||||
"reference_id": entry.reference_id,
|
||||
"text": entry.text,
|
||||
"missing": entry.missing,
|
||||
# The ids of the places that cite it; the rows
|
||||
# themselves are in citations above.
|
||||
"citations": [row.id for row in entry.citations],
|
||||
}
|
||||
for entry in document.references
|
||||
]
|
||||
payload["reference_style"] = document.reference_style
|
||||
if document.warnings:
|
||||
payload["warnings"] = document.warnings
|
||||
return s.dumps(payload)
|
||||
@@ -291,7 +311,8 @@ def register(server: MCPServer) -> None:
|
||||
Field(
|
||||
description=(
|
||||
"要写的段落数组。每段用 heading(如 “1. Introduction”)或 position 指定,"
|
||||
"正文放 sentences(字符串数组或带 citations 的对象数组),"
|
||||
"正文放 sentences(字符串数组或带 citations 的对象数组,"
|
||||
"要另起一行的公式或条目加 line_break_before: true),"
|
||||
"或放 text + split 让服务端切句"
|
||||
)
|
||||
),
|
||||
@@ -324,6 +345,7 @@ def register(server: MCPServer) -> None:
|
||||
SentenceCreate(
|
||||
paper_template_filed_sort=position,
|
||||
content=item.content,
|
||||
line_break_before=item.line_break_before,
|
||||
citations=item.citations,
|
||||
sort=item.sort,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user