-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA 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
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
Poem
✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
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
toresources.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
toresources.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 sinceresetFields
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
📒 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 thegetFormConfig
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 fipackages/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.
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' } | ||
} | ||
} |
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.
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.
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.
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' } | ||
} | ||
}, |
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.
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.
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.
feat: 添加form表单的mcp工具
Summary by CodeRabbit
/form
route demonstrating diverse input types and validation methods.