{"slug": "mcp-has-no-concept-of-tool-order-here-s-how-to-enforce-it-anyway", "title": "MCP Has No Concept of Tool Order — Here's How to Enforce It Anyway", "summary": "A developer demonstrated a pattern for enforcing tool-call ordering in MCP servers, which have no built-in concept of tool order. The approach tracks per-session state and returns a structured isError response when a dependent tool is invoked before its prerequisite, avoiding exceptions that would kill the connection.", "body_md": "session_state = {} # session_id -> {\"step_a_done\": False}\n\ndef tool_b(session_id, **kwargs):\n\n    state = session_state.setdefault(session_id, {\"step_a_done\": False})\n\n    if not state[\"step_a_done\"]:\n\n        # a normal tool error, not an exception that kills the connection\n\n        return {\n\n            \"isError\": True,\n\n            \"content\": [{\"type\": \"text\", \"text\": \"call tool_a first — tool_b requires its output\"}],\n\n        }\n\n    # ... do the real work", "url": "https://wpnews.pro/news/mcp-has-no-concept-of-tool-order-here-s-how-to-enforce-it-anyway", "canonical_source": "https://dev.to/ramdai_bista/mcp-has-no-concept-of-tool-order-heres-how-to-enforce-it-anyway-3c4l", "published_at": "2026-11-25 14:32:24+00:00", "updated_at": "2026-11-25 14:42:44.241736+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["MCP"], "also_reported_by": [], "takeaway": "Enforce MCP tool ordering by tracking per-session prerequisite state and returning an isError result with a 'call tool_a first' message instead of throwing an exception that drops the connection.", "recommendation": {"advice": "When one MCP tool depends on another's output, gate it on per-session state and return a structured isError telling the model which tool to call first, rather than raising.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/mcp-has-no-concept-of-tool-order-here-s-how-to-enforce-it-anyway", "markdown": "https://wpnews.pro/news/mcp-has-no-concept-of-tool-order-here-s-how-to-enforce-it-anyway.md", "text": "https://wpnews.pro/news/mcp-has-no-concept-of-tool-order-here-s-how-to-enforce-it-anyway.txt", "jsonld": "https://wpnews.pro/news/mcp-has-no-concept-of-tool-order-here-s-how-to-enforce-it-anyway.jsonld"}}