-
Notifications
You must be signed in to change notification settings - Fork 55
Add selective tool loading to component load #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
010745f to
80b4a63
Compare
- 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>
80b4a63 to
8b8f283
Compare
|
@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>
There was a problem hiding this 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
toolsparameter to theload-componentbuiltin 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.
tests/selective_tool_loading_test.rs
Outdated
| 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"); |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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().
crates/wassette/src/lib.rs
Outdated
| total_tools = tool_metadata.len(), | ||
| "Filtering tools for component" | ||
| ); | ||
| tool_metadata.retain(|tool| filter.contains(&tool.normalized_name)); |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
crates/mcp-server/src/components.rs
Outdated
| 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>>() | ||
| }); |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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().
|
@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>
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:
load-componentbuiltin tool schema to accept optionaltoolsparameter (array of tool names)handle_load_componentandhandle_load_component_clito accept and pass tools parameterLifecycleManager::load_componentto accept optional tools filtercompile_and_register_componentto filter tools based on the provided listImplementation Summary:
Core Functionality
toolsas an optional array parameter to theload-componenttool's input schemaload_component_with_toolsmethod in LifecycleManager that accepts optional tools filtercompile_and_register_componentto filter tool metadata before registrationCLI Support
--toolsoption to thecomponent loadCLI commandTesting
test_selective_tool_loading: Verifies loading only specified toolstest_load_all_tools_when_no_filter: Verifies default behavior (load all)test_empty_tools_filter: Verifies empty filter loads no toolstest_nonexistent_tool_filter: Verifies graceful handling of non-matching filtersDocumentation
✅ Updated
docs/reference/built-in-tools.md:✅ Updated
docs/reference/cli.md:Code Quality
cargo +nightly fmtFeature Usage
MCP Server (via load-component tool):
{ "path": "oci://ghcr.io/microsoft/fetch-rs:latest", "tools": ["fetch"] }CLI:
Test Results
Original prompt
💡 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.