xstate-mcp-bridge
Exposes XState actors as MCP tools, allowing clients to inspect current state and context, send valid events to advance state machines, retrieve transition history, and wait for specific states.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@xstate-mcp-bridgeSend the PAY event to the order workflow and show me its new state."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
xstate-mcp-bridge
Expose a running XState actor through controlled Model Context Protocol tools.
Verify in 60 Seconds
git clone https://github.com/keshavvashishth212121-oss/xstate-mcp-bridge.git
cd xstate-mcp-bridge
npm install
npm test
npx tsx examples/demo.tsThe demo starts an MCP server over stdio, connects an MCP client, walks an
order through pending, paid, and shipped, rejects an invalid transition,
and prints the transition history.
Related MCP server: Agent NextUp
Why this exists
AI clients increasingly need to observe and advance business workflows, but they should not bypass the transition rules, guards, or context owned by the application. This bridge exposes a narrow MCP interface around a running XState actor so clients can request state, submit events, and wait for transitions while the state machine remains the source of truth.
Architecture
MCP Client -> xstate-mcp-bridge -> XState Actor
(permissions, (state, guards,
validation, transitions, context)
history)The bridge is transport-agnostic. Connect the returned MCP server to stdio, HTTP, or another supported MCP transport.
Tools
Tool | Input | Description |
| None | Returns the actor's current state value and context, optionally redacted. |
|
| Validates the event with |
| None | Returns recent observed transitions and truncation metadata. |
|
| Waits for a matching state and cleans up its subscription on completion or timeout. |
| None | Returns the bridge name, current state, available event types, and permissions. |
Safety model
Permissions:
readState,sendEvent, andresetcan be restricted independently. Permissions default to enabled unless explicitly set tofalse.Transition validation:
send_eventchecks the actor snapshot's XStatecan()method before sending, so invalid events are rejected explicitly.Context redaction: Provide
redactContextto remove secrets such as API keys before context is returned byget_state.Bounded history: Transition history is limited by
maxHistory, which defaults to1000. When entries are dropped,get_historyreportstruncatedanddroppedCount.
Limitations
There is no built-in authentication or authorization beyond bridge permissions.
The bridge does not provide process isolation; it runs in the host application's process.
Transition history is in-memory and is lost when the process exits.
Deployment responsibility
Bridge permissions are application-level capability controls, not client authentication. This library does not authenticate MCP callers, authorize users, isolate the actor process, or make context and tool output trustworthy. Applications exposing the bridge over a network must provide transport-level authentication, authorization, network restrictions, and any required approval workflow or process isolation.
Use cases
Approvals: An AI assistant can request or observe approvals, but cannot skip
pending -> approvedguards.Deployments: An operator can expose build, test, approval, and deploy states without allowing an MCP client to jump directly to
deployed.Incident runbooks: An agent can advance a remediation workflow while the application retains authority over valid transitions.
Non-goals
This is not an MCP authentication server.
This is not a durable event store.
This is not a replacement for XState.
This does not provide process isolation.
API reference
interface CreateMcpBridgeOptions {
name: string;
actor: AnyActorRef;
permissions?: {
readState?: boolean;
sendEvent?: boolean;
reset?: boolean;
};
maxHistory?: number;
redactContext?: (context: any) => any;
}
function createMcpBridge(options: CreateMcpBridgeOptions): McpBridge;The returned McpBridge is an McpServer with an additional
reset(): void method. The actor must be started by the application before
creating the bridge.
Development
npm install
npm test
npm run build
npm run example
npx tsx examples/demo.tsRelationship to DevCompanion AI
This library was extracted from the state-machine integration work in DevCompanion AI. It is now a standalone, open-source bridge with no runtime dependency on DevCompanion AI, its application, prompts, storage, or user interface. It can be used independently in any TypeScript project that already owns an XState actor.
DevCompanion AI was the first real consumer of this bridge, not a runtime dependency. The reusable boundary is the running XState actor: applications own their machines, guards, context, and business rules; this library adds a controlled MCP interface without importing application-specific prompts, storage, sandbox logic, or UI.
Package status
The repository is the source release for the current hackathon submission. An npm package release is planned after the API stabilizes.
Security Warning
Note: Mutating permissions (
sendEvent,reset) default to enabled for ease of use in local development. For externally reachable MCP servers, explicitly configure permissions to deny mutations unless required, rather than relying on defaults.
Roadmap
Add optional persistence adapters for transition history.
Support richer matching for deeply nested state values.
Add examples for HTTP and WebSocket MCP transports.
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Runtime permission, approval, and audit layer for AI agent tool execution.
Hosted MCP memory and agent control plane for durable conversations, jobs, and operations.
Human-input bridge for AI agents with voice-first answer links, MCP tools, and HTTP APIs.
Related MCP Servers
- AlicenseAqualityBmaintenanceGoverned agent execution gateway for LLM workflows, providing deterministic FSM-based execution, audit trails, and idempotency guarantees via MCP.5MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to maintain project continuity through a file-based state hub with tasks, phases, and handoff snapshots. Provides MCP tools for reading and updating project state, with gatekeeping enforced via real-state evaluation and per-tool authorization.2MIT
- AlicenseNot gradedqualityAmaintenanceEnables MCP-compatible LLM clients to execute server-verified agent workflows, with enforced transitions, invocation caps, and signed audit trails.MIT
- FlicenseNot gradedqualityBmaintenanceBridges MCP clients to interactive Reasonix agents, letting you spawn, steer, poll, resume, and manage agents via tools and callbacks. Enables orchestrating long-running AI agents from any MCP host.2-