An MCP server that hosts dynamically configurable finite state machines for managing agent and team process state.
Marshalling multiple agents toward a big goal is about more than just breaking down a prompt into tasks and enabling collaboration.
A large software project typically moves through a non-linear and occasionally looping path from inception to design to building to testing to documentation to marketing to production. Different teams are focused on different aspects over time, informed by what's gone before and with an eye toward an ever-changing goal that is refined according to lessons learned.
You can't control all that with just a prompt.
A Puzzle in puzzlebox is a finite state machine. It's just easier to say, write, and think about.
Imagine the Rubik's Cube puzzle. It has 43 quintillion states, and to move between them, you make twists on the planes of the cube.
An even more challenging puzzle is how create a non-trivial thing with AI agents, as that thing becomes more complex.
- A finite number of discrete states, e.g., "Inception", "Specification", "DomainModeling", "Design", "Build", etc.
- Each state may have any number of actions (including 0) that initiate transition to another state.
- There is an initial state.
- There is a current state that may differ after actions have been performed on the puzzle.
- Transitions can be canceled by state exit and enter guards, e.g., Consult LLM via client sampling request.
An MCP Server implementation that:
- Manages puzzle instances
- Exposes tools for:
- Adding puzzles
- Getting a snapshot of the state and available actions for a given puzzle in the box
- Performing actions on a given puzzle in the box that trigger state transitions
- Exposes registered puzzles as resources
- Clients can use the
Puzzle Snapshot
resource template to fetch the resource by ID - Resource URI is
puzzlebox:/puzzle/{puzzleId}
- Clients can subscribe/unsubscribe to individual resource URIs
- Clients can use the
{
"initialState": "LOBBY",
"states": {
"LOBBY": {
"name": "LOBBY",
"actions": {
"START_GAME": { "name": "START_GAME", "targetState": "PLAYING" }
}
},
"PLAYING": {
"name": "PLAYING",
"actions": {
"END_GAME": { "name": "END_GAME", "targetState": "GAME_OVER" }
}
},
"GAME_OVER": {
"name": "GAME_OVER",
"actions": {
"RESTART": { "name": "RESTART", "targetState": "PLAYING" }
}
}
}
}
Testing of the server was done with the official reference client - the MCP Inspector. These screenshots show the various MCP tools and resources implemented by the sever..
- Clients connect to a puzzlebox SSE server.
- Clients register puzzles with the server.
- Clients perform actions on puzzles that may change their state and available actions.
- The puzzlebox server ensures that any attempted action is valid for the current state of the given puzzle.
- If an action is valid, a transition to the target state is initiated.
- During transition, optional exit and enter guards may send sampling requests to the client, the results of which could lead to cancellation of the transition (think acceptance testing by stakeholders)
- If guards pass, the state transition completes.
- Clients update their UI based on the new state.
- Clients can subscribe to a given puzzle to receive updates when its state changes.
- If the client receives a resource updated notification, they can either read the resource or use the
get_puzzle_snapshot
tool to get the current state and available actions.
- Inputs: None
- Returns: JSON object with boolean
success
andpuzzleId
- Inputs:
puzzleId
- Returns: JSON object with
currentState
andavailableActions
array - Note: MCP clients that don't support resource subscriptions can poll this tool to watch for state changes.
- Inputs:
puzzleId
andactionName
- Returns: JSON object with
currentState
andavailableActions
array
- Inputs: None
- Returns: JSON object with current
count
of registered puzzles
cd /path/to/puzzlebox/
npm install
npm run build
- Builds the stdio-based MCP server runtime at
/dist/index.js
npm run start
- Launches an SSE-based/MCP server on port
:3001
with endpoint/sse
- This has a single instance of the MCP server which multiple clients can connect to via SSE
- MUST BE LAUNCHED BEFORE RUNNING INSPECTOR
npm run inspector
- Runs the Model Context Protocol Inspector
- The Inspector UI will be available at: http://localhost:5173
- In the Inspector UI:
- Make sure
Transport Type
is set toSSE
- Make sure
URL
is set to http://localhost:3001/sse - Click its "Connect" button to connect to the MCP Proxy
- You should see Green light 🟢and "Connected" message.
- Click its List Tools button
- Make sure
npm run format
- Runs
prettier
on the code, adjusting formatting
npm run typecheck
- Runs
tsc
with args to check and report type issues
npm run lint
- Runs
eslint
to non-destructively check for and report syntax problems
npm run lint:fix
- Runs
eslint
to check for and fix syntax problems
npm run test
- Run the unit tests