wrice commited on
Commit
3ccdaee
·
1 Parent(s): e1eb182

fix(server): cap list_recent days at 365

Browse files

An unbounded days argument let one call dump the entire corpus; bound
it the same way search_papers bounds limit.

Files changed (2) hide show
  1. src/papers_mcp/server.py +3 -2
  2. tests/test_server.py +9 -0
src/papers_mcp/server.py CHANGED
@@ -26,6 +26,7 @@ CORPORA = {
26
  DATA_DIR = Path("data")
27
  REFRESH_INTERVAL_SECONDS = 6 * 60 * 60
28
  MAX_SEARCH_LIMIT = 50
 
29
 
30
  corpora: dict[str, Corpus] = {}
31
  indexes: dict[str, SearchIndex] = {}
@@ -128,8 +129,8 @@ def make_server(name: str) -> FastMCP:
128
  @mcp.tool()
129
  def list_recent(days: int = 30) -> str:
130
  """List papers submitted in the last N days, newest first."""
131
- if days < 1:
132
- raise ValueError("days must be at least 1")
133
  cutoff = (date.today() - timedelta(days=days)).isoformat()
134
  recent = sorted(
135
  (p for p in corpora[name].papers.values() if p.submitted >= cutoff),
 
26
  DATA_DIR = Path("data")
27
  REFRESH_INTERVAL_SECONDS = 6 * 60 * 60
28
  MAX_SEARCH_LIMIT = 50
29
+ MAX_RECENT_DAYS = 365
30
 
31
  corpora: dict[str, Corpus] = {}
32
  indexes: dict[str, SearchIndex] = {}
 
129
  @mcp.tool()
130
  def list_recent(days: int = 30) -> str:
131
  """List papers submitted in the last N days, newest first."""
132
+ if not 1 <= days <= MAX_RECENT_DAYS:
133
+ raise ValueError(f"days must be between 1 and {MAX_RECENT_DAYS}")
134
  cutoff = (date.today() - timedelta(days=days)).isoformat()
135
  recent = sorted(
136
  (p for p in corpora[name].papers.values() if p.submitted >= cutoff),
tests/test_server.py CHANGED
@@ -97,3 +97,12 @@ def test_list_recent_tool(client: TestClient) -> None:
97
  assert len(dates) > 5
98
  assert dates == sorted(dates, reverse=True) # newest first
99
  assert min(dates) >= (date.today() - timedelta(days=365)).isoformat()
 
 
 
 
 
 
 
 
 
 
97
  assert len(dates) > 5
98
  assert dates == sorted(dates, reverse=True) # newest first
99
  assert min(dates) >= (date.today() - timedelta(days=365)).isoformat()
100
+
101
+
102
+ def test_list_recent_days_over_cap_is_an_error(client: TestClient) -> None:
103
+ resp = client.post(
104
+ "/lipsync/mcp",
105
+ json=rpc("tools/call", {"name": "list_recent", "arguments": {"days": 366}}),
106
+ headers=MCP_HEADERS,
107
+ )
108
+ assert resp.json()["result"]["isError"] is True