From 7affba78f6ef1671183fc7b223f8870fce72a282 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 3 Apr 2025 15:53:11 -0500 Subject: [PATCH] add mcp display --- .../agent-info/chat-agent-info.svelte | 5 +- .../agent-components/agent-mcp-tool.svelte | 56 +++++++++---------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/routes/chat/[agentId]/[conversationId]/agent-info/chat-agent-info.svelte b/src/routes/chat/[agentId]/[conversationId]/agent-info/chat-agent-info.svelte index 3be3565c..5f22cc65 100644 --- a/src/routes/chat/[agentId]/[conversationId]/agent-info/chat-agent-info.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/agent-info/chat-agent-info.svelte @@ -35,7 +35,10 @@ {agent?.functions?.length || 0} {agent?.functions?.length > 1 ? 'functions' : 'function'}{', '} {/if} {#if !!agent?.utilities} - {agent?.utilities?.length || 0} {agent?.utilities?.length > 1 ? 'utilities' : 'utility'} + {agent?.utilities?.length || 0} {agent?.utilities?.length > 1 ? 'utilities' : 'utility'}{', '} + {/if} + {#if !!agent?.mcp_tools} + {agent?.mcp_tools?.length || 0} {agent?.mcp_tools?.length > 1 ? 'MCPs' : 'MCP'} {/if} diff --git a/src/routes/page/agent/[agentId]/agent-components/agent-mcp-tool.svelte b/src/routes/page/agent/[agentId]/agent-components/agent-mcp-tool.svelte index 61793de4..d198d451 100644 --- a/src/routes/page/agent/[agentId]/agent-components/agent-mcp-tool.svelte +++ b/src/routes/page/agent/[agentId]/agent-components/agent-mcp-tool.svelte @@ -13,7 +13,7 @@ export let handleAgentChange = () => {}; export const fetchMcpTools = () => { - const candidates = innerTools?.filter(x => !!x.name)?.map(x => { + const candidates = innerMcps?.filter(x => !!x.name)?.map(x => { /** @type {import('$commonTypes').NameBase[]} */ const functions = []; @@ -50,16 +50,16 @@ } export const fetchOriginalMcpTools = () => { - return innerTools; + return innerMcps; } export const refresh = () => init(); /** @type {any[]} */ - let toolOptions = []; + let mcpOptions = []; /** @type {import('$agentTypes').AgentMcpTool[]} */ - let innerTools = []; + let innerMcps = []; onMount(async () => { @@ -70,7 +70,7 @@ name: x.name }; }) || []; - toolOptions = [ + mcpOptions = [ { id: '', name: '' @@ -78,7 +78,7 @@ ...list ]; }).catch(() => { - toolOptions = []; + mcpOptions = []; }); init(); }); @@ -95,7 +95,7 @@ /** @param {import('$agentTypes').AgentMcpTool[]} list */ function innerRefresh(list) { - innerTools = list?.map(x => { + innerMcps = list?.map(x => { return { name: x.name, server_id: x.server_id, @@ -110,21 +110,21 @@ * @param {number} idx */ function changeTool(e, idx) { - const found = innerTools.find((_, index) => index === idx); + const found = innerMcps.find((_, index) => index === idx); if (!found) return; const val = e.target.value; - const name = toolOptions.find(x => x.id == val)?.name || ''; + const name = mcpOptions.find(x => x.id == val)?.name || ''; found.name = name; found.server_id = val; - innerRefresh(innerTools); + innerRefresh(innerMcps); handleAgentChange(); } function addTool() { - innerTools = [ - ...innerTools, + innerMcps = [ + ...innerMcps, { name: '', server_id: '', @@ -137,7 +137,7 @@ /** @param {number} idx */ function deleteTool(idx) { - innerTools = innerTools.filter((_, index) => index !== idx); + innerMcps = innerMcps.filter((_, index) => index !== idx); handleAgentChange(); } @@ -146,11 +146,11 @@ * @param {number} uid */ function toggleTool(e, uid) { - const found = innerTools.find((_, index) => index === uid); + const found = innerMcps.find((_, index) => index === uid); if (!found) return; found.disabled = !e.target.checked; - innerRefresh(innerTools); + innerRefresh(innerMcps); handleAgentChange(); } @@ -161,7 +161,7 @@ * @param {string} type */ function changeContent(e, tid, id, type) { - const found = innerTools.find((_, index) => index === tid); + const found = innerMcps.find((_, index) => index === tid); if (!found) return; const val = e.target.value; @@ -172,7 +172,7 @@ } } - innerRefresh(innerTools); + innerRefresh(innerMcps); handleAgentChange(); } @@ -181,14 +181,14 @@ * @param {string} type */ function addToolContent(id, type) { - const found = innerTools.find((_, index) => index === id); + const found = innerMcps.find((_, index) => index === id); if (!found || found.disabled) return; if (type === 'function') { found.functions.push({ name: '' }); } - innerRefresh(innerTools); + innerRefresh(innerMcps); handleAgentChange(); } @@ -198,7 +198,7 @@ * @param {string} type */ function deleteToolContent(uid, id, type) { - const found = innerTools.find((_, index) => index === uid); + const found = innerMcps.find((_, index) => index === uid); if (!found || found.disabled) return; if (type === 'function') { @@ -206,7 +206,7 @@ found.functions = fns; } - innerRefresh(innerTools); + innerRefresh(innerMcps); handleAgentChange(); } @@ -214,15 +214,15 @@ - MCP Tools + MCP - {#each innerTools as tool, uid (uid)} + {#each innerMcps as tool, uid (uid)} - {`Tool #${uid + 1}`} + {`MCP #${uid + 1}`} @@ -248,7 +248,7 @@ disabled={tool.disabled} on:change={e => changeTool(e, uid)} > - {#each [...toolOptions] as option} + {#each [...mcpOptions] as option} {option.displayName || option.name} @@ -335,12 +335,12 @@ {/each} - {#if innerTools.length < limit} + {#if innerMcps.length < limit} addTool()}> - Add Tool + Add MCP