使用说明
McpHello世界
展示MCP与 两种扩展模式并排:
- 应用程序脚本 --商店软件应用程序脚本(Twig+DAL,进程内,无外部服务器)
- Node.js webhook --外部HTTP服务器接收HMAC签名的POST
部分 MCP服务器POC 商店用品。
暴露的工具、提示和资源
| 名称 | 图案 | 背衬 |
|---|---|---|
McpHelloWorld-hello |
应用程序脚本 | Resources/scripts/api-mcp-hello-world-hello/hello.twig |
McpHelloWorld-ping |
应用程序脚本 | Resources/scripts/api-mcp-hello-world-ping/ping.twig |
McpHelloWorld-product-count |
应用程序脚本 | Resources/scripts/api-mcp-hello-world-product-count/count.twig |
McpHelloWorld-hello-webhook |
Node.js webhook | server.js → /mcp/hello |
McpHelloWorld-ping-webhook |
Node.js webhook | server.js → /mcp/ping |
McpHelloWorld-greeting-context (提示) |
Node.js webhook | server.js → /mcp/prompt/greeting-context |
McpHelloWorld-usage-guide (提示) |
Node.js webhook | server.js → /mcp/prompt/usage-guide |
mcp-hello-world://status (资源) |
Node.js webhook | server.js → /mcp/resource/status |
mcp-hello-world://stats (资源) |
Node.js webhook | server.js → /mcp/resource/stats |
设置
# Start the webhook server (needed for the *-webhook tools and all prompts/resources)
node server.js
# Install the app (registers with the webhook server, then makes all tools available)
bin/console app:install --activate McpHelloWorld
# Verify
bin/console debug:mcp
如果你只关心应用程序脚本方面,你仍然需要开始 node server.js 一次安装握手(<setup> 在 manifest.xml).之后,脚本工具在服务器不运行的情况下工作。要完全跳过服务器,请删除 <setup> 阻止来自 manifest.xml 并从中删除webhook工具/提示/资源 Resources/mcp.xml.
每种模式是如何工作的
模式A:商店软件应用程序脚本
这 url 属性于 mcp.xml 指向 /api/script/mcp-hello-world-* --由匹配的Twig文件提供的内部Shopware路由 Resources/scripts/. AppMcpToolExecutor 检测 /-前缀URL并分派Symfony子请求。参数作为名为的POST表单参数到达 arguments 并且可以通过以下方式访问 hook.request.request.all('arguments').
无外部进程,无网络往返,完全DAL访问(受 <required-privileges>).
模式B:Node.js webhook
这 url 属性是一个绝对的HTTP URL。 AppMcpToolExecutor 使用应用程序密钥签名的HMAC标头将调用发布到该URL。Node.js服务器 server.js 显示了所需的最小值:a /register 安装握手端点和每个工具端点。当工具逻辑存在于商店之外时(第三方服务、独立语言等),请使用此功能。
文件
manifest.xml--应用元数据+<setup>Node.js webhook注册块Resources/mcp.xml--两种模式的MCP定义Resources/scripts/api-mcp-hello-world-*--模式A的商店软件应用程序脚本(Twig)server.js--模式B的Node.js webhook服务器
