feat: update npm scope default value and enhance error handling in MCP tool calls (#3440)
This commit is contained in:
parent
7096f81234
commit
486563062c
@ -24,7 +24,7 @@ const NpxSearch: FC = () => {
|
|||||||
const { Paragraph, Text } = Typography
|
const { Paragraph, Text } = Typography
|
||||||
|
|
||||||
// Add new state variables for npm scope search
|
// Add new state variables for npm scope search
|
||||||
const [npmScope, setNpmScope] = useState('')
|
const [npmScope, setNpmScope] = useState('@modelcontextprotocol')
|
||||||
const [searchLoading, setSearchLoading] = useState(false)
|
const [searchLoading, setSearchLoading] = useState(false)
|
||||||
const [searchResults, setSearchResults] = useState<SearchResult[]>([])
|
const [searchResults, setSearchResults] = useState<SearchResult[]>([])
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import {
|
|||||||
openAIToolsToMcpTool,
|
openAIToolsToMcpTool,
|
||||||
upsertMCPToolResponse
|
upsertMCPToolResponse
|
||||||
} from '@renderer/utils/mcp-tools'
|
} from '@renderer/utils/mcp-tools'
|
||||||
import { isString, takeRight } from 'lodash'
|
import { takeRight } from 'lodash'
|
||||||
import OpenAI, { AzureOpenAI } from 'openai'
|
import OpenAI, { AzureOpenAI } from 'openai'
|
||||||
import {
|
import {
|
||||||
ChatCompletionAssistantMessageParam,
|
ChatCompletionAssistantMessageParam,
|
||||||
|
|||||||
@ -77,13 +77,26 @@ export function openAIToolsToMcpTool(
|
|||||||
|
|
||||||
export async function callMCPTool(tool: MCPTool): Promise<any> {
|
export async function callMCPTool(tool: MCPTool): Promise<any> {
|
||||||
console.log(`[MCP] Calling Tool: ${tool.serverName} ${tool.name}`, tool)
|
console.log(`[MCP] Calling Tool: ${tool.serverName} ${tool.name}`, tool)
|
||||||
const resp = await window.api.mcp.callTool({
|
try {
|
||||||
client: tool.serverName,
|
const resp = await window.api.mcp.callTool({
|
||||||
name: tool.name,
|
client: tool.serverName,
|
||||||
args: tool.inputSchema
|
name: tool.name,
|
||||||
})
|
args: tool.inputSchema
|
||||||
console.log(`[MCP] Tool called: ${tool.serverName} ${tool.name}`, resp)
|
})
|
||||||
return resp
|
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> {
|
export function mcpToolsToAnthropicTools(mcpTools: MCPTool[]): Array<ToolUnion> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user