Find all primes $p$ such that there exist an integer $n$ and positive integers $k, m$ which satisfies the following.

$$ \frac{(mk^2+2)p-(m^2+2k^2)}{mp+2} = n^2$$
1. **Isolate \( p \) in the given equation:**
   \[
   \frac{(mk^2+2)p-(m^2+2k^2)}{mp+2} = n^2
   \]
   Rearrange to solve for \( p \):
   \[
   (mk^2 + 2)p - (m^2 + 2k^2) = n^2(mp + 2)
   \]
   \[
   (mk^2 + 2)p - m^2 - 2k^2 = n^2mp + 2n^2
   \]
   \[
   (mk^2 + 2)p - n^2mp = m^2 + 2k^2 + 2n^2
   \]
   \[
   p(mk^2 + 2 - n^2m) = m^2 + 2k^2 + 2n^2
   \]
   \[
   p = \frac{m^2 + 2k^2 + 2n^2}{mk^2 + 2 - n^2m}
   \]

2. **Substitute \( u = k + n \) and \( v = k - n \):**
   \[
   p = \frac{m^2 + u^2 + v^2}{2 + muv}
   \]
   with the condition \( u \equiv v \pmod{2} \).

3. **Simplify the problem to solving:**
   \[
   p = \frac{a^2 + b^2 + c^2}{2 + abc}
   \]
   over \(\mathbb{Z}\).

4. **Use Vieta jumping to show \( p \) must be 2, 3, or \( 4k + 1 \):**
   - Let \( S = \{a, b, c\} \) be the solution to the equation with minimal \( a + b + c \).
   - Write the equation as a quadratic in \( a \):
     \[
     a^2 - (bcp)a + (b^2 + c^2 - 2p) = 0
     \]

5. **Case 1: \( S \) contains 0:**
   - WLOG, let \( c = 0 \):
     \[
     p = \frac{a^2 + b^2}{2}
     \]
     Therefore, \( p = 2 \) or \( p \equiv 1 \pmod{4} \).

6. **Case 2: \( S \) does not contain 0:**
   - WLOG, let \( a \geq b \geq c \).
   - Solve for \( a \):
     \[
     a = \frac{pbc - \sqrt{p^2b^2c^2 - 4b^2 - 4c^2 + 8p}}{2}
     \]
     - Since \( a \geq b \geq c \):
       \[
       2a = pbc - \sqrt{p^2b^2c^2 - 4b^2 - 4c^2 + 8p} \geq 2b
       \]
       \[
       (pbc - 2b)^2 \geq p^2b^2c^2 - 4b^2 - 4c^2 + 8p
       \]
       \[
       2b^2 + c^2 \geq 2p + pb^2c
       \]
       - Since \( b \geq c > 0 \):
         \[
         3b^2 \geq 2b^2 + c^2 \geq 2p + pb^2c > pb^2c
         \]
         Hence, \( pc < 3 \), so \( (p, c) = (2, 1) \). This contradicts \( 2b^2 + c^2 > 2p + pb^2c \), so no possible \( p \) in this subcase.

7. **Case 2.2: \( c < 0 \):**
   - From \( p > 0 \) and \( a^2 + b^2 + c^2 \geq 0 \), it follows that \( 2 + abc > 0 \).
   - Therefore, \( \{a, b, c\} = \{1, 1, -1\} \) and this gives \( p = 3 \).

8. **Show that \( p \) cannot be 2:**
   - Suppose we have solutions \( S = \{a, b, c\} \) and \( S' = \{a', b', c'\} \) to the equation.
   - Call them similar if \( |S \cap S'| = 2 \).
   - Fix a "connected component" of the solutions and let \( S = \{a', b', c'\} \) be the solution with minimal \( a + b + c \).
   - Similar to step 1, we have \( c = 0 \), and \( 4 = 2p = a^2 + b^2 \), so \( \{a, b, c\} = \{2, 0, 0\} \).
   - The connected component containing \( \{2, 0, 0\} \) has only two members: \( \{2, 0, 0\} \) and \( \{0, 0, -2\} \), which fail to give both \( k, m \) positive. Hence, no solutions for \( p = 2 \).

9. **Exhibit solutions for \( p = 3 \) or \( 4k + 1 \):**
   - For \( p = 3 \), choose \( (a, b, c) = (4, 1, 1) \), which reduces to \( (m, k, n) = (4, 1, 0) \).
   - For \( p = 4k + 1 \), let \( x, y \) be positive integers such that \( x^2 + y^2 = p \). WLOG, let \( x \) be even.
   - Then \( (m, n, k) = \left(y, \frac{x}{2}, \frac{x}{2}\right) \) is a solution.

The final answer is \( \boxed{ p = 3 } \) and \( p \equiv 1 \pmod{4} \).