aurelian 0.3.3__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aurelian/agents/paperqa/__init__.py +27 -0
- aurelian/agents/paperqa/paperqa_agent.py +65 -0
- aurelian/agents/paperqa/paperqa_cli.py +305 -0
- aurelian/agents/paperqa/paperqa_config.py +142 -0
- aurelian/agents/paperqa/paperqa_gradio.py +90 -0
- aurelian/agents/paperqa/paperqa_mcp.py +155 -0
- aurelian/agents/paperqa/paperqa_tools.py +566 -0
- aurelian/cli.py +27 -0
- {aurelian-0.3.3.dist-info → aurelian-0.3.4.dist-info}/METADATA +3 -1
- {aurelian-0.3.3.dist-info → aurelian-0.3.4.dist-info}/RECORD +13 -6
- {aurelian-0.3.3.dist-info → aurelian-0.3.4.dist-info}/WHEEL +1 -1
- {aurelian-0.3.3.dist-info → aurelian-0.3.4.dist-info}/LICENSE +0 -0
- {aurelian-0.3.3.dist-info → aurelian-0.3.4.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
"""
|
2
|
+
MCP tools for working with PaperQA for scientific literature search and analysis.
|
3
|
+
"""
|
4
|
+
import os
|
5
|
+
from typing import Dict, List, Any, Optional
|
6
|
+
|
7
|
+
from mcp.server.fastmcp import FastMCP
|
8
|
+
|
9
|
+
import aurelian.agents.paperqa.paperqa_tools as pt
|
10
|
+
from aurelian.agents.paperqa.paperqa_agent import paperqa_agent, PAPERQA_SYSTEM_PROMPT
|
11
|
+
from aurelian.agents.paperqa.paperqa_config import PaperQADependencies
|
12
|
+
from pydantic_ai import RunContext
|
13
|
+
|
14
|
+
mcp = FastMCP("paperqa", instructions=PAPERQA_SYSTEM_PROMPT.strip())
|
15
|
+
|
16
|
+
|
17
|
+
from aurelian.dependencies.workdir import WorkDir
|
18
|
+
|
19
|
+
def deps() -> PaperQADependencies:
|
20
|
+
deps = PaperQADependencies()
|
21
|
+
loc = os.getenv("AURELIAN_WORKDIR", "/tmp/paperqa")
|
22
|
+
deps.workdir = WorkDir(loc)
|
23
|
+
|
24
|
+
paper_dir = os.getenv("PAPERQA_PAPER_DIRECTORY", os.path.join(loc, "papers"))
|
25
|
+
deps.paper_directory = paper_dir
|
26
|
+
|
27
|
+
if os.getenv("PAPERQA_LLM"):
|
28
|
+
deps.llm = os.getenv("PAPERQA_LLM")
|
29
|
+
|
30
|
+
if os.getenv("PAPERQA_EMBEDDING"):
|
31
|
+
deps.embedding = os.getenv("PAPERQA_EMBEDDING")
|
32
|
+
|
33
|
+
return deps
|
34
|
+
|
35
|
+
def ctx() -> RunContext[PaperQADependencies]:
|
36
|
+
rc: RunContext[PaperQADependencies] = RunContext[PaperQADependencies](
|
37
|
+
deps=deps(),
|
38
|
+
model=None, usage=None, prompt=None,
|
39
|
+
)
|
40
|
+
return rc
|
41
|
+
|
42
|
+
|
43
|
+
@mcp.tool()
|
44
|
+
async def search_papers(query: str, max_papers: Optional[int] = None) -> Any:
|
45
|
+
"""
|
46
|
+
Search for papers relevant to the query using PaperQA.
|
47
|
+
|
48
|
+
Args:
|
49
|
+
query: The search query for scientific papers
|
50
|
+
max_papers: Maximum number of papers to return (overrides config)
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
The search results with paper information
|
54
|
+
|
55
|
+
This searches for scientific papers based on your query. It returns papers
|
56
|
+
that are most relevant to the topic you're searching for. You can optionally
|
57
|
+
specify a maximum number of papers to return.
|
58
|
+
"""
|
59
|
+
return await pt.search_papers(ctx(), query, max_papers)
|
60
|
+
|
61
|
+
|
62
|
+
@mcp.tool()
|
63
|
+
async def query_papers(query: str) -> Any:
|
64
|
+
"""
|
65
|
+
Query the papers to answer a specific question using PaperQA.
|
66
|
+
|
67
|
+
Args:
|
68
|
+
query: The question to answer based on the papers
|
69
|
+
|
70
|
+
Returns:
|
71
|
+
Detailed answer with citations from the papers
|
72
|
+
|
73
|
+
This tool analyzes the papers in your collection to provide an evidence-based
|
74
|
+
answer to your question. It extracts relevant information from across papers
|
75
|
+
and synthesizes a response with citations to the source papers.
|
76
|
+
"""
|
77
|
+
return await pt.query_papers(ctx(), query)
|
78
|
+
|
79
|
+
|
80
|
+
@mcp.tool()
|
81
|
+
async def add_paper(path: str, citation: Optional[str] = None) -> Any:
|
82
|
+
"""
|
83
|
+
Add a specific paper to the collection.
|
84
|
+
|
85
|
+
Args:
|
86
|
+
path: Path to the paper file or URL
|
87
|
+
citation: Optional citation for the paper
|
88
|
+
|
89
|
+
Returns:
|
90
|
+
Information about the added paper
|
91
|
+
|
92
|
+
You can add a paper by providing its file path (PDF) or a URL to the paper
|
93
|
+
(must be accessible). The paper will be added to your collection for searching
|
94
|
+
and querying. You can optionally provide a citation string.
|
95
|
+
"""
|
96
|
+
return await pt.add_paper(ctx(), path, citation)
|
97
|
+
|
98
|
+
@mcp.tool()
|
99
|
+
async def add_papers(path: str,) -> Any:
|
100
|
+
"""
|
101
|
+
Add multiple papers to the collection.
|
102
|
+
Args:
|
103
|
+
path: Path to the paper file or URL
|
104
|
+
citation: Optional citation for the paper
|
105
|
+
|
106
|
+
Returns:
|
107
|
+
Informations about the added papers
|
108
|
+
|
109
|
+
You can add multiple papers by providing its file path (PDF) or a URL to the
|
110
|
+
paper (must be accessible). The paper will be added to your collection for
|
111
|
+
searching and querying.
|
112
|
+
"""
|
113
|
+
return await pt.add_papers(ctx(), path)
|
114
|
+
|
115
|
+
|
116
|
+
@mcp.tool()
|
117
|
+
async def list_papers() -> Any:
|
118
|
+
"""
|
119
|
+
List all papers in the current paper directory.
|
120
|
+
|
121
|
+
Args:
|
122
|
+
None
|
123
|
+
|
124
|
+
Returns:
|
125
|
+
Information about all papers in the paper directory
|
126
|
+
|
127
|
+
This lists all papers currently in your collection, showing their file paths and
|
128
|
+
any other available metadata. Use this to see what papers you have available
|
129
|
+
for searching and querying.
|
130
|
+
"""
|
131
|
+
return await pt.list_papers(ctx())
|
132
|
+
|
133
|
+
|
134
|
+
@mcp.tool()
|
135
|
+
async def build_index() -> Any:
|
136
|
+
"""
|
137
|
+
Rebuild the search index for papers.
|
138
|
+
|
139
|
+
Args:
|
140
|
+
None
|
141
|
+
|
142
|
+
Returns:
|
143
|
+
Information about the indexing process
|
144
|
+
|
145
|
+
This rebuilds the search index for all papers in your paper directory.
|
146
|
+
The index is required for searching and querying papers. You should run this
|
147
|
+
after adding new papers to make them searchable.
|
148
|
+
"""
|
149
|
+
return await pt.build_index(ctx())
|
150
|
+
|
151
|
+
|
152
|
+
if __name__ == "__main__":
|
153
|
+
print("Running the PaperQA MCP server")
|
154
|
+
print("Use Ctrl-C to exit")
|
155
|
+
mcp.run(transport='stdio')
|