MCP: Model Context ProtocolBeginnerModule 05 — Understanding MCP tools
How does the MCP tools/call method work?
Question 39 of 43 · Updated
On this page
Direct answer#
MCP tools/call invokes a named tool on an MCP server. The client supplies the tool name and its arguments, the server validates and executes the operation, and a correlated response carries the outcome.
Think of tools/list as reading a restaurant menu and tools/call as placing an order. Listing describes the available operations; calling requests an actual operation.
The examples below use the historical MCP 2025-06-18 specification.
1. Follow a real invocation#
Suppose a customer asks: "Where is shipment SHP-1042?"
The assistant has already discovered a tool named track_shipment. Its input schema requires a non-empty string named tracking_id. After initialization and the host's permission checks, the MCP client sends:
JSON{ "jsonrpc": "2.0", "id": 17, "method": "tools/call", "params": { "name": "track_shipment", "arguments": {"tracking_id": "SHP-1042"} } }
| Field | Meaning |
|---|---|
| method | The standard MCP operation: tools/call |
| params.name | The specific tool advertised by this server |
| params.arguments | Values passed to that tool |
| id | Correlates this request with its response |
The arguments object is optional in the historical request schema, but this particular tool requires an argument. Omitting it would not satisfy the advertised tool contract.
The server resolves track_shipment, validates the input and checks whether the authenticated actor may access that shipment. Its handler obtains the current status. An illustrative successful response is:
JSON{ "jsonrpc": "2.0", "id": 17, "result": { "content": [ {"type": "text", "text": "In transit"} ] } }
The response ID matches the request ID. The host can now present the verified result to the customer. These are fictional shipment data, not a live tracking service.
The host may use an LLM to propose the call, but an LLM is not required. The model does not execute server code or supply trusted authorization.
2. What happens inside the server?#
A typical implementation performs three independent checks before returning business data:
- Resolve the named tool in the server's supported registry.
- Validate the arguments against its input schema and business constraints.
- Enforce the actor's permission to perform that particular operation.
For example, tracking_id must be a string, but a correctly formatted tracking ID belonging to another customer must still be rejected. Never accept an argument such as admin: true as proof of authorization. Identity and permission come from trusted application mechanisms, not model-generated arguments.
Only after the applicable checks does the handler access the shipment service. The server packages the result into the supported content format. Clients must associate it with the original request and validate any advertised result schema. Structured output is covered in Q52.
3. Understand three different outcomes#
A response containing result does not always mean the tool succeeded.
| Outcome | What the client sees | Example |
|---|---|---|
| Successful invocation | result with content; isError absent or false | Shipment is in transit |
| Tool execution error | result with isError: true | Shipment unavailable or backend operation failed |
| Protocol error | JSON-RPC error instead of result | Unsupported tool name or invalid protocol-level request |
For example, the recognized tracking tool might report an application-level failure:
JSON{ "jsonrpc": "2.0", "id": 18, "result": { "content": [ {"type": "text", "text": "Shipment unavailable."} ], "isError": true } }
A different request targeting an unknown tool might receive a protocol error such as:
JSON{ "jsonrpc": "2.0", "id": 19, "error": { "code": -32602, "message": "Unknown tool" } }
These are illustrative outcomes for different requests. The exact error mapping depends on the failure, applicable specification and SDK. Do not invent a universal rule that every validation or permission failure must use one error code. A malformed protocol envelope differs from a recognized tool reporting an execution failure.
A transport timeout is different again: the client may not receive a usable response at all. For a state-changing tool, that does not establish whether the operation committed. Never blindly repeat an uncertain payment or booking.
4. Practical Python example: the tool handler#
Here is the small business handler behind the tracking operation. It accepts the decoded arguments and trusted application data, not a complete JSON-RPC envelope.
PYTHONdef track_shipment(arguments, allowed_ids, statuses): def error(message): return {'content': [{'type': 'text', 'text': message}], 'isError': True} if (type(arguments) is not dict or set(arguments) != {'tracking_id'} or type(arguments['tracking_id']) is not str or not arguments['tracking_id']): return error('Provide a non-empty tracking_id.') tracking_id = arguments['tracking_id'] if tracking_id not in allowed_ids or tracking_id not in statuses: return error('Shipment unavailable.') return {'content': [{'type': 'text', 'text': statuses[tracking_id]}]}
Example inputs:
PYTHONresult = track_shipment( {"tracking_id": "SHP-1042"}, {"SHP-1042"}, {"SHP-1042": "In transit"} ) print(result)
Output:
{'content': [{'type': 'text', 'text': 'In transit'}]}The allowed_ids set represents a trusted permission decision for the current actor. It is not supplied by the model. Missing and unauthorized shipment records deliberately produce the same message, avoiding an obvious distinction that could disclose another customer's shipment existence.
Six actual unit tests passed: successful invocation, missing argument, invalid argument types, unexpected arguments, empty tracking ID, and identical error results for unavailable and unauthorized shipments.
This is a local, synchronous handler fixture, not a runnable MCP server. It validates a deliberately small contract and returns a result fragment. A real SDK supplies transport, dispatch, correlation and serialization; real authentication, tenant scoping, storage and authorization must be implemented separately. The fixture does not establish complete resistance to information leaks, including timing side channels.
5. Common mistakes#
| Mistake | Better approach |
|---|---|
| Use track_shipment as the JSON-RPC method | Use tools/call and put track_shipment in params.name |
| Invoke a guessed or stale tool name | Resolve the current descriptor from the approved server |
| Assume valid arguments imply permission | Check both input validity and actor authority |
| Treat any result as success | Inspect isError and the actual business outcome |
| Execute a side effect again after a timeout | Establish the previous outcome or use an appropriate idempotency contract |
For debugging, inspect the selected server, tool name, validated arguments, request ID and response category. Avoid logging sensitive shipment references or credentials.
Interview-ready answer#
tools/call invokes a specific MCP tool by sending its name and arguments to the server. The server resolves the tool, validates inputs, enforces authorization and executes its implementation. It returns a correlated response containing content, optional structured output or a tool execution error. Protocol failures use the applicable JSON-RPC error mechanism. Discovery does not authorize invocation, and a timeout does not prove an external action failed.
Next: Q49 explains how tool input schemas define the arguments clients are expected to supply.
References and verification#
Historical 2025-06-18 baseline; authorized offline research and changelog exceptions applied. Official references were not retrieved live. The Python handler and external test suite were syntax-compiled and executed on Python 3.13.5 with warnings treated as errors (6/6 tests passed). No live MCP SDK, carrier service or transport was exercised; Mermaid rendering is unverified.
References
- 1.MCP toolsmodelcontextprotocol.io
- 2.MCP lifecyclemodelcontextprotocol.io
- 3.JSON-RPC 2.0 specificationjsonrpc.org
- 4.Official MCP Python SDKgithub.com
- 5.Python unittestdocs.python.org
Related questions
Explore other topics:Forward Deployed EngineeringAI AgentsLarge Language ModelsRetrieval-Augmented Generation