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 mcpruns on your machine and uses the login of your CLI. Nothing is configured on the server.- The
/mcpendpoint of the api is part of every server,aion serveas 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:
claude mcp add iwentsourcing -- npx @iwentsourcing/cli mcp --tenant devFor any client that reads an mcpServers config:
{
"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:
| Header | Value |
|---|---|
Authorization | Bearer <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:
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
| Tool | What it does | Changes data |
|---|---|---|
tenant_list | The tenants you are a member of | no |
tenant_create | Register a new tenant | yes |
upload | Deploy definitions to a tenant. Takes the content of the manifesto file aion build writes | yes |
realm_list | The realms deployed to a tenant | no |
realm_show | The stream and aggregation patterns and auth providers of a realm | no |
stream_list | Stream instances, filterable by realm and pattern | no |
stream_schema | What the events of an instance look like, as JSON schema with descriptions, and its states | no |
stream_events | The events of an instance, oldest first | no |
stream_state | The states an instance declares, or the rows of one | no |
stream_push | Append an event to an instance | yes |
aggregation_list | Aggregation instances | no |
aggregation_state | The states of an aggregation instance, or the rows of one | no |
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 iwentsourcingoraion 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-adaand 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."