POST /api/mcp
Envoyer une requête JSON-RPC au serveur MCP Smart BTP, authentifiée par un jeton porteur.
Méthode POST. Corps JSON-RPC 2.0. Réponse JSON. Il n’y a pas de session : un GET authentifié répond 405 et indique que les connexions utilisent POST. Sans jeton, GET et POST répondent 401.
Authentification
En-tête Authorization: Bearer suivi du jeton. Un jeton absent, mal formé, expiré ou révoqué donne 401, avec un en-tête d’authentification qui pointe vers les métadonnées de la ressource.
Corps
| Champ | Rôle |
|---|---|
| jsonrpc | Doit valoir 2.0. |
| id | Identifiant de la requête, ou null pour une notification. |
| method | Méthode MCP, par exemple tools/list ou tools/call. |
| params | Paramètres de la méthode. |
L’en-tête facultatif MCP-Protocol-Version annonce la version du protocole utilisée par le client.
Réponses
| Code | Sens |
|---|---|
| 200 | Réponse JSON-RPC. |
| 400 | Requête MCP ou JSON-RPC invalide. |
| 401 | Jeton absent, expiré ou révoqué. |
| 403 | L’en-tête Origin est présent et n’est pas autorisé. |
| 405 | GET alors que le transport attend POST. |
OPTIONS répond 204 et annonce les méthodes POST et OPTIONS. Une erreur d’outil, par exemple un projet interdit, revient dans le corps JSON-RPC avec un indicateur d’erreur, pas forcément avec un code HTTP 4xx.
curl
curl -s https://www.smartbtp.ai/api/mcp \
-H 'Authorization: Bearer VOTRE_JETON' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "projects_list",
"arguments": {}
}
}'JavaScript
const response = await fetch('https://www.smartbtp.ai/api/mcp', {
method: 'POST',
headers: {
Authorization: 'Bearer VOTRE_JETON',
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: { name: 'projects_list', arguments: {} },
}),
});
const payload = await response.json();Python
import json
from urllib.request import Request, urlopen
request = Request(
'https://www.smartbtp.ai/api/mcp',
data=json.dumps({
'jsonrpc': '2.0',
'id': 1,
'method': 'tools/call',
'params': {'name': 'projects_list', 'arguments': {}},
}).encode(),
headers={
'Authorization': 'Bearer VOTRE_JETON',
'Content-Type': 'application/json',
'Accept': 'application/json',
},
method='POST',
)
with urlopen(request) as response:
print(response.read().decode())Les outils et leurs arguments sont décrits un par un dans la référence MCP.