> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.claw-ops.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.claw-ops.com/_mcp/server.

# 에이전트에 외부 MCP 연결·도구 지정

PUT https://api.claw-ops.com/v1/accounts/{accountId}/agents/{agentId}/mcp-connections/{connectionId}
Content-Type: application/json

에이전트가 사용할 도구를 지정합니다(멱등). allowedTools 에 넣은 도구만 모델에 노출되며, 같은 연결이라도 에이전트마다 다른 도구를 허용할 수 있습니다.

도구는 1개 이상이어야 하고, 연결 테스트에서 발견된 도구여야 합니다. 연결은 status=tested 이고 enabled 여야 합니다.

저장 즉시 다음 통화부터 적용됩니다(에이전트 설정 저장과 별개).

Reference: https://docs.claw-ops.com/api-레퍼런스/claw-ops-api/agents/set-agent-mcp-connection

## Authentication

- `Authorization` header (bearer token, required) — API Key를 Bearer 토큰으로 전달

## Request

### Path parameters

- `accountId` (string, required) — 계정 ID
- `agentId` (string, required) — 에이전트 ID
- `connectionId` (string, required) — MCP 연결 ID

### Body (application/json)

- `allowedTools` (list of string, required)
- `failureMode` (enum, optional, default: continue) — continue 는 MCP 서버 장애 시 그 도구만 빼고 통화를 계속합니다. fail_session 은 연결 실패 시 세션 시작을 실패시킵니다.
  - Allowed values: `continue`, `fail_session`

## Response

### 200

지정 성공

- `connectionId` (string, required)
- `name` (string, required)
- `host` (string, required)
- `status` (enum, required)
  - Allowed values: `untested`, `tested`, `credential_error`
- `enabled` (boolean, required)
- `allowedTools` (list of string, required) — 이 에이전트가 호출할 수 있는 도구. 여기 없는 도구는 모델에 노출되지 않습니다.
- `failureMode` (enum, required) — continue 는 MCP 서버 장애 시 해당 도구만 빼고 통화를 계속합니다. fail_session 은 연결하지 못하면 세션 시작 자체를 실패시킵니다(외부 시스템이 필수인 경우).
  - Allowed values: `continue`, `fail_session`
- `missingTools` (list of string, required) — allowedTools 에 있지만 마지막 연결 테스트 결과에는 없는 도구. 서버가 도구를 없앴거나 이름을 바꾼 경우이며, 통화에서는 호출되지 않습니다.
- `dateUpdated` (datetime, required)

## Examples

**Request**

```json
{
  "allowedTools": [
    "get_reservation"
  ]
}
```

**Response**

```json
{
  "connectionId": "clx0mcp0000000000000001",
  "name": "예약 CRM",
  "host": "crm.example.com",
  "status": "tested",
  "enabled": true,
  "allowedTools": [
    "get_reservation"
  ],
  "failureMode": "continue",
  "missingTools": [],
  "dateUpdated": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId"

payload = { "allowedTools": ["get_reservation"] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"allowedTools":["get_reservation"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId"

	payload := strings.NewReader("{\n  \"allowedTools\": [\n    \"get_reservation\"\n  ]\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"allowedTools\": [\n    \"get_reservation\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"allowedTools\": [\n    \"get_reservation\"\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId', [
  'body' => '{
  "allowedTools": [
    "get_reservation"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"allowedTools\": [\n    \"get_reservation\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["allowedTools": ["get_reservation"]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.claw-ops.com/v1/accounts/accountId/agents/agentId/mcp-connections/connectionId")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```