# Connecting Swarmica features to LLM using MCP
## Symptoms

* Can Swarmica be connected as an MCP server?
* Is it possible to teach our AI model (LLM) to work with Swarmica?

## Solution

Yes, Swarmica is built according to the API-first approach, so almost all operations that can be performed through the graphical interface can be delegated to AI models that can work with MCP tools.

For your convenience, we provide an official MCP server that makes all operations available via the MCP protocol, except for deleting entities.

To use the official MCP server, follow these steps:

1. Log in to the server where Swarmica is installed under a `root` account and go to the folder where the software is installed:
```bash
cd /root/swarmica
```
2. In the `/root/swarmica/.env` file, make sure that there is a variable:
```txt
SW_MCP_VERSION=main
```
3. Create a backup copy of the `/root/swarmica/docker-compose.yml` file:
```bash
cp docker-compose.yml{,.backup}
```
4. Using a text editor, open this file and add mcp to the services section:
```yaml
mcp:
  image: reg.gl.swd.im/swarmica/mcp:${SW_MCP_VERSION}
  restart: always
  depends_on:
   - django
  env_file:
   - .env
  labels:
    - "traefik.enable=true"
    - "traefik.http.services.mcp.loadbalancer.server.port=8001"
    - "traefik.http.routers.mcp-router.rule=Host(`${SW_HOSTNAME}`)&&PathPrefix(`/mcp`)"
    - "traefik.http.routers.mcp-router.priority=20"
    - "traefik.http.routers.mcp-router.entrypoints=web-secure"
    - "traefik.http.routers.mcp-router.middlewares=secure-headers,compression"
    - "traefik.http.routers.mcp-router.service=mcp"
    - "traefik.http.routers.mcp-router.tls.certresolver=letsencrypt"  
```
If you are using an installation behind a load balancer that terminates the HTTPS connection, use the following settings:
```yaml
mcp:
  image: reg.gl.swd.im/swarmica/mcp:${SW_MCP_VERSION}
  restart: always
  depends_on:
   - django
  env_file:
   - .env
  labels:
    - "traefik.enable=true"
    - "traefik.http.services.mcp.loadbalancer.server.port=8001"
    - "traefik.http.routers.mcp-router.rule=Host(`${SW_HOSTNAME}`)&&PathPrefix(`/mcp`)"
    - "traefik.http.routers.mcp-router.priority=20"
    - "traefik.http.routers.mcp-router.entrypoints=web"
    - "traefik.http.routers.mcp-router.middlewares=compression"
    - "traefik.http.routers.mcp-router.service=mcp"
```
5. Download the container images and start the service:
```bash
docker compose pull
docker compose up -d
```

Now the MCP toolkit for connecting to your LLM will be available at `https://your_swarmica_address/mcp`.

## Connecting Swarmica MCP to LLM

This MCP can be connected to AI that support connecting external tools via the MCP protocol.

To use the available APIs with the desired level of privileges, you must create an API token in the **Settings > Integrations > API and Integrations > + Create New** section:

* For all operations — with the "**Admin**" role
* For all operations, except for performing settings — with the "**Manager**" role
* For operations at the "Support Agent" level — with the "**Agent**" role
* For read-only operations — with the "**Employee**" role

Instructions for various AI tools:

1. [Connecting Swarmica MCP to Claude](https://support.swarmica.com/article/ru/1665)
2. [Connecting Swarmica MCP to Yandex GPT](https://support.swarmica.com/article/ru/1666)
3. [Connecting Swarmica MCP to Deepseek](https://support.swarmica.com/article/ru/1668)
4. [Connecting Swarmica MCP to ChatGPT](https://support.swarmica.com/article/ru/1681-podklyuchenie-swarmica-k-chatgpt.html)

## What is MCP?

[MCP (Model Context Protocol)](https://ru.wikipedia.org/wiki/Model_Context_Protocol) is a context expansion protocol for large language AI models (LLM) that helps them "learn" additional operations.