Skip to main content
Glama
heizaheiza

Charles MCP Server

filter_func

Filter network traffic from Charles Proxy captures using host, method, or content criteria to isolate specific requests for debugging and monitoring.

Instructions

Filter traffic from a fixed capture window or the latest saved history package.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
capture_secondsYes录制持续时长,单位为秒。绝对不是 Unix 时间戳(如 1700000000)也不是毫秒时间戳(如 1700000000000)。0 表示读取最新历史流量包。
host_containsNo按 host 子串过滤(包含匹配)。例如:api.example.com
http_methodNoHTTP 方法过滤。仅允许标准 HTTP 方法。必须是方法名,不是正则表达式,不是路径。
keyword_regexNo用于搜索请求/响应内容的 Python 正则表达式。建议使用短表达式,避免灾难性回溯。
keep_requestNo
keep_responseNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The filter_func function is the handler that implements the traffic filtering logic based on provided criteria such as time, host, HTTP method, and regex keywords.
    async def filter_func(
        capture_seconds: RecordSeconds,
        ctx: ToolContext,
        host_contains: HostContains = None,
        http_method: HttpMethodFilter = None,
        keyword_regex: KeywordRegex = None,
        keep_request: bool = True,
        keep_response: bool = True,
    ) -> list[dict]:
        """Filter traffic from a fixed capture window or the latest saved history package."""
        logger.info(
            "Tool called: filter_func(capture_seconds=%s, host_contains=%s, http_method=%s)",
            capture_seconds,
            host_contains,
            http_method,
        )
        deps = get_tool_dependencies(ctx)
    
        error_payload = seconds_input_error(
            parameter="capture_seconds",
            value=capture_seconds,
            max_allowed=deps.config.max_stoptime,
            retry_example='filter_func(capture_seconds=30, host_contains="api.example.com")',
        )
        if error_payload:
            return error_payload
    
        host_contains_normalized = normalize_text_filter(host_contains)
        method_normalized, method_error = normalize_http_method(http_method)
        if method_error:
            return method_error
    
        if keyword_regex:
            valid, error_msg = validate_regex(keyword_regex)
            if not valid:
                return 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='filter_func(capture_seconds=0, keyword_regex="token|session")',
                )
    
        raw_data = await get_proxy_data(capture_seconds, ctx, deps=deps)
        if not isinstance(raw_data, list):
            return raw_data
    
        return deps.history_service.filter_entries(
            raw_data,
            host_contains=host_contains_normalized,
            method_normalized=method_normalized,
            keyword_regex=keyword_regex,
            keep_request=keep_request,
            keep_response=keep_response,
        )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but fails to clarify whether 'filter' implies a destructive operation or simple querying, what the return format contains, or performance characteristics (e.g., regex execution limits). It does not disclose whether filtered results are removed from source or merely returned.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single 11-word sentence that is efficiently structured with the verb front-loaded. However, it is arguably underspecified for a 6-parameter tool with complex filtering capabilities, leaving insufficient semantic weight to guide proper invocation without heavy reliance on the schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters including regex filtering, boolean retention flags, and historical/live data modes) and the presence of an output schema, the description remains incomplete. It fails to explain the filtering logic, prerequisites (e.g., existing capture requirements), or behavioral implications of the keep_request/keep_response parameters.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 67% (4/6 parameters). While capture_seconds, host_contains, http_method, and keyword_regex are well-documented in the schema, 'keep_request' and 'keep_response' lack descriptions. The tool description provides no compensation for these gaps, nor does it explain the interaction between filtering criteria (AND/OR logic) or the impact of the boolean flags.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool filters traffic from either a 'fixed capture window' or 'latest saved history package', providing specific verb (filter) and resource (traffic). However, it does not explicitly differentiate this from sibling tools like 'query_recorded_traffic' or 'analyze_recorded_traffic' which may perform similar operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying data sources (capture window vs history package), suggesting when to use it based on data availability. However, it lacks explicit 'when not to use' guidance or named alternatives, leaving ambiguity regarding when to choose this over 'query_recorded_traffic' or other analysis tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/heizaheiza/Charles-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server