收据处理代理工具

一个基于Dify平台的收据处理代理工具,通过集成LLM模型和MCP服务器实现自动化收据处理功能。

  • by lucasjhan08
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 bloobglob/HOA-mcp-server

使用说明

HOA MCP代理教程

本指南提供了使用“llm_en_v_1_3_1”模型在Dify中设置和运行收据MCP代理的分步说明。

先决条件

在开始之前,请确保您拥有以下内容:

  1. Dify已安装并通过Docker运行(不在本地主机上运行)
  2. 访问LLM端点
  3. 可从您的端点访问模型“llm_en_v_1_3_1”

步骤1:将LLM模型添加到Dify

  1. 点击界面右上角的用户图标
  2. 从下拉菜单中选择“设置”
  3. 导航到“模型提供程序”选项卡
  4. 如果尚未安装,请安装“OpenAI-API-compatible”模型
  5. 在“OpenAI-API-compatible”模型中,单击“添加模型”并按如下方式进行配置:
    • 模型类型LLM
    • 型号名称: llm_en_v_1_3_1
    • API密钥:留空
    • API端点URL: http://<your-server-ip>:5001/openai/v1
    • 模型上下文大小: 4096

步骤2:设置MCP代理

  1. 在Dify界面的顶部,导航到“工具”选项卡
  2. 点击“自定义”选项卡
  3. 点击“创建自定义工具”
  4. 将“名称”字段设置为“调用MCP工具”
  5. 确保MCP服务器正在运行。您可以通过在终端中输入以下内容来启动它:
    python server.py
    
  6. 将“架构”字段设置为以下配置:
{
  "openapi": "3.0.0",
  "info": {
    "title": "Call MCP Tool",
    "version": "1.0.0",
    "description": "Call various MCP tools via MCP Server"
  },
  "servers": [
    {
      "url": "http://host.docker.internal:8000"
    }
  ],
  "paths": {
    "/mcp/execute": {
      "post": {
        "summary": "Call MCP Tool",
        "description": "Call MCP Tool",
        "operationId": "callTool",
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "required": true,
            "description": "Client must accept both application/json and text/event-stream",
            "schema": {
              "type": "string",
              "example": "application/json, text/event-stream"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": {
                    "type": "string"
                  },
                  "id": {
                    "type": "integer"
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "tools/list", "tools/call"
                    ],
                    "description": "Method to execute"
                  },
                  "params": {
                    "type": "object",
                    "description": "Parameters for the method"
                  }
                },
                "required": [
                  "method"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "result": {
                      "type": "string",
                      "description": "Result of the operation"
                    }
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Server-sent events stream"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request"
          },
          "406": {
            "description": "Not Acceptable - Client must accept both application/json and text/event-stream",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "Client must accept both application/json and text/event-stream content types"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Error message"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
  1. 完成后单击“保存”

步骤3:通过Dify集成LLM和MCP代理

创建临时聊天流

  1. 在主界面上,找到“创建应用程序”框
  2. 点击“从空白创建”
  3. 选择“聊天流”
  4. 将聊天流命名为“temp”

添加“调用工具”块

  1. 右键单击“答案”块
  2. 选择“更改块”
  3. 在“工具”选项卡下,选择“调用MCP工具”
  4. 将“调用工具”块连接到LLM块

导出临时聊天流

  1. 点击左上角的聊天流名称
  2. 点击“导出DSL”
  3. 将“temp.yml”移动到项目文件夹

导入HOA MCP代理yml

  1. 在项目文件夹中,运行:
    python generate_yml.py
    
  2. 在主界面上,找到“创建应用程序”框
  3. 点击“导入DSL文件”
  4. 在项目文件夹中选择文件“HOA MCP Agent.yml”
  5. 在“登录”块的“参数”部分,将参数“host_ip”、“email”和“password”替换为您的凭据

配置说明

  • 确保更换 <your-server-ip> 使用您的实际服务器IP地址
  • 确保在最后一步中正确配置了所有必需的凭据
  • 在尝试使用代理之前,MCP服务器必须正在运行

故障排除

  • 如果遇到连接问题,请验证Docker是否未在本地主机上运行
  • 确保MCP服务器可以在指定的URL访问
  • 检查所有必需的端口是否打开且可访问