add mcp tools

This commit is contained in:
duanfuxiang
2025-06-03 09:33:53 +08:00
parent ec6c4cde83
commit 1dffe5292a
10 changed files with 25 additions and 33 deletions

View File

@@ -783,7 +783,6 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
model: undefined,
},
})
console.log('Updated chat messages:', newChatMessages);
}
setChatMessages(newChatMessages);

View File

@@ -63,7 +63,7 @@ const CustomModeView = () => {
const [roleDefinition, setRoleDefinition] = useState<string>('')
// Selected tool groups
const [selectedTools, setSelectedTools] = useState<GroupEntry[]>([])
const [selectedTools, setSelectedTools] = useState<GroupEntry[]>([]);
// Custom instructions
const [customInstructions, setCustomInstructions] = useState<string>('')
@@ -87,7 +87,7 @@ const CustomModeView = () => {
setModeName(builtinMode.slug);
setRoleDefinition(builtinMode.roleDefinition);
setCustomInstructions(builtinMode.customInstructions || '');
setSelectedTools(builtinMode.groups);
setSelectedTools(builtinMode.groups as GroupEntry[]);
setCustomModeId(''); // Built-in modes don't have custom IDs
} else {
setIsBuiltinMode(false);

View File

@@ -1,9 +1,8 @@
import { Server } from 'lucide-react'
import React from 'react'
import { useSettings } from "../../../contexts/SettingsContext"
import { t } from '../../../lang/helpers'
import { ApplyStatus, SearchWebToolArgs } from "../../../types/apply"
import { ApplyStatus, UseMcpToolArgs } from "../../../types/apply"
export default function UseMcpToolBlock({
applyStatus,
@@ -14,16 +13,13 @@ export default function UseMcpToolBlock({
finish
}: {
applyStatus: ApplyStatus
onApply: (args: SearchWebToolArgs) => void
onApply: (args: UseMcpToolArgs) => void
serverName: string,
toolName: string,
parameters: Record<string, unknown>,
finish: boolean
}) {
const { settings } = useSettings()
React.useEffect(() => {
if (finish && applyStatus === ApplyStatus.Idle) {
onApply({
@@ -43,7 +39,7 @@ export default function UseMcpToolBlock({
<div className={'infio-chat-code-block-header'}>
<div className={'infio-chat-code-block-header-filename'}>
<Server size={14} className="infio-chat-code-block-header-icon" />
use mcp tool from
{t('mcpHub.useMcpToolFrom')}
<span className="infio-mcp-tool-server-name">{serverName}</span>
</div>
</div>
@@ -56,7 +52,7 @@ export default function UseMcpToolBlock({
<span className="infio-mcp-tool-name">{toolName}</span>
</div>
</div>
: <div className="infio-mcp-tool-parameters">
{t('mcpHub.parameters')}: <div className="infio-mcp-tool-parameters">
<pre className="infio-json-pre"><code>{JSON.stringify(parameters, null, 2)}</code></pre>
</div>
</div>

View File

@@ -21,10 +21,8 @@ const McpHubView = () => {
const fetchServers = async () => {
const hub = await getMcpHub()
console.log('Fetching MCP Servers from hub:', hub)
if (hub) {
const serversData = hub.getAllServers()
console.log('Fetched MCP Servers:', serversData)
setMcpServers(serversData)
}
}
@@ -65,7 +63,7 @@ const McpHubView = () => {
const handleDelete = async (serverName: string) => {
const hub = await getMcpHub();
if (hub) {
if (confirm(t('mcpHub.deleteConfirm', { name: serverName }))) {
if (confirm(t('mcpHub.deleteConfirm').replace('{name}', serverName) as string)) {
await hub.deleteServer(serverName, "global")
const updatedServers = hub.getAllServers()
setMcpServers(updatedServers)
@@ -103,9 +101,9 @@ const McpHubView = () => {
// 清空表单
setNewServerName('')
setNewServerConfig('')
new Notice(t('mcpHub.createSuccess', { name: newServerName }))
new Notice(t('mcpHub.createSuccess').replace('{name}', newServerName) as string)
} catch (error) {
new Notice(t('mcpHub.createFailed', { error: error.message }))
new Notice(t('mcpHub.createFailed').replace('{error}', error.message) as string)
}
}
}