Skip to main content
Glama
mcpcap

mcpacket

by mcpcap

analyze_tcp_retransmissions

Analyze TCP retransmission patterns in packet captures to identify network issues. Filter by server IP and set a retransmission rate threshold to detect problematic connections.

Instructions

Analyze TCP retransmission patterns.

Args: pcap_file: HTTP URL or absolute local file path to PCAP file server_ip: Optional filter for server IP address threshold: Retransmission rate threshold (default: 2%)

Returns: A structured dictionary containing: - total_retransmissions: Total number of retransmissions - retransmission_rate: Overall retransmission rate - by_connection: Per-connection retransmission statistics - summary: Worst connections and threshold violations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pcap_fileYes
server_ipNo
thresholdNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The public tool method 'analyze_tcp_retransmissions' in TCPModule. Delegates to analyze_packets with analysis_type='retransmissions', which routes to _analyze_retrans.
    def analyze_tcp_retransmissions(
        self,
        pcap_file: str,
        server_ip: str | None = None,
        threshold: float = 0.02,
    ) -> dict[str, Any]:
        """
        Analyze TCP retransmission patterns.
    
        Args:
            pcap_file: HTTP URL or absolute local file path to PCAP file
            server_ip: Optional filter for server IP address
            threshold: Retransmission rate threshold (default: 2%)
    
        Returns:
            A structured dictionary containing:
            - total_retransmissions: Total number of retransmissions
            - retransmission_rate: Overall retransmission rate
            - by_connection: Per-connection retransmission statistics
            - summary: Worst connections and threshold violations
        """
        return self.analyze_packets(
            pcap_file,
            analysis_type="retransmissions",
            server_ip=server_ip,
            threshold=threshold,
        )
  • Private helper _analyze_retrans that performs the actual retransmission analysis logic. Groups TCP packets by connection, calculates retransmission counts and rates per connection, sorts by rate descending, and returns retransmission metrics including threshold comparison.
    def _analyze_retrans(
        self, pcap_file: str, tcp_packets: list, all_packets: list
    ) -> dict[str, Any]:
        """Analyze TCP retransmissions."""
        threshold = self._analysis_kwargs.get("threshold", 0.02)
    
        # Group by connection
        connections = defaultdict(list)
        for pkt in tcp_packets:
            conn_key = self._get_connection_key(pkt)
            connections[conn_key].append(pkt)
    
        by_connection = []
        total_retrans = 0
        worst_rate = 0
        worst_conn = ""
    
        for conn_key, pkts in connections.items():
            src_ip, src_port, dst_ip, dst_port = conn_key
            conn_str = f"{src_ip}:{src_port} <-> {dst_ip}:{dst_port}"
    
            conn_info = self._analyze_single_connection(conn_key, pkts)
            retrans_count = conn_info["retransmissions"]
            total_retrans += retrans_count
    
            retrans_rate = retrans_count / len(pkts) if len(pkts) > 0 else 0
    
            by_connection.append(
                {
                    "connection": conn_str,
                    "retrans_count": retrans_count,
                    "total_packets": len(pkts),
                    "retrans_rate": retrans_rate,
                }
            )
    
            if retrans_rate > worst_rate:
                worst_rate = retrans_rate
                worst_conn = conn_str
    
        # Sort by retransmission rate
        by_connection.sort(key=lambda x: x["retrans_rate"], reverse=True)
    
        overall_rate = total_retrans / len(tcp_packets) if len(tcp_packets) > 0 else 0
        connections_above_threshold = sum(
            1 for c in by_connection if c["retrans_rate"] > threshold
        )
    
        return {
            "file": pcap_file,
            "analysis_timestamp": datetime.now().isoformat(),
            "total_packets": len(tcp_packets),
            "total_retransmissions": total_retrans,
            "retransmission_rate": overall_rate,
            "threshold": threshold,
            "exceeds_threshold": overall_rate > threshold,
            "by_connection": by_connection[:10],  # Top 10
            "summary": {
                "worst_connection": worst_conn,
                "worst_retrans_rate": worst_rate,
                "connections_above_threshold": connections_above_threshold,
            },
        }
  • Registration of the tool via FastMCP's @tool decorator in _register_tools, passing the module's method reference.
    self.mcp.tool(module.analyze_tcp_retransmissions)
  • The function signature and docstring define the input schema (pcap_file: str, server_ip: str|None, threshold: float) and output schema (dict with total_retransmissions, retransmission_rate, by_connection, summary).
    def analyze_tcp_retransmissions(
        self,
        pcap_file: str,
        server_ip: str | None = None,
        threshold: float = 0.02,
    ) -> dict[str, Any]:
        """
        Analyze TCP retransmission patterns.
    
        Args:
            pcap_file: HTTP URL or absolute local file path to PCAP file
            server_ip: Optional filter for server IP address
            threshold: Retransmission rate threshold (default: 2%)
    
        Returns:
            A structured dictionary containing:
            - total_retransmissions: Total number of retransmissions
            - retransmission_rate: Overall retransmission rate
            - by_connection: Per-connection retransmission statistics
            - summary: Worst connections and threshold violations
        """
        return self.analyze_packets(
            pcap_file,
            analysis_type="retransmissions",
            server_ip=server_ip,
            threshold=threshold,
        )
Behavior3/5

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

No annotations provided, so the description must carry transparency. It describes inputs and return structure but does not disclose behavioral traits like read-only nature, error conditions, performance considerations, or side effects. It partially compensates by listing return fields.

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

Conciseness4/5

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

The description is well-structured with a title, Args, and Returns sections. It is moderately sized and front-loaded with the purpose. Minor redundancy could be trimmed (e.g., 'Returns' details are helpful but slightly verbose).

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

Completeness3/5

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

Given the tool's moderate complexity (3 params, no nested objects, output schema exists), the description covers inputs and return values adequately. However, missing usage guidelines and behavioral transparency reduces completeness. The output schema existence reduces the burden on description for return details, but overall it feels adequate with gaps.

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

Parameters5/5

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

Schema description coverage is 0%, requiring the description to define parameters. It does so effectively: pcap_file as 'HTTP URL or absolute local file path', server_ip as 'Optional filter for server IP address', threshold as 'Retransmission rate threshold (default: 2%)'. This adds essential meaning beyond the bare schema.

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

Purpose5/5

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

The description clearly states 'Analyze TCP retransmission patterns' and explains inputs and outputs, distinguishing it from sibling tools like analyze_tcp_anomalies or analyze_tcp_connections by focusing specifically on retransmissions.

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 does not explicitly state when to use this tool over siblings. While the purpose implies usage for retransmission analysis, there is no guidance on when not to use it or which sibling to use for other needs.

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/mcpcap/mcpacket'

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