Resources provide the necessary context for a Large Language Model (LLM) to understand a domain, but they are read-only by design. To enable the model to modify systems or retrieve specific data based on dynamic arguments, such as querying a database or hitting an external API, you must implement Tools. Tools differ from Resources in that they are executable functions exposed by the server that the client can invoke when the model determines an action is required.
This chapter focuses on the server-side implementation of these executable primitives. You will define the interface for your tools using JSON Schema, ensuring the model understands exactly what arguments are required and what the tool accomplishes. We will apply input validation using Pydantic to enforce type safety and handle edge cases before executing any logic.
Additionally, we will examine patterns for wrapping external API calls within an MCP tool and managing error propagation through the JSON-RPC layer. A common architectural decision involves choosing between a computed Resource and a Tool; we will analyze the criteria for making this distinction. By the end of this chapter, you will apply these concepts by building a functional server capable of executing SQL queries against a local SQLite database.
3.1 Tool Definition Schema
3.2 Input Validation with Pydantic
3.3 Executing External API Calls
3.4 Error Handling and Reporting
3.5 Designing Computed Resources
3.6 Hands-on Practice: Creating a Database Tool
© 2026 ApX Machine LearningEngineered with