mcp-security
mcp-security copied to clipboard
[gti-mcp] Fix collection/file tool bugs and trim verbose response fields without dropping core threat indicators
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_typecompares the loop variable against itself (alwaysFalse) instead of checkingrule_types.- Using
and not rulesinstead ofor not rulesmeans any unrequestedrule_typewith non-emptyrulesstill 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_fileis annotated with-> list[dict[str, typing.Any]]:, but whenrelationship_name not in FILE_RELATIONSHIPS, it returns adict({"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 withget_entities_related_to_a_collectionincollections.py).
3. Unhandled KeyError: 'data' in get_collections_commonalities
In server/gti/gti_mcp/tools/collections.py (lines 645-652):
get_collections_commonalitiesaccessesdata["data"]directly without checking whether"data"is present in the API response, raising an unhandledKeyError: '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 optionalextra_excluded_attrsin_search_threats_by_collection_typeto exclude verbose vulnerability metadata (cpes,vendor_fix_references,sources,version_history,field_sources,tags_details,alt_names_details) viaexclude_attributes.get_entities_related_to_a_file(files.py): Only passexclude_attributeswhenrelationship_name == "behaviours" and not descriptors_only(rather than unconditionally across all 41 file relationships), and only exclude genuinely bulky raw dump fields (such asmemory_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).