Skip to content

Commit 4517ab7

Browse files
committed
formatting
1 parent 8f63ef2 commit 4517ab7

File tree

8 files changed

+148
-1087
lines changed

8 files changed

+148
-1087
lines changed

pyproject.toml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ test = [
3636
"pytest-mock>=3.10.0",
3737
"aioresponses>=0.7.6"
3838
]
39+
dev = [
40+
"black>=23.3.0"
41+
]
3942

4043
[tool.pytest.ini_options]
4144
asyncio_mode = "auto"
@@ -50,4 +53,22 @@ arxiv-mcp-server = "arxiv_mcp_server:main"
5053
packages = ["src/arxiv_mcp_server"]
5154

5255
[tool.hatch.metadata]
53-
allow-direct-references = true
56+
allow-direct-references = true
57+
58+
[tool.black]
59+
line-length = 88
60+
target-version = ["py311"]
61+
include = '\.pyi?$'
62+
exclude = '''
63+
/(
64+
\.git
65+
| \.hg
66+
| \.mypy_cache
67+
| \.tox
68+
| \.venv
69+
| _build
70+
| buck-out
71+
| build
72+
| dist
73+
)/
74+
'''

src/arxiv_mcp_server/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Main entry point for the arxiv-mcp-server package."""
2+
23
from . import main
34

4-
if __name__ == '__main__':
5+
if __name__ == "__main__":
56
main()

src/arxiv_mcp_server/prompts/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
from .handlers import list_prompts, get_prompt
44

5-
__all__ = ['list_prompts', 'get_prompt']
5+
__all__ = ["list_prompts", "get_prompt"]

src/arxiv_mcp_server/prompts/prompts.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
description="Synthesize findings across multiple papers",
4646
arguments=[
4747
PromptArgument(
48-
name="paper_ids", description="Comma-separated list of arXiv paper IDs", required=True
48+
name="paper_ids",
49+
description="Comma-separated list of arXiv paper IDs",
50+
required=True,
4951
),
5052
PromptArgument(
5153
name="synthesis_type",
@@ -64,7 +66,9 @@
6466
description="Formulate research questions based on literature",
6567
arguments=[
6668
PromptArgument(
67-
name="paper_ids", description="Comma-separated list of arXiv paper IDs", required=True
69+
name="paper_ids",
70+
description="Comma-separated list of arXiv paper IDs",
71+
required=True,
6872
),
6973
PromptArgument(
7074
name="topic", description="Research topic or question", required=True

src/arxiv_mcp_server/tools/download.py

Lines changed: 113 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@dataclass
2323
class ConversionStatus:
2424
"""Track the status of a PDF to Markdown conversion."""
25+
2526
paper_id: str
2627
status: str # 'downloading', 'converting', 'success', 'error'
2728
started_at: datetime
@@ -37,16 +38,16 @@ class ConversionStatus:
3738
"properties": {
3839
"paper_id": {
3940
"type": "string",
40-
"description": "The arXiv ID of the paper to download"
41+
"description": "The arXiv ID of the paper to download",
4142
},
4243
"check_status": {
4344
"type": "boolean",
4445
"description": "If true, only check conversion status without downloading",
45-
"default": False
46-
}
46+
"default": False,
47+
},
4748
},
48-
"required": ["paper_id"]
49-
}
49+
"required": ["paper_id"],
50+
},
5051
)
5152

5253

@@ -63,19 +64,19 @@ def convert_pdf_to_markdown(paper_id: str, pdf_path: Path) -> None:
6364
logger.info(f"Starting conversion for {paper_id}")
6465
markdown = pymupdf4llm.to_markdown(pdf_path, show_progress=False)
6566
md_path = get_paper_path(paper_id, ".md")
66-
67+
6768
with open(md_path, "w", encoding="utf-8") as f:
6869
f.write(markdown)
6970

7071
status = conversion_statuses.get(paper_id)
7172
if status:
7273
status.status = "success"
7374
status.completed_at = datetime.now()
74-
75+
7576
# Clean up PDF after successful conversion
7677
pdf_path.unlink()
7778
logger.info(f"Conversion completed for {paper_id}")
78-
79+
7980
except Exception as e:
8081
logger.error(f"Conversion failed for {paper_id}: {str(e)}")
8182
status = conversion_statuses.get(paper_id)
@@ -90,108 +91,137 @@ async def handle_download(arguments: Dict[str, Any]) -> List[types.TextContent]:
9091
try:
9192
paper_id = arguments["paper_id"]
9293
check_status = arguments.get("check_status", False)
93-
94+
9495
# If only checking status
9596
if check_status:
9697
status = conversion_statuses.get(paper_id)
9798
if not status:
9899
if get_paper_path(paper_id, ".md").exists():
99-
return [types.TextContent(
100+
return [
101+
types.TextContent(
102+
type="text",
103+
text=json.dumps(
104+
{
105+
"status": "success",
106+
"message": "Paper is ready",
107+
"resource_uri": f"file://{get_paper_path(paper_id, '.md')}",
108+
}
109+
),
110+
)
111+
]
112+
return [
113+
types.TextContent(
100114
type="text",
101-
text=json.dumps({
102-
"status": "success",
103-
"message": "Paper is ready",
104-
"resource_uri": f"file://{get_paper_path(paper_id, '.md')}"
105-
})
106-
)]
107-
return [types.TextContent(
115+
text=json.dumps(
116+
{
117+
"status": "unknown",
118+
"message": "No download or conversion in progress",
119+
}
120+
),
121+
)
122+
]
123+
124+
return [
125+
types.TextContent(
108126
type="text",
109-
text=json.dumps({
110-
"status": "unknown",
111-
"message": "No download or conversion in progress"
112-
})
113-
)]
114-
115-
return [types.TextContent(
116-
type="text",
117-
text=json.dumps({
118-
"status": status.status,
119-
"started_at": status.started_at.isoformat(),
120-
"completed_at": status.completed_at.isoformat() if status.completed_at else None,
121-
"error": status.error,
122-
"message": f"Paper conversion {status.status}"
123-
})
124-
)]
125-
127+
text=json.dumps(
128+
{
129+
"status": status.status,
130+
"started_at": status.started_at.isoformat(),
131+
"completed_at": (
132+
status.completed_at.isoformat()
133+
if status.completed_at
134+
else None
135+
),
136+
"error": status.error,
137+
"message": f"Paper conversion {status.status}",
138+
}
139+
),
140+
)
141+
]
142+
126143
# Check if paper is already converted
127144
if get_paper_path(paper_id, ".md").exists():
128-
return [types.TextContent(
129-
type="text",
130-
text=json.dumps({
131-
"status": "success",
132-
"message": "Paper already available",
133-
"resource_uri": f"file://{get_paper_path(paper_id, '.md')}"
134-
})
135-
)]
136-
145+
return [
146+
types.TextContent(
147+
type="text",
148+
text=json.dumps(
149+
{
150+
"status": "success",
151+
"message": "Paper already available",
152+
"resource_uri": f"file://{get_paper_path(paper_id, '.md')}",
153+
}
154+
),
155+
)
156+
]
157+
137158
# Check if already in progress
138159
if paper_id in conversion_statuses:
139160
status = conversion_statuses[paper_id]
140-
return [types.TextContent(
141-
type="text",
142-
text=json.dumps({
143-
"status": status.status,
144-
"message": f"Paper conversion {status.status}",
145-
"started_at": status.started_at.isoformat()
146-
})
147-
)]
148-
161+
return [
162+
types.TextContent(
163+
type="text",
164+
text=json.dumps(
165+
{
166+
"status": status.status,
167+
"message": f"Paper conversion {status.status}",
168+
"started_at": status.started_at.isoformat(),
169+
}
170+
),
171+
)
172+
]
173+
149174
# Start new download and conversion
150175
pdf_path = get_paper_path(paper_id, ".pdf")
151176
client = arxiv.Client()
152-
177+
153178
# Initialize status
154179
conversion_statuses[paper_id] = ConversionStatus(
155-
paper_id=paper_id,
156-
status="downloading",
157-
started_at=datetime.now()
180+
paper_id=paper_id, status="downloading", started_at=datetime.now()
158181
)
159-
182+
160183
# Download PDF
161184
paper = next(client.results(arxiv.Search(id_list=[paper_id])))
162185
paper.download_pdf(dirpath=pdf_path.parent, filename=pdf_path.name)
163-
186+
164187
# Update status and start conversion
165188
status = conversion_statuses[paper_id]
166189
status.status = "converting"
167-
190+
168191
# Start conversion in thread
169192
asyncio.create_task(
170193
asyncio.to_thread(convert_pdf_to_markdown, paper_id, pdf_path)
171194
)
172-
173-
return [types.TextContent(
174-
type="text",
175-
text=json.dumps({
176-
"status": "converting",
177-
"message": "Paper downloaded, conversion started",
178-
"started_at": status.started_at.isoformat()
179-
})
180-
)]
181-
195+
196+
return [
197+
types.TextContent(
198+
type="text",
199+
text=json.dumps(
200+
{
201+
"status": "converting",
202+
"message": "Paper downloaded, conversion started",
203+
"started_at": status.started_at.isoformat(),
204+
}
205+
),
206+
)
207+
]
208+
182209
except StopIteration:
183-
return [types.TextContent(
184-
type="text",
185-
text=json.dumps({
186-
"status": "error",
187-
"message": f"Paper {paper_id} not found on arXiv"
188-
})
189-
)]
210+
return [
211+
types.TextContent(
212+
type="text",
213+
text=json.dumps(
214+
{
215+
"status": "error",
216+
"message": f"Paper {paper_id} not found on arXiv",
217+
}
218+
),
219+
)
220+
]
190221
except Exception as e:
191-
return [types.TextContent(
192-
type="text",
193-
text=json.dumps({
194-
"status": "error",
195-
"message": f"Error: {str(e)}"
196-
})
197-
)]
222+
return [
223+
types.TextContent(
224+
type="text",
225+
text=json.dumps({"status": "error", "message": f"Error: {str(e)}"}),
226+
)
227+
]

src/arxiv_mcp_server/tools/list_papers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def list_papers() -> list[str]:
2626

2727

2828
async def handle_list_papers(
29-
arguments: Optional[Dict[str, Any]] = None
29+
arguments: Optional[Dict[str, Any]] = None,
3030
) -> List[types.TextContent]:
3131
"""Handle requests to list all stored papers."""
3232
try:

src/arxiv_mcp_server/tools/read_paper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ async def handle_read_paper(arguments: Dict[str, Any]) -> List[types.TextContent
4949
]
5050

5151
# Get paper content
52-
content = Path(settings.STORAGE_PATH, f"{paper_id}.md").read_text(encoding="utf-8")
52+
content = Path(settings.STORAGE_PATH, f"{paper_id}.md").read_text(
53+
encoding="utf-8"
54+
)
5355

5456
return [
5557
types.TextContent(

0 commit comments

Comments
 (0)