Dev.to
7/26/2026

Stop Hardcoding AI Tools: Dynamic Tool Discovery and Schema Validation with Zod & MCP
Short summary
The article argues against hardcoding tool definitions in AI agents and advocates for dynamic tool discovery using Model Context Protocol (MCP) combined with Zod runtime schema validation. It draws an analogy to microservice architecture, where services discover dependencies at runtime rather than hardcoding them. The approach decouples LLM reasoning from external capabilities, allowing agents to discover new tools mid-execution while validating payloads to prevent hallucination-induced errors.
- •Hardcoding AI agent tool definitions creates brittle architectures that break when APIs change
- •MCP enables dynamic tool discovery analogous to microservice service-discovery patterns
- •Zod runtime validation prevents LLM hallucinations from corrupting downstream systems via malformed tool calls
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



