Skip to content

Conversation

@kagol
Copy link
Member

@kagol kagol commented Feb 5, 2026

PR

效果如下:

AI切换路由+添加词条

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added a route-switching tool that intelligently handles navigation between pages, validating the current route path before initiating transitions.
  • Chores

    • Updated server initialization to establish connection before client setup.

@github-actions github-actions bot added the enhancement New feature or request label Feb 5, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Walkthrough

Adds WebMcpServer functionality to App.vue with a new "switch-router" tool that enables route navigation through MCP protocol. The tool checks the current route path and either returns the existing path or navigates to a new one via the router context.

Changes

Cohort / File(s) Summary
MCP Server Router Tool
template/tinyvue/src/App.vue
Imports WebMcpServer and z from SDK, plus Vue Router utilities. Instantiates WebMcpServer in onMounted, registers "switch-router" tool with routerPath input schema, implements conditional navigation logic using $route and $router, and establishes server connection.

Sequence Diagram(s)

sequenceDiagram
    participant Client as MCP Client
    participant Server as WebMcpServer
    participant Router as Vue Router
    
    Client->>Server: Call tool "switch-router"<br/>(routerPath: "/target")
    activate Server
    Server->>Router: Check current route
    Router-->>Server: Current path: "/current"
    
    alt Route matches
        Server-->>Client: Return current path
    else Route differs
        Server->>Router: Navigate to "/target"
        Router->>Router: Update route
        Server-->>Client: Return "/target"
    end
    deactivate Server
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A server springs to life with wings,
Routes now dance at MCP's call,
Paths switch smooth as morning things,
The router responds to one and all! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add mcp tool: switch-router' directly and clearly describes the main change: adding a new MCP tool for router switching functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kagol/add-mcp-switch-router

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🤖 Fix all issues with AI agents
In `@template/tinyvue/src/App.vue`:
- Line 55: The router push concatenation can produce double or missing slashes
when combining import.meta.env.VITE_CONTEXT and routerPath; update the code that
calls $router.push(import.meta.env.VITE_CONTEXT + routerPath) to normalize the
two parts so there is exactly one slash between them (trim a trailing '/' from
VITE_CONTEXT and ensure routerPath begins with a single '/' or vice versa)
before calling $router.push; reference the variables
import.meta.env.VITE_CONTEXT and routerPath and the call site $router.push(...)
when making the change.
- Around line 36-37: Move the calls to the Vue composables useRouter() and
useRoute() out of any lifecycle hooks and invoke them at the top level of the
<script setup> so they are called synchronously; create top-level constants
(e.g. const $router = useRouter(), const $route = useRoute()) and then reference
those $router and $route variables inside onMounted (or other hooks) instead of
calling useRouter()/useRoute() there.
🧹 Nitpick comments (3)
template/tinyvue/src/App.vue (3)

44-45: Consider making the description more informative.

The title and description are identical ('切换路由'). A more descriptive explanation would help users and AI agents understand when to use this tool.

💡 Suggestion
     {
       title: '切换路由',
-      description: '切换路由',
+      description: '根据路由路径切换到指定页面。如果当前已在目标页面,则不执行跳转。',
       inputSchema: {

51-57: Tool response does not distinguish between "already at path" and "navigated".

Both branches return the same { content: [{ type: 'text', text: routerPath }] } response. This makes it impossible for the caller to know if navigation actually occurred, which could be useful for debugging or conditional logic.

💡 Suggestion
       if ($route.path === routerPath) {
-        return { content: [{ type: 'text', text: routerPath }] }
+        return { content: [{ type: 'text', text: `Already at ${routerPath}` }] }
       }

       $router.push(import.meta.env.VITE_CONTEXT + routerPath)
-      return { content: [{ type: 'text', text: routerPath }] }
+      return { content: [{ type: 'text', text: `Navigated to ${routerPath}` }] }

39-40: TODO comments indicate incomplete implementation.

The comments describe important usability improvements: users should be able to specify menu names rather than exact route paths, and the system should support compound actions (navigate + create). Consider tracking these in issues to ensure they're addressed.

Would you like me to open a GitHub issue to track these TODO items for future implementation?

Comment on lines +36 to +37
const $router = useRouter()
const $route = useRoute()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Move useRouter() and useRoute() to the top level of <script setup>.

Vue composables like useRouter() and useRoute() must be called synchronously in the setup context, not inside lifecycle hooks like onMounted. Calling them inside async callbacks or lifecycle hooks can lead to warnings or unexpected behavior.

🔧 Proposed fix

Move the composable calls to the top level and reference them inside onMounted:

 import { useRoute, useRouter } from 'vue-router'
 import GlobalSetting from '@/components/global-setting/index.vue'
 import { useTheme } from './hooks/useTheme'
 import '@opentiny/next-remoter/dist/style.css'

 const theme = new TinyThemeTool()
 useTheme(theme)
+
+const $router = useRouter()
+const $route = useRoute()

 const design = {
   name: 'x-design',

Then remove the calls from inside onMounted:

 onMounted(async () => {
   const server = new WebMcpServer()
-  const $router = useRouter()
-  const $route = useRoute()

   // TODO: ...
🤖 Prompt for AI Agents
In `@template/tinyvue/src/App.vue` around lines 36 - 37, Move the calls to the Vue
composables useRouter() and useRoute() out of any lifecycle hooks and invoke
them at the top level of the <script setup> so they are called synchronously;
create top-level constants (e.g. const $router = useRouter(), const $route =
useRoute()) and then reference those $router and $route variables inside
onMounted (or other hooks) instead of calling useRouter()/useRoute() there.

return { content: [{ type: 'text', text: routerPath }] }
}

$router.push(import.meta.env.VITE_CONTEXT + routerPath)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Potential path concatenation issue with slashes.

If VITE_CONTEXT ends with / and routerPath starts with /, this will produce double slashes (e.g., /context//path). Conversely, if neither has a slash, the path will be malformed.

Consider normalizing the path construction:

🔧 Proposed fix
-      $router.push(import.meta.env.VITE_CONTEXT + routerPath)
+      const context = (import.meta.env.VITE_CONTEXT || '').replace(/\/$/, '')
+      const normalizedPath = routerPath.startsWith('/') ? routerPath : `/${routerPath}`
+      $router.push(context + normalizedPath)
📝 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
$router.push(import.meta.env.VITE_CONTEXT + routerPath)
const context = (import.meta.env.VITE_CONTEXT || '').replace(/\/$/, '')
const normalizedPath = routerPath.startsWith('/') ? routerPath : `/${routerPath}`
$router.push(context + normalizedPath)
🤖 Prompt for AI Agents
In `@template/tinyvue/src/App.vue` at line 55, The router push concatenation can
produce double or missing slashes when combining import.meta.env.VITE_CONTEXT
and routerPath; update the code that calls
$router.push(import.meta.env.VITE_CONTEXT + routerPath) to normalize the two
parts so there is exactly one slash between them (trim a trailing '/' from
VITE_CONTEXT and ensure routerPath begins with a single '/' or vice versa)
before calling $router.push; reference the variables
import.meta.env.VITE_CONTEXT and routerPath and the call site $router.push(...)
when making the change.

@kagol kagol merged commit 0cf5a24 into dev Feb 5, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant