Agent / foldkit-agent-webmcp

Keep tools synchronized with the Model

Capabilities with an available(model) predicate appear and disappear automatically as application state changes:

ts
import { Option } from 'effect'

const SelectionModel = Schema.Struct({ selectedTodoId: Schema.Option(Schema.String) })
const SelectionMessage = defineMessageUnion({ RequestedDeleteTodo: { id: Schema.String } })
const SelectionAgent = Agent.forModel<typeof SelectionModel.Type>()

const SelectionDef = SelectionAgent.make({
  messages: SelectionAgent.expose(SelectionMessage, {
    RequestedDeleteTodo: {
      name: 'delete_todo',
      description: 'Delete the selected todo',
      available: model => Option.isSome(model.selectedTodoId),
    },
  }),
})

With followModel: true (the default) and a host providing subscribe, selecting a todo registers delete_todo and clearing the selection unregisters it. Reconciliations run serially so rapid transitions never double-register a tool, and failed browser registrations retry on the next reconciliation. Invoking a tool name that disappeared between discovery and execution is still refused at dispatch time.