Skip to content

feat: MCP tool for adding tree controls #23

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wuyiping0628
Copy link
Collaborator

@wuyiping0628 wuyiping0628 commented Jun 20, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a Tree component for displaying and interacting with hierarchical data.
    • Added new route and view for the Tree component in the documentation site.
    • Provided tools for manipulating tree nodes, such as selecting, expanding, collapsing, removing, and inserting nodes.
  • Documentation

    • Added English and Chinese documentation for the Tree component and its features.
  • Localization

    • Enhanced localization support with new tree-related tool descriptions in both English and Chinese.
  • Style

    • Included scoped styles for the new Tree component view.

Copy link

coderabbitai bot commented Jun 20, 2025

Walkthrough

A Tree component and related tools were integrated into the project. This includes adding the TinyTree component globally, introducing a new route and view for displaying the tree, providing internationalized documentation and tool descriptions, and implementing a set of tree manipulation utilities with parameter validation and localized resources.

Changes

Files/Paths Change Summary
docs/components.d.ts Added TinyTree to Vue global components interface.
docs/src/router/index.ts Added /tree route mapping to a new Tree view component.
docs/src/views/tree/tree.vue Introduced a new Vue component rendering a hierarchical tree using TinyTree with interactive features.
packages/mcp/index.ts Registered Tree component configuration in MCP components.
packages/mcp/src/lang/en.ts
packages/mcp/src/lang/zh-CN.ts
Added localized tree tool descriptions and updated button tool string (en only).
packages/mcp/src/tree/index.ts Introduced tree utilities: export of localized resources and getTreeConfig with tree manipulation tools and validation.
packages/mcp/src/tree/resouces.en.md
packages/mcp/src/tree/resouces.zh.md
Added English and Chinese markdown documentation for the Tree component.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Router
    participant TreeView
    participant TinyTree

    User->>Router: Navigate to /tree
    Router->>TreeView: Render tree.vue
    TreeView->>TinyTree: Pass tree data and config
    User->>TinyTree: Interact (select, check, etc.)
    TinyTree-->>TreeView: Emit events (node toggled, checked)
Loading
sequenceDiagram
    participant Tool
    participant getTreeConfig
    participant TreeInstance

    Tool->>getTreeConfig: Request tree tool (e.g., setCurrentKey)
    getTreeConfig->>TreeInstance: Execute operation (e.g., set current node)
    TreeInstance-->>getTreeConfig: Operation result
    getTreeConfig-->>Tool: Return success message
Loading

Poem

🌳
Oh, what a tree we’ve grown today,
With branches stretching every way!
New routes to walk, new tools to try,
In many tongues, the leaves reply.
A bunny hops from node to node—
In this fresh forest, code bestowed!
🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch wyp/tree-mcp-0611

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@wuyiping0628 wuyiping0628 added the enhancement New feature or request label Jun 20, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🔭 Outside diff range comments (2)
packages/mcp/src/tree/resouces.en.md (1)

1-4: Fix filename typo: resouces.en.mdresources.en.md.
The directory and import paths likely expect “resources” instead of “resouces”. Rename the file and update any import statements accordingly to avoid missing file errors.

packages/mcp/src/tree/resouces.zh.md (1)

1-4: Fix filename typo: resouces.zh.mdresources.zh.md.
Rename this file to correct the spelling and align with its English counterpart. Update import references in the codebase.

🧹 Nitpick comments (5)
docs/src/router/index.ts (1)

20-24: Consider naming the Webpack chunk for the Tree route.
Adding a /* webpackChunkName: "tree" */ comment to the dynamic import can improve chunk naming and debugging during code splitting.

docs/src/views/tree/tree.vue (3)

2-2: Remove unused CSS classes and fix container class mismatch.

The template uses .ecs-container class but the CSS defines .checkbox-demo classes that are never used. This creates confusion and unnecessary code.

 <template>
-  <div class="ecs-container">
+  <div class="tree-container">
-.checkbox-demo {
+.tree-container {
   display: flex;
   margin: 16px;
 }
 
-.checkbox-demo .tiny-tree {
+.tree-container .tiny-tree {
   flex: 1;
   min-width: 300px;
 }
 
-.checkbox-demo div {
+.tree-container div {
   margin-bottom: 8px;
 }

Also applies to: 57-75


30-47: Improve data structure consistency and formatting.

The tree data has inconsistent spacing and formatting that affects readability and maintainability.

       { id: '2', label: ' windows', 
         children: [
-            { id: '3', label: ' windows 10' },
-            { id: '4', label: ' windows 11' },
-            { id: '5', label: ' windows 12' },
-            { id: '7', label: ' windows 13' }
+          { id: '3', label: 'Windows 10' },
+          { id: '4', label: 'Windows 11' },
+          { id: '5', label: 'Windows 12' },
+          { id: '7', label: 'Windows 13' }
         ]
-        },
+      },
       { id: '8', label: 'linux',
         children: [
-            { id: '9', label: 'linux 10' },
-            { id: '10', label: 'linux 11' },
-            { id: '11', label: 'linux 12' },
-            { id: '12', label: 'linux 13' }
+          { id: '9', label: 'Linux 10' },
+          { id: '10', label: 'Linux 11' },
+          { id: '11', label: 'Linux 12' },
+          { id: '12', label: 'Linux 13' }
         ]
       },
-      { id: '13', label: 'macos'},
-      { id: '14', label: 'harmonyOS'},
+      { id: '13', label: 'macOS'},
+      { id: '14', label: 'HarmonyOS'},

7-9: Consider internationalization for business description.

The business description is hardcoded in Chinese, but this component may be used in international contexts.

Consider using the localization system:

         business: {
           id: 'cpu-tree',
-          description: 'CPU规格的树'
+          description: t('tree.cpuSpecTree') // Add to localization files
         }
packages/mcp/src/lang/en.ts (1)

31-31: Improve button description consistency.

The modified button description has grammatical issues and inconsistent formatting.

-      triggerClick: 'trigger button click,click self'
+      triggerClick: 'Trigger button click'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5dfbe90 and a12ee3c.

📒 Files selected for processing (9)
  • docs/components.d.ts (1 hunks)
  • docs/src/router/index.ts (1 hunks)
  • docs/src/views/tree/tree.vue (1 hunks)
  • packages/mcp/index.ts (2 hunks)
  • packages/mcp/src/lang/en.ts (1 hunks)
  • packages/mcp/src/lang/zh-CN.ts (1 hunks)
  • packages/mcp/src/tree/index.ts (1 hunks)
  • packages/mcp/src/tree/resouces.en.md (1 hunks)
  • packages/mcp/src/tree/resouces.zh.md (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/mcp/index.ts (1)
packages/mcp/src/tree/index.ts (1)
  • getTreeConfig (12-70)
🔇 Additional comments (2)
docs/components.d.ts (1)

22-22: New global component declaration is correct.
The TinyTree component has been added to GlobalComponents as expected, enabling its use across Vue templates.

packages/mcp/src/lang/zh-CN.ts (1)

25-34: LGTM! Well-structured localization additions.

The Chinese localization follows the existing patterns and provides clear, descriptive text for all tree operations. The structure is consistent with other component sections.

tree: {
description: 'Collection of Tools Related to Tree Control Components',
setCurrentKey: 'Please enter the ID value to set the current selected state of a node',
expandHlNode: 'Please enter the ID value to set the current deployment status of a node',
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix terminology: "deployment" should be "expanded".

The term "deployment status" is incorrect in the context of tree nodes. It should refer to the expanded/collapsed state.

-      expandHlNode: 'Please enter the ID value to set the current deployment status of a node',
+      expandHlNode: 'Please enter the ID value to set the expanded state of a node',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expandHlNode: 'Please enter the ID value to set the current deployment status of a node',
expandHlNode: 'Please enter the ID value to set the expanded state of a node',
🤖 Prompt for AI Agents
In packages/mcp/src/lang/en.ts at line 36, the phrase "deployment status" is
incorrect for describing the state of a tree node. Replace "deployment status"
with "expanded state" to accurately reflect the node's expanded or collapsed
condition.

}
},
insertBefore: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertBefore')),
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve validation schema for insert operations.

The current schema z.record(z.any()) is too permissive and doesn't validate the required structure for insert operations.

-        paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertBefore')),
+        paramsSchema: z.object({
+          id: z.string().describe('Target node ID'),
+          label: z.string().describe('New node label')
+        }).describe(t('ai.tree.insertBefore')),

Apply the same change to insertAfter:

-        paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertAfter')),
+        paramsSchema: z.object({
+          id: z.string().describe('Target node ID'),
+          label: z.string().describe('New node label')
+        }).describe(t('ai.tree.insertAfter')),

Also applies to: 61-61

🤖 Prompt for AI Agents
In packages/mcp/src/tree/index.ts at lines 52 and 61, the validation schema for
insert operations uses z.record(z.any()), which is too permissive and does not
enforce the required structure. Update the schema to a more specific zod schema
that accurately reflects the expected shape of the insert operation parameters,
ensuring proper validation. Apply this improved schema to both insertBefore
(line 52) and insertAfter (line 61).

Comment on lines +28 to +43
expandHlNode: {
paramsSchema: z.string().optional().describe(t('ai.tree.expandHlNode')),
cb: (instance, value) => {
const node = instance.getNode(value)
node.expand()
return { type: 'text', text: 'success' }
}
},
collapseHlNode: {
paramsSchema: z.string().optional().describe(t('ai.tree.collapseHlNode')),
cb: (instance, value) => {
const node = instance.getNode(value)
node.collapse()
return { type: 'text', text: 'success' }
}
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for node operations.

The expandHlNode and collapseHlNode functions don't handle cases where getNode() returns null/undefined or when the value parameter is undefined.

       expandHlNode: {
         paramsSchema:  z.string().optional().describe(t('ai.tree.expandHlNode')),
         cb: (instance, value) => {
+          if (!value) {
+            return { type: 'text', text: 'Error: ID value is required' }
+          }
           const node = instance.getNode(value)
+          if (!node) {
+            return { type: 'text', text: `Error: Node with ID ${value} not found` }
+          }
           node.expand()
           return { type: 'text', text: 'success' }
         }
       },
       collapseHlNode: {
         paramsSchema:  z.string().optional().describe(t('ai.tree.collapseHlNode')),
         cb: (instance, value) => {
+          if (!value) {
+            return { type: 'text', text: 'Error: ID value is required' }
+          }
           const node = instance.getNode(value)
+          if (!node) {
+            return { type: 'text', text: `Error: Node with ID ${value} not found` }
+          }
           node.collapse()
           return { type: 'text', text: 'success' }
         }
       },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expandHlNode: {
paramsSchema: z.string().optional().describe(t('ai.tree.expandHlNode')),
cb: (instance, value) => {
const node = instance.getNode(value)
node.expand()
return { type: 'text', text: 'success' }
}
},
collapseHlNode: {
paramsSchema: z.string().optional().describe(t('ai.tree.collapseHlNode')),
cb: (instance, value) => {
const node = instance.getNode(value)
node.collapse()
return { type: 'text', text: 'success' }
}
},
expandHlNode: {
paramsSchema: z.string().optional().describe(t('ai.tree.expandHlNode')),
cb: (instance, value) => {
if (!value) {
return { type: 'text', text: 'Error: ID value is required' }
}
const node = instance.getNode(value)
if (!node) {
return { type: 'text', text: `Error: Node with ID ${value} not found` }
}
node.expand()
return { type: 'text', text: 'success' }
}
},
collapseHlNode: {
paramsSchema: z.string().optional().describe(t('ai.tree.collapseHlNode')),
cb: (instance, value) => {
if (!value) {
return { type: 'text', text: 'Error: ID value is required' }
}
const node = instance.getNode(value)
if (!node) {
return { type: 'text', text: `Error: Node with ID ${value} not found` }
}
node.collapse()
return { type: 'text', text: 'success' }
}
},
🤖 Prompt for AI Agents
In packages/mcp/src/tree/index.ts around lines 28 to 43, the expandHlNode and
collapseHlNode callbacks do not handle cases where the value parameter is
undefined or getNode(value) returns null or undefined. Add checks to verify that
value is defined and that getNode(value) returns a valid node before calling
expand() or collapse(). If these checks fail, return an error response instead
of proceeding with the operation.

Comment on lines +17 to +27
setCurrentKey: {
paramsSchema: z.string().optional().describe(t('ai.tree.setCurrentKey')),
cb: (instance, value) => {
if(instance.showCheckbox){
instance.setCheckedKeys([value])
}else{
instance.setCurrentKey(value)
}
return { type: 'text', text: 'success' }
}
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for undefined values.

The setCurrentKey function doesn't handle the case where value is undefined, which is possible since the schema uses .optional().

       setCurrentKey: {
         paramsSchema:  z.string().optional().describe(t('ai.tree.setCurrentKey')),
         cb: (instance, value) => {
+          if (!value) {
+            return { type: 'text', text: 'Error: ID value is required' }
+          }
           if(instance.showCheckbox){
             instance.setCheckedKeys([value])
           }else{
             instance.setCurrentKey(value)
           }
           return { type: 'text', text: 'success' }
         }
       },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setCurrentKey: {
paramsSchema: z.string().optional().describe(t('ai.tree.setCurrentKey')),
cb: (instance, value) => {
if(instance.showCheckbox){
instance.setCheckedKeys([value])
}else{
instance.setCurrentKey(value)
}
return { type: 'text', text: 'success' }
}
},
setCurrentKey: {
paramsSchema: z.string().optional().describe(t('ai.tree.setCurrentKey')),
cb: (instance, value) => {
if (!value) {
return { type: 'text', text: 'Error: ID value is required' }
}
if(instance.showCheckbox){
instance.setCheckedKeys([value])
}else{
instance.setCurrentKey(value)
}
return { type: 'text', text: 'success' }
}
},
🤖 Prompt for AI Agents
In packages/mcp/src/tree/index.ts between lines 17 and 27, the setCurrentKey
callback does not handle the case when the value parameter is undefined, which
can occur because the paramsSchema marks it as optional. Add a check at the
start of the callback to verify if value is undefined, and if so, return an
appropriate error response or handle it gracefully to prevent runtime errors.
This ensures the function only proceeds with valid defined values.

Comment on lines +51 to +68
insertBefore: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertBefore')),
cb: (instance, value) => {
let id = 1000
instance.insertBefore({ id, label: value.label }, value.id)
id++
return { type: 'text', text: 'success' }
}
},
insertAfter: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertAfter')),
cb: (instance, value) => {
let id = 1000
instance.insertAfter({ id, label: value.label }, value.id)
id++
return { type: 'text', text: 'success' }
}
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix ID generation logic causing duplicate IDs.

The insertBefore and insertAfter functions have a critical bug where the id variable is redeclared each time, always resulting in ID 1000. This will cause duplicate IDs and potential conflicts.

+let nextId = 1000 // Move outside the functions

       insertBefore: {
         paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertBefore')),
         cb: (instance, value) => {
-          let id = 1000
-          instance.insertBefore({ id, label: value.label }, value.id)
-          id++
+          if (!value || !value.id || !value.label) {
+            return { type: 'text', text: 'Error: Both id and label are required' }
+          }
+          instance.insertBefore({ id: nextId++, label: value.label }, value.id)
           return { type: 'text', text: 'success' }
         }
       },
       insertAfter: {
         paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertAfter')),
         cb: (instance, value) => {
-          let id = 1000
-          instance.insertAfter({ id, label: value.label }, value.id)
-          id++
+          if (!value || !value.id || !value.label) {
+            return { type: 'text', text: 'Error: Both id and label are required' }
+          }
+          instance.insertAfter({ id: nextId++, label: value.label }, value.id)
           return { type: 'text', text: 'success' }
         }
       },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
insertBefore: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertBefore')),
cb: (instance, value) => {
let id = 1000
instance.insertBefore({ id, label: value.label }, value.id)
id++
return { type: 'text', text: 'success' }
}
},
insertAfter: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertAfter')),
cb: (instance, value) => {
let id = 1000
instance.insertAfter({ id, label: value.label }, value.id)
id++
return { type: 'text', text: 'success' }
}
},
// Move this to the top of the file (module scope)
let nextId = 1000
insertBefore: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertBefore')),
cb: (instance, value) => {
if (!value || !value.id || !value.label) {
return { type: 'text', text: 'Error: Both id and label are required' }
}
instance.insertBefore(
{ id: nextId++, label: value.label },
value.id
)
return { type: 'text', text: 'success' }
}
},
insertAfter: {
paramsSchema: z.record(z.any()).optional().describe(t('ai.tree.insertAfter')),
cb: (instance, value) => {
if (!value || !value.id || !value.label) {
return { type: 'text', text: 'Error: Both id and label are required' }
}
instance.insertAfter(
{ id: nextId++, label: value.label },
value.id
)
return { type: 'text', text: 'success' }
}
},
🤖 Prompt for AI Agents
In packages/mcp/src/tree/index.ts around lines 51 to 68, the id variable is
redeclared and reset to 1000 inside each callback, causing duplicate IDs. To fix
this, move the id declaration outside the callback functions so it persists
across calls and increments properly, ensuring unique IDs are generated for each
insertBefore and insertAfter operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant