remove toolname prefix in sidebar and remove unused logic

This commit is contained in:
Andrew Pareles 2025-05-30 20:54:52 -07:00
parent e138744816
commit 857eda72fd
3 changed files with 12 additions and 35 deletions

View file

@ -34,6 +34,7 @@ import ErrorBoundary from './ErrorBoundary.js';
import { ToolApprovalTypeSwitch } from '../void-settings-tsx/Settings.js';
import { persistentTerminalNameOfId } from '../../../terminalToolService.js';
import { removeMCPToolNamePrefix } from '../../../../common/mcpServiceTypes.js';
@ -1857,7 +1858,7 @@ const MCPToolWrapper = ({ toolMessage }: WrapperProps<string>) => {
const mcpService = accessor.get('IMCPService')
const title = getTitle(toolMessage)
const desc1 = toolMessage.name
const desc1 = removeMCPToolNamePrefix(toolMessage.name)
const icon = null

View file

@ -234,3 +234,9 @@ export interface MCPToolCallParams {
toolName: string;
params: Record<string, unknown>;
}
export const removeMCPToolNamePrefix = (name: string) => {
return name.split('_').slice(1).join('_')
}

View file

@ -13,7 +13,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
import { MCPConfigFileJSON, MCPConfigFileEntryJSON, MCPServer, RawMCPToolCall, MCPToolErrorResponse, MCPServerEventResponse, MCPToolCallParams } from '../common/mcpServiceTypes.js';
import { MCPConfigFileJSON, MCPConfigFileEntryJSON, MCPServer, RawMCPToolCall, MCPToolErrorResponse, MCPServerEventResponse, MCPToolCallParams, removeMCPToolNamePrefix } from '../common/mcpServiceTypes.js';
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
import { MCPUserStateOfName } from '../common/voidSettingsTypes.js';
@ -310,7 +310,7 @@ export class MCPChannel implements IServerChannel {
// Call the tool with the provided parameters
const response = await client.callTool({
name: toolName,
name: removeMCPToolNamePrefix(toolName),
arguments: params
})
const { content } = response as CallToolResult
@ -354,41 +354,11 @@ export class MCPChannel implements IServerChannel {
const response = await this._callTool(serverName, toolName, params)
return response
} catch (err) {
let errorMessage: string;
// Check if it's an MCP error with a code
if (err && typeof err === 'object' && 'code' in err) {
const errorCode = err.code;
const errorName = err.name || 'Unknown Error';
const errorMsg = err.message || '';
// Map common JSON-RPC error codes to user-friendly messages
let codeDescription = '';
switch (errorCode) {
case -32700:
codeDescription = 'Parse Error';
break;
case -32600:
codeDescription = 'Invalid Request';
break;
case -32601:
codeDescription = 'Method Not Found';
break;
case -32602:
codeDescription = 'Invalid Parameters';
break;
case -32603:
codeDescription = 'Internal Error';
break;
default:
codeDescription = `Error Code ${errorCode}`;
}
errorMessage = `${errorName} (${codeDescription})${errorMsg ? ': ' + errorMsg : ''}`;
} else if (err && typeof err === 'object' && 'message' in err) {
// Standard error with message
errorMessage = err.message;
} else if (typeof err === 'string') {
if (typeof err === 'string') {
// String error
errorMessage = err;
} else {