MCP Shopify GraphQL自检服务器
🇧🇷 阅读中文
针对LLM使用进行了优化的PHP MCP(模型上下文协议)服务器。提供细粒度、分页的工具,用于检查Shopify的GraphQL Admin API架构、探索类型和构建查询,旨在返回紧凑、可读的数据,而不是原始的自省转储。
项目结构
graphql/
├── src/
│ ├── Config.php # environment-based configuration
│ ├── GraphQLClient.php # Guzzle HTTP client for GraphQL
│ ├── GraphQLClientInterface.php # client contract
│ ├── SchemaRegistry.php # schema loading, type resolution, flatten helpers
│ └── Tools/
│ ├── SchemaExplorerTool.php # list queries/mutations, search, cache
│ ├── TypeInspectorTool.php # inspect types, enums, inputs, connections
│ └── QueryBuilderTool.php # query/mutation details, skeleton builder
├── tests/
│ ├── FakeGraphQLClient.php # test double for GraphQLClientInterface
│ ├── fixtures/
│ │ └── schema.json # static schema for tests
│ └── Unit/
│ ├── SchemaRegistryTest.php
│ └── Tools/
│ ├── SchemaExplorerToolTest.php
│ ├── TypeInspectorToolTest.php
│ └── QueryBuilderToolTest.php
├── var/
│ ├── cache/ # on-disk schema cache (gitignored)
│ └── logs/ # runtime logs (gitignored)
├── composer.json
└── server.php # STDIO entrypoint需求
- PHP 8.5或更高版本
- 作曲家
安装
composer install复制 .env.example 到 .env 并填写所需值:
cp .env.example .env配置
| 环境变量 | 默认值 | 描述 |
|---|---|---|
SHOPIFY_STORE | -- | Shopify商店域(例如。 my-store.myshopify.com) |
SHOPIFY_ACCESS_TOKEN | - | Shopify Admin API访问令牌 |
SHOPIFY_API_VERSION | 2025-01 | Shopify管理API版本 |
用法
启动服务器(标准)
php server.php
# or via Composer script
composer serve服务器使用 工作室 传输——它从中读取JSON-RPC消息 stdin.
在Claude桌面中配置
{
"mcpServers": {
"graphql": {
"command": "php",
"args": ["/absolute/path/to/server.php"],
"env": {
"SHOPIFY_STORE": "my-store.myshopify.com",
"SHOPIFY_ACCESS_TOKEN": "shpat_xxxxxxxxxxxxxxxxxxxx"
}
}
}
}在VS代码中配置
添加 .vscode/mcp.json:
{
"servers": {
"ShopifyGraphQLIntrospection": {
"type": "stdio",
"command": "php",
"args": ["-dxdebug.mode=off", "server.php"],
"cwd": "/absolute/path/to/graphql",
"env": {
"SHOPIFY_STORE": "my-store.myshopify.com",
"SHOPIFY_ACCESS_TOKEN": "shpat_xxxxxxxxxxxxxxxxxxxx"
}
}
}
}可用工具
架构资源管理器
| 工具 | 参数 | 说明 |
|---|---|---|
listQueries | offset, limit, filter | 使用分页和可选名称过滤器列出查询 |
listMutations | offset, limit, filter | 使用分页和可选名称过滤器列出突变 |
search | term: string | 按名称或描述搜索类型和字段(最多50个结果/类别) |
clearCache | -- | 从端点或文件重新加载架构 |
类型检查器
| 工具 | 参数 | 说明 |
|---|---|---|
listTypes | kind, offset, limit | 按种类筛选的列表类型(OBJECT、ENUM、INPUT_OBJECT等) |
getType | name: string | 获取具有可读字段类型的完整类型定义 |
getEnumValues | name: string | 获取ENUM类型的所有值 |
getInputFields | name: string | 获取INPUT_OBJECT类型的所有字段 |
getFieldDetails | typeName, fieldName | 获取具有参数的特定字段的完整详细信息 |
getConnections | typeName: string | 列出连接/分页字段(中继模式) |
查询构建器
| 工具 | 参数 | 说明 |
|---|---|---|
getQueryDetails | name: string | 获取查询的完整详细信息,包括参数和返回类型字段 |
getMutationDetails | name: string | 获取突变的完整详细信息,包括参数和返回类型字段 |
buildQuerySkeleton | operationName, operationType | 生成GraphQL查询/变异骨架,以适应 |
getRequiredArgs | operationName, operationType | 仅列出操作所需的(非空)参数 |
测试
composer test静态分析
composer analyse安全
- 访问令牌从未在工具响应中记录或公开。
- 模式在启动时提取一次并缓存;在工具调用期间不执行实时查询。
- 缓存文件存储在本地
var/cache/并被排除在版本控制之外。
