Skip to content

Conversation

@hexqi
Copy link
Collaborator

@hexqi hexqi commented Dec 30, 2025

English | 简体中文

PR

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)
  • Built its own designer, fully self-validated

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:

Background and solution

  • 升级TinyRobot版本到0.3.1,支持自动滚动的打断与继续
  • 支持添加自定义MCP服务器
image

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

    • Manage multiple custom MCP servers: add/remove, connect/disconnect, enable/disable, and view/invoke their tools with per-server tool routing.
  • Bug Fixes

    • More reliable server toggles and improved tool discovery/refresh behavior.
  • Documentation

    • Added a guide for customizing MCP servers in advanced AI plugin docs.
  • Chores

    • Updated package metadata to include the Model Context Protocol SDK.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 30, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

Walkthrough

Adds Model Context Protocol (MCP) support to the robot plugin: new MCPHost service manages MCP connections/transports and tool calls, composable changes for per-server lifecycle and tool routing, custom MCP server configuration and UI toggle wiring, a small tool-utils mutation, and an MCP SDK dependency.

Changes

Cohort / File(s) Summary
Documentation
docs/advanced-features/new-ai-plugin-usage.md
Add mcpConfig.mcpServers docs with TypeScript interfaces and usage example for declarative custom MCP server configuration.
MCP Host service
packages/plugins/robot/src/services/MCPHost.ts
New MCPHost class and exports: manages Clients & Transports, connectToServer/listTools/callTool/disconnect/cleanup, supports SSE and StreamableHTTP transports, exports Tool/ServerConfig types.
Composable / MCP integration
packages/plugins/robot/src/composables/features/useMcp.ts
Large refactor: integrate MCPHost; add connectMcpServer, disconnectMcpServer, updateMcpServerToggle, updateCustomMcpServers; replace addedaddState; add tools, toolsMap, isToolsEnabled; change callTool routing to per-server clients; remove listTools export; return engineTools.
Tool utilities
packages/common/composable/mcp/toolUtils.ts
Tool registration now pushes the original ToolItem into state.toolList after successful toolInstance creation.
Plugin metadata
packages/plugins/robot/meta.js
Expose new mcpConfig property under options with a commented mcpServers example entry.
Package manifest
packages/plugins/robot/package.json
Added dependency @modelcontextprotocol/sdk@^1.20.2; bumped @opentiny/tiny-robot* packages 0.3.0 → 0.3.1.
UI component
packages/plugins/robot/src/components/footer-extension/McpServer.vue
Replaced local mutation handler with composable call: use updateMcpServerToggle(plugin, enabled) from useMcp for plugin toggle events.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as McpServer.vue
    participant Composable as useMcp
    participant MCPHost as MCPHost
    participant MCP as MCP Server

    User->>UI: toggle server (enable/disable)
    UI->>Composable: updateMcpServerToggle(server, enabled)

    alt enable server
        Composable->>Composable: updateCustomMcpServers()
        Composable->>MCPHost: connectToServer(serverConfig)
        MCPHost->>MCP: establish transport (SSE / StreamableHTTP)
        MCP-->>MCPHost: connection + tools list
        MCPHost-->>Composable: { id, tools }
        Composable->>Composable: update toolsMap and server addState/tools
        Composable-->>UI: updated state
    else disable server
        Composable->>MCPHost: disconnect(serverId)
        MCPHost->>MCP: close connection
        MCPHost-->>Composable: disconnected
        Composable->>Composable: remove tools from toolsMap / update addState
        Composable-->>UI: updated state
    end
Loading
sequenceDiagram
    actor LLM as AI Plugin
    participant Composable as useMcp
    participant Tools as toolsMap
    participant MCPHost as MCPHost
    participant MCP as MCP Server

    LLM->>Composable: callTool(toolId, args)
    Composable->>Tools: resolve toolId -> { serverId, toolName }
    Composable->>MCPHost: callTool({ serverId, toolName, toolArgs: args })
    MCPHost->>MCP: invoke tool
    MCP-->>MCPHost: tool result
    MCPHost-->>Composable: result
    Composable-->>LLM: return tool output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐇 I nudged a host, I tied a thread,

Servers wake and tools are led,
Toggles hop and calls take flight,
I skitter home — the plugin's bright.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature: adding support for custom MCP servers, which is confirmed by multiple file changes including MCPHost.ts, useMcp.ts, and documentation.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
Contributor

@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: 6

🧹 Nitpick comments (2)
packages/plugins/robot/src/composables/features/useMcp.ts (2)

9-9: Module-level singleton may cause issues in testing or SSR.

The MCPHost instance is created at module load time, which makes it difficult to mock in tests and could cause issues in SSR environments. Consider using a factory function or dependency injection pattern if these scenarios are relevant.


211-226: Consider Promise.allSettled for resilience in getLLMTools.

Using Promise.all means if one MCP server fails to list tools, the entire operation fails. Using Promise.allSettled would allow successful servers to return their tools while logging failures for problematic servers.

🔎 Proposed approach
 const getLLMTools = async () => {
   const servers = inUseMcpServers.value.filter((server) => server.enabled && server.tools.length > 0)
-  const tools = await Promise.all(
+  const results = await Promise.allSettled(
     servers.map(async (server) => {
       const enabledTools = server.tools?.filter((tool) => tool.enabled).map((tool) => tool.id || tool.name) || []
       const client = mcpHost.getClient(server.id)
       if (client) {
         const listToolResult: { tools: McpTool[] } = await client.listTools()
         return listToolResult.tools.filter((tool) => enabledTools.includes(tool.name))
       }
       return []
     })
   )
+  const tools = results
+    .filter((r): r is PromiseFulfilledResult<McpTool[]> => r.status === 'fulfilled')
+    .map((r) => r.value)

   return convertMCPToOpenAITools(tools.flat())
 }
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af870d4 and cd73e9f.

📒 Files selected for processing (7)
  • docs/advanced-features/new-ai-plugin-usage.md
  • packages/common/composable/mcp/toolUtils.ts
  • packages/plugins/robot/meta.js
  • packages/plugins/robot/package.json
  • packages/plugins/robot/src/components/footer-extension/McpServer.vue
  • packages/plugins/robot/src/composables/features/useMcp.ts
  • packages/plugins/robot/src/services/MCPHost.ts
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-09-30T07:51:10.036Z
Learnt from: chilingling
Repo: opentiny/tiny-engine PR: 837
File: packages/vue-generator/src/plugins/genDependenciesPlugin.js:66-66
Timestamp: 2024-09-30T07:51:10.036Z
Learning: In the `tiny-engine` project, `opentiny/tiny-engine-dsl-vue` refers to the current package itself, and importing types from it may cause circular dependencies.

Applied to files:

  • packages/plugins/robot/package.json
📚 Learning: 2024-12-14T05:53:28.501Z
Learnt from: gene9831
Repo: opentiny/tiny-engine PR: 917
File: docs/开始/快速上手.md:31-31
Timestamp: 2024-12-14T05:53:28.501Z
Learning: The latest stable version of `opentiny/tiny-engine-cli` is `2.0.0`, and documentation should reference this version instead of any release candidates.

Applied to files:

  • packages/plugins/robot/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: push-check
🔇 Additional comments (7)
docs/advanced-features/new-ai-plugin-usage.md (1)

251-266: Documentation looks good.

The new MCP server configuration section clearly documents the mcpConfig.mcpServers structure with a practical example. The supported transport types (SSE and StreamableHttp) and required properties (type, url) are well-documented.

packages/plugins/robot/src/services/MCPHost.ts (2)

109-121: Clarify why client.disconnect() is commented out.

The commented-out client.disconnect() at line 114 may indicate incomplete cleanup. If the MCP SDK doesn't require explicit client disconnection when closing the transport, consider adding a comment explaining this. Otherwise, uncommenting it may be necessary to properly release resources.


123-134: Cleanup and utility methods look good.

The cleanup() method properly iterates through all transports, closes them, and clears both maps. The hasActiveSessions() helper is a clean utility.

packages/plugins/robot/meta.js (1)

18-28: Configuration structure looks good.

The new mcpConfig.mcpServers configuration surface is well-structured with a helpful commented example showing the expected format. This aligns with the MCPHost implementation and documentation.

packages/plugins/robot/src/components/footer-extension/McpServer.vue (1)

50-61: Good refactor to delegate toggle handling.

The change from direct mutation (plugin.enabled = enabled) to using updateMcpServerToggle(plugin, enabled) properly centralizes the async server connection/disconnection logic in the composable. This improves maintainability and encapsulation.

packages/plugins/robot/src/composables/features/useMcp.ts (2)

72-93: Engine server toggle doesn't update tool states.

For ENGINE_MCP_SERVER, the toggle only sets server.enabled without calling updateEngineServer() to sync tool states. This differs from updateMcpServerStatus which does call updateEngineServer. Is this inconsistency intentional?


202-241: Computed properties and exports look good.

The tools computed property correctly filters and converts enabled tools from enabled servers. The isToolsEnabled computed provides a clean boolean for UI state. The exported API surface is comprehensive for the MCP server management use case.

@hexqi hexqi added this to the v2.10.0 milestone Jan 29, 2026
Copy link
Contributor

@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: 1

🤖 Fix all issues with AI agents
In `@packages/plugins/robot/src/composables/features/useMcp.ts`:
- Around line 217-232: In getLLMTools, enabledTools is built from PluginTool as
tool.id || tool.name but the filter against McpTool currently checks only
tool.name, which drops tools whose id differs from name; update the filter
inside the servers.map (where listToolResult.tools is filtered) to check
enabledTools.includes(tool.id || tool.name) so it matches by id first then name
(i.e., use tool.id || tool.name when comparing), keeping the rest of the logic
(mcpHost.getClient, Promise.all, convertMCPToOpenAITools) unchanged.
🧹 Nitpick comments (1)
packages/plugins/robot/src/composables/features/useMcp.ts (1)

81-102: Log failures when toggling custom MCP servers.
Silent failures make diagnosing connectivity/config issues harder; a brief error log would help.

📝 Suggested tweak
   } catch (error) {
     inuseServer.enabled = false
+    console.error('MCP server toggle failed', { serverId: inuseServer.id, enabled, error })
   }
 }

@chilingling chilingling merged commit 295a806 into opentiny:develop Jan 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants