Exemples JSON-RPC detailles
Le MCP utilise le protocole JSON-RPC 2.0. Voici des exemples complets pour chaque outil disponible.
Endpoint MCP
Header requis : X-API-Key: pk_live_xxx
1. Initialisation
Premiere requete pour etablir la connexion MCP.
Requete :
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}Reponse :
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": { "tools": {} },
"serverInfo": {
"name": "skema-cms",
"version": "1.0.0"
}
}
}2. Lister les outils
Requete :
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}Reponse (extrait) :
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "get_collections",
"description": "Liste les collections",
"inputSchema": { ... }
},
...
]
}
}3. get_collections
Liste toutes les collections accessibles.
Requete :
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get_collections",
"arguments": {}
}
}Reponse :
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{
"type": "text",
"text": "{"collections":["articles","clients"]}"
}]
}
}4. get_collection (schema)
Recupere le schema complet d'une collection.
Requete :
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "get_collection",
"arguments": {
"collection": "articles"
}
}
}Reponse :
{
"jsonrpc": "2.0",
"id": 4,
"result": {
"content": [{
"type": "text",
"text": "{"name":"articles","fields":[...]}"
}]
}
}5. get_collection_items
Liste les items avec pagination, tri et populate. Pour le populate, utilisez le nom du champ (local_key).
{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "get_collection_items",
"arguments": {
"collection": "commandes",
"page": 1,
"perPage": 10,
"sort": "-created_at",
"populate": "id_client,id_produit"
}
}
}6. get_collection_item
Recupere un item par son ID.
{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "get_collection_item",
"arguments": {
"collection": "articles",
"id": "550e8400-e29b-41d4-a716-446655440000",
"populate": "id_author"
}
}
}7. create_collection_item
Cree un nouvel item.
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "create_collection_item",
"arguments": {
"collection": "articles",
"data": {
"title": "Mon nouvel article",
"content": "Le contenu de l'article...",
"published": true
}
}
}
}8. update_collection_item
Met a jour un item existant (merge partiel).
{
"jsonrpc": "2.0",
"id": 8,
"method": "tools/call",
"params": {
"name": "update_collection_item",
"arguments": {
"collection": "articles",
"id": "550e8400-e29b-41d4-a716-446655440000",
"data": {
"title": "Titre modifie",
"published": false
}
}
}
}9. delete_collection_item
Supprime un item. Irreversible.
{
"jsonrpc": "2.0",
"id": 9,
"method": "tools/call",
"params": {
"name": "delete_collection_item",
"arguments": {
"collection": "articles",
"id": "550e8400-e29b-41d4-a716-446655440000"
}
}
}10. search_collection_items
Recherche textuelle dans une collection.
{
"jsonrpc": "2.0",
"id": 10,
"method": "tools/call",
"params": {
"name": "search_collection_items",
"arguments": {
"collection": "articles",
"query": "javascript",
"fields": "title,content",
"page": 1,
"perPage": 20
}
}
}11. count_collection_items
Compte le nombre d'items.
{
"jsonrpc": "2.0",
"id": 11,
"method": "tools/call",
"params": {
"name": "count_collection_items",
"arguments": {
"collection": "articles",
"filters": { "published": true }
}
}
}12. batch_create_items
Cree plusieurs items en une requete.
{
"jsonrpc": "2.0",
"id": 12,
"method": "tools/call",
"params": {
"name": "batch_create_items",
"arguments": {
"collection": "articles",
"items": [
{ "title": "Article 1", "content": "..." },
{ "title": "Article 2", "content": "..." },
{ "title": "Article 3", "content": "..." }
]
}
}
}13. batch_update_items
Met a jour plusieurs items en une requete.
{
"jsonrpc": "2.0",
"id": 13,
"method": "tools/call",
"params": {
"name": "batch_update_items",
"arguments": {
"collection": "articles",
"items": [
{ "id": "uuid-1", "published": true },
{ "id": "uuid-2", "published": true },
{ "id": "uuid-3", "published": false }
]
}
}
}Gestion des erreurs
En cas d'erreur, la reponse contient un objet error :
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32000,
"message": "Cle API invalide ou expiree"
}
}