Refactor duplicated code in tool name constants and permission handlers#418
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor duplicated code to improve maintainability
Refactor duplicated code in tool name constants and permission handlers
Oct 17, 2025
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
93ac4a7 to
45714ef
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors duplicated code to improve maintainability by consolidating tool name strings and permission handler logic.
- Introduces centralized
constdefinitions for tool names insrc/main.rs, creating a single source of truth - Consolidates grant permission handlers into a generic helper function, reducing duplication across four permission types
- Consolidates revoke permission handlers into a generic helper function, reducing duplication across two permission types
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main.rs | Refactored ToolName enum to use centralized const definitions, eliminating string duplication between TryFrom and AsRef implementations |
| crates/mcp-server/src/tools.rs | Introduced generic helper functions for grant and revoke permission handlers, consolidating previously duplicated logic |
| CHANGELOG.md | Documented the refactoring changes in the Changed section |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
Mossaka
added a commit
to Mossaka/wassette
that referenced
this pull request
Feb 2, 2026
…rs (microsoft#418) Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com> Co-authored-by: Jiaxiao Zhou <duibao55328@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR refactors duplicated code across the codebase to improve maintainability and reduce technical debt by consolidating similar logic into reusable helper functions and centralized constants.
Changes Made
1. Tool Name Constants (
src/main.rs)Before: Tool name strings were duplicated across both
TryFromandAsReftrait implementations, requiring changes in two places whenever a tool name needed updating.After: Centralized
constdefinitions provide a single source of truth:2. Grant Permission Handlers (
crates/mcp-server/src/tools.rs)Before: Four nearly identical functions (~50 lines each) for granting different permission types:
handle_grant_storage_permissionhandle_grant_network_permissionhandle_grant_environment_variable_permissionhandle_grant_memory_permissionEach function duplicated the same logic: extract arguments, validate component_id, ensure component loaded, call lifecycle_manager, format response.
After: Generic helper function with thin wrappers:
Impact: Reduced ~150 lines of duplicated code while maintaining identical functionality and error handling.
3. Revoke Permission Handlers (
crates/mcp-server/src/tools.rs)Before: Two nearly identical functions for revoking permissions:
handle_revoke_network_permissionhandle_revoke_environment_variable_permissionAfter: Generic helper function following the same pattern as grant handlers.
Note:
handle_revoke_storage_permissionintentionally kept separate because it uses a different internal API (revoke_storage_permission_by_urivsrevoke_permission).Results
cargo +nightly fmtBenefits
This refactoring addresses technical debt without introducing new features or breaking changes, making the codebase more maintainable for future development.
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.