Louis 919b6671a1
enahancement: mcp server activation response and error handling (#5220)
* fix: mcp server error handling

* fix: custom installation path of MCP package managers

* chore: clean up

* chore: clean up

* chore: append mcp server errors to app logs

* fix: logs reading

* chore: typo
2025-06-09 19:43:16 +07:00

60 lines
1.5 KiB
TypeScript

import { MCPTool } from '@/types/completion'
/**
* @description This file contains the functions to interact with the MCP API.
* It includes functions to get and update the MCP configuration.
* @param configs
*/
export const updateMCPConfig = async (configs: string) => {
await window.core?.api?.saveMcpConfigs({ configs })
}
/**
* @description This function restarts the MCP servers.
* @param configs
*/
export const restartMCPServers = async () => {
await window.core?.api?.restartMcpServers()
}
/**
* @description This function gets the MCP configuration.
* @returns {Promise<object>} The MCP configuration.
*/
export const getMCPConfig = async () => {
const mcpConfig = JSON.parse(
(await window.core?.api?.getMcpConfigs()) ?? '{}'
)
return mcpConfig
}
/**
* @description This function gets the MCP configuration.
* @returns {Promise<string>} The MCP configuration.
*/
export const getTools = (): Promise<MCPTool[]> => {
return window.core?.api?.getTools()
}
/**
* @description This function gets connected MCP servers.
* @returns {Promise<string[]>} The MCP names
* @returns
*/
export const getConnectedServers = (): Promise<string[]> => {
return window.core?.api?.getConnectedServers()
}
/**
* @description This function invoke an MCP tool
* @param tool
* @param params
* @returns
*/
export const callTool = (args: {
toolName: string
arguments: object
}): Promise<{ error: string; content: { text: string }[] }> => {
return window.core?.api?.callTool(args)
}