MCP for PrestaShop
  • English
  • Français
  • Español
  • Italiano
  • English
  • Français
  • Español
  • Italiano
  • Getting started
    • Introduction
    • Installation
    • Setup
    • Security
    • Connect your AI application
  • MCP Overview
    • What is MCP? Glossary
    • How to create my own MCP elements?
  • Troubleshooting

How to create my own MCP elements?

Module developers can create their own MCP elements 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 MCP elements for PrestaShop MCP Server, declare your module as MCP-compatible and define your custom elements using PHP attributes.

Tables of contents

1. Declare your module as MCP-compatible

To let PrestaShop MCP Server know your module includes MCP elements, declare it as MCP-compatible by adding the isMcpCompliant() method to your main module class:

<?php

class Ps_MySuperModule extends Module
{
    // This method allows ps_mcp_server to discover your MCP elements
    public function isMcpCompliant()
    {
        return true;
    }
}

?>

2. Implement your MCP Tools

Warning

MCP elements must be created exclusively in the src directory and its subdirectories. Any code located in other directories will be ignored.

Tools are actions that an AI agent can invoke to interact with your store (e.g. search products, update orders). To create MCP tools in your module, use PHP attributes from the PrestaShop MCP Server module:

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpTool;
use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpSchema;
use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpIcon;
use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpToolAnnotations;

class MySuperTool
{
    #[PsMcpTool(
        name: 'say_hello',
        title: 'Hello User',
        description: 'Say hello to a user',
        annotations: new PsMcpToolAnnotations(
            title: 'Hello User',
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: false,
        ),
        icons: [
            new PsMcpIcon(
                src: 'https://picsum.photos/100/100',
                mimeType: 'image/png',
                sizes: ['100x100']
            )
        ],
        meta: ['category' => 'greeting']
    )]
    #[PsMcpSchema(
        properties: [
            'username' => ['type' => 'string', 'description' => 'Username'],
        ],
        required: ['username']
    )]
    public function sayHello(string $username): string
    {
        try {
            return "Hello, $username! Welcome to your PrestaShop store.";
        } catch (\Exception $e) {
            throw new PsMcpToolCallException($e->getMessage(), $e->getCode());
        }
    }
}

?>

PsMcpToolAnnotations is exclusive to Tools. It provides hints to the AI client about the tool's behavior:

PropertyTypeDescription
titlestringHuman-readable title for the tool
readOnlyHintboolThe tool does not modify the environment
destructiveHintboolThe tool may perform destructive updates
idempotentHintboolThe tool can be called repeatedly without side effects
openWorldHintboolThe tool interacts with external systems

PsMcpSchema defines the tool's input parameters via JSON Schema. It applies only to Tools.

Check the ps_mcp_boilerplate project for a full implementation example.

Security note: For development only, you can disable authentication by adding this constant to your PrestaShop configuration:

define('_PS_MCP_SERVER_ALLOW_INSECURE_MODE_', true);

Warning

Never enable insecure mode in production environments.

3. Implement your MCP Resources

Resources expose read-only data that an AI agent can access (e.g. store configuration, product catalog). Each resource is identified by a fixed URI.

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpResource;
use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpIcon;

class MyStoreResources
{
    #[PsMcpResource(
        uri: 'store://configuration',
        name: 'store_configuration',
        description: 'Returns the current store configuration (currency, language, timezone...)',
        mimeType: 'application/json',
        size: 18,
        icons: [
            new PsMcpIcon(
                src: 'https://picsum.photos/100/100',
                mimeType: 'image/png',
                sizes: ['100x100']
            )
        ],
        meta: ['category' => 'store_management']
    )]
    public function getStoreConfiguration(): array
    {
        try {
            return [
                'currency' => Configuration::get('PS_CURRENCY_DEFAULT'),
                'language' => Configuration::get('PS_LANG_DEFAULT'),
            ];
        } catch (\Exception $e) {
            throw new PsMcpResourceReadException($e->getMessage(), $e->getCode());
        }
    }
}

?>

Tips

Resources do not use PsMcpToolAnnotations or PsMcpSchema. These attributes are reserved for Tools.

4. Implement your MCP Resource Templates

Resource Templates define URI patterns (RFC 6570) that allow an AI agent to dynamically request resources by filling in variables (e.g. products://{id}). They are useful when the set of possible resources is large or unknown in advance.

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpResourceTemplate;

class MyResourceTemplates
{
    #[PsMcpResourceTemplate(
        uriTemplate: 'products://{id}',
        name: 'product_by_id',
        description: 'Returns the full details of a product identified by its numeric ID',
        mimeType: 'application/json',
        meta: ['category' => 'product_management']
    )]
    public function getProductById(int $id): array
    {
        try {
            $product = new Product($id, true);
            return $product->getFields();
        } catch (\Exception $e) {
            throw new PsMcpResourceReadException($e->getMessage(), $e->getCode());
        }
    }
}

?>

Tips

Like Resources, Resource Templates do not use PsMcpToolAnnotations or PsMcpSchema.

5. Implement your MCP Prompts

Prompts are reusable conversation templates that help an AI agent start an exchange with pre-filled context. They are surfaced in the client UI so users can trigger them with a single click.

A prompt returns a message array (role + content), representing a conversation exchange:

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpPrompt;
use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpIcon;

class MyStorePrompts
{
    #[PsMcpPrompt(
        name: 'image_generation',
        title: 'Image Generation',
        description: 'Generate images for products',
        icons: [
            new PsMcpIcon(
                src: 'https://picsum.photos/100/100',
                mimeType: 'image/png',
                sizes: ['100x100']
            )
        ],
        meta: ['category' => 'image_generation']
    )]
    public function generateImage(string $color, string $size): array
    {
        try {
            return [
                ['role' => 'assistant', 'content' => 'You are an image generation tool for a PrestaShop store.'],
                ['role' => 'user', 'content' => "Generate an image with color: $color, size: $size."],
                ['role' => 'assistant', 'content' => 'Here is your generated image: https://example.com/image?color=' . urlencode($color) . '&size=' . urlencode($size)],
            ];
        } catch (\Exception $e) {
            throw new PsMcpPromptGetException($e->getMessage(), $e->getCode());
        }
    }
}

?>

Tips

Prompts do not use PsMcpToolAnnotations, PsMcpSchema, or annotations. Only name, title, description, icons and meta are available.

Attribute summary by element type

AttributeToolsResourcesResource TemplatesPrompts
PsMcpSchemayes---
PsMcpToolAnnotationsyes---
PsMcpIconyesyes-yes
metayesyesyesyes
titleyes--yes
nameyesyesyesyes
descriptionyesyesyesyes

Error handling

PrestaShop MCP Server provides dedicated exception classes to handle errors in tools, resources and prompts. Each exception wraps the corresponding MCP SDK exception and ensures that the error is properly communicated to the AI agent through the MCP protocol.

Exception classWraps (SDK)Use in
PsMcpToolCallExceptionToolCallExceptionTools
PsMcpResourceReadExceptionResourceReadExceptionResources / Resource Templates
PsMcpPromptGetExceptionPromptGetExceptionPrompts

All constructors take the same two parameters:

  • message (string): A human-readable error description that will be sent to the AI agent.
  • exitCode (int): A numeric exit code indicating the type of error.

Error handling in Tools

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpTool;
use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpSchema;
use PrestaShop\Module\PsMcpServer\Server\Exceptions\PsMcpToolCallException;

class MySuperTool
{
    #[PsMcpTool(
        name: 'get_order_by_id',
        description: 'Retrieve an order by its ID'
    )]
    #[PsMcpSchema(
        properties: [
            'orderId' => ['type' => 'integer', 'description' => 'The order ID'],
        ],
        required: ['orderId']
    )]
    public function getOrderById(int $orderId): array
    {
        try {
            $order = new Order($orderId);

            if (!Validate::isLoadedObject($order)) {
                throw new \Exception('Order not found');
            }

            return $order->getFields();
        } catch (\Exception $e) {
            throw new PsMcpToolCallException(
                'Failed to retrieve order: ' . $e->getMessage(),
                1
            );
        }
    }
}

?>

Error handling in Resources

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpResource;
use PrestaShop\Module\PsMcpServer\Server\Exceptions\PsMcpResourceReadException;

class MyStoreResources
{
    #[PsMcpResource(
        uri: 'store://configuration',
        name: 'store_configuration',
        description: 'Returns the current store configuration',
        mimeType: 'application/json',
    )]
    public function getStoreConfiguration(): array
    {
        try {
            $currency = Configuration::get('PS_CURRENCY_DEFAULT');

            if (!$currency) {
                throw new \Exception('Currency configuration not found');
            }

            return ['currency' => $currency];
        } catch (\Exception $e) {
            throw new PsMcpResourceReadException(
                'Failed to read store configuration: ' . $e->getMessage(),
                1
            );
        }
    }
}

?>

Error handling in Prompts

<?php

use PrestaShop\Module\PsMcpServer\Server\Attributes\PsMcpPrompt;
use PrestaShop\Module\PsMcpServer\Server\Exceptions\PsMcpPromptGetException;

class MyStorePrompts
{
    #[PsMcpPrompt(
        name: 'low_stock_analysis',
        description: 'Analyze products with low stock and suggest restocking actions',
    )]
    public function lowStockAnalysis(): array
    {
        try {
            $threshold = Configuration::get('PS_LOW_STOCK_THRESHOLD');

            if ($threshold === false) {
                throw new \Exception('Low stock threshold not configured');
            }

            return [
                ['role' => 'user', 'content' => 'List all products with stock below ' . $threshold],
            ];
        } catch (\Exception $e) {
            throw new PsMcpPromptGetException(
                'Failed to generate prompt: ' . $e->getMessage(),
                1
            );
        }
    }
}

?>

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:

#[PsMcpTool(
    name: 'search_product_by_name',
    description: 'Search a product in the store by name only. This search uses fuzzy matching. Results are sorted by relevance.'
)]
#[PsMcpSchema(
    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 preferred language.']
    ],
    required: ['searchTerms']
)]

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 #[PsMcpSchema()] annotation provided, to ensure they are correct and consistent.

4. Do sanity checks

After validating parameters, ensure agents make reasonable requests to your tools. 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.

Guidelines for effective Resources

1. Choose clear and predictable URIs

Use a consistent URI scheme that reflects the hierarchy of your data. The agent should be able to guess a resource's URI from its name.

Examples:

  • store://configuration for global configuration
  • store://catalog/products for the product catalog
  • store://orders/stats for order statistics

2. Document the return format

Clearly indicate the mimeType and describe the structure of returned data in the description. The agent cannot guess the format without guidance.

3. Use size when relevant

The size parameter helps the agent estimate the response size before requesting it, which is useful for large resources.

4. Prefer Resource Templates for parameterized data

If your resource accepts an identifier or filter, use a Resource Template (products://{id}) rather than a Tool. Templates are lighter and more explicit for data reading.

Guidelines for effective Prompts

1. Return structured messages

A prompt returns an array of role/content messages. Use the assistant role to provide context instructions and the user role to formulate the initial request.

2. Make your prompts parameterizable

Accept arguments to customize the prompt's behavior. This allows the agent or user to adapt the prompt without creating a new one.

3. Keep prompts focused

Each prompt should correspond to a specific task or scenario. Avoid overly generic prompts that try to cover everything.

4. Clearly describe the expected output

The prompt's description should indicate what the agent will produce as a result. The user should understand what they will get before triggering the prompt.

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 the .mcp/cache directory.

Use the MCP inspector to verify your server is working and validate that your MCP elements are functioning properly.

Dependencies

  • modelcontextprotocol/php-sdk - PHP MCP SDK

Documentation

  • MCP Protocol spec: modelcontextprotocol.io
Last Updated: 4/30/26, 9:18 AM
Contributors: khanhmas, John.R, fox-john, cnavarro-prestashop, Cyril Navarro, Jonathan Renard, dependabot[bot], gericfo, Claude Opus 4.6
Prev
What is MCP? Glossary