mcp-security icon indicating copy to clipboard operation
mcp-security copied to clipboard

[gti-mcp] Fix collection/file tool bugs and trim verbose response fields without dropping core threat indicators

Open dandye opened this issue 1 month ago • 0 comments

Summary

Several bugs and response-size issues in server/gti/gti_mcp/ were surfaced during triage of #275:

1. Broken rule_types filter condition in get_collection_rules

In server/gti/gti_mcp/tools/collections.py (line 755):

for key, rule_type in rule_keys_map.items():
  rules = files_aggregations.get(key, [])
  if rule_type not in rule_type and not rules:
    continue
  • rule_type not in rule_type compares the loop variable against itself (always False) instead of checking rule_types.
  • Using and not rules instead of or not rules means any unrequested rule_type with non-empty rules still executes and returns rules.
  • Fix: Change to if rule_type not in rule_types or not rules:.

2. Return type annotation mismatch on error path in get_entities_related_to_a_file

In server/gti/gti_mcp/tools/files.py (lines 138-183):

  • get_entities_related_to_a_file is annotated with -> list[dict[str, typing.Any]]:, but when relationship_name not in FILE_RELATIONSHIPS, it returns a dict ({"error": ...}), causing FastMCP structured-output validation to fail on invalid relationship names.
  • Fix: Widen the return type annotation to typing.Union[typing.List[typing.Dict[str, typing.Any]], typing.Dict[str, str]] (consistent with get_entities_related_to_a_collection in collections.py).

3. Unhandled KeyError: 'data' in get_collections_commonalities

In server/gti/gti_mcp/tools/collections.py (lines 645-652):

  • get_collections_commonalities accesses data["data"] directly without checking whether "data" is present in the API response, raising an unhandled KeyError: 'data' when a collection ID does not exist or the API returns an error payload.
  • Fix: Guard if "data" not in data: and return a clean error message or dictionary.

4. Scoped response payload trimming for verbose GTI fields

Several GTI endpoints return large administrative or raw dump fields that bloat LLM context windows, but trimming must not strip high-signal threat analysis fields:

  • search_vulnerabilities (collections.py): Support optional extra_excluded_attrs in _search_threats_by_collection_type to exclude verbose vulnerability metadata (cpes, vendor_fix_references, sources, version_history, field_sources, tags_details, alt_names_details) via exclude_attributes.
  • get_entities_related_to_a_file (files.py): Only pass exclude_attributes when relationship_name == "behaviours" and not descriptors_only (rather than unconditionally across all 41 file relationships), and only exclude genuinely bulky raw dump fields (such as memory_dumps) while preserving core behavioral fields (processes_tree, processes_created, command_executions, ip_traffic, http_conversations, files_dropped, attack_techniques, signature_matches, ids_alerts, mutexes_created).
  • get_file_behavior_summary (files.py) & get_collections_commonalities (collections.py): Only strip low-signal/bulk metadata fields (e.g., memory_dumps, text_highlighted, exiftool_*, office_*, main_icon_*) while retaining core hunting and behavioral pivots (processes_tree, command_executions, ip_traffic, attack_techniques, imphash, vhash, tlshhash, crowdsourced_yara_results, crowdsourced_sigma_results, crowdsourced_ids_results, itw_urls, embedded_domains, embedded_ips).

dandye avatar Oct 27 '26 02:10 dandye