Along the same line as the other answers, but also using the intersections library.
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\length}{2}
\coordinate (A) at (0,0) ;
\coordinate (B) at (4,4);
\coordinate (mid) at ($(A)!0.5!(B)$);
\path[name path=line,draw=lightgray] (A) node[left] {$A$} -- (B) node[right] {$B$};
\path[name path=circle,draw=lightgray] (mid) circle[radius=0.5*\length];
\draw [red, blue,ultra thick, name intersections={of=line and circle}]
(intersection-1) -- (intersection-2);
\end{tikzpicture}
\end{document}
The output is

The length of the blue segment is determined by the value of the macro \length
.
Another option is to clip the path :
\begin{tikzpicture}
\pgfmathsetmacro{\length}{2}
\coordinate[label=left:$A$] (A) at (0,0) ;
\coordinate[label=right:$B$] (B) at (4,4);
\coordinate (mid) at ($(A)!0.5!(B)$);
\begin{scope}
\clip (mid) circle[radius=0.5*\length];
\draw[blue,ultra thick] (A) -- (B);
\end{scope}
\end{tikzpicture}