Add MCP Resources for ROS Metadata etc #205
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale
Tools are great for operations, but they're not ideal for read-only data that gets accessed frequently. Every tool call is a full round-trip with no caching, and LLMs need to know tool names ahead of time to use them.
Features added
MCP Resources solve this by:
list_resources(), so LLMs can discover what's availableFor example, getting a full ROS system snapshot currently requires calling
get_topics(),get_services(),get_nodes(), andget_parameters()separately. With resources, it's one call toros-mcp://ros-metadata/allthat returns everything, and the client caches it.Implementation
Added two resources:
ros-mcp://ros-metadata/all- Aggregates all ROS system info (topics, services, nodes, parameters, ROS version) in a single JSON response. Handles ROS1/ROS2 differences gracefully.ros-mcp://robot-specs/get_all_robots- Lists available robot specification files for discovery.Both resources are registered in
resources/__init__.pyand automatically loaded on server startup. Also fixed a bug where the metadata resource was calling the non-existent/rosapi/parametersservice - now correctly uses/rosapi/get_param_names.Fully backward compatible - all existing tools remain unchanged. Resources complement tools rather than replace them.
Future Plans
If we agree, I plan to convert simple read-only list operations (like
get_topics(),get_services(),get_nodes()) into resources for better caching and discovery, while keeping parameterized queries (likeget_topic_type(topic),get_parameter(name)) as tools since they require specific inputs and benefit from structured error handling. This will help ROS discovery and introspection while keeping the number of tools limited. At the same time I am planning to merge some tools (inspect + details/type) for better clarity.