feat: update npm scope default value and enhance error handling in MCP tool calls (#3440)

This commit is contained in:
LiuVaayne 2025-03-17 12:45:35 +08:00 committed by GitHub
parent 7096f81234
commit 486563062c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 9 deletions

View File

@ -24,7 +24,7 @@ const NpxSearch: FC = () => {
const { Paragraph, Text } = Typography
// Add new state variables for npm scope search
const [npmScope, setNpmScope] = useState('')
const [npmScope, setNpmScope] = useState('@modelcontextprotocol')
const [searchLoading, setSearchLoading] = useState(false)
const [searchResults, setSearchResults] = useState<SearchResult[]>([])

View File

@ -33,7 +33,7 @@ import {
openAIToolsToMcpTool,
upsertMCPToolResponse
} from '@renderer/utils/mcp-tools'
import { isString, takeRight } from 'lodash'
import { takeRight } from 'lodash'
import OpenAI, { AzureOpenAI } from 'openai'
import {
ChatCompletionAssistantMessageParam,

View File

@ -77,6 +77,7 @@ export function openAIToolsToMcpTool(
export async function callMCPTool(tool: MCPTool): Promise<any> {
console.log(`[MCP] Calling Tool: ${tool.serverName} ${tool.name}`, tool)
try {
const resp = await window.api.mcp.callTool({
client: tool.serverName,
name: tool.name,
@ -84,6 +85,18 @@ export async function callMCPTool(tool: MCPTool): Promise<any> {
})
console.log(`[MCP] Tool called: ${tool.serverName} ${tool.name}`, resp)
return resp
} catch (e) {
console.error(`[MCP] Error calling Tool: ${tool.serverName} ${tool.name}`, e)
return Promise.resolve({
isError: true,
content: [
{
type: 'text',
text: `Error calling tool ${tool.name}: ${JSON.stringify(e)}`
}
]
})
}
}
export function mcpToolsToAnthropicTools(mcpTools: MCPTool[]): Array<ToolUnion> {