Practical Tool Calling Setup for Claude Sonnet

Experience integrating tool calling for Claude Sonnet by building a real-world agent system with provider factories and MCP servers.

gray adjustable wrench and gray pipe wrench

Many people read the Anthropic API documentation, copy the sample code, run it, and then realize their agent system breaks immediately when facing real-world errors. There is nothing worse than an AI taking it upon itself to call a data deletion API just because we lack a control mechanism.

What is tool calling, really?

Previously, LLMs were just machines that answered questions by generating text. Now, tool calling transforms an LLM into an active operator. It allows the AI to understand when it needs to fetch additional information from the outside and return a data structure to call functions you have defined.

If you are wondering about the broader theoretical aspects, you can read AI Tool Calling: When AI actually works to understand its core nature. Here, I will focus on the practical technical side and the system architecture behind it.

The practical agent architecture I’m using

I am currently writing a small agent layer for the onmee project. Instead of being locked into a single model, I built a provider factory that can flexibly swap between Claude, Gemini, and OpenAI. This helps me always choose the most suitable model for each specific type of task.

Cost-free testing strategy

In the “agent/providers/” directory of the onmee repo, I wrote a separate deterministic provider. Its function is to run local tests without making any actual external API calls. (It might sound redundant, but trust me, it saves me a lot of API money every month). Separating this logic makes the system much more stable before pushing to production.

Try Cursor to automate JSON schema writing for tool calling via my referral link here.

Using Claude Code with MCP servers

In my daily work, I use Claude Code connected directly to MCP servers like Slack, Figma, and Shopify. Letting the AI read documentation from Figma and then automatically send update messages via Slack is a daily workflow. What I share about tool calling comes entirely from actual operational experience, not just reading documentation online.

Why use Claude Sonnet right now?

With the release of Claude Sonnet 4.5 and 4.6, Anthropic’s JSON schema compliance has improved significantly. According to the official Anthropic API documentation (docs.anthropic.com/en/docs/tool-use), providing clear tool descriptions helps the model choose the right tool with a near-perfect success rate. This is a major improvement over older versions, where the model would sometimes hallucinate and invent non-existent variable names.

You can consider more about model versions by reading the post Claude Sonnet 4 vs Opus 4: Which model to choose?.

Quick comparison table

Criteria Claude Sonnet 4.6 GPT-5.2 Notes
Schema Compliance Excellent Excellent Both return standard JSON
Response Speed Fast Average Sonnet 4.6 is optimized for execution time
MCP Integration Native Support Requires wrapper Claude has better support via the Anthropic ecosystem

How to use it effectively

  1. Define schemas strictly. Don’t just name a tool “get_user_info”; describe it in detail like “Fetch user information based on user_id to display on the dashboard.”
  2. Use the Factory Pattern for providers. Just like I do with the onmee project, separate the LLM API calling logic from the system’s business logic.
  3. Fallbacks are mandatory. When the model calls the wrong tool or misses a parameter, your system must catch the error and proactively send that error message back to the LLM so it can self-correct.
  4. Always use a mock provider when running unit tests. No one wants to be charged for thousands of API calls every day when pushing code.

Frequently Asked Questions

What is a mock provider for?

It returns fixed results that you define in advance. This helps you check if your source code handles tool calling results correctly without paying for real API calls.

Is an MCP server hard to set up?

If you use popular tools like Slack or Figma, the community already has these servers available. You just need to run them as a local service and point the path to Claude Code.

Can I use multiple tools at once?

Absolutely. Claude Sonnet supports parallel tool calling, meaning it can request the execution of multiple functions simultaneously if it deems it necessary to save time.

Conclusion

Building an automated AI system isn’t about how “cool” your prompt is. It’s about how you architect the system so the AI can confidently operate and self-correct when it makes a mistake. Decoupling the provider layer and using MCP servers has helped me reduce daily repetitive tasks. I think writing code for an AI to use is not much different from writing an API for a frontend—keep it clear and strict, and it will run stably.

You might also like

← Back to Blog