import React, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom/client'; import { MCPProvider, useMCP, MCPStatus, InputSchemaForm, ReactJson } from 'mcp-uiux'; const AppContent: React.FC = () => { const [serverUrl, setServerUrl] = useState(''); const [resourcePath, setResourcePath] = useState(''); const [selectedTool, setSelectedTool] = useState(null); const [formData, setFormData] = useState(null); const [debug, setDebug] = useState(false); const { connect, loading, error, tools, resources, resourceTemplates, prompts, notifications } = useMCP(); useEffect(() => { if (localStorage.getItem('mcp-uiux-serverUrl')) { setServerUrl(localStorage.getItem('mcp-uiux-serverUrl') || 'http://localhost:8080'); } else { setServerUrl('http://localhost:8080'); } if (localStorage.getItem('mcp-uiux-resourcePath')) { setResourcePath(localStorage.getItem('mcp-uiux-resourcePath') || ''); } }, []) useEffect(() => { connect(serverUrl, resourcePath); }, [serverUrl, resourcePath]); const handleToolSelect = (tool: any) => { setSelectedTool(tool); setFormData(null); }; const handleFormComplete = (data: any) => { setFormData(data); setSelectedTool(null); // console.log('表单数据:', data); // 这里可以添加调用工具的逻辑 }; return (

MCP UIUX 示例

{ debug&& Object.keys(notifications).map((key, index) => (
{key}: {notifications[key]}
)) } {debug&&
{tools.length > 0 &&

工具列表 ({tools.length})

    {tools.map((tool, index) => (
  • handleToolSelect(tool)} style={{ padding: '8px', backgroundColor: selectedTool && selectedTool.name === tool.name ? '#e6f7ff' : 'transparent', borderRadius: '4px' }} > {tool.name}
  • ))}
}
{selectedTool && (

工具:{selectedTool.name}

)} {formData && (

表单数据

{/*
{JSON.stringify(formData, null, 2)}
*/}
)}
} {debug&& resources.length > 0 &&

资源列表 ({resources.length})

    {resources.map((resource, index) => (
  • {decodeURIComponent(resource.uri)}
  • ))}
}
); }; const App: React.FC = () => { return ( ); }; ReactDOM.createRoot(document.getElementById('root')!).render( );