feat: Add dynamic MCP tool registration per page
- webmcp.ts: Add tool tracking, unregisterTool(), clearAllTools() - tools/canvasTools.ts: render_html, render_vue_component - tools/componentTools.ts: save/load/list/delete_vue_component - tools/themeTools.ts: get_design_tokens, get_active_theme, set_theme_variable, save_theme - tools/globalTools.ts: get_current_page, navigate_to, list_available_tools - toolRegistry.ts: Orchestrates tool registration per page - App.vue: Initializes WebMCP once, watches route for tool changes - Canvas.vue: Removed tool registration (now handled by registry) Tools are now registered when entering a page and unregistered when leaving. Refresh initializes tools correctly for the current page. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useCanvasStore } from '../stores/canvas'
|
||||
|
||||
let webmcpInstance: any = null
|
||||
const registeredTools = new Set<string>()
|
||||
|
||||
export async function initWebMCP() {
|
||||
if (webmcpInstance) return webmcpInstance
|
||||
@@ -46,7 +47,51 @@ export function registerTool(
|
||||
) {
|
||||
if (!webmcpInstance) {
|
||||
console.warn('[WebMCP] Instance not initialized')
|
||||
return
|
||||
return false
|
||||
}
|
||||
if (registeredTools.has(name)) {
|
||||
console.warn(`[WebMCP] Tool "${name}" already registered, skipping`)
|
||||
return false
|
||||
}
|
||||
webmcpInstance.registerTool(name, description, schema, handler)
|
||||
registeredTools.add(name)
|
||||
console.log(`[WebMCP] Tool registered: ${name}`)
|
||||
return true
|
||||
}
|
||||
|
||||
export function unregisterTool(name: string) {
|
||||
if (!webmcpInstance) {
|
||||
console.warn('[WebMCP] Instance not initialized')
|
||||
return false
|
||||
}
|
||||
if (!registeredTools.has(name)) {
|
||||
return false
|
||||
}
|
||||
webmcpInstance.unregisterTool(name)
|
||||
registeredTools.delete(name)
|
||||
console.log(`[WebMCP] Tool unregistered: ${name}`)
|
||||
return true
|
||||
}
|
||||
|
||||
export function unregisterTools(names: string[]) {
|
||||
for (const name of names) {
|
||||
unregisterTool(name)
|
||||
}
|
||||
}
|
||||
|
||||
export function clearAllTools() {
|
||||
if (!webmcpInstance) return
|
||||
for (const name of registeredTools) {
|
||||
webmcpInstance.unregisterTool(name)
|
||||
}
|
||||
console.log(`[WebMCP] Cleared ${registeredTools.size} tools`)
|
||||
registeredTools.clear()
|
||||
}
|
||||
|
||||
export function getRegisteredTools(): string[] {
|
||||
return [...registeredTools]
|
||||
}
|
||||
|
||||
export function isToolRegistered(name: string): boolean {
|
||||
return registeredTools.has(name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user