Magento API元数据生成器

一个Magento 2模块,用于以MCP兼容格式暴露REST和GraphQL API,供LangChain、OpenAI Assistants等AI代理使用。

  • by sprinixtech
  • PHP
  • 本地部署
  • 更新于
在 GitHub 查看 sprinixtech/magento-mcp-server

使用说明

Sprinix_MageMCP服务器

Magento 2模块以MCP兼容格式公开REST和GraphQL API,供LangChain、OpenAI Assistants和自主工具等AI代理使用。


🔧 它做什么

此模块动态生成 MCP样式工具元数据 (作为JSON模式)用于所有Magento REST端点。这些元数据文件可供以下人员使用:

  • LangChain代理商
  • OpenAI助手API
  • RAG管道
  • 自定义AI工作流程

🚀 特性

  • ✅ REST API元数据通过 /mcp/metadata
  • ✅ 启用/禁用和缓存TTL的管理配置
  • ✅ 缓存的元数据 var/ 对于速度
  • ✅ OpenAPI 风格 JSON 和 /mcp/metadata/openapi
  • ✅ LangChain和助手-API友好输出

🛠️ 安装

composer require sprinixtech/magento-mcp-server
php bin/magento setup:upgrade
php bin/magento cache:flush

⚙️ 管理员配置

导航到:

Stores → Configuration → MCP Server

你可以:

  • 启用/禁用MCP服务器
  • 设置元数据缓存生存期(秒)

📱 可用端点

端点URL 描述
/mcp/metadata REST API的MCP元数据
/mcp/metadata/graphql GraphQL查询/突变的MCP元数据
/mcp/metadata/openapi OpenAPI风格的REST元数据

🧠 LangChain使用示例(Node.js)

import { ChatOpenAI } from "langchain/chat_models/openai";
import { DynamicTool } from "langchain/tools";

const res = await fetch("https://your-magento.com/mcp/metadata/graphql");
const toolsJson = await res.json();

const tools = toolsJson.map(tool => new DynamicTool({
  name: tool.name,
  description: tool.description,
  func: async (input) => {
    const response = await fetch(tool.api.url, {
      method: tool.api.method,
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ query: `{ ${tool.name} { id name } }` })
    });
    return await response.text();
  }
}));

🔮 未来的增强功能

  • ✅ 用于刷新缓存元数据的CLI命令
  • 🧬 参数和返回类型自省
  • 📊 OpenAPI元数据的Swagger UI
  • 🌐 多店铺视图支持
  • 🔐 身份验证/令牌集成

👨‍💻 作者

古尔山·莫里亚
📧 gulshan.4dream@gmail.com
🔗 领英


📄 许可证

麻省理工学院