mcp-use TypeScript API
    Preparing search index...

    Function useMcp

    • React hook for connecting to and interacting with MCP servers

      Provides a complete interface for MCP server connections including:

      • Automatic connection management with reconnection
      • OAuth authentication with automatic token refresh
      • Tool, resource, and prompt access
      • AI chat functionality with conversation memory
      • Streamable HTTP transport

      Parameters

      • options: UseMcpInternalOptions

        Configuration options for the MCP connection

      Returns UseMcpResult

      MCP connection state and methods

      const mcp = useMcp({
      url: 'http://localhost:3000/mcp',
      headers: { Authorization: 'Bearer YOUR_API_KEY' }
      })

      // Wait for connection
      useEffect(() => {
      if (mcp.state === 'ready') {
      console.log('Connected!', mcp.tools)
      }
      }, [mcp.state])

      // Call a tool
      const result = await mcp.callTool('send-email', { to: '[email protected]' })