The semiconducting two-dimensional transition metal dichalcogenides MX 2 show an abundance of onedimensional metallic edges and grain boundaries. Standard techniques for calculating edge states typically model nanoribbons, and require the use of supercells. In this paper, we formulate a Green's function technique for calculating edge states of (semi-)infinite two-dimensional systems with a single well-defined edge or grain boundary. We express Green's functions in terms of Bloch matrices, constructed from the solutions of a quadratic eigenvalue equation. The technique can be applied to any localized basis representation of the Hamiltonian. Here, we use it to calculate edge states of MX 2 monolayers by means of tight-binding models. Aside from the basic zigzag and armchair edges, we study edges with a more general orientation, structurally modifed edges, and grain boundaries. A simple three-band model captures an important part of the edge electronic structures. An 11-band model comprising all valence orbitals of the M and X atoms is required to obtain all edge states with energies in the MX 2 band gap. Here, states of odd symmetry with respect to a mirror plane through the layer of M atoms have a dangling-bond character, and tend to pin the Fermi level.