-
Notifications
You must be signed in to change notification settings - Fork 311
feat(common): add support for MCP configuration in component setup #3469
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -48,6 +48,7 @@ export const $props = { | |||||||||||||||||||||||||
'tiny_template': [Function, Object], | ||||||||||||||||||||||||||
'tiny_renderless': Function, | ||||||||||||||||||||||||||
'tiny_theme': String, | ||||||||||||||||||||||||||
'tiny_mcp_config': Object, | ||||||||||||||||||||||||||
'tiny_chart_theme': Object | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -59,7 +60,17 @@ export const props: Array< | |||||||||||||||||||||||||
| '_constants' | ||||||||||||||||||||||||||
| 'tiny_theme' | ||||||||||||||||||||||||||
| 'tiny_chart_theme' | ||||||||||||||||||||||||||
> = ['tiny_mode', 'tiny_mode_root', 'tiny_template', 'tiny_renderless', '_constants', 'tiny_theme', 'tiny_chart_theme'] | ||||||||||||||||||||||||||
| 'tiny_mcp_config' | ||||||||||||||||||||||||||
> = [ | ||||||||||||||||||||||||||
'tiny_mode', | ||||||||||||||||||||||||||
'tiny_mode_root', | ||||||||||||||||||||||||||
'tiny_template', | ||||||||||||||||||||||||||
'tiny_renderless', | ||||||||||||||||||||||||||
'_constants', | ||||||||||||||||||||||||||
'tiny_theme', | ||||||||||||||||||||||||||
'tiny_chart_theme', | ||||||||||||||||||||||||||
'tiny_mcp_config' | ||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const resolveMode = (props, context) => { | ||||||||||||||||||||||||||
let isRightMode = (mode) => ~['pc', 'mobile', 'mobile-first'].indexOf(mode) | ||||||||||||||||||||||||||
|
@@ -169,6 +180,22 @@ const getDesignConfig = () => { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const getComponentMcpConfig = () => { | ||||||||||||||||||||||||||
const mcpConfig = globalMcpConfig.mcpConfig | ||||||||||||||||||||||||||
const componentName = getComponentName().replace($prefix, '') | ||||||||||||||||||||||||||
return mcpConfig?.components?.[componentName] | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const globalMcpConfig = { | ||||||||||||||||||||||||||
mcpConfig: null, | ||||||||||||||||||||||||||
createMcpTools: null | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const registerMcpConfig = (mcpConfig, defineTool) => { | ||||||||||||||||||||||||||
globalMcpConfig.mcpConfig = mcpConfig | ||||||||||||||||||||||||||
globalMcpConfig.createMcpTools = defineTool | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export const $setup = ({ props: propData, context, template, extend = {} }) => { | ||||||||||||||||||||||||||
const mode = resolveMode(propData, context) | ||||||||||||||||||||||||||
const view = hooks.computed(() => { | ||||||||||||||||||||||||||
|
@@ -277,6 +304,11 @@ export const setup = ({ props, context, renderless, api, extendOptions = {}, mon | |||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const componentMcpConfig = getComponentMcpConfig() | ||||||||||||||||||||||||||
if (componentMcpConfig && props.tiny_mcp_config && globalMcpConfig.createMcpTools) { | ||||||||||||||||||||||||||
globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+307
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling to prevent component setup crashes. The conditional logic is well-structured, but the MCP tool creation call could potentially throw errors that would crash the component setup process. Apply this diff to add error handling: const componentMcpConfig = getComponentMcpConfig()
if (componentMcpConfig && props.tiny_mcp_config && globalMcpConfig.createMcpTools) {
- globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
+ try {
+ globalMcpConfig.createMcpTools(attrs.vm, props.tiny_mcp_config, componentMcpConfig)
+ } catch (error) {
+ console.warn('Failed to create MCP tools:', error)
+ }
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return attrs | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
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.
🛠️ Refactor suggestion
Improve type safety with more specific type definitions.
The function works correctly but uses overly generic types that could lead to runtime errors and poor developer experience.
Consider adding more specific type definitions:
📝 Committable suggestion
🤖 Prompt for AI Agents