Functorial interpretation of formal completion

Let $$S$$ be a scheme, $$X/S$$ a "nice" scheme (I think "nice" = separated) and $$e : S \to X$$ a section. Let $$\hat{X}$$ be the formal completion of $$X$$ along the section $$e$$. (i.e., = $$\lim_n S_n$$, where $$S_n$$ is the "$$n$$-th-thickened of $$S \to X$$".) Then does $$\hat{X}$$ represent (or pro-represent) a nice functor?

First, the case that $$S$$ is a field $$k$$:
Let $$\mathscr{C}_k$$ be a category of artin local $$k$$-algebras with the residue field $$k$$. (Maps are local $$k$$-homomorphisms.) and $$\hat{\mathscr{C}}_k$$ be a category of complete local noetherian $$k$$-algebra with the residue field $$k$$.
And consider a functor $$\mathscr{C}_k \to \mathscr{S}et \\ A \mapsto \{ f : \operatorname{Spec}A \to X, \text{ an S-morphism which takes the only closed point to e } \}.$$

Then this is $$\operatorname{Hom}_{\mathscr{C}_k}(\mathscr{O}_{X,e}, A) = \operatorname{Hom}_{\hat{\mathscr{C}}_k}( \hat{\mathscr{O}_{X,e}}, A) = \hat{X}(A).$$ So this functor is pro-represented by $$\hat{X}$$.
And if $$X$$ is a group scheme, then this functor is $$\operatorname{ker} (X(A) \to X(A/\mathfrak{m}_A))$$, so inherits the group structure of $$X$$.

How about the general case? Here is what I have tried:
Let $$\mathscr{C}_S$$ be the full subcategory of $$\mathscr{S}ch/S$$ whose objects are the spectrum of artin local ring. Then by the same arguments, it seems that the functor $$\mathscr{C}_S^{\text{op}} \to \mathscr{S}et \\ T \mapsto \{ f : T \to X, \text{ an S-morphism whose set-theoritically image is contained in e(S)} \}$$

is equals to $$\hat{X}(T)$$. However $$\hat{X}$$ is not in " $$\hat{\mathscr{C}}_S$$ ", so this functor is "bad" in order to study $$\hat{X}$$.

If $$S$$ is affine and if we take $$\mathscr{C}_S$$ to be the category of finite $$S$$-schemes of finite length, then it seems to $$\hat{X} \in \hat{\mathscr{C}_S}$$. But I cannot show that $$\hat{X}$$ pro-represents that functor, and this does not coincide with the case that $$S$$ is a field.

Thank you very much!