query_recorded_traffic
Search and filter previously captured network traffic recordings to analyze HTTP requests and responses by host, method, or content patterns.
Instructions
Query the latest saved recording. This tool never reads the live Charles session.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host_contains | No | 按 host 子串过滤(包含匹配)。例如:api.example.com | |
| http_method | No | HTTP 方法过滤。仅允许标准 HTTP 方法。必须是方法名,不是正则表达式,不是路径。 | |
| keyword_regex | No | 用于搜索请求/响应内容的 Python 正则表达式。建议使用短表达式,避免灾难性回溯。 | |
| keep_request | No | ||
| keep_response | No |
Implementation Reference
- charles_mcp/tools/history.py:204-240 (handler)The implementation of the `query_recorded_traffic` MCP tool, which queries the latest saved recording.
async def query_recorded_traffic( ctx: ToolContext, host_contains: HostContains = None, http_method: HttpMethodFilter = None, keyword_regex: KeywordRegex = None, keep_request: bool = True, keep_response: bool = True, ) -> RecordedTrafficQueryResult: """Query the latest saved recording. This tool never reads the live Charles session.""" deps = get_tool_dependencies(ctx) host_contains_normalized = normalize_text_filter(host_contains) method_normalized, method_error = normalize_http_method(http_method) if method_error: raise ValueError(guidance_error_message(method_error)) if keyword_regex: valid, error_msg = deps.history_service.validate_keyword_regex(keyword_regex) if not valid: raise ValueError( guidance_error_message( build_tool_guidance_error( parameter="keyword_regex", received=keyword_regex, reason=f"invalid regex: {error_msg}", valid_input="Provide a valid Python regular expression.", retry_example='query_recorded_traffic(keyword_regex="token|session")', ) ) ) return await deps.history_service.query_latest_result( host_contains=host_contains_normalized, method_normalized=method_normalized, keyword_regex=keyword_regex, keep_request=keep_request, keep_response=keep_response, )