Skip to content

Commit c2ee833

Browse files
committed
modify search to fix claude issues
datefilter is optional, and only used if user provided
1 parent fb9e22e commit c2ee833

File tree

5 files changed

+74
-5
lines changed

5 files changed

+74
-5
lines changed

src/planet_mcp/servers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from . import sdk
22
from . import tiles
3+
from . import search
34

45
all = [
56
sdk,
67
tiles,
8+
search,
79
]

src/planet_mcp/servers/descriptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
}
2121
```
2222
23-
search_filter: a Planet Data API filter for advanced searches.
23+
start_date: An optional datestring to use as the start date for the search. Use ISO 8601 format, e.g. 2022-04-14T00:00:00Z.
24+
end_date: An optional datestring to use as the end date for the search. Use ISO 8601 format. If not provided, searches from start_date onwards.
2425
2526
If the user does not ask for specific item types, default to ["PSScene", "SkySatScene", "SkySatCollect"].
2627
2728
Avoid using search_filter unless the user has asked for specific date ranges or other advanced parameters. If a
2829
user asks for a scene from "today", do a search as normal and present the first (most recent) result.
30+
31+
Note: The search automatically filters for cloud_cover <= 0.2 (20%).
2932
"""
3033
}

src/planet_mcp/servers/sdk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import planet
1111
from typing import Union
1212

13-
1413
# tools we don't want enabled at all.
1514
# they simply don't work well in an AI context.
1615
_DEFAULT_IGNORE = {
@@ -19,6 +18,7 @@
1918
"data_get_search",
2019
"data_get_stats",
2120
"data_list_searches",
21+
"data_search",
2222
"data_update_search",
2323
"data_wait_asset",
2424
"destinations_patch_destination",
@@ -35,7 +35,6 @@
3535
TOOL_SIG_OVERRIDE = {
3636
"features_add_items",
3737
"data_get_item_coverage",
38-
"data_search",
3938
"mosaics_download_quad",
4039
"mosaics_download_quads",
4140
"mosaics_get_quad",

src/planet_mcp/servers/search.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from datetime import datetime
2+
3+
from fastmcp import FastMCP
4+
from planet import Planet
5+
from planet_mcp import models
6+
from planet_mcp.servers import descriptions
7+
8+
# technically not using the sdk to make the tool but we can add it to that
9+
10+
mcp = FastMCP("sdk")
11+
12+
13+
@mcp.tool(
14+
name="data_search",
15+
description=descriptions.overrides["data_search"],
16+
tags={"data", "search"},
17+
)
18+
async def data_search(
19+
item_types: list[str],
20+
start_date: str,
21+
end_date: str | None,
22+
geometry: models.Geometry,
23+
):
24+
25+
planet = Planet()
26+
cloud_filter = {
27+
"type": "RangeFilter",
28+
"field_name": "cloud_cover",
29+
"config": {"lte": 0.2},
30+
}
31+
filter = {
32+
"type": "AndFilter",
33+
"config": [cloud_filter],
34+
}
35+
if start_date is not None or end_date is not None:
36+
datefilter_config = {}
37+
if start_date is not None:
38+
datefilter_config["gte"] = datetime.fromisoformat(
39+
start_date.replace("Z", "+00:00")
40+
).isoformat()
41+
if end_date is not None:
42+
datefilter_config["lte"] = datetime.fromisoformat(
43+
end_date.replace("Z", "+00:00")
44+
).isoformat()
45+
datefilter = {
46+
"type": "DateRangeFilter",
47+
"field_name": "acquired",
48+
"config": datefilter_config,
49+
}
50+
filter["config"].append(datefilter)
51+
52+
results = planet.data.search(
53+
item_types=item_types,
54+
geometry=dict(geometry),
55+
search_filter=filter,
56+
)
57+
return results

tests/test_server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ async def test_search_tool():
1818
)
1919
async with client:
2020
result = await client.call_tool(
21-
"sdk_data_search", {"item_types": ["SkySatScene"]}
21+
"sdk_data_search",
22+
{
23+
"item_types": ["SkySatScene"],
24+
"start_date": "2023-01-01",
25+
"end_date": "2023-01-02",
26+
"geometry": {"type": "Point", "coordinates": [0, 0], "content": None},
27+
},
2228
)
23-
assert result.structured_content == {"result": [{"type": "Feature"}]}
29+
assert len(result.content) == 1
30+
assert result.content[0].type == "text"
31+
assert result.content[0].text == '[{"type":"Feature"}]'

0 commit comments

Comments
 (0)