Tools
The Model Context Protocol (MCP) allows servers to expose tools that can be invoked by language models. Tools enable models to interact with external systems, such as querying databases, calling APIs, or performing computations. Each tool is uniquely identified by a name and includes metadata describing its schema.
User Interaction Model
Tools in MCP are designed to be model-controlled, meaning that the language model can discover and invoke tools automatically based on its contextual understanding and the user’s prompts.
However, implementations are free to expose tools through any interface pattern that suits their needs—the protocol itself does not mandate any specific user interaction model.
For trust & safety and security, there SHOULD always be a human in the loop with the ability to deny tool invocations.
Applications SHOULD:
- Provide UI that makes clear which tools are being exposed to the AI model
- Insert clear visual indicators when tools are invoked
- Present confirmation prompts to the user for operations, to ensure a human is in the loop
Capabilities
Servers that support tools MUST declare the tools
capability:
listChanged
indicates whether the server will emit notifications when the list of
available tools changes.
Protocol Messages
Listing Tools
To discover available tools, clients send a tools/list
request. This operation supports
pagination.
Request:
Response:
Calling Tools
To invoke a tool, clients send a tools/call
request:
Request:
Response:
List Changed Notification
When the list of available tools changes, servers that declared the listChanged
capability SHOULD send a notification:
Message Flow
Data Types
Tool
A tool definition includes:
name
: Unique identifier for the tooldescription
: Human-readable description of functionalityinputSchema
: JSON Schema defining expected parametersoutputSchema
: Optional JSON Schema defining expected output structureannotations
: optional properties describing tool behavior
Tool Result
Tool results may be structured or unstructured, depending on whether the tool definition specifies an output schema.
Structured tool results are JSON objects that are valid with respect to the tool’s output schema.
Unstructured tool results can contain multiple content items of different types:
Text Content
Image Content
Audio Content
Embedded Resources
Resources MAY be embedded, to provide additional context or data, behind a URI that can be subscribed to or fetched again by the client later:
Output Schema
Tools that produce structured results can use the outputSchema
property to provide a JSON Schema describing the expected structure of their output.
When a tool specifies an outputSchema
:
-
Clients MUST validate that results from that tool contain a
structuredContent
field whose contents validate against the declaredoutputSchema
. -
Servers MUST provide structured results in
structuredContent
that conform to the declaredoutputSchema
of the tool.
For backwards compatibility, a tool that declares an outputSchema
may also return unstructured results in the content
field.
- If present, the unstructured result should be functionally equivalent to the structured result. (For example, serialized JSON can be returned in a
TextContent
block.) - Clients that support
structuredContent
should ignore thecontent
field if present.
Example tool with output schema:
Example valid response for this tool:
The outputSchema
helps clients and LLMs understand and properly handle structured tool outputs by:
- Enabling strict schema validation of responses
- Providing type information for better integration with programming languages
- Guiding clients and LLMs to properly parse and utilize the returned data
- Supporting better documentation and developer experience
Error Handling
Tools use two error reporting mechanisms:
-
Protocol Errors: Standard JSON-RPC errors for issues like:
- Unknown tools
- Invalid arguments
- Server errors
-
Tool Execution Errors: Reported in tool results with
isError: true
:- API failures
- Invalid input data
- Business logic errors
Example protocol error:
Example tool execution error:
Security Considerations
-
Servers MUST:
- Validate all tool inputs
- Implement proper access controls
- Rate limit tool invocations
- Sanitize tool outputs
-
Clients SHOULD:
- Prompt for user confirmation on sensitive operations
- Show tool inputs to the user before calling the server, to avoid malicious or accidental data exfiltration
- Validate tool results before passing to LLM
- Implement timeouts for tool calls
- Log tool usage for audit purposes