mirror of
https://github.com/voideditor/void
synced 2026-05-23 09:28:23 +00:00
Updated tool name to add a unique prefix on a per session basis. Created a function that removes that prefix when displaying tools to users
This commit is contained in:
parent
826571b410
commit
0625ce4b40
2 changed files with 14 additions and 4 deletions
|
|
@ -908,6 +908,8 @@ const MCPServerComponent = ({ name, server }: { name: string, server: MCPServer
|
|||
const voidSettings = useSettingsState()
|
||||
const isOn = voidSettings.mcpUserStateOfName[name]?.isOn
|
||||
|
||||
const removeUniquePrefix = (name: string) => name.split('_').slice(1).join('_')
|
||||
|
||||
return (
|
||||
<div className="border-b border-gray-800 bg-gray-300/10 py-4 rounded-lg ">
|
||||
<div className="flex items-center mx-4">
|
||||
|
|
@ -948,7 +950,7 @@ const MCPServerComponent = ({ name, server }: { name: string, server: MCPServer
|
|||
data-tooltip-content={tool.description || ''}
|
||||
data-tooltip-class-name='void-max-w-[20px]'
|
||||
>
|
||||
{tool.name}
|
||||
{removeUniquePrefix(tool.name)}
|
||||
</span>
|
||||
))
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -175,19 +175,22 @@ export class MCPChannel implements IServerChannel {
|
|||
await client.connect(transport);
|
||||
console.log(`Connected via HTTP to ${serverName}`);
|
||||
const { tools } = await client.listTools()
|
||||
const toolsWithUniqueName = tools.map(({ name, ...rest }) => ({ name: this._addUniquePrefix(name), ...rest }))
|
||||
info = {
|
||||
status: isOn ? 'success' : 'offline',
|
||||
tools: tools,
|
||||
tools: toolsWithUniqueName,
|
||||
command: server.url.toString(),
|
||||
}
|
||||
} catch (httpErr) {
|
||||
console.warn(`HTTP failed for ${serverName}, trying SSE…`, httpErr);
|
||||
transport = new SSEClientTransport(server.url);
|
||||
await client.connect(transport);
|
||||
const { tools } = await client.listTools()
|
||||
const toolsWithUniqueName = tools.map(({ name, ...rest }) => ({ name: this._addUniquePrefix(name), ...rest }))
|
||||
console.log(`Connected via SSE to ${serverName}`);
|
||||
info = {
|
||||
status: isOn ? 'success' : 'offline',
|
||||
tools: [],
|
||||
tools: toolsWithUniqueName,
|
||||
command: server.url.toString(),
|
||||
}
|
||||
}
|
||||
|
|
@ -206,6 +209,7 @@ export class MCPChannel implements IServerChannel {
|
|||
|
||||
// Get the tools from the server
|
||||
const { tools } = await client.listTools()
|
||||
const toolsWithUniqueName = tools.map(({ name, ...rest }) => ({ name: this._addUniquePrefix(name), ...rest }))
|
||||
|
||||
// Create a full command string for display
|
||||
const fullCommand = `${server.command} ${server.args?.join(' ') || ''}`
|
||||
|
|
@ -213,7 +217,7 @@ export class MCPChannel implements IServerChannel {
|
|||
// Format server object
|
||||
info = {
|
||||
status: isOn ? 'success' : 'offline',
|
||||
tools: tools,
|
||||
tools: toolsWithUniqueName,
|
||||
command: fullCommand,
|
||||
}
|
||||
|
||||
|
|
@ -225,6 +229,10 @@ export class MCPChannel implements IServerChannel {
|
|||
return { _client: client, mcpServerEntryJSON: server, mcpServer: info }
|
||||
}
|
||||
|
||||
private _addUniquePrefix(base: string) {
|
||||
return `${Math.random().toString(36).slice(2, 8)}_${base}`;
|
||||
}
|
||||
|
||||
private async _createClient(serverConfig: MCPConfigFileEntryJSON, serverName: string, isOn = true): Promise<ClientInfo> {
|
||||
try {
|
||||
const c: ClientInfo = await this._createClientUnsafe(serverConfig, serverName, isOn)
|
||||
|
|
|
|||
Loading…
Reference in a new issue