> Source: https://wexa.ai/docs/tools/handshake-peer-agent

# handshake-peer-agent

Ask a candidate external agent who it is and what it says it can do, without creating anything. Use it to
confirm that an endpoint answers before you commit a credential to it with
[`register-peer-agent`](/docs/tools/register-peer-agent).

The `secret` you pass is used for this one call and is not stored. A handshake that fails reports why and
leaves nothing behind.

## What it is called on each surface

The wire name is `handshake-peer-agent` everywhere: it is what the Wexa MCP server advertises, the REST path is
`POST /v1/handshake-peer-agent`, and each SDK exposes it under its own language's naming convention.

| Surface | Name |
| --- | --- |
| Wexa MCP server | `handshake-peer-agent` |
| REST API | `POST /v1/handshake-peer-agent` |
| TypeScript SDK | `fabric.handshakePeerAgent()` |
| Python SDK | `fabric.handshake_peer_agent()` |

## Arguments

2 of the 5 arguments are required. Omitting a required one is refused before the tool runs, at the validation stage, so it costs nothing and changes nothing.

| Argument | Type | Required | Notes |
| --- | --- | --- | --- |
| `endpoint` | string | Required | The external agent's full http:// or https:// URL. |
| `protocol` | string | Required | `mcp` or `a2a` — which protocol the external agent speaks. |
| `secret` | string | Optional | The bearer token or API key the external agent needs. Used for this call only; nothing is stored. |
| `platform` | string | Optional | A label for which platform this agent runs on, recorded on the audit event. |
| `auth` | string | Optional | `key`, `oauth` or `mtls`. Default `key`. |

A `protocol` other than `mcp` or `a2a` is refused, and the refusal names both.

`project_id`, `projectID`, `organization_id` and `executed_by` are not arguments you pass: the
platform binds all four from the credential you authenticated with, and both SDKs refuse them
before the request leaves your process — see
[server-bound arguments](/docs/get-started/scope-and-server-bound-arguments).

## What it returns

A handshake that went through returns `ok: true`, the `endpoint` and `protocol` you passed, and what the
external agent said about itself:

| Field | What it is |
| --- | --- |
| `ok` | Whether the external agent answered the handshake. |
| `endpoint`, `protocol` | What you passed. |
| `external_agent_name`, `declared_capability` | The name and the description the external agent gave for itself. |
| `declared_abilities` | The abilities the external agent listed for itself. Absent when it listed none. |
| `protocol_version` | The protocol version the external agent reported, when it reported one. |
| `supports_cancel` | Whether the external agent says a delegated goal can be cancelled. |

A handshake that fails is a result, not an error: it returns `ok: false`, the `endpoint` and `protocol` you
passed, and a `reason`. Nothing was created, and the call can be repeated once the endpoint, the protocol or
the credential is fixed. Read `ok` before you read anything else.

The three surfaces wrap this differently, and code written against one will not read another
correctly — see [return shape](/docs/tools/overview#return-shape).

An example of what `handshake-peer-agent` returns. Every field shown is one the tool really sets: the
shape was checked against a live call to a running deployment. The ids, endpoints and
names are illustrative, so swap them for your own.

**Result of handshake-peer-agent**

**REST API**

```json
{
  "lifecycle_id": "qlc_000062",
  "result": {
    "ok": true,
    "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
    "protocol": "a2a",
    "external_agent_name": "Invoice Reconciler",
    "declared_capability": "Matches supplier invoices against purchase orders and flags mismatches.",
    "declared_abilities": [
      "match-invoice",
      "flag-mismatch"
    ],
    "protocol_version": "0.2.5",
    "supports_cancel": true
  }
}
```

**Wexa MCP server**

```json
{
  "content": [
    {
      "type": "text",
      "text": "{\"lifecycle_id\":\"qlc_000062\",\"result\":{\"ok\":true,\"endpoint\":\"https://agents.example.com/a2a/invoice-reconciler\",\"protocol\":\"a2a\",\"external_agent_name\":\"Invoice Reconciler\",\"declared_capability\":\"Matches supplier invoices against purchase orders and flags mismatches.\",\"declared_abilities\":[\"match-invoice\",\"flag-mismatch\"],\"protocol_version\":\"0.2.5\",\"supports_cancel\":true}}"
    }
  ],
  "isError": false
}
```

**TypeScript SDK**

```ts
// the object you get back IS the result — there is no `.result` to read
{
  "ok": true,
  "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
  "protocol": "a2a",
  "external_agent_name": "Invoice Reconciler",
  "declared_capability": "Matches supplier invoices against purchase orders and flags mismatches.",
  "declared_abilities": [
    "match-invoice",
    "flag-mismatch"
  ],
  "protocol_version": "0.2.5",
  "supports_cancel": true
}

// The TS SDK names these camelCase — lifecycleId, traceId — where Python uses
// lifecycle_id and trace_id. Both are non-enumerable: readable, but omitted by
// Object.keys() and JSON.stringify(). `result.lifecycleId` here is undefined.
result.lifecycleId // 'qlc_000062'
```

**Python SDK**

```python
# a dict subclass; `result` is already unwrapped
{
 "ok": True,
 "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
 "protocol": "a2a",
 "external_agent_name": "Invoice Reconciler",
 "declared_capability": "Matches supplier invoices against purchase orders and flags mismatches.",
 "declared_abilities": [
  "match-invoice",
  "flag-mismatch"
 ],
 "protocol_version": "0.2.5",
 "supports_cancel": True
}

out.lifecycle_id  # 'qlc_000062' — an attribute, not a key
```

The same call, against an endpoint that did not answer:

**Result of a failed handshake-peer-agent**

**REST API**

```json
{
  "lifecycle_id": "qlc_000063",
  "result": {
    "ok": false,
    "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
    "protocol": "a2a",
    "reason": "the external agent could not be reached, or did not complete the a2a handshake. Check the endpoint, the protocol and the credential. Nothing was created."
  }
}
```

**Wexa MCP server**

```json
{
  "content": [
    {
      "type": "text",
      "text": "{\"lifecycle_id\":\"qlc_000063\",\"result\":{\"ok\":false,\"endpoint\":\"https://agents.example.com/a2a/invoice-reconciler\",\"protocol\":\"a2a\",\"reason\":\"the external agent could not be reached, or did not complete the a2a handshake. Check the endpoint, the protocol and the credential. Nothing was created.\"}}"
    }
  ],
  "isError": false
}
```

**TypeScript SDK**

```ts
// the object you get back IS the result — there is no `.result` to read
{
  "ok": false,
  "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
  "protocol": "a2a",
  "reason": "the external agent could not be reached, or did not complete the a2a handshake. Check the endpoint, the protocol and the credential. Nothing was created."
}

// The TS SDK names these camelCase — lifecycleId, traceId — where Python uses
// lifecycle_id and trace_id. Both are non-enumerable: readable, but omitted by
// Object.keys() and JSON.stringify(). `result.lifecycleId` here is undefined.
result.lifecycleId // 'qlc_000063'
```

**Python SDK**

```python
# a dict subclass; `result` is already unwrapped
{
 "ok": False,
 "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
 "protocol": "a2a",
 "reason": "the external agent could not be reached, or did not complete the a2a handshake. Check the endpoint, the protocol and the credential. Nothing was created."
}

out.lifecycle_id  # 'qlc_000063' — an attribute, not a key
```

Keeping the `lifecycle_id` is what lets you ask later why a call was allowed, refused or held.

## Calling it

The same call on all four surfaces. Pick a tab once and every code block in the documentation follows it.

A value in angle brackets is one only you can supply, and the platform refuses a literal `<...>`.

**Call handshake-peer-agent**

**Wexa MCP server**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "handshake-peer-agent",
    "arguments": {
      "endpoint": "https://agents.example.com/a2a/invoice-reconciler",
      "protocol": "a2a",
      "secret": "<the external agent's token>"
    }
  }
}
```

**REST API**

```bash
curl -sS https://fabric.wexa.ai/v1/handshake-peer-agent \
  -H "authorization: Bearer $FABRIC_API_KEY" \
  -H "content-type: application/json" \
  -d '{"endpoint":"https://agents.example.com/a2a/invoice-reconciler","protocol":"a2a","secret":"<the external agent's token>"}'
```

**TypeScript SDK**

```ts
import { Fabric } from '@wexa-fabric/sdk'

const fabric = new Fabric()
const result = await fabric.handshakePeerAgent({
  endpoint: "https://agents.example.com/a2a/invoice-reconciler",
  protocol: "a2a",
  secret: "<the external agent's token>"
})
```

**Python SDK**

```python
from wexa import Fabric

fabric = Fabric()
out = fabric.handshake_peer_agent(
    endpoint="https://agents.example.com/a2a/invoice-reconciler",
    protocol="a2a",
    secret="<the external agent's token>",
)
```

## Errors

Both SDKs raise the same typed errors, chosen from the gateway's own error string first and its
HTTP status second. `handshake-peer-agent` checks the `fabric:orchestrate.read` grant, and reaches the seven classes every
tool reaches — listed under [the common set](/docs/tools/errors#the-common-set). These are the ones specific to it:

| Error | Status | Raised when |
| --- | --- | --- |
| `ValidationError` | 422 | `endpoint` is missing, or `protocol` is not `mcp` or `a2a`. |
| `ConfigurationError` | 5xx | `handshake-peer-agent` is not available to you. Retrying will not help. |

An endpoint that cannot be reached, or that does not complete the handshake, is not an error: it comes back
as the `ok: false` result shown above.

## Governance

Every call to `handshake-peer-agent` runs through the same ten-stage lifecycle as every other tool: the
credential is resolved to a scope, the `fabric:orchestrate.read` grant is checked, quota is drawn down, the arguments are
validated, policy rules are evaluated, the call is executed, the result is shaped and redacted, and an audit
record is written. The `lifecycle_id` in the response is the handle to that record.

`handshake-peer-agent` creates nothing, so it is not marked consequential: it is audited lightly and is never
held for approval. It still consumes quota and is still refused by policy like anything else.

## See also

[`register-peer-agent`](/docs/tools/register-peer-agent) to commit the connection,
[`list-peer-agents`](/docs/tools/list-peer-agents),
[the tool index](/docs/tools/overview), [errors](/docs/tools/errors),
and [which identifier goes where](/docs/tools/identifiers).
