Model Context Protocol

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.

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 tool
  • title: Optional human-readable name of the tool for display purposes.
  • description: Human-readable description of functionality
  • inputSchema: JSON Schema defining expected parameters
  • outputSchema: Optional JSON Schema defining expected output structure
  • annotations: optional properties describing tool behavior

Tool Result

Tool results may contain structured or unstructured content. Unstructured content is returned in the content field of a result, and can contain multiple content items of different types:

Text Content

Image Content

This example demonstrates the use of an optional Annotation.

Audio Content

Resource Links

A tool MAY return links to Resources, to provide additional context or data. In this case, the tool will return a URI that can be subscribed to or fetched by the client:

Resource links support the same Resource annotations as regular resources to help clients understand how to use them.

Embedded Resources

Resources MAY be embedded to provide additional context or data using a suitable URI scheme. Servers that use embedded resources SHOULD implement the resources capability:

Embedded resources support the same Resource annotations as regular resources to help clients understand how to use them.

Structured Content

Structured content is returned as a JSON object in the structuredContent field of a result. For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block.

Output Schema

Tools may also provide an output schema for validation of structured results. If an output schema is provided:

  • Servers MUST provide structured results that conform to this schema.
  • Clients SHOULD validate structured results against this schema.

Example tool with output schema:

Example valid response for this tool:

Providing an output schema 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:

  1. Protocol Errors: Standard JSON-RPC errors for issues like:
    • Unknown tools
    • Invalid arguments
    • Server errors
  2. 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

  1. Servers MUST:
    • Validate all tool inputs
    • Implement proper access controls
    • Rate limit tool invocations
    • Sanitize tool outputs
  2. 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

Read the original on modelcontextprotocol.io ↗