|
4 | 4 | import { getServerConfigs } from '$lib/services/mcp-service'; |
5 | 5 | |
6 | 6 | const limit = 10; |
7 | | - const textLimit = 100; |
8 | 7 |
|
9 | 8 | /** @type {import('$agentTypes').AgentModel} */ |
10 | 9 | export let agent; |
|
36 | 35 | }); |
37 | 36 |
|
38 | 37 | /** @type {import('$agentTypes').AgentMcpTool[]} */ |
39 | | - const tools = []; |
| 38 | + const mcps = []; |
40 | 39 | const unique = new Set(); |
41 | 40 | candidates.forEach(x => { |
42 | 41 | if (!unique.has(x.name)) { |
43 | | - tools.push(x); |
| 42 | + mcps.push(x); |
44 | 43 | unique.add(x.name); |
45 | 44 | } |
46 | 45 | }); |
47 | 46 |
|
48 | | - innerRefresh(tools); |
49 | | - return tools; |
| 47 | + innerRefresh(mcps); |
| 48 | + return mcps; |
50 | 49 | } |
51 | 50 |
|
52 | 51 | export const fetchOriginalMcpTools = () => { |
|
67 | 66 | const list = res?.map(x => { |
68 | 67 | return { |
69 | 68 | id: x.id, |
70 | | - name: x.name |
| 69 | + name: x.name, |
| 70 | + tools: [ |
| 71 | + '', |
| 72 | + ...x.tools |
| 73 | + ] |
71 | 74 | }; |
72 | 75 | }) || []; |
73 | 76 | mcpOptions = [ |
74 | 77 | { |
75 | 78 | id: '', |
76 | | - name: '' |
| 79 | + name: '', |
| 80 | + tools: [''] |
77 | 81 | }, |
78 | 82 | ...list |
79 | 83 | ]; |
|
109 | 113 | * @param {any} e |
110 | 114 | * @param {number} idx |
111 | 115 | */ |
112 | | - function changeTool(e, idx) { |
| 116 | + function changeMcp(e, idx) { |
113 | 117 | const found = innerMcps.find((_, index) => index === idx); |
114 | 118 | if (!found) return; |
115 | 119 | |
|
118 | 122 |
|
119 | 123 | found.name = name; |
120 | 124 | found.server_id = val; |
| 125 | + found.functions = []; |
121 | 126 | innerRefresh(innerMcps); |
122 | 127 | handleAgentChange(); |
123 | 128 | } |
124 | 129 |
|
125 | | - function addTool() { |
| 130 | + function addMcp() { |
126 | 131 | innerMcps = [ |
127 | 132 | ...innerMcps, |
128 | 133 | { |
|
136 | 141 | } |
137 | 142 |
|
138 | 143 | /** @param {number} idx */ |
139 | | - function deleteTool(idx) { |
| 144 | + function deleteMcp(idx) { |
140 | 145 | innerMcps = innerMcps.filter((_, index) => index !== idx); |
141 | 146 | handleAgentChange(); |
142 | 147 | } |
|
145 | 150 | * @param {any} e |
146 | 151 | * @param {number} uid |
147 | 152 | */ |
148 | | - function toggleTool(e, uid) { |
| 153 | + function toggleMcp(e, uid) { |
149 | 154 | const found = innerMcps.find((_, index) => index === uid); |
150 | 155 | if (!found) return; |
151 | 156 |
|
|
156 | 161 |
|
157 | 162 | /** |
158 | 163 | * @param {any} e |
159 | | - * @param {number} tid |
160 | | - * @param {number} id |
| 164 | + * @param {number} id |
| 165 | + * @param {number} refId |
161 | 166 | * @param {string} type |
162 | 167 | */ |
163 | | - function changeContent(e, tid, id, type) { |
164 | | - const found = innerMcps.find((_, index) => index === tid); |
| 168 | + function changeMcpContent(e, id, refId, type) { |
| 169 | + const found = innerMcps.find((_, index) => index === id); |
165 | 170 | if (!found) return; |
166 | 171 |
|
167 | 172 | const val = e.target.value; |
168 | 173 | if (type === 'function') { |
169 | | - const fn = found.functions.find((_, index) => index == id); |
| 174 | + const fn = found.functions.find((_, index) => index == refId); |
170 | 175 | if (fn) { |
171 | 176 | fn.name = val; |
172 | 177 | } |
173 | 178 | } |
174 | | -
|
175 | 179 | innerRefresh(innerMcps); |
176 | 180 | handleAgentChange(); |
177 | 181 | } |
|
180 | 184 | * @param {number} id |
181 | 185 | * @param {string} type |
182 | 186 | */ |
183 | | - function addToolContent(id, type) { |
| 187 | + function addMcpContent(id, type) { |
184 | 188 | const found = innerMcps.find((_, index) => index === id); |
185 | 189 | if (!found || found.disabled) return; |
186 | 190 |
|
|
197 | 201 | * @param {number} id |
198 | 202 | * @param {string} type |
199 | 203 | */ |
200 | | - function deleteToolContent(uid, id, type) { |
| 204 | + function deleteMcpContent(uid, id, type) { |
201 | 205 | const found = innerMcps.find((_, index) => index === uid); |
202 | 206 | if (!found || found.disabled) return; |
203 | 207 |
|
|
218 | 222 | </div> |
219 | 223 |
|
220 | 224 | <div class="agent-utility-container"> |
221 | | - {#each innerMcps as tool, uid (uid)} |
| 225 | + {#each innerMcps as mcp, uid (uid)} |
222 | 226 | <div class="utility-wrapper"> |
223 | 227 | <div class="utility-row utility-row-primary"> |
224 | 228 | <div class="utility-label fw-bold"> |
|
227 | 231 | <div class="line-align-center"> |
228 | 232 | <Input |
229 | 233 | type="checkbox" |
230 | | - checked={!tool.disabled} |
231 | | - on:change={e => toggleTool(e, uid)} |
| 234 | + checked={!mcp.disabled} |
| 235 | + on:change={e => toggleMcp(e, uid)} |
232 | 236 | /> |
233 | 237 | </div> |
234 | 238 | <div |
|
245 | 249 | <div class="utility-input line-align-center"> |
246 | 250 | <Input |
247 | 251 | type="select" |
248 | | - disabled={tool.disabled} |
249 | | - on:change={e => changeTool(e, uid)} |
| 252 | + disabled={mcp.disabled} |
| 253 | + on:change={e => changeMcp(e, uid)} |
250 | 254 | > |
251 | 255 | {#each [...mcpOptions] as option} |
252 | | - <option value={option.id} selected={option.id == tool.server_id}> |
| 256 | + <option value={option.id} selected={option.id == mcp.server_id}> |
253 | 257 | {option.displayName || option.name} |
254 | 258 | </option> |
255 | 259 | {/each} |
|
261 | 265 | role="link" |
262 | 266 | tabindex="0" |
263 | 267 | on:keydown={() => {}} |
264 | | - on:click={() => deleteTool(uid)} |
| 268 | + on:click={() => deleteMcp(uid)} |
265 | 269 | /> |
266 | 270 | </div> |
267 | 271 | </div> |
|
278 | 282 | <Input |
279 | 283 | type="text" |
280 | 284 | disabled |
281 | | - value={tool.server_id} |
| 285 | + value={mcp.server_id} |
282 | 286 | /> |
283 | 287 | </div> |
284 | 288 | <div class="utility-delete line-align-center"></div> |
285 | 289 | </div> |
286 | 290 | </div> |
287 | 291 | </div> |
288 | 292 | <div class="utility-content"> |
289 | | - {#each tool.functions as fn, fid (fid)} |
| 293 | + {#each mcp.functions as fn, fid (fid)} |
290 | 294 | <div class="utility-list-item"> |
291 | 295 | <div class="utility-label line-align-center"> |
292 | 296 | {fid === 0 ? 'Tools' : ''} |
293 | 297 | </div> |
294 | 298 | <div class="utility-value"> |
295 | 299 | <div class="utility-input line-align-center"> |
296 | 300 | <Input |
297 | | - type="text" |
298 | | - maxlength={textLimit} |
299 | | - disabled={tool.disabled} |
300 | | - value={fn.name} |
301 | | - on:change={e => changeContent(e, uid, fid, 'function')} |
302 | | - /> |
| 301 | + type="select" |
| 302 | + disabled={mcp.disabled} |
| 303 | + on:change={e => changeMcpContent(e, uid, fid, 'function')} |
| 304 | + > |
| 305 | + {#each [...mcpOptions.find(x => x.id === mcp.server_id)?.tools || []] as option} |
| 306 | + <option value={option} selected={option == fn.name}> |
| 307 | + {option} |
| 308 | + </option> |
| 309 | + {/each} |
| 310 | + </Input> |
303 | 311 | </div> |
304 | 312 | <div class="utility-delete line-align-center"> |
305 | 313 | <i |
306 | 314 | class="bx bxs-no-entry text-danger clickable" |
307 | 315 | role="link" |
308 | 316 | tabindex="0" |
309 | 317 | on:keydown={() => {}} |
310 | | - on:click={() => deleteToolContent(uid, fid, 'function')} |
| 318 | + on:click={() => deleteMcpContent(uid, fid, 'function')} |
311 | 319 | /> |
312 | 320 | </div> |
313 | 321 | </div> |
314 | 322 | </div> |
315 | 323 | {/each} |
316 | 324 |
|
317 | | - {#if tool.functions?.length < limit} |
| 325 | + {#if mcp.functions?.length < limit} |
318 | 326 | <div class="utility-list-item"> |
319 | 327 | <div class="utility-label"> |
320 | | - {tool.functions.length === 0 ? 'Functions' : ''} |
| 328 | + {mcp.functions.length === 0 ? 'Functions' : ''} |
321 | 329 | </div> |
322 | 330 | <div class="utility-value"> |
323 | 331 | <i |
324 | 332 | class="bx bx-list-plus add-list clickable" |
325 | 333 | role="link" |
326 | 334 | tabindex="0" |
327 | 335 | on:keydown={() => {}} |
328 | | - on:click={() => addToolContent(uid, 'function')} |
| 336 | + on:click={() => addMcpContent(uid, 'function')} |
329 | 337 | /> |
330 | 338 | </div> |
331 | 339 | </div> |
|
337 | 345 |
|
338 | 346 | {#if innerMcps.length < limit} |
339 | 347 | <div class="add-utility"> |
340 | | - <Button color="primary" on:click={() => addTool()}> |
| 348 | + <Button color="primary" on:click={() => addMcp()}> |
341 | 349 | <span> |
342 | 350 | <i class="bx bx-plus" /> |
343 | 351 | <span>Add MCP</span> |
|
0 commit comments