Skip to content

Use it with AI agents ​

iwentsourcing has an MCP server, so an agent can look at a tenant, read the events and state of a stream, push events and deploy definitions. It comes in two forms with the same tools:

  • aion mcp runs on your machine and uses the login of your CLI. Nothing is configured on the server.
  • The /mcp endpoint of the api is part of every server, aion serve as well as the deployed platform. An agent connects over HTTP with a bearer token, so it works from anywhere, without the CLI on the same machine.

Connect an agent on your machine ​

Sign in once with the CLI (see Inspect with the CLI), then add the server to your agent.

For Claude Code:

bash
claude mcp add iwentsourcing -- npx @iwentsourcing/cli mcp --tenant dev

For any client that reads an mcpServers config:

json
{
  "mcpServers": {
    "iwentsourcing": {
      "command": "npx",
      "args": ["@iwentsourcing/cli", "mcp", "--tenant", "dev"],
      "env": { "IWENTSOURCING_HOST": "http://localhost:3333" }
    }
  }
}

--tenant is the tenant the tools use unless the agent names another one. --host (or IWENTSOURCING_HOST) points at the API, the default is https://api.iwentsourcing.com.

Connect to the api ​

The endpoint is POST /mcp on the api, with the tenant as a query parameter: https://api.iwentsourcing.com/mcp?tenant=dev, or http://localhost:3333/mcp?tenant=dev on a local aion serve. It keeps no session, every request is authorised by its own headers:

HeaderValue
AuthorizationBearer <token>, the developer login. aion token prints it. Required.
X-Realm-Tokens<realm>=<token>,<realm>=<token>, the logins of deployed realms. Only needed to read or push to a stream. aion token --realm <realm> prints one.

For Claude Code:

bash
claude mcp add --transport http iwentsourcing \
  "https://api.iwentsourcing.com/mcp?tenant=dev" \
  --header "Authorization: Bearer $(npx aion token)" \
  --header "X-Realm-Tokens: todo=$(npx aion token --realm todo)"

The tools call the api again with the token of the request, so an agent can do no more than the owner of the token could. Tokens are short lived. When one expires the agent gets a 401 or an error from the tool, and you run aion token again.

What it can do ​

ToolWhat it doesChanges data
tenant_listThe tenants you are a member ofno
tenant_createRegister a new tenantyes
uploadDeploy definitions to a tenant. Takes the content of the manifesto file aion build writesyes
realm_listThe realms deployed to a tenantno
realm_showThe stream and aggregation patterns and auth providers of a realmno
stream_listStream instances, filterable by realm and patternno
stream_schemaWhat the events of an instance look like, as JSON schema with descriptions, and its statesno
stream_eventsThe events of an instance, oldest firstno
stream_stateThe states an instance declares, or the rows of oneno
stream_pushAppend an event to an instanceyes
aggregation_listAggregation instancesno
aggregation_stateThe states of an aggregation instance, or the rows of oneno

Every tool describes its arguments and its result as JSON schema, built from the same types the api uses, and the arguments are checked against it. stream_push also checks the payload against the schema of the event before it is sent, and names the schema when it does not fit, so an agent can read stream_schema first. Results come back as structured content.

Every tool that lists is paged. take is the number of rows (50 by default, 1000 at most) and skip how many to leave out. The result repeats both and adds hasMore; when it is true, the agent asks again with skip increased by take.

The tools are the same operations as the CLI commands, so what an agent sees matches what you see in a terminal. Failures come back as a message the agent can act on, for example the handler's error when a pushed event is rejected, or which realm token is missing.

Logins ​

Tokens are issued per realm, so the agent can read what its logins allow:

  • The tenant and realm tools, and upload, use the developer login: aion register iwentsourcing or aion login iwentsourcing.
  • Reading or pushing to a stream needs a login in that realm: aion login <provider> --realm <realm>.

Pushed events are permanent, which is why stream_push, upload and tenant_create are marked as changing data, so a client can ask before running them.

Try it ​

Ask the agent things like:

  • "Which realms are deployed to dev, and what streams do they have?"
  • "Show the last events of personal-ada and explain what the user did."
  • "Complete the todo called Learn iwentsourcing for personal-ada."
  • "Build the manifesto of this project and upload it to dev."