Skip to content

Commit 9966992

Browse files
committed
Enhance OTX search tools with pagination support and improved error handling
- Updated `search_indicators` function to clarify its behavior and added error handling. - Introduced `search_pulses_paginated` function for explicit pagination control, allowing users to specify page and limit parameters. - Updated README.md to reflect changes in tool descriptions and usage.
1 parent 795338f commit 9966992

2 files changed

Lines changed: 47 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ This MCP server is designed to be used with any MCP-compatible client. The serve
102102
The MCP server provides the following tools:
103103

104104
### Indicator Tools
105-
- `search_indicators`: Search OTX for pulses containing indicators matching a keyword
105+
- `search_indicators`: Search OTX for pulses containing indicators matching a keyword (uses default library behavior, may fetch multiple pages internally; use 'search_pulses_paginated' for explicit control).
106+
- `search_pulses_paginated`: Search OTX pulses with explicit pagination control via page and limit parameters.
106107
- `get_indicator_details`: Get detailed information about a specific indicator
107108
- `get_indicator_details_full`: Get all available details about a specific indicator
108109
- `validate_indicator`: Validate an indicator before adding it to a pulse

main.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,57 @@ def log_memory_usage():
2828

2929
@mcp.tool()
3030
async def search_indicators(keyword: str) -> Any:
31-
"""Search OTX for pulses containing indicators matching the keyword.
32-
31+
"""Search OTX for pulses matching the keyword (using default library behavior).
32+
3333
This tool searches the OTX platform for pulses that contain indicators matching the provided keyword.
34-
It's useful for finding relevant threat intelligence about specific indicators, domains, IPs, or other
35-
threat-related terms.
36-
37-
Use this tool when:
38-
- You need to find threat intelligence about a specific indicator or keyword
39-
- You want to discover pulses related to a particular threat or topic
40-
- You're investigating a potential security incident and need context
41-
34+
It uses the standard OTXv2 library function which may fetch multiple pages internally up to a default limit,
35+
potentially causing delays or large responses.
36+
37+
Note: This tool reflects the default OTXv2 library behavior.
38+
Use `search_pulses_paginated` for explicit page/limit control.
39+
4240
Args:
4341
keyword: The search term to look for in pulses (e.g., "malware", "ransomware", "CVE-2023-1234")
44-
42+
4543
Returns:
4644
A dictionary containing search results with pulses matching the keyword.
47-
Each pulse includes metadata like name, description, author, and creation date.
4845
"""
49-
return otx.search_pulses(keyword)
46+
try:
47+
return otx.search_pulses(keyword)
48+
except Exception as e:
49+
log_debug(f"Error in search_indicators: {e}")
50+
return {"error": f"Error executing tool search_indicators: {str(e)}"}
51+
52+
@mcp.tool()
53+
async def search_pulses_paginated(keyword: str, page: int = 1, limit: int = 10) -> Any:
54+
"""Search OTX pulses with explicit pagination control.
55+
56+
This tool searches the OTX platform for pulses matching the keyword,
57+
allowing direct control over pagination via `page` and `limit` parameters.
58+
It bypasses the standard library's internal pagination to make a single API call for the requested page.
59+
60+
Use this tool for finer control over results and to avoid potential timeouts associated with large searches.
61+
62+
Args:
63+
keyword: The search term to look for in pulses.
64+
page: The page number of results to retrieve (default: 1).
65+
limit: The maximum number of results per page (default: 10).
66+
67+
Returns:
68+
The raw API response dictionary for the requested page, including 'results',
69+
'count', 'next', and 'previous' fields, allowing the client to handle further pagination.
70+
"""
71+
try:
72+
# Manually construct the URL using the base path and parameters
73+
search_url = otx.create_url("/api/v1/search/pulses", q=keyword, page=page, limit=limit)
74+
log_debug(f"Calling paginated search: {search_url}")
75+
# Use the lower-level get() method to fetch the specific page
76+
response = otx.get(search_url)
77+
log_memory_usage()
78+
return response
79+
except Exception as e:
80+
log_debug(f"Error in search_pulses_paginated: {e}")
81+
return {"error": f"Error executing tool search_pulses_paginated: {str(e)}"}
5082

5183
@mcp.tool()
5284
async def get_pulse(pulse_id: str) -> Any:

0 commit comments

Comments
 (0)