Skip to main content
Glama
mcpcap

mcpacket

by mcpcap

analyze_capinfos

Extract metadata from PCAP files, including packet statistics, file information, and temporal data, by providing a local path or remote URL.

Instructions

Return metadata from a PCAP file, similar to Wireshark's capinfos utility.

IMPORTANT: This tool expects a FILE PATH or URL, not file content.

  • For local files: "/path/to/capture.pcap"

  • For remote files: "https://example.com/capture.pcap"

  • File uploads are NOT supported - save the file locally first

Args: pcap_file: Path to local PCAP file or HTTP URL to remote PCAP file (NOT file content - must be a path or URL)

Returns: A structured dictionary containing PCAP metadata including: - File information (size, name, encapsulation type) - Packet statistics (count, data size, average sizes) - Temporal data (duration, timestamps, rates)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pcap_fileYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler for the 'analyze_capinfos' tool. Delegates to the inherited 'analyze_packets' method from BaseModule.
    def analyze_capinfos(self, pcap_file: str) -> dict[str, Any]:
        """
        Return metadata from a PCAP file, similar to Wireshark's capinfos utility.
    
        IMPORTANT: This tool expects a FILE PATH or URL, not file content.
        - For local files: "/path/to/capture.pcap"
        - For remote files: "https://example.com/capture.pcap"
        - File uploads are NOT supported - save the file locally first
    
        Args:
            pcap_file: Path to local PCAP file or HTTP URL to remote PCAP file
                      (NOT file content - must be a path or URL)
    
        Returns:
            A structured dictionary containing PCAP metadata including:
            - File information (size, name, encapsulation type)
            - Packet statistics (count, data size, average sizes)
            - Temporal data (duration, timestamps, rates)
        """
        return self.analyze_packets(pcap_file)
  • Actual protocol analysis implementation: reads a local PCAP file with rdpcap, generates file info and packet statistics.
    def _analyze_protocol_file(self, pcap_file: str) -> dict[str, Any]:
        """Perform the actual information gathering on a local PCAP file."""
        try:
            packets = rdpcap(pcap_file)
    
            # Generate statistics
            stats = self._generate_statistics(packets)
    
            results = {
                "file_size_bytes": os.path.getsize(pcap_file),
                "filename": os.path.basename(pcap_file),
                "file_encapsulation": self._detect_linktype(pcap_file),
            }
    
            return results | stats
    
        except Exception as e:
            return {
                "error": f"Error reading PCAP file '{pcap_file}': {str(e)}",
                "file": pcap_file,
            }
  • Helper that computes packet statistics (count, sizes, timing, rates) similar to Wireshark's capinfos utility.
    def _generate_statistics(self, packet_details: list) -> dict[str, Any]:
        """Return metadata about the capture file, similar to capinfos(1) utility."""
        if not packet_details:
            return {"error": "No packets found"}
    
        packet_count = len(packet_details)
        data_size = sum(len(pkt) for pkt in packet_details)
        first_time = float(packet_details[0].time)
        last_time = float(packet_details[-1].time)
        duration = max(last_time - first_time, 0.000001)
        data_byte_rate = data_size / duration if duration > 0 else 0
        data_bit_rate = (data_size * 8) / duration if duration > 0 else 0
        avg_packet_size = data_size / packet_count if packet_count > 0 else 0
        avg_packet_rate = packet_count / duration if duration > 0 else 0
    
        return {
            "packet_count": packet_count,
            "data_size_bytes": data_size,
            "capture_duration_seconds": duration,
            "first_packet_time": first_time,
            "last_packet_time": last_time,
            "data_rate_bytes": data_byte_rate,
            "data_rate_bits": data_bit_rate,
            "average_packet_size_bytes": avg_packet_size,
            "average_packet_rate": avg_packet_rate,
        }
  • Helper to detect and map the link-layer encapsulation type to a human-readable name.
    def _detect_linktype(self, path: str) -> str:
        """Detect the linktype and try to map it to a human-readable encapsulation type.
    
        Args:
            path: Path to the packet capture
    
        Returns:
            Detected link-layer header (linktype)
    
        """
        # mapping based on pcap-linktype(7) and https://github.com/wireshark/wireshark/blob/master/wiretap/wtap.c#L656
        LINKTYPE_MAP = {
            1: "Ethernet",
            101: "Raw IP",
            105: "IEEE 802.11 Wireless LAN",
            113: "Linux cooked-mode capture v1",
            228: "Raw IPv4",
            229: "Raw IPv6",
            276: "Linux cooked-mode capture v2",
        }
        try:
            with PcapReader(path) as reader:
                linktype = getattr(reader, "linktype", None)
        except Exception:
            linktype = None
    
        return LINKTYPE_MAP.get(
            linktype, f"Unknown ({linktype})" if linktype else "Unknown"
        )
  • Registration of 'analyze_capinfos' as an MCP tool via self.mcp.tool().
    elif module_name == "capinfos":
        self.mcp.tool(module.analyze_capinfos)
Behavior4/5

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

With no annotations, the description carries full behavioral burden. It clearly states the tool returns a structured dictionary of metadata and warns about input type. It does not mention destructive actions, authentication, or rate limits, but these are not relevant for a read-only metadata tool. Could add notes on large file handling.

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

Conciseness5/5

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

The description is well-structured with an important note, clear args/returns sections, and no unnecessary words. Every sentence adds value, making it efficient and easy to parse.

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

Completeness5/5

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

Given the single parameter (well-documented in description), presence of an output schema (mentioned but not shown), and no annotations, the description fully covers what an agent needs to use the tool correctly: what it does, how to input, and what output to expect.

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?

The input schema has 0% coverage for the single parameter, but the description provides comprehensive semantics: it explains the parameter is a file path or URL, not content, gives concrete examples, and specifies the required format. This fully compensates for the missing schema description.

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 the tool returns metadata from a PCAP file, similar to Wireshark's capinfos. It specifies the input type (file path or URL) and lists the kinds of metadata returned (file info, packet stats, temporal data), distinguishing it from sibling analysis tools.

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

Usage Guidelines4/5

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

The description explicitly says it expects a file path or URL, not file content, and gives examples for local and remote files. It also notes that file uploads are not supported and advises saving locally first. However, it does not explicitly compare with sibling tools or state when to use this tool over others.

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