# How to create my own MCP tools?
Module developers can create their own tools to expose their module's functionality to AI applications, or to expose native PrestaShop features beyond what the default tools offer.
To create your own tools for PrestaShop MCP Server, declare your module as MCP-compatible and define your custom tools using PHP attributes.
Tables of contents
# 1. Declare your module as MCP-compatible
To let PrestaShop MCP Server know your module includes MCP tools, declare it as MCP-compatible by adding the isMcpCompliant() method to your main module class:
<?php
class Ps_MySuperModule extends Module
{
// This method allow ps_mcp_server to discover your tools
public function isMcpCompliant()
{
return true;
}
}
?>
# 2. Implement your MCP tools
Use the PHP-MCP attributes McpTool and Schema to declare your function as an MCP tool. Your tools will be automatically discovered and made available.
For more information about PHP-MCP attributes, visit the PHP-MCP documentation (opens new window).
Example:
<?php
class MySuperTool
{
// example of a tool to retrieve products from the database
#[PhpMcp\\Server\\Attributes\\McpTool(
name: 'update_prestashop_product_by_id',
description: 'Update a product description by its ID in the PrestaShop store'
)]
#[PhpMcp\\Server\\Attributes\\Schema(
properties: [
'productId' => ['type' => 'integer', 'description' => 'Product ID'],
],
required: ['productId']
)]
public function getProducts(int $langId): array {
return Product::getProducts($langId, 0, 100, 'id_product', 'ASC');
}
}
?>
# Guidelines for effective tools
These guidelines will help you design tools that agents can understand and leverage to accomplish complex tasks.
# 1. Describe your tools clearly and concisely
Define each tool's purpose and behavior clearly and concisely. This helps AI models understand the tool's functionality and use it correctly.
Example:
#[PhpMcp\\Server\\Attributes\\McpTool(
name: 'search_product_by_name',
description: 'Search a product in the store by name only. This search uses fuzzy matching. Result are sorted by relevance. '
)]
#[PhpMcp\\Server\\Attributes\\Schema(
properties: [
'searchTerms' => ['type' => 'string', 'description' => 'Search terms to look up in product names. Several terms can be provided as a semicolon separated list.'],
'language' => ['type' => 'integer', 'description' => 'Language to run the search in. Defaults to prefered language.']
],
required: ['productId']
)]
In this example, the tool name and description leave no doubt on the use of the tool. The field searchTerms also shows how an agent can be guided to make full use of your tools.
# 2. Use consistent vocabulary
Use consistent vocabulary throughout your MCP server to help agents connect your tools and plan complex workflows using multiple tools together. This includes parameters, error messages, and other technical terms.
# 3. Validate your inputs
Validate your tool inputs using the #[Schema()] annotation provided by PHP-MCP (opens new window) to ensure they are correct and consistent.
# 4. Do sanity checks
After validating parameters, ensure agents make reasonable requests to your tool. This includes:
- Limiting the size of results and complexity of requests
- Enforcing permissions
- Checking for inappropriate content when the AI generates text or images
- Detecting erratic behavior, such as an agent stuck in a loop
For more guidelines on writing effective MCP tools, visit the MCP Development Guide (opens new window).
# Debug
PrestaShop MCP Server stores logs, cache, and configuration files in the .mcp folder. .logs files are created when the MCP module parameter Enable logs is set to true.
To force a rescan of locations, delete .cache.json.
Use the MCP inspector (opens new window) to verify your server is working and validate that your MCP tools are functioning properly.
# Dependencies
php-mcp/server(opens new window) - PHP MCP Server libraryphp-mcp/client(opens new window) - PHP MCP Client library
# Documentation
- MCP Protocol spec: modelcontextprotocol.io (opens new window)
- PHP MCP library: PHP-MCP (opens new window)