Skip to main content
Glama
Canton MCP Server

Canton MCP Server

by JohnLilic
README.md
# Canton MCP Server

A read-only [Model Context Protocol](https://modelcontextprotocol.io/) server that gives AI agents the ability to query [Canton Network](https://www.canton.network/) ledger data — active contracts, transactions, parties, and network status.

Works with Claude Code, Claude Desktop, GPT, Cursor, and any MCP-compatible AI agent.

## Why read-only?

This is a deliberate security decision. AI agents should not write to financial ledgers without explicit human approval. This server provides **read-only access** — no contract creation, no choice exercises, no writes of any kind.

## Install

```bash
npm install -g canton-mcp-server
```

Or run directly:

```bash
npx canton-mcp-server
```

## Configuration

The server reads these environment variables:

| Variable | Default | Description |
|---|---|---|
| `CANTON_LEDGER_HOST` | `localhost` | Canton participant node host |
| `CANTON_LEDGER_PORT` | `6865` | Canton Ledger API gRPC port |
| `CANTON_PARTY` | `Alice::1220abcdef` | Default party for queries |
| `CANTON_USE_MOCK` | `true` | Use mock data (`true`) or connect to a real node (`false`) |

## Add to Claude Code

Add to `~/.mcp.json`:

```json
{
  "mcpServers": {
    "canton": {
      "command": "canton-mcp-server",
      "env": {
        "CANTON_USE_MOCK": "true"
      }
    }
  }
}
```

## Add to Claude Desktop

Add to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "canton": {
      "command": "npx",
      "args": ["-y", "canton-mcp-server"],
      "env": {
        "CANTON_USE_MOCK": "true"
      }
    }
  }
}
```

## Tools

### canton_search_transactions

Search transactions by party, template ID, or time range.

**Parameters:** `party`, `template_id`, `start_time`, `end_time`, `limit`

```
> Search for all Iou transactions

{
  "source": "mock",
  "count": 2,
  "transactions": [
    {
      "transactionId": "tx-001-abcdef1234",
      "offset": "000000000000000010",
      "effectiveAt": "2025-01-15T10:30:00Z",
      "events": [...]
    }
  ]
}
```

### canton_get_transaction

Get full details of a specific transaction.

**Parameters:** `transaction_id` (required)

```
> Get transaction tx-001-abcdef1234

{
  "source": "mock",
  "transaction": {
    "transactionId": "tx-001-abcdef1234",
    "events": [
      {
        "kind": "created",
        "event": {
          "contractId": "#1:0",
          "templateId": { "moduleName": "Daml.Finance.Iou", "entityName": "Iou" },
          "payload": { "issuer": "Bank::...", "owner": "Alice::...", "amount": "1000000.00" }
        }
      }
    ]
  }
}
```

### canton_list_active_contracts

List active contracts with optional filters.

**Parameters:** `party`, `template_id`, `limit`

```
> List all active Account contracts

{
  "source": "mock",
  "count": 1,
  "contracts": [
    {
      "contractId": "#3:0",
      "templateId": { "moduleName": "Daml.Finance.Account", "entityName": "Account" },
      "payload": { "owner": "Alice::...", "accountId": "ACC-001" }
    }
  ]
}
```

### canton_get_contract

Get a specific contract by ID.

**Parameters:** `contract_id` (required)

```
> Get contract #1:0

{
  "source": "mock",
  "contract": {
    "contractId": "#1:0",
    "templateId": { "moduleName": "Daml.Finance.Iou", "entityName": "Iou" },
    "payload": { "currency": "USD", "amount": "1000000.00" },
    "signatories": ["Bank::...", "Alice::..."]
  }
}
```

### canton_list_parties

List all known parties on the ledger.

**Parameters:** none

```
> List parties

{
  "source": "mock",
  "count": 3,
  "parties": [
    { "partyId": "Alice::1220abc...", "displayName": "Alice", "isLocal": true },
    { "partyId": "Bob::1220fed...", "displayName": "Bob", "isLocal": true },
    { "partyId": "Bank::1220aab...", "displayName": "Global Bank", "isLocal": false }
  ]
}
```

### canton_network_status

Get network health information.

**Parameters:** none

```
> Check network status

{
  "source": "mock",
  "status": {
    "participantId": "participant1::1220aabb",
    "ledgerId": "canton-ledger-mock",
    "healthy": true,
    "activeContractCount": 4,
    "knownPartyCount": 3,
    "latestOffset": "000000000000000012"
  }
}
```

## Connecting to a real Canton node

The server ships with a `GrpcCantonClient` stub in `src/canton-client.ts`. To connect to a real Canton participant node:

1. Install gRPC dependencies:
   ```bash
   npm install @grpc/grpc-js @grpc/proto-loader
   ```

2. Obtain Canton proto files from the [Canton repository](https://github.com/digital-asset/canton) under `canton/community/ledger-api/src/main/protobuf/`.

3. Generate TypeScript bindings:
   ```bash
   npx proto-loader-gen-types \
     --longs=String --enums=String --defaults --oneofs \
     --grpcLib=@grpc/grpc-js \
     -O ./src/generated \
     proto/com/daml/ledger/api/v2/*.proto
   ```

4. Implement the methods in `GrpcCantonClient` (see the class JSDoc for which Canton API services map to each method).

5. Run with mock disabled:
   ```bash
   CANTON_USE_MOCK=false CANTON_LEDGER_HOST=your-node CANTON_LEDGER_PORT=6865 canton-mcp-server
   ```

## Data source indicator

Every response includes a `source` field:
- `"source": "mock"` — data is from the built-in mock client
- `"source": "live"` — data is from a real Canton participant node

AI agents can use this to indicate confidence in their answers.

## Development

```bash
npm install
npm run build
npm test
```

## Roadmap

This server is read-only by design. Planned additions:

- [ ] Implement `GrpcCantonClient` against a real Canton testnet
- [ ] Add write tools (`canton_create_contract`, `canton_exercise_choice`) behind an explicit opt-in flag, after testing against real nodes
- [ ] Add streaming support for real-time transaction feeds
- [ ] Publish to npm registry

## License

[BSD-0-Clause](LICENSE)

TDQS

A3.7/5.0

Scored across 6 tools

Disambiguation5/5

Each tool targets a distinct resource and action: searching transactions vs getting one transaction, listing contracts vs getting one contract, listing parties, and fetching network status. The boundaries are clear, and the descriptions reinforce the distinctions.

Naming Consistency4/5

All tools use a consistent snake_case convention with the canton_ prefix. Most follow verb_noun, but canton_network_status is a noun phrase rather than a verb-led name, which is a minor deviation.

Tool Count5/5

Six tools are well-scoped for a Canton ledger inspection server. Each tool earns its place by covering a distinct query or inspection need without obvious redundancy.

Completeness3/5

The server covers read-side inspection of transactions, contracts, parties, and network status. However, it lacks any mutation or lifecycle operations such as submitting commands, creating or exercising contracts, or party management, which are notable gaps for a Canton ledger server.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues