Probo API Integration with MCP

Probo API Integration with MCP

site icon
2025.04.27 0
JavaScript打印服务API 集成内容生成
Probo MCP Server 是一个基于 Model Context Protocol (MCP) 的服务,它封装了 Probo API,使得与 Probo 的打印服务交互更加便捷。该服务通过 MCP 协议标准化 API 交互,提供输入验证,简化集成过程,并为请求和响应提供标准化结构。
View on GitHub

Overview

基本能力

产品定位

Probo MCP Server 是一个中间件服务,旨在通过 MCP 协议简化与 Probo 打印服务的交互,提供标准化的 API 接口和输入验证。

核心功能

  1. 标准化 API 交互:通过 MCP 协议封装 Probo API,提供一致的接口。
  2. 输入验证:使用 Zod schemas 验证输入,减少错误。
  3. 简化集成:使 AI 助手和其他系统能够轻松发现和使用可用工具。
  4. 结构化请求和响应:为请求和响应提供标准化结构。

适用场景

  1. 需要通过 AI 助手或聊天界面与 Probo 打印服务交互的场景。
  2. 需要标准化 API 交互和输入验证的打印服务集成。
  3. 需要简化复杂打印服务工作流的场景。

工具列表

  1. searchProducts:搜索 Probo API 提供的产品。
  2. configureProduct:配置带有选定选项的产品。
  3. placeOrder:向 Probo 下订单。
  4. getOrderStatus:获取特定订单的状态信息。
  5. getAllOrders:获取所有订单列表,支持过滤。
  6. cancelOrder:取消特定订单。

常见问题解答

  1. 测试订单:所有设置为 isTest: truePROBO_API_MODE=test 的订单将被 Probo 自动取消。
  2. API 凭证:使用此集成需要 API 凭证,请联系 Probo 获取 API 密钥。

使用教程

使用依赖

  1. 确保已安装 Node.js 和 npm。
  2. 克隆仓库后,安装依赖: bash npm install

安装教程

  1. 克隆仓库。
  2. 创建 .env 文件并填写 Probo API 凭证: PROBO_API_KEY=your_api_key_here PROBO_API_URL=https://api.proboprints.com PROBO_API_MODE=test # 使用 'test' 进行沙盒测试,'production' 用于生产订单
  3. 启动服务: bash node server.js

调试方式

  1. 运行自动化测试套件: bash node test.js
  2. 使用 debug.js 测试特定操作: ```bash # 搜索产品 node debug.js products

# 获取所有订单 node debug.js orders

# 获取订单状态 node debug.js status

# 下简单测试订单 node debug.js simple-order

# 取消订单 node debug.js cancel-order ORDER_ID ```

技术集成

初始化客户端

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';

async function runClient() {
  const client = new Client({
    name: 'probo-mcp-client',
    version: '0.1.0',
  });

  await client.connect(new StdioClientTransport({
    command: 'node',
    args: ['server.js'],
  }));

  console.log('Connected to server successfully!');

  // 调用工具

  await client.close();
}

runClient().catch(console.error);

完整示例

// 搜索产品、配置产品并下单的完整示例
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';

async function runClient() {
  const client = new Client({
    name: 'probo-mcp-client',
    version: '0.1.0',
  });

  await client.connect(new StdioClientTransport({
    command: 'node',
    args: ['server.js'],
  }));

  // 1. 搜索产品
  const searchResult = await client.callTool({
    name: 'searchProducts',
    arguments: {},
  });

  // 2. 配置产品
  const configureResult = await client.callTool({
    name: 'configureProduct',
    arguments: {
      productCode: 'tensioner-with-spinhook',
      options: [
        { code: 'width', value: 1000 },
        { code: 'height', value: 1000 },
        { code: 'amount', value: 1 }
      ],
      language: 'en',
    },
  });

  // 3. 下单
  const orderResult = await client.callTool({
    name: 'placeOrder',
    arguments: {
      configuration: {
        language: 'en',
        products: [
          {
            code: 'tensioner-with-spinhook',
            options: [
              { code: 'amount', value: '1' }
            ]
          }
        ]
      },
      address: {
        address_company_name: 'Test Company',
        address_first_name: 'John',
        address_last_name: 'Doe',
        address_street: 'Test Street',
        address_house_number: '123',
        address_postal_code: '1234AB',
        address_city: 'Test City',
        address_country: 'NL',
        address_telephone_number: '1234567890',
        address_email: '[email protected]'
      },
      reference: 'Test Order',
      isTest: true,
      additionalOptions: {
        orderId: `test-order-${Date.now()}`
      }
    },
  });

  await client.close();
}

runClient().catch(console.error);

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。