Skip to content

Commit fb21cb7

Browse files
committed
Update readme
1 parent c01e4cc commit fb21cb7

File tree

4 files changed

+229
-1
lines changed

4 files changed

+229
-1
lines changed

README.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,231 @@
99
</p>
1010

1111
<h1 align="center">MCP Server Plugin</h1>
12+
13+
<p align="center"><a href="https://sylius.com/plugins/" target="_blank"><img src="https://sylius.com/assets/badge-official-sylius-plugin.png" width="200"></a></p>
14+
15+
<p align="center">
16+
A Sylius plugin that exposes a Model Context Protocol (MCP) server for enabling interaction with your store via
17+
Large Language Models (LLMs) like ChatGPT.
18+
</p>
19+
20+
# Installation
21+
22+
## Requirements
23+
We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.
24+
25+
| Package | Version |
26+
|---------------|---------|
27+
| PHP | ^8.2 |
28+
| sylius/sylius | ^2.1 |
29+
| MySQL | ^8.4 |
30+
| NodeJS | ^20.x |
31+
32+
---
33+
#### Beware!
34+
35+
This installation instruction assumes that you're using Symfony Flex.
36+
37+
1. Require plugin with composer:
38+
39+
```bash
40+
composer require sylius/mcp-server-plugin
41+
```
42+
43+
**Clear application cache by using command:**
44+
45+
```bash
46+
bin/console cache:clear
47+
```
48+
49+
---
50+
51+
## Documentation
52+
53+
### What is MCP Server?
54+
55+
The Model Context Protocol (MCP) is a standardized way to connect language models (like ChatGPT) with external tools,
56+
APIs, and systems. It allows an AI model to make structured tool calls — similar to calling functions — during a conversation.
57+
58+
The MCP Server acts as a bridge between the language model and your application logic. It exposes a list of tools
59+
(like “search for a product” or “create an order”) and executes them in response to requests from the AI.
60+
61+
This plugin integrates Sylius with an MCP Server, enabling AI agents to interact with your store
62+
(e.g., search products, check prices, start checkout).
63+
64+
We use the official [php-mcp/server](https://github.com/php-mcp/server) package to provide the MCP server runtime.
65+
```
66+
┌────────────────┐ ┌───────────────┐ ┌────────┐
67+
│ MCP Client │◄────────────────►│ MCP Server │◄─────►│ Sylius │
68+
│ (OpenAi, etc.) │ (Stdio/HTTP/SSE) │ (Tools, etc.) │ (API) │ │
69+
└────────────────┘ └───────────────┘ └────────┘
70+
```
71+
72+
To learn more, see the official MCP introduction at [modelcontextprotocol.io](https://modelcontextprotocol.io/introduction).
73+
74+
### Running the MCP Server
75+
76+
You can run the server using the following command:
77+
78+
```bash
79+
bin/console sylius:mcp-server:start
80+
```
81+
82+
By default, the server runs at: http://localhost:8080/mcp and it uses **Streamable HTTP Transport**.
83+
84+
### MCP Server Configuration
85+
86+
Create a file `config/packages/sylius_mcp_server.yaml` and customize it if needed.
87+
Below is the default configuration:
88+
89+
```yaml
90+
sylius_mcp_server:
91+
server:
92+
name: 'Sylius MCP Server'
93+
version: '0.1.0'
94+
transport:
95+
host: 127.0.0.1
96+
port: 8080
97+
prefix: 'mcp'
98+
enable_json_response: false
99+
ssl:
100+
enabled: false
101+
context: []
102+
103+
session:
104+
driver: cache
105+
ttl: 3600
106+
107+
discovery:
108+
locations:
109+
- { base_path: '%sylius_mcp_server.plugin_root%', scan_dirs: ['src/Tool'] }
110+
```
111+
112+
You can enable SSL support by setting `ssl.enabled` to `true` and configuring the appropriate SSL context.
113+
For details on how to configure the context, refer to the [SSL section in the php-mcp/server documentation](https://github.com/php-mcp/server?tab=readme-ov-file#ssl-context-configuration).
114+
115+
### Transport
116+
117+
By default, the server uses the Streamable HTTP Transport.
118+
You may implement your own transport by creating a custom factory that implements `Sylius\McpServerPlugin\Factory\ServerTransportFactoryInterface`.
119+
Then, override the transport in the McpServerCommand service definition.
120+
121+
### Sylius API
122+
123+
Tools communicate with the Sylius API through pre-configured HTTP clients:
124+
125+
```yaml
126+
sylius_mcp_server.http_client.api_shop:
127+
base_uri: '%sylius_mcp_server.api.shop_base_uri%'
128+
headers:
129+
- 'Accept: application/ld+json'
130+
- 'Content-Type: application/ld+json'
131+
sylius_mcp_server.http_client.api_shop_merge_patch:
132+
base_uri: '%sylius_mcp_server.api.shop_base_uri%'
133+
headers:
134+
- 'Accept: application/ld+json'
135+
- 'Content-Type: application/merge-patch+json'
136+
```
137+
138+
The default API base URI is http://localhost:8000/api/v2/shop/, and can be overridden using the environment variable `SYLIUS_MCP_SERVER_API_SHOP_BASE_URI`.
139+
140+
### Tools
141+
142+
The following tools are available out of the box:
143+
144+
| Name | Description |
145+
|-------------------------|---------------------------------------------------------------|
146+
| add_item_to_order | Adds an item to the order. |
147+
| complete_checkout | Completes the checkout process. (Final step) |
148+
| create_order | Creates a new order. |
149+
| fetch_channel | Fetches a channel by code. |
150+
| fetch_currency | Fetches a currency by code. |
151+
| fetch_order | Fetches an order by its token. |
152+
| fetch_product | Fetches a product by its code. |
153+
| fetch_product_variant | Fetches a product variant by its code. |
154+
| list_payment_methods | Lists all available payment methods. |
155+
| list_shipping_methods | Lists all available shipping methods. |
156+
| search_products | Searches for products by name. |
157+
| search_product_variants | Searches for product variants by name. |
158+
| select_payment_method | Selects a payment method for the order. (Step 3 of checkout) |
159+
| select_shipping_method | Selects a shipping method for the order. (Step 2 of checkout) |
160+
| update_order_address | Updates the order address. (Step 1 of checkout) |
161+
162+
These tools currently operate in guest mode only — `fetch_order` returns data only if the order has no associated customer account.
163+
164+
#### Adding custom tools
165+
166+
You can extend the server with your own tools by creating PHP classes annotated with attributes like **#[McpTool]**.
167+
These tools will then be exposed to the MCP client just like the built-in ones.
168+
169+
To learn how to define and structure a tool, see the ["Defining MCP Elements" section of the php-mcp/server documentation](https://github.com/php-mcp/server?tab=readme-ov-file#-defining-mcp-elements).
170+
171+
Once your tool is ready, make sure the plugin is configured to discover it:
172+
```yaml
173+
sylius_mcp_server:
174+
server:
175+
discovery:
176+
locations:
177+
- { base_path: 'your_base_path', scan_dirs: ['your/custom/Tool/Directory'] }
178+
```
179+
180+
### Usage Example
181+
182+
You can use the server directly in [OpenAI Playground](https://platform.openai.com/playground/prompts), exposing it via [ngrok](https://ngrok.com/) or similar tunneling tools.
183+
184+
#### Example with OpenAI Playground
185+
186+
1. Add a new tool in the OpenAI Playground.
187+
![add_tool](doc/images/playground_one.png)
188+
189+
2. Configure the tool with the following settings:
190+
- **URL**: `http://localhost:8080/mcp` (or your ngrok URL)
191+
- **Label**: Sylius
192+
- **Authentication**: None
193+
![configure_tool](doc/images/playground_two.png)
194+
195+
#### Example with API Call
196+
197+
```bash
198+
curl https://api.openai.com/v1/responses \
199+
-H "Content-Type: application/json" \
200+
-H "Authorization: Bearer $OPENAI_API_KEY" \
201+
-d '{
202+
"model": "gpt-4.1",
203+
204+
"tools": [
205+
{
206+
"type": "mcp",
207+
"server_label": "Sylius",
208+
"server_url": "$YOUR_MCP_SERVER_URL",
209+
"require_approval": "never"
210+
}
211+
],
212+
213+
"input": [
214+
{
215+
"role": "user",
216+
"content": [
217+
{
218+
"type": "input_text",
219+
"text": "Find me red shoes"
220+
}
221+
]
222+
}
223+
],
224+
"max_output_tokens": 1024
225+
}'
226+
```
227+
228+
## Security issues
229+
230+
If you think that you have found a security issue, please do not use the issue tracker and do not post it publicly.
231+
Instead, all security issues must be sent to `security@sylius.com`
232+
233+
## Community
234+
235+
For online communication, we invite you to chat with us & other users on [Sylius Slack](https://sylius-devs.slack.com/).
236+
237+
## License
238+
239+
This plugin's source code is completely free and released under the terms of the MIT license.

config/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
env(SYLIUS_MCP_SERVER_API_SHOP_BASE_URI): 'https://localhost:8010/api/v2/shop/'
2+
env(SYLIUS_MCP_SERVER_API_SHOP_BASE_URI): 'https://localhost:8000/api/v2/shop/'
33
sylius_mcp_server.api.shop_base_uri: '%env(SYLIUS_MCP_SERVER_API_SHOP_BASE_URI)%'
44

55
framework:

doc/images/playground_one.png

16.7 KB
Loading

doc/images/playground_two.png

6.64 KB
Loading

0 commit comments

Comments
 (0)