Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 13, 2025

Plan: Add selective tool loading to wassette component load

Overview

Implement the ability to selectively load specific tools from a component instead of loading all tools by default.

Changes completed:

  • Explore repository structure and understand component loading mechanism
  • Build project successfully
  • Modify load-component builtin tool schema to accept optional tools parameter (array of tool names)
  • Update handle_load_component and handle_load_component_cli to accept and pass tools parameter
  • Modify LifecycleManager::load_component to accept optional tools filter
  • Update compile_and_register_component to filter tools based on the provided list
  • Add tests for selective tool loading
  • Update documentation to reflect this new feature
  • Run all tests to ensure no regressions
  • Fix linting issues with cargo +nightly fmt
  • Address code review feedback

Implementation Summary:

Core Functionality

  1. ✅ Added tools as an optional array parameter to the load-component tool's input schema
  2. ✅ Created load_component_with_tools method in LifecycleManager that accepts optional tools filter
  3. ✅ Modified compile_and_register_component to filter tool metadata before registration
  4. ✅ Updated both server and CLI handlers to extract and pass the tools filter

CLI Support

  1. ✅ Added --tools option to the component load CLI command
  2. ✅ Updated command handler to pass tools parameter to underlying load-component tool
  3. ✅ Verified CLI functionality with manual testing

Testing

  1. ✅ Added comprehensive test coverage with 4 passing tests:
    • test_selective_tool_loading: Verifies loading only specified tools
    • test_load_all_tools_when_no_filter: Verifies default behavior (load all)
    • test_empty_tools_filter: Verifies empty filter loads no tools
    • test_nonexistent_tool_filter: Verifies graceful handling of non-matching filters

Documentation

  1. ✅ Updated docs/reference/built-in-tools.md:

    • Added tools parameter to load-component documentation
    • Included usage examples for selective tool loading
    • Updated tool description in summary table
  2. ✅ Updated docs/reference/cli.md:

    • Added CLI examples for --tools option
    • Documented comma-separated tool list syntax
    • Included both single and multiple tool examples

Code Quality

  1. ✅ Fixed linting issues with cargo +nightly fmt
  2. ✅ Addressed code review feedback:
    • Extracted duplicated component path logic into helper function
    • Improved performance with HashSet for O(1) tool lookup
    • Extracted duplicated tools filter extraction logic

Feature Usage

MCP Server (via load-component tool):

{
  "path": "oci://ghcr.io/microsoft/fetch-rs:latest",
  "tools": ["fetch"]
}

CLI:

# Load only specific tools
wassette component load oci://ghcr.io/microsoft/fetch-rs:latest --tools fetch

# Load multiple tools
wassette component load file:///path/to/component.wasm --tools tool1,tool2,tool3

Test Results

  • All unit tests passing (4/4)
  • CLI manual testing successful
  • No regressions in existing functionality
  • Code formatting verified with cargo +nightly fmt
Original prompt

wassette component load should be able to pass a argument to select tools to load (by defualt, it loads all the tools).

The built-in load-component should also support that

Last, modify the docs to reflect this new feature


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add argument support for selecting tools to load Add selective tool loading to component load Nov 13, 2025
Copilot AI requested a review from Mossaka November 13, 2025 23:53
@Mossaka Mossaka marked this pull request as ready for review November 14, 2025 03:47
@Mossaka Mossaka force-pushed the copilot/add-load-tools-argument branch from 010745f to 80b4a63 Compare November 14, 2025 04:07
Copilot AI and others added 2 commits November 14, 2025 00:03
- Add optional 'tools' parameter to load-component builtin tool schema
- Update handle_load_component and handle_load_component_cli to extract and pass tools filter
- Add load_component_with_tools method to LifecycleManager
- Modify compile_and_register_component to filter tools based on provided list
- Add comprehensive tests for selective tool loading functionality
- All tests passing successfully

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
- Add --tools option to 'component load' CLI command
- Update CLI help text and command structure
- Update built-in-tools.md with new tools parameter and examples
- Update cli.md with selective tool loading examples
- Verify CLI functionality with manual testing
- All features working correctly

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
@Mossaka Mossaka force-pushed the copilot/add-load-tools-argument branch from 80b4a63 to 8b8f283 Compare November 14, 2025 05:03
@Mossaka
Copy link
Collaborator

Mossaka commented Nov 14, 2025

@copilot resolve the linting issues by running cargo +nightly fmt and then commit

Run cargo +nightly fmt to fix code formatting issues as requested

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 14, 2025

@copilot resolve the linting issues by running cargo +nightly fmt and then commit

Fixed in commit b12d6ee. Ran cargo +nightly fmt to resolve all formatting issues.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements selective tool loading functionality for WebAssembly components, allowing users to load only specific tools from a component instead of loading all tools by default.

Key changes:

  • Added an optional tools parameter to the load-component builtin tool and CLI command to filter which tools get loaded
  • Modified the component loading pipeline to filter tool metadata before registration
  • Added comprehensive test coverage for selective tool loading scenarios

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/selective_tool_loading_test.rs New integration tests covering selective tool loading, empty filters, and non-existent tool filters
crates/wassette/src/lib.rs Added load_component_with_tools method and tools_filter parameter to compile_and_register_component
crates/mcp-server/src/components.rs Updated MCP handlers to extract and pass the optional tools filter parameter
crates/mcp-server/src/tools.rs Updated builtin tool schema to include the optional tools array parameter
src/main.rs Added tools parameter handling in CLI command execution
src/commands.rs Added --tools option with comma-separated value delimiter to the component load CLI command
docs/reference/built-in-tools.md Documented the new tools parameter with usage examples
docs/reference/cli.md Documented the --tools CLI option with examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to 23
let project_root = std::env::current_dir().context("Failed to get current directory")?;
let fetch_component_path = project_root
.join("examples")
.join("fetch-rs")
.join("target")
.join("wasm32-wasip2")
.join("release")
.join("fetch_rs.wasm");
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded path to the fetch-rs component is duplicated across all four test functions. Consider extracting this into a helper function like get_fetch_component_path() to improve maintainability and reduce code duplication.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 6e73d8c. Extracted the duplicated component path logic into a helper function get_fetch_component_path().

total_tools = tool_metadata.len(),
"Filtering tools for component"
);
tool_metadata.retain(|tool| filter.contains(&tool.normalized_name));
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using filter.contains() with a Vec<String> performs linear search for each tool, resulting in O(n*m) complexity where n is the number of tools and m is the filter size. Consider converting the filter to a HashSet before the retain operation for O(n) complexity when dealing with components that have many tools.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 6e73d8c. Converted the filter to a HashSet before the retain operation for O(n) complexity instead of O(n*m).

Comment on lines 56 to 60
let tools_filter = args.get("tools").and_then(|v| v.as_array()).map(|arr| {
arr.iter()
.filter_map(|v| v.as_str().map(|s| s.to_string()))
.collect::<Vec<String>>()
});
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tools filter extraction logic is duplicated in both handle_load_component (lines 56-60) and handle_load_component_cli (lines 410-414). Consider extracting this into a shared helper function to follow the DRY principle.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 6e73d8c. Extracted the tools filter extraction logic into a shared helper function extract_tools_filter().

@Mossaka
Copy link
Collaborator

Mossaka commented Nov 14, 2025

@copilot address the comments

- Extract duplicated component path logic into get_fetch_component_path() helper
- Use HashSet for O(1) lookup performance in tool filtering instead of O(n*m) Vec
- Extract duplicated tools filter extraction logic into shared helper function

All tests passing (4/4)

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 14, 2025

@copilot address the comments

Addressed all comments in commit 6e73d8c:

  • Extracted duplicated component path logic into helper function
  • Improved performance with HashSet for O(1) lookup
  • Extracted duplicated tools filter extraction logic

All tests passing (4/4).

Copilot AI requested a review from Mossaka November 14, 2025 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants