Skip to content

feat: 添加form表单的mcp工具 #22

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
Open

feat: 添加form表单的mcp工具 #22

wants to merge 2 commits into from

Conversation

James-9696
Copy link
Collaborator

@James-9696 James-9696 commented Jun 16, 2025

feat: 添加form表单的mcp工具

Summary by CodeRabbit

  • New Features
    • Introduced a form validation demo page at the /form route demonstrating diverse input types and validation methods.
    • Added form manipulation tools including reset, clear validation, and field-specific or full form validation.
  • Documentation
    • Provided English and Chinese documentation outlining the form component and its capabilities.
    • Enhanced localization with detailed form-related descriptions in English and Chinese.

Copy link

coderabbitai bot commented Jun 16, 2025

Walkthrough

A form validation feature has been introduced, including a new Vue route and component demonstrating form validation with TinyVue UI. Supporting this, a form configuration module and localization resources in English and Chinese were added, and the MCP configuration was updated to register the new form tools.

Changes

File(s) Change Summary
docs/src/router/index.ts Added /form route mapped to a new form validation component.
docs/src/views/form/form-validate.vue Introduced a new Vue SFC demonstrating form validation with TinyVue UI, including multiple fields and validation logic.
packages/mcp/index.ts Registered the new Form component in the MCP configuration using getFormConfig().
packages/mcp/src/form/index.ts Added a module exporting getFormConfig, providing form manipulation tools and localized resources.
packages/mcp/src/form/resouces.en.md
packages/mcp/src/form/resouces.zh.md
Added English and Chinese markdown documentation describing the form component.
packages/mcp/src/lang/en.ts
packages/mcp/src/lang/zh-CN.ts
Added localized strings for form-related tool descriptions under the ai.form namespace.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Router
    participant FormComponent
    participant MCPFormTools

    User->>Router: Navigate to /form
    Router->>FormComponent: Render form-validate.vue
    User->>FormComponent: Fill form fields and submit
    FormComponent->>MCPFormTools: Call validate/resetFields/clearValidate etc.
    MCPFormTools-->>FormComponent: Return validation result or reset/clear status
    FormComponent-->>User: Show success or error dialog
Loading

Poem

In fields of forms, a rabbit hops,
With TinyVue tools, it never stops.
Validation dances, errors clear,
Success and failure both appear.
English and Chinese guide the way—
Forms are smarter, starting today!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feat-form-mcp

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.

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: 2

🧹 Nitpick comments (5)
packages/mcp/src/form/resouces.zh.md (1)

1-3: Fix filename typo: "resouces" should be "resources".

The documentation content is appropriate, but the filename contains a typo. Consider renaming resouces.zh.md to resources.zh.md for consistency and correctness.

packages/mcp/src/form/resouces.en.md (1)

1-3: Fix filename typo: "resouces" should be "resources".

The documentation content accurately describes the form component functionality. However, the filename should be corrected from resouces.en.md to resources.en.md.

packages/mcp/src/form/index.ts (3)

17-23: Align parameter schema with callback implementation.

The resetFields tool defines a boolean parameter schema but the callback doesn't use the parameter. Consider removing the parameter schema since resetFields typically doesn't need parameters.

Apply this diff to simplify the tool:

-        paramsSchema: z.boolean().optional().describe(t('ai.form.resetFields')),
-        cb: (instance) => {
+        paramsSchema: z.object({}).describe(t('ai.form.resetFields')),
+        cb: (instance) => {

38-44: Align parameter schema with callback implementation.

Similar to resetFields, this tool defines a boolean parameter schema but doesn't use the parameter in the callback. Consider simplifying the schema.

Apply this diff:

-        paramsSchema: z.boolean().optional().describe(t('ai.form.clearValidateAll')),
+        paramsSchema: z.object({}).describe(t('ai.form.clearValidateAll')),

45-51: Fix parameter schema and approve async validation logic.

The async validation logic is correctly implemented with proper success/fail responses. However, the boolean parameter schema should be aligned with the callback implementation.

Apply this diff to fix the parameter schema:

-        paramsSchema: z.boolean().optional().describe(t('ai.form.validate')),
+        paramsSchema: z.object({}).describe(t('ai.form.validate')),
📜 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 9290c10.

📒 Files selected for processing (8)
  • docs/src/router/index.ts (1 hunks)
  • docs/src/views/form/form-validate.vue (1 hunks)
  • packages/mcp/index.ts (2 hunks)
  • packages/mcp/src/form/index.ts (1 hunks)
  • packages/mcp/src/form/resouces.en.md (1 hunks)
  • packages/mcp/src/form/resouces.zh.md (1 hunks)
  • packages/mcp/src/lang/en.ts (1 hunks)
  • packages/mcp/src/lang/zh-CN.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/mcp/src/form/index.ts (2)
packages/mcp/src/utils/defineComponentTool.ts (1)
  • defineComponentTool (34-56)
packages/mcp/src/utils/locale.ts (1)
  • t (7-22)
🔇 Additional comments (8)
docs/src/router/index.ts (1)

20-24: Route configuration looks good, but verify target component exists.

The route structure follows the established pattern correctly. However, please ensure the target component ../views/form/form-validate.vue exists and is properly implemented.

#!/bin/bash
# Verify the form validation component exists
fd -t f "form-validate.vue" docs/src/views/
packages/mcp/index.ts (2)

33-34: Form component integration follows correct pattern.

The Form component is properly integrated into the MCP configuration using the same structure as existing components.


10-10: Verify that the imported getFormConfig function exists.

The import follows the established pattern, but please ensure the ./src/form module exists and exports the getFormConfig function.

#!/bin/bash
# Verify the form module and getFormConfig export exist
fd -t f "index.ts" packages/mcp/src/form/
if [ -f "packages/mcp/src/form/index.ts" ]; then
  rg "export.*getFormConfig" packages/mcp/src/form/index.ts
fi
packages/mcp/src/lang/zh-CN.ts (1)

25-33: Form localization is comprehensive and addresses previous feedback.

The form localization object includes all necessary descriptions:

  • Component description (line 27)
  • Method descriptions for resetFields, clearValidate, clearValidateAll, validate, and validateField

This addresses the previous review comment about missing ai.form.description internationalization.

packages/mcp/src/lang/en.ts (1)

33-41: LGTM: Well-structured localization strings.

The English localization strings for form tools are comprehensive and clearly describe each tool's functionality. The descriptions are consistent with the existing pattern and provide sufficient detail for users to understand the purpose of each form operation.

docs/src/views/form/form-validate.vue (3)

6-18: LGTM: Proper MCP configuration and form structure.

The form template is well-structured with appropriate MCP configuration. The tiny_mcp_config object correctly identifies the business context and integrates with the form validation tools.


91-107: Well-designed validation rules with comprehensive coverage.

The validation rules effectively demonstrate various validation scenarios including required fields, length constraints, type validations, and custom validators. The IP address custom validator with the specific "1.1.1.1" requirement provides a good example of custom validation logic.


109-128: Good demonstration of dual validation approaches.

The implementation of both callback-based (handleSubmit) and promise-based (handleSubmitPromise) validation methods provides excellent examples of different validation patterns available in the form component.

Comment on lines +52 to +65
validateField: {
paramsSchema: z.string().optional().describe(t('ai.form.validateField')),
cb: (instance, value) => {
if (typeof value === 'string' && value) {
const arr = value.split(',')
if(arr.length > 0) {
instance.validateField(arr)
}else {
instance.validateField(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

Fix identical logic error in validateField.

This tool has the same logic error as clearValidate - the condition if(arr.length > 0) will always be true after split, making the else block unreachable.

Apply this diff to fix the logic:

-        cb: (instance, value) => {
-          if (typeof value === 'string' && value) {
-            const arr = value.split(',')
-            if(arr.length > 0) {
-             instance.validateField(arr)
-            }else {
-              instance.validateField(value)
-            }
-          } 
-          return { type: 'text', text: 'success' }
-        }
+        cb: (instance, value) => {
+          if (typeof value === 'string' && value) {
+            const arr = value.split(',').map(s => s.trim()).filter(s => s)
+            if (arr.length > 1) {
+              instance.validateField(arr)
+            } else if (arr.length === 1) {
+              instance.validateField(arr[0])
+            }
+          }
+          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
validateField: {
paramsSchema: z.string().optional().describe(t('ai.form.validateField')),
cb: (instance, value) => {
if (typeof value === 'string' && value) {
const arr = value.split(',')
if(arr.length > 0) {
instance.validateField(arr)
}else {
instance.validateField(value)
}
}
return { type: 'text', text: 'success' }
}
}
validateField: {
paramsSchema: z.string().optional().describe(t('ai.form.validateField')),
cb: (instance, value) => {
if (typeof value === 'string' && value) {
const arr = value
.split(',')
.map(s => s.trim())
.filter(s => s)
if (arr.length > 1) {
instance.validateField(arr)
} else if (arr.length === 1) {
instance.validateField(arr[0])
}
}
return { type: 'text', text: 'success' }
}
}
🤖 Prompt for AI Agents
In packages/mcp/src/form/index.ts around lines 52 to 65, the validateField
callback contains a logic error where the else block is unreachable because
after splitting a non-empty string by ',', the resulting array length is always
greater than 0. To fix this, remove the unnecessary else block and always call
instance.validateField with the array when value is a non-empty string. This
eliminates the redundant condition and unreachable code.

Comment on lines +24 to +37
clearValidate: {
paramsSchema: z.string().optional().describe(t('ai.form.clearValidate')),
cb: (instance, value) => {
if (typeof value === 'string' && value) {
const arr = value.split(',')
if(arr.length > 0) {
instance.clearValidate(arr)
}else {
instance.clearValidate(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

Fix logic error in field name handling.

The condition if(arr.length > 0) will always be true after split(',') because split always returns at least one element. This makes the else block unreachable and the logic incorrect.

Apply this diff to fix the logic:

-        cb: (instance, value) => {
-          if (typeof value === 'string' && value) {
-            const arr = value.split(',')
-            if(arr.length > 0) {
-             instance.clearValidate(arr)
-            }else {
-              instance.clearValidate(value)
-            }
-          } 
-          return { type: 'text', text: 'success' }
-        }
+        cb: (instance, value) => {
+          if (typeof value === 'string' && value) {
+            const arr = value.split(',').map(s => s.trim()).filter(s => s)
+            if (arr.length > 1) {
+              instance.clearValidate(arr)
+            } else if (arr.length === 1) {
+              instance.clearValidate(arr[0])
+            }
+          } else {
+            instance.clearValidate()
+          }
+          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
clearValidate: {
paramsSchema: z.string().optional().describe(t('ai.form.clearValidate')),
cb: (instance, value) => {
if (typeof value === 'string' && value) {
const arr = value.split(',')
if(arr.length > 0) {
instance.clearValidate(arr)
}else {
instance.clearValidate(value)
}
}
return { type: 'text', text: 'success' }
}
},
clearValidate: {
paramsSchema: z.string().optional().describe(t('ai.form.clearValidate')),
cb: (instance, value) => {
if (typeof value === 'string' && value) {
const arr = value
.split(',')
.map(s => s.trim())
.filter(s => s)
if (arr.length > 1) {
instance.clearValidate(arr)
} else if (arr.length === 1) {
instance.clearValidate(arr[0])
}
} else {
instance.clearValidate()
}
return { type: 'text', text: 'success' }
}
},
🤖 Prompt for AI Agents
In packages/mcp/src/form/index.ts around lines 24 to 37, the condition checking
if arr.length > 0 after splitting the string is always true, making the else
block unreachable and the logic incorrect. Fix this by removing the else block
and always calling instance.clearValidate with the array resulting from
splitting the string, ensuring correct handling of the field names.

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