Skip to content

Commit c2a3f05

Browse files
authoredDec 7, 2024··
Support multiple MCP tools
1 parent b480a2a commit c2a3f05

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed
 

‎index.html

+21-9
Original file line numberDiff line numberDiff line change
@@ -882,15 +882,23 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
882882
state: () => ({
883883
}),
884884

885+
getters: {
886+
getServers: () => {
887+
return window.mcpServers
888+
},
889+
890+
},
891+
885892
actions: {
886893
listTools: async function (resourceName) {
887-
if (!window.mcp) {
894+
const mcpServers = this.getServers
895+
if (!mcpServers) {
888896
return null
889897
}
890-
const mcpKeys = Object.keys(window.mcp)
898+
const mcpKeys = Object.keys(mcpServers)
891899
const mcpTools = []
892900
await Promise.all(mcpKeys.map(async (key) => {
893-
const tools = await window.mcp[key].list();
901+
const tools = await mcpServers[key].list();
894902
for (const tool of tools.tools) {
895903
mcpTools.push({
896904
type: 'function',
@@ -906,18 +914,21 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
906914
return mcpTools
907915
},
908916
getTool: async function (tool_name) {
909-
const mcpKeys = Object.keys(window.mcp)
910-
const result = await Promise.race(mcpKeys.map(async (key) => {
911-
const tools = await window.mcp[key].list();
917+
const mcpServers = this.getServers
918+
const mcpKeys = Object.keys(mcpServers)
919+
const result = await Promise.any(mcpKeys.map(async (key) => {
920+
const tools = await mcpServers[key].list();
912921
const foundTool = tools.tools.find(tool => tool.name === tool_name);
913922
if (foundTool) {
914923
return {
915924
server: key,
916925
tool: foundTool
917-
}
926+
};
918927
}
928+
throw new Error(`Tool ${tool_name} not found on server ${key}`);
919929
}));
920-
return result
930+
931+
return result;
921932
},
922933
callTool: async function (tool_name, tool_args) {
923934
const tool = await this.getTool(tool_name)
@@ -938,7 +949,7 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
938949
arguments: tool_arguments
939950
}
940951

941-
const result = await window.mcp[tool.server].call(params)
952+
const result = await this.getServers[tool.server].call(params)
942953
return result
943954
},
944955
packReturn: (string) => {
@@ -1963,6 +1974,7 @@ <h5 class="font-weight-bold">{{ column.key }}</h5>
19631974
};
19641975

19651976
const resizeAvatar = () => {
1977+
// console.log(window.innerWidth)
19661978
if (window.innerWidth <= 1310) {
19671979
settingStore.avatarSize = 26
19681980
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.