# Client MCP

URL: https://swb.one/fr/docs/setup/mcp-client

MCP est la méthode standard qui permet à une application d'utiliser des outils externes. Ce guide appaire une application avec SwB grâce à une clé.

## Avant de commencer [#avant-de-commencer]

Utilisez une application compatible avec le MCP distant en Streamable HTTP. Cette méthode permet aux applications d'appeler des outils sur le web. L'application doit aussi accepter des en-têtes de requête personnalisés pour la clé. Il vous faut un client propriétaire SwB ou un terminal sur l'ordinateur de SwB.

Pour lancer SwB sur le même ordinateur que l'application, exécutez `uvx swb-one up` dans un dossier vide. Ouvrez le lien de connexion à usage unique affiché dans votre terminal. La page [Installer](/fr/docs/install) présente d'autres options.

Claude, ChatGPT, Grok et les agents de code ont leurs propres pages avec une connexion OAuth. Utilisez ces pages pour ces applications.

## Copier le prompt de configuration [#copier-le-prompt-de-configuration]

https://swb.one/prompts/mcp-client.md

````
Read the setup guide at https://swb.one/docs/setup/mcp-client.

Help me connect an MCP client that supports Streamable HTTP and custom request headers. Streamable HTTP is how the client sends tool requests to SwB.

For a new local SwB server, follow **This computer** at https://swb.one/prompts/deploy.md.

Use `http://localhost:8870` if the client runs on the SwB computer. Use the port shown at startup. Use my public HTTPS address if the client runs elsewhere.

## Owner client

Use owner access for the first client if it will set up other apps. On the SwB computer, set up a private owner client. Use the local SwB address with `/mcp` at the end. Load `SWB_KEY_OWNER` from the instance `.env` inside that client. Keep the key in its local config with file mode `0600`. Send it in the `Authorization: Bearer <key>` header only to the local address. Keep the key out of commands, logs and chat. Check that the client can call `inbox`. Give the owner client https://swb.one/prompts/coordinator.md for the remaining connections.

## Paired client

Ask me to pick a short name for the app, such as `notes-bot`. From an app with SwB owner access, call `connect(what="mcp-client", choose={"agent":"notes-bot"})` with my chosen name. If I use a terminal instead, ask me to run this command in my SwB instance folder.

```bash
swb connect mcp-client --choose agent=notes-bot
```

Use `uvx swb-one connect mcp-client --choose agent=notes-bot` if I run SwB with uvx. The result gives me a pairing code. It works once within 10 minutes.

A scope is a group of memory entries. The key gets `agent:<name>` and any scope I grant to that agent. It also gets the scope of a project named in the pairing. Read `general` if the key has access to it.

If you can edit the client settings on this computer, add an MCP server named `swb`. Use a hidden prompt if I have the pairing code. Send the code to `POST /connect` and read the response in memory. Use `mcp_url` for Streamable HTTP and `key` for the `Authorization: Bearer <key>` header. Write the key straight to the client config with file mode `0600`. Keep the code and key out of commands, logs and chat. For a local server, use the MCP address shown at startup.

If I must edit the settings myself, give me this command. Ask me to run it in a private folder on the computer that runs the client. For a different server, give me the command with its base address. Ask me to enter the pairing code at the hidden prompt.

```bash
bash -c '
  umask 077
  set -C
  read -rsp "Pairing code: " code || exit
  printf "\n"
  printf "{\"code\":\"%s\"}" "$code" |
    curl -fsS http://localhost:8870/connect -H "Content-Type: application/json" \
      --data-binary @- > .swb-pairing.json
'
```

SwB returns the key once. Ask me to open `.swb-pairing.json` in a private editor.

Ask me to add an MCP server named `swb` in the client settings. Ask me to choose Streamable HTTP. Ask me to use the `mcp_url` from the file. For a local server, ask me to use the MCP address shown at startup. Ask me to set `Authorization: Bearer <key>` with the `key` from the file. Ask me to delete the file after setup.

Have the new app call `inbox`. A successful call confirms the connection, even when the inbox is empty.

For a round trip, use an app with SwB owner access. On the SwB computer, you can use a private MCP session instead. Load `SWB_KEY_OWNER` from the instance `.env` inside the client. Send it only as a bearer token to the local SwB address. Keep the key out of commands, logs and chat.

Call `send(to="agent:notes-bot", task="SwB setup test. Reply pong.")`. Replace `notes-bot` with my chosen name. Ask the new agent to read the message with `inbox`. Ask it to answer with `reply` and the item's `handle`. From the owner session, call `wait` with the `conversation` returned by `send`. Show me the reply.

For the first shared memory check, use a scope both agents can read. Ask the new agent to call `memory_list` with the scope in `scopes`.

Ask me to paste the coordinator prompt from https://swb.one/prompts/coordinator.md into the new app. The client can subscribe to `switchboard.message.created` if it supports MCP events. It can also use `wait` or `inbox` to read messages.

For each owner-only connection, give me its matching `swb connect` command. For example, give me `swb connect slack`.
````

Collez le prompt dans un client propriétaire SwB ou dans l'application à connecter.

## Client propriétaire local [#client-propriétaire-local]

Utilisez un client privé sur l'ordinateur de SwB pour configurer d'autres applications. Utilisez l'adresse locale `/mcp` affichée au démarrage. Utilisez `SWB_KEY_OWNER` du fichier `.env` de l'instance comme `Authorization: Bearer <key>`. Cette clé donne un accès propriétaire complet. Enregistrez-la dans la configuration locale privée du client avec le mode de fichier `0600`. Envoyez-la uniquement au SwB local.

## Appairer un client [#appairer-un-client]

Laissez votre agent configurer l'application s'il peut modifier ses paramètres en local. Gardez la clé dans les paramètres privés de l'application. Utilisez le mode de fichier `0600` pour un fichier de paramètres.

### Nommer l'application [#nommer-lapplication]

Donnez à l'agent un nom court pour l'application, par exemple `notes-bot`. SwB affiche ce nom sur les messages de l'application.
### Obtenir le code d'appairage [#obtenir-le-code-dappairage]

Demandez à un agent propriétaire SwB d'appeler `connect_code` avec le nom de l'application. Depuis le dossier de l'instance SwB, vous pouvez aussi exécuter `uvx swb-one connect mcp-client --choose agent=notes-bot`. Remplacez `notes-bot` par le nom de votre application.
### Obtenir la clé [#obtenir-la-clé]

Sur l'ordinateur qui exécute l'application, ouvrez un dossier privé dans votre terminal. Remplacez `https://swb.example.com` par votre adresse SwB. Gardez `/connect` à la fin. Pour un SwB local, utilisez `http://localhost:8870/connect` avec le port affiché au démarrage. Saisissez le code d'appairage à l'invite masquée dans les 10 minutes.

```bash
bash -c '
  umask 077
  set -C
  read -rsp "Pairing code: " code || exit
  printf "\n"
  printf "{\"code\":\"%s\"}" "$code" |
    curl -fsS https://swb.example.com/connect -H "Content-Type: application/json" \
      --data-binary @- > .swb-pairing.json
'
```
### Garder la clé privée [#garder-la-clé-privée]

Ouvrez `.swb-pairing.json` dans un éditeur privé. La commande enregistre la réponse avec le mode de fichier `0600`. Reportez sa valeur `key` dans les paramètres de l'application. SwB renvoie la clé une seule fois.
### Ajouter SwB à l'application [#ajouter-swb-à-lapplication]

Ajoutez un serveur nommé `swb` dans les paramètres MCP de l'application. Sélectionnez Streamable HTTP. Pour un serveur SwB public, utilisez `mcp_url` du fichier. Pour un SwB local, utilisez l'adresse MCP affichée au démarrage.
### Ajouter la clé [#ajouter-la-clé]

Ajoutez l'en-tête `Authorization: Bearer <key>` dans les paramètres privés de l'application. Supprimez `.swb-pairing.json` après l'enregistrement de la clé.

## Ce que fait l'agent [#ce-que-fait-lagent]

L'agent appelle `connect(what="mcp-client")` depuis la connexion propriétaire. SwB renvoie l'adresse MCP et demande le nom de l'application. L'agent rappelle `connect` avec `choose={"agent":"notes-bot"}`.

SwB crée un code d'appairage pour ce nom et renvoie l'étape `POST /connect`. Un code d'appairage est un code à usage unique valable 10 minutes. Si l'application a déjà une clé, SwB le signale. Il crée alors un nouveau code uniquement après `connect_revoke`.

Depuis le terminal du serveur SwB, `swb connect mcp-client --choose agent=notes-bot` donne les mêmes étapes.

## Identifiants [#identifiants]

| Élément | Où il apparaît | Format | Destination |
| - | - | - | - |
| Code d'appairage | Le résultat de `connect` ou de `connect_code` | `XXXXX-XXXXX`, valable 10 minutes, un seul usage | La requête `POST /connect` |
| Clé d'agent | La réponse à `POST /connect`, une seule fois | Commence par `swb_` | L'en-tête `Authorization` dans les paramètres privés de l'application |

Gardez la clé dans les paramètres privés de l'application. SwB conserve uniquement une empreinte de la clé.

## Vérifier la connexion [#vérifier-la-connexion]

Demandez au nouvel agent d'appeler `inbox`. Demandez à l'agent connecté en tant que propriétaire d'appeler `connect_list` et de vérifier l'heure du dernier appel de la nouvelle clé. Faites envoyer un message de test à `agent:notes-bot` par l'agent propriétaire. Faites-le lire au nouvel agent avec `inbox`, puis répondre avec `reply`.

## Résoudre les problèmes [#résoudre-les-problèmes]

Vérifiez l'adresse SwB si `POST /connect` échoue. Demandez un nouveau code au propriétaire si le code a expiré ou a déjà servi. Si une clé a fuité, révoquez-la avec `connect_revoke`. SwB refuse ensuite les appels qui utilisent cette clé.
