Ajout de Dockerfile et configuration MCP

Ajout du Dockerfile pour containeriser l'application MCP

- Création du Dockerfile avec l'image Python 3.11 slim
- Installation du SDK FastMCP
- Copie du code source dans le conteneur
- Exposition du port 6666
- Configuration du point d'entrée

Ajout du fichier opencode.json pour la configuration MCP

Ajout du script Python src/mon_mcp.py avec les outils echo, shout et additionner

Ajout du fichier test.py pour les tests de l'API
This commit is contained in:
2026-01-25 12:07:21 +01:00
parent 7412b51ab5
commit 9f9d9bc3b3
5 changed files with 68 additions and 2 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,5 @@
reseau
# ---> macOS # ---> macOS
# General # General
.DS_Store .DS_Store
@@ -7,6 +9,7 @@
# Icon must end with two \r # Icon must end with two \r
Icon Icon
# Thumbnails # Thumbnails
._* ._*
@@ -201,4 +204,3 @@ cython_debug/
# PyPI configuration file # PyPI configuration file
.pypirc .pypirc
.pypirc

16
Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
# Installer le SDK MCP Python
RUN pip install --no-cache-dir fastmcp
# Copier le serveur
COPY src/* .
# Exposer le port
EXPOSE 6666
# Lancer le serveur
CMD ["python", "./mon_mcp.py"]

9
opencode.json Normal file
View File

@@ -0,0 +1,9 @@
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"echo-server": {
"type": "remote",
"url": "http://localhost:7860/mcp"
}
}
}

32
src/mon_mcp.py Normal file
View File

@@ -0,0 +1,32 @@
from fastmcp import FastMCP
# Création du serveur MCP
mcp = FastMCP("Serveur Echo MCP")
# Déclaration d'un outil
@mcp.tool(description="Renvoie le texte reçu")
def echo_texte(texte: str) -> str:
return f"Écho du serveur : {texte} mec"
# Déclaration d'un second outil pour démonstration
@mcp.tool(description="Renvoie le texte en majuscules")
def shout_texte(texte: str) -> str:
return texte.upper()
# Déclaration d'un outil pour additionner deux nombres
@mcp.tool(description="Additionne deux nombres")
def additionner(a: float, b: float) -> float:
return a + b
# Lancement du serveur MCP
if __name__ == "__main__":
mcp.run(
transport="http", # Transport réseau HTTP
host="0.0.0.0", # Adresse découte
port=7860, # Port TCP
path="/mcp", # Chemin MCP (par défaut /mcp)
)

7
test.py Normal file
View File

@@ -0,0 +1,7 @@
import requests
url = "http://localhost:6666" # point d'entrée principal
payload = {"tool": "echo", "input": {"text": "Bonjour MCP!"}}
resp = requests.post(url, json=payload)
print(resp.json()) # {"echo": "Bonjour MCP!"} attendu