# A2A agent

> Call Market History from another agent over the Agent2Agent (A2A) protocol, version 1.0, JSON-RPC binding.

Source: https://getmarkethistory.com/docs/a2a

Market History is also an [A2A](https://a2a-protocol.org/latest/specification/) agent. Its Agent
Card is at
[`/.well-known/agent-card.json`](https://getmarkethistory.com/.well-known/agent-card.json) and its
one interface is `https://getmarkethistory.com/a2a`: protocol version `1.0`, JSON-RPC binding, no
streaming and no push notifications. The skills are the [MCP server](https://getmarkethistory.com/docs/mcp)'s tools, run by
the same code: same key, same balance, same [limits](https://getmarkethistory.com/docs/limits), each call billed exactly like
the matching `/query/v1/` request.

## Authenticate

Every call needs `Authorization: Bearer <token>`, free skills included: an API key from the
[dashboard](https://getmarkethistory.com/dashboard), or an OAuth access token from the MCP server's sign-in (authorization
code with PKCE, metadata at `/.well-known/oauth-authorization-server`). Without one, `/a2a`
answers `401` with a `WWW-Authenticate` challenge naming the resource metadata. An OAuth client that sends `resource`
(RFC 8707) sends the origin, `https://getmarkethistory.com`, which is the resource that metadata
names.

Send `A2A-Version: 1.0` on every request. The spec reads a missing header as version 0.3, which
this server does not speak: it answers error `-32009` (version not supported).

## Call a skill

A request is one `SendMessage` whose message holds exactly one data part:
`{"skill": "<skill id>", "arguments": {...}}`. The arguments are the MCP tool's, and each skill's
description on the card carries their JSON Schema. Text, file and URL parts are refused with
`-32005`: there is no language model behind the agent to read prose.

```sh
curl https://getmarkethistory.com/a2a \
  -H "Authorization: Bearer $MARKET_HISTORY_KEY" \
  -H "A2A-Version: 1.0" -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "SendMessage", "params": {"message": {
        "messageId": "m1", "role": "ROLE_USER",
        "parts": [{"data": {"skill": "get_bars", "arguments": {
          "dataset": "stocks/us", "ticker": "AAPL", "timeframe": "1d",
          "start": "2025-01-01", "end": "2025-01-31"}}}]}}}'
```

The call runs before the reply, so the answer is a finished task: `TASK_STATE_COMPLETED` with the
result (the same text the MCP tool returns: CSV plus `bars_charged` and `next_cursor` lines for
billed skills) in an artifact as a `text/plain` part, or `TASK_STATE_FAILED` with the reason in
`status.message`, for instance a balance too low, with the top-up link.

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "task": {
      "id": "…",
      "contextId": "…",
      "status": { "state": "TASK_STATE_COMPLETED", "timestamp": "…" },
      "artifacts": [
        {
          "artifactId": "result",
          "name": "get_bars",
          "parts": [
            { "text": "timestamp,open,…\n…\nbars_charged: 100\n…", "mediaType": "text/plain" }
          ]
        }
      ]
    }
  }
}
```

## Skills

| Skill                   | Cost                             |
| ----------------------- | -------------------------------- |
| `get_coverage`          | Free                             |
| `search_symbols`        | Free                             |
| `inspect_instrument`    | Free                             |
| `estimate_cost`         | Free                             |
| `get_bars`              | Bars returned, rounded up to 100 |
| `get_funding`           | Rows returned, rounded up to 100 |
| `get_corporate_actions` | Rows returned, rounded up to 100 |

What each returns: [MCP server, Tools](https://getmarkethistory.com/docs/mcp#tools). The free skills still count toward the
per-account request limits.

## Methods

| Method                                    | Answer                                                                      |
| ----------------------------------------- | --------------------------------------------------------------------------- |
| `SendMessage`                             | `{"task": …}`, completed or failed                                          |
| `GetTask`                                 | the task, for an hour after it ran; another account's id is `-32001`        |
| `ListTasks`                               | your tasks of the last hour, newest first (`pageSize` 1 to 100, default 50) |
| `CancelTask`                              | `-32002`: every task is already finished                                    |
| `SendStreamingMessage`, `SubscribeToTask` | `-32004`: no streaming                                                      |
| push notification config methods          | `-32003`: no push notifications                                             |
| `GetExtendedAgentCard`                    | `-32004`: no extended card                                                  |

A2A-specific errors carry a `google.rpc.ErrorInfo` in `error.data` with the spec's `reason` (for
instance `TASK_NOT_FOUND`) and domain `a2a-protocol.org`.
