Skip to content

Bug: Topics metadata missing fallback for empty types array #237

@mokcontoro

Description

@mokcontoro

Description

In ros_mcp/resources/ros_metadata.py, the get_all_ros_metadata() function has a vulnerability in the topics handling code that mirrors the bug fixed in PR #236 for services.

Problem

The topics code at lines 78-81 uses:

metadata["topics"] = [
    {"name": topic, "type": topic_type}
    for topic, topic_type in zip(topics, types)
]

If types is empty or has a different length than topics, this will silently drop topics - the same issue that was fixed for services.

Expected Behavior

Topics should be returned with "type": "unknown" when type information is unavailable, rather than being dropped entirely.

Suggested Fix

Apply the same fallback pattern used for services:

if types and len(types) == len(topics):
    metadata["topics"] = [
        {"name": topic, "type": topic_type}
        for topic, topic_type in zip(topics, types)
    ]
else:
    metadata["topics"] = [
        {"name": topic, "type": "unknown"} for topic in topics
    ]

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions