packages/kilo-docs/pages/automate/tools/use-mcp-tool.md
The use_mcp_tool tool enables interaction with external tools provided by connected Model Context Protocol (MCP) servers. It extends Kilo Code's capabilities with domain-specific functionality through a standardized protocol.
The tool accepts these parameters:
server_name (required): The name of the MCP server providing the tooltool_name (required): The name of the tool to executearguments (required/optional): A JSON object containing the tool's input parameters, following the tool's input schema. May be optional for tools that require no input.This tool allows Kilo Code to access specialized functionality provided by external MCP servers. Each MCP server can offer multiple tools with unique capabilities, extending Kilo Code beyond its built-in functionality. The system validates arguments against schemas, manages server connections, and processes responses of various content types (text, image, resource).
@modelcontextprotocol/sdk libraryaccess_mcp_resource tool for resource retrievalMCP servers can be configured globally or at the project level:
.kilocode/mcp.json file within your project's root directory..kilocode/mcp.json can be committed to version control, it simplifies sharing configurations with your team.When the use_mcp_tool tool is invoked, it follows this process:
Initialization and Validation:
Execution and Communication:
StdioClientTransport: For communicating with local processes via standard I/OSSEClientTransport: For communicating with HTTP servers via Server-Sent Events@modelcontextprotocol/sdk library for standardized interactionsResponse Processing:
access_mcp_resource)isError flag to determine if error handling is neededResource and Error Handling:
The MCP architecture provides several security features:
Requesting weather forecast data with text response:
<use_mcp_tool>
<server_name>weather-server</server_name>
<tool_name>get_forecast</tool_name>
<arguments>
{
"city": "San Francisco",
"days": 5,
"format": "text"
}
</arguments>
</use_mcp_tool>
Analyzing source code with a specialized tool that returns JSON:
<use_mcp_tool>
<server_name>code-analysis</server_name>
<tool_name>complexity_metrics</tool_name>
<arguments>
{
"language": "typescript",
"file_path": "src/app.ts",
"include_functions": true,
"metrics": ["cyclomatic", "cognitive"]
}
</arguments>
</use_mcp_tool>
Generating an image with specific parameters:
<use_mcp_tool>
<server_name>image-generation</server_name>
<tool_name>create_image</tool_name>
<arguments>
{
"prompt": "A futuristic city with flying cars",
"style": "photorealistic",
"dimensions": {
"width": 1024,
"height": 768
},
"format": "webp"
}
</arguments>
</use_mcp_tool>
Accessing a resource through a tool that returns a resource reference:
<use_mcp_tool>
<server_name>database-connector</server_name>
<tool_name>query_and_store</tool_name>
<arguments>
{
"database": "users",
"type": "select",
"fields": ["name", "email", "last_login"],
"where": {
"status": "active"
},
"store_as": "active_users"
}
</arguments>
</use_mcp_tool>
Tool with no required arguments:
<use_mcp_tool>
<server_name>system-monitor</server_name>
<tool_name>get_current_status</tool_name>
<arguments>
{}
</arguments>
</use_mcp_tool>