From 9f9d9bc3b306edcd917417d435cd1c354d06355f Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sun, 25 Jan 2026 12:07:21 +0100 Subject: [PATCH] Ajout de Dockerfile et configuration MCP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .gitignore | 6 ++++-- Dockerfile | 16 ++++++++++++++++ opencode.json | 9 +++++++++ src/mon_mcp.py | 32 ++++++++++++++++++++++++++++++++ test.py | 7 +++++++ 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 opencode.json create mode 100644 src/mon_mcp.py create mode 100644 test.py diff --git a/.gitignore b/.gitignore index 4a945b3..3a12a40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +reseau + # ---> macOS # General .DS_Store @@ -5,7 +7,8 @@ .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -201,4 +204,3 @@ cython_debug/ # PyPI configuration file .pypirc - diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e05aa76 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/opencode.json b/opencode.json new file mode 100644 index 0000000..ad01805 --- /dev/null +++ b/opencode.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://opencode.ai/config.json", + "mcp": { + "echo-server": { + "type": "remote", + "url": "http://localhost:7860/mcp" + } + } +} diff --git a/src/mon_mcp.py b/src/mon_mcp.py new file mode 100644 index 0000000..6aed017 --- /dev/null +++ b/src/mon_mcp.py @@ -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) + ) diff --git a/test.py b/test.py new file mode 100644 index 0000000..2b0a299 --- /dev/null +++ b/test.py @@ -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