-
Notifications
You must be signed in to change notification settings - Fork 86
UI MCP tool definitions and automations service #7601
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
cstns
wants to merge
3
commits into
7430_mcp-platform-tools
Choose a base branch
from
7561_frontend-mcp-tool-wrappers
base: 7430_mcp-platform-tools
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+240
−10
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { useContextStore } from '@/stores/context.js' | ||
| import type { McpToolDefinition } from '@/types' | ||
|
|
||
| const tools: McpToolDefinition[] = [ | ||
| { | ||
| name: 'ui.get-context', | ||
| description: 'Get the current UI context: what team, application, instance, or device the user is viewing, the current page, scope (immersive editor vs main app), and editor state when applicable.', | ||
| annotations: { readOnlyHint: true, destructiveHint: false }, | ||
| inputSchema: { | ||
| type: 'object', | ||
| properties: {} | ||
| }, | ||
| handler () { | ||
| const contextStore = useContextStore() | ||
| return contextStore.expert | ||
| } | ||
| } | ||
| ] | ||
|
|
||
| export default tools |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import contextTools from './context.js' | ||
| import navigationTools from './navigation.js' | ||
| import routesTools from './routes.js' | ||
|
|
||
| import type { McpToolDefinition } from '@/types' | ||
|
|
||
| const allTools: McpToolDefinition[] = [ | ||
| ...contextTools, | ||
| ...routesTools, | ||
| ...navigationTools | ||
| ] | ||
|
|
||
| export default allTools |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import type { McpToolDefinition } from '@/types' | ||
|
|
||
| const tools: McpToolDefinition[] = [ | ||
| { | ||
| name: 'ui.navigate', | ||
| description: 'Navigate the user\'s browser to a specific page. Takes a route name and optional params. Use ui.list-routes to discover valid route names and their required parameters.', | ||
| annotations: { readOnlyHint: true, destructiveHint: false }, | ||
| inputSchema: { | ||
| type: 'object', | ||
| properties: { | ||
| route: { | ||
| type: 'string', | ||
| description: 'The route name to navigate to (e.g. "instance-overview", "team-home")' | ||
| }, | ||
| params: { | ||
| type: 'object', | ||
| description: 'Route parameters (e.g. { id: "abc123" } or { team_slug: "my-team" })', | ||
| additionalProperties: { type: 'string' } | ||
| } | ||
| }, | ||
| required: ['route'] | ||
| }, | ||
| async handler (args, { router }) { | ||
| const { route: routeName, params } = args as { route: string, params?: Record<string, string> } | ||
|
Contributor
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. This |
||
|
|
||
| const resolved = router.resolve({ name: routeName, params }) | ||
| if (!resolved || !resolved.matched.length) { | ||
| return { success: false, error: `Route "${routeName}" not found` } | ||
| } | ||
|
|
||
| await router.push({ name: routeName, params }) | ||
| return { success: true, route: routeName, path: resolved.fullPath } | ||
| } | ||
| } | ||
| ] | ||
|
|
||
| export default tools | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { Router } from 'vue-router' | ||
|
|
||
| import type { McpToolDefinition } from '@/types' | ||
|
|
||
| function getRouteList (router: Router) { | ||
| return router.getRoutes() | ||
| .filter(route => route.name && !route.redirect) | ||
| .map(route => ({ | ||
| name: route.name as string, | ||
| path: route.path, | ||
| meta: { | ||
| title: route.meta?.title || null, | ||
| adminOnly: route.meta?.adminOnly || false, | ||
| requiresLogin: route.meta?.requiresLogin ?? true | ||
| } | ||
| })) | ||
| .sort((a, b) => a.name.localeCompare(b.name)) | ||
| } | ||
|
|
||
| const tools: McpToolDefinition[] = [ | ||
| { | ||
| name: 'ui.list-routes', | ||
| description: 'List all available UI routes with their names, path patterns, and metadata. Use this to discover valid route names for the ui.navigate tool.', | ||
| annotations: { readOnlyHint: true, destructiveHint: false }, | ||
| inputSchema: { | ||
| type: 'object', | ||
| properties: {} | ||
| }, | ||
| handler (_args, { router }) { | ||
| return { routes: getRouteList(router) } | ||
| } | ||
| } | ||
| ] | ||
|
|
||
| export default tools |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { BaseService } from './service.contract' | ||
|
|
||
| import allTools from '@/mcp/tools' | ||
| import type { AutomationsServiceI, CreateServiceOptions, McpToolDefinition, McpToolWireDefinition } from '@/types' | ||
|
|
||
| class AutomationsService extends BaseService implements AutomationsServiceI { | ||
| private $tools: Map<string, McpToolDefinition> | ||
|
|
||
| constructor ({ app, router, services }: CreateServiceOptions) { | ||
| super({ | ||
| name: 'automations', | ||
| app, | ||
| router, | ||
| services | ||
| }) | ||
|
|
||
| this.$tools = new Map() | ||
| for (const tool of allTools) { | ||
| this.$tools.set(tool.name, tool) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns tool definitions without handlers, suitable for | ||
| * sending over MQTT in response to a tool list discovery request. | ||
| */ | ||
| getToolDefinitions (): McpToolWireDefinition[] { | ||
| return Array.from(this.$tools.values()).map((tool) => ({ | ||
| name: tool.name, | ||
| description: tool.description, | ||
| annotations: tool.annotations, | ||
| inputSchema: tool.inputSchema | ||
| })) | ||
| } | ||
|
|
||
| /** | ||
| * Dispatches a tool call by name. Returns the tool result or an error object. | ||
| */ | ||
| async dispatch (toolName: string, args: unknown = {}): Promise<unknown> { | ||
| const tool = this.$tools.get(toolName) | ||
| if (!tool) { | ||
| return { error: `Unknown UI tool: ${toolName}` } | ||
| } | ||
|
|
||
| try { | ||
| return await tool.handler(args, { router: this.$router! }) | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : String(err) | ||
| return { error: `Tool "${toolName}" failed: ${message}` } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let AutomationsServiceInstance: AutomationsService | null = null | ||
|
|
||
| export function createAutomationsService ({ app, router, services }: CreateServiceOptions): AutomationsService { | ||
| if (!AutomationsServiceInstance) { | ||
| AutomationsServiceInstance = new AutomationsService({ | ||
| app, | ||
| router, | ||
| services | ||
| }) | ||
| } | ||
| return AutomationsServiceInstance | ||
| } | ||
|
|
||
| export default createAutomationsService |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import { createAutomationsService } from './automations.service' | ||
| import { createBootstrapService } from './bootstrap.service' | ||
| import { createMqttService } from './mqtt.service' | ||
| import { createMessagingService } from './post-message.service' | ||
|
|
||
| export default [ | ||
| { key: 'bootstrap' as const, create: createBootstrapService, requiredLifecycle: ['init', 'destroy'] as const }, | ||
| { key: 'postMessage' as const, create: createMessagingService, requiredLifecycle: ['destroy'] as const }, | ||
| { key: 'mqtt' as const, create: createMqttService, requiredLifecycle: ['destroy'] as const } | ||
| { key: 'mqtt' as const, create: createMqttService, requiredLifecycle: ['destroy'] as const }, | ||
| { key: 'automations' as const, create: createAutomationsService, requiredLifecycle: [] as const } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './types.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './mcp.types.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { Router } from 'vue-router' | ||
|
|
||
| export interface McpToolAnnotations { | ||
| readOnlyHint?: boolean | ||
| destructiveHint?: boolean | ||
| idempotentHint?: boolean | ||
| openWorldHint?: boolean | ||
| } | ||
|
|
||
| export interface McpToolInputSchema { | ||
| type: 'object' | ||
| properties: Record<string, unknown> | ||
| required?: string[] | ||
| } | ||
|
|
||
| export interface McpToolHandlerContext { | ||
| router: Router | ||
| } | ||
|
|
||
| export interface McpToolDefinition { | ||
| name: string | ||
| description: string | ||
| annotations: McpToolAnnotations | ||
| inputSchema: McpToolInputSchema | ||
| handler: (args: unknown, context: McpToolHandlerContext) => unknown | Promise<unknown> | ||
| } | ||
|
|
||
| export interface McpToolWireDefinition { | ||
| name: string | ||
| description: string | ||
| annotations: McpToolAnnotations | ||
| inputSchema: McpToolInputSchema | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { McpToolWireDefinition } from '@/types' | ||
|
|
||
| export interface AutomationsServiceI { | ||
| getToolDefinitions(): McpToolWireDefinition[] | ||
| dispatch(toolName: string, args?: unknown): Promise<unknown> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './subscriber.types' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './transport.types.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be
readOnlyHint: falsesince it can navigate for the user??