11<script lang="ts" setup>
2+ import { WebMcpClient } from ' @opentiny/next-sdk'
23import { TinyRemoter } from ' @opentiny/next-remoter'
34import { TinyConfigProvider } from ' @opentiny/vue'
45import TinyThemeTool from ' @opentiny/vue-theme/theme-tool'
5- import { onMounted } from ' vue'
6+ import { onMounted , ref } from ' vue'
67import GlobalSetting from ' @/components/global-setting/index.vue'
78import { useTheme } from ' ./hooks/useTheme'
89import { clientTransport , createMcpServer } from ' ./mcp-servers'
@@ -34,9 +35,25 @@ const mcpServers = {
3435 },
3536}
3637
38+ const AGENT_URL = ' https://agent.opentiny.design/api/v1/webmcp-trial/'
39+ const sessionID = ref (' ' )
40+
3741// 启动 MCP Server(注册工具 + 建立通信通道)
3842onMounted (async () => {
3943 await createMcpServer ()
44+
45+ // 远程连接
46+ const client = new WebMcpClient ()
47+ await client .connect (clientTransport )
48+ // 这个 sessionId 是 Web 应用与 WebAgent 服务建立连接后,由 WebAgent 服务生成的,用来唯一标识被操控的 Web 应用(被控端)
49+ const { sessionId } = await client .connect ({
50+ agent: true ,
51+ url: ` ${AGENT_URL }mcp ` ,
52+ sessionId: ' 5343d3ee-47c6-49a3-9052-c68eed6f5b50'
53+ })
54+ console .log (' sessionId' , sessionId );
55+
56+ sessionID .value = sessionId
4057})
4158 </script >
4259
@@ -50,7 +67,8 @@ onMounted(async () => {
5067 </div >
5168 <TinyRemoter
5269 :skills =" skills"
53- :mcp-servers =" mcpServers"
70+ :agent-root =" AGENT_URL"
71+ :session-id =" sessionID"
5472 />
5573</template >
5674
0 commit comments