Posted on Nov 25 • Originally published at agentkitworks.com
MCP Has No Concept of Tool Order — Here's How to Enforce It Anyway
session_state = {} # session_id -> {"step_a_done": False}
def tool_b(session_id, **kwargs):
state = session_state.setdefault(session_id, {"step_a_done": False})
if not state["step_a_done"]:
# a normal tool error, not an exception that kills the connection
return {
"isError": True,
"content": [{"type": "text", "text": "call tool_a first — tool_b requires its output"}],
}
# ... do the real work