STOA Learn

Training

10–15 min · Free · open access

Expose a REST API as MCP tools

Your agent needs to look up orders. Give it a tool to read them and verify that only identities with the right permissions can create them.

1. Map the two operations

  • Familiarity with HTTP requests and JSON.
  • No account or installation is needed for the browser exercise.

Choose two operations from your OpenAPI contract. Their HTTP method and path determine what the gateway will call on your API.

REST APIMCP toolPermission tested
GET /orderslist-ordersstoa:read
POST /orderscreate-orderstoa:write

The signed tenant policy allows both tools. The reader has stoa:read and the writer has stoa:write. Each identity’s effective permission determines whether it can perform the operation.

Preview the mapping in your lab

In a test setup with the STOA Tool controller, preview the two operations from your orders.yaml contract. The tutorial below explains how to generate and verify the manifests.

stoactl bridge orders.yaml --namespace stoa-demo --include-ops list-orders,create-order --dry-run

Watch the 21-second test run

Lab replay recorded on 22 November 2026 at 19:48 UTC. Silent video with French and English captions.

STOA test terminal. Read allowed, reader create denied, writer create allowed.
Read the transcript
  1. The reader calls list-orders. The API receives one GET and the write count stays at zero.
  2. The reader calls create-order with a synthetic reference. The gateway returns JSON-RPC error −32001 with policy status 403. No POST reaches the API.
  3. The writer calls the same tool with the same reference. The gateway permits the write, and the API receives exactly one POST.

2. Inspect the three calls

All three calls go to POST /mcp. Expand each case and compare the gateway decision with the orders API counter.

Reader · list orders Allowed

orders-reader · stoa:read · list-orders

Cumulative API counters 1 GET · 0 POST

MCP request body

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "list-orders",
    "arguments": {}
  }
}

JSON-RPC response excerpt

{
  "id": 1,
  "result": {
    "is_error": false,
    "content": [
      {
        "type": "text",
        "text": "{\"orders\":[]}"
      }
    ]
  }
}

OpenTelemetry trace 8b15ad6ef122136e98a152455f9151f1 · policy.opa ALLOW

Reader · try to create an order Denied

orders-reader · stoa:read · create-order

Cumulative API counters 1 GET · 0 POST

MCP request body

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "create-order",
    "arguments": {
      "reference": "SEO-RMCP-001"
    }
  }
}

JSON-RPC response excerpt

{
  "id": 2,
  "error": {
    "code": -32001,
    "data": {
      "httpStatus": 403
    }
  }
}

OpenTelemetry trace 943c663ffec203dd651f8f26842521da · policy.opa DENY

Writer · create the same order Allowed

orders-writer · stoa:write · create-order

Cumulative API counters 1 GET · 1 POST

MCP request body

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "create-order",
    "arguments": {
      "reference": "SEO-RMCP-001"
    }
  }
}

JSON-RPC response excerpt

{
  "id": 3,
  "result": {
    "is_error": false,
    "content": [
      {
        "type": "text",
        "text": "{\"created\":\"SEO-RMCP-001\"}"
      }
    ]
  }
}

OpenTelemetry trace 386513956c62aa682f3a0eee85f435f5 · policy.opa ALLOW

HTTP transport returns 200 for all three calls. For the denial, status 403 appears in error.data.httpStatus and in the MCP span. The API log confirms it received no POST during this attempt.

3. Check your reasoning

You make the three calls in this order against an empty test API. How many POST /orders entries should be in its log after each call? Which field explains the rejection of the second call?

Show the answer

0 → 0 → 1. For the second call, error.code is −32001 and error.data.httpStatus is 403. One POST after two create-order calls confirms that only the writer reached the API in this test.

In your own lab, use the same synthetic reference for both write attempts and read the counters before and after each call.

Reproduce this on your own infrastructure

The lab runs the STOA Rust Gateway and the actual policy signing route. Identity, the catalogue and the orders API are test fixtures, and traces were collected locally.

When self-hosting, check where the identity provider, collector and AI model run. An external model still receives any data your agent sends it.

Test run of 22 November 2026 · STOA Gateway 0.9.27