供应链风险分析工具

基于World Bank数据和Next.js的供应链风险分析工具,提供国家级的供应链风险评估和数据分析功能。

  • by gumaz14
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 gumaz14/Supplier-Risk-MCP-Agent

使用说明

供应链风险分析——Next.js + MCP(世界银行)

利用Next.js 15、TypeScript、AI SDK 5、shadcn/ui、AI Elements和MCP服务器,基于世界银行数据按国家分析供应链风险。

特点/特性

  • 使用AI元素(对话、消息、提示输入)打造简洁的聊天界面
  • 世界银行MCP工具: list_countries, list_indicators, get_indicator_data
  • shadcn/UI设计系统
  • 通过AI SDK流式传输UI消息响应
  • TypeScript 准备就绪

设置

  1. 安装依赖项:

    pnpm install
    
  2. 创建 .env.local 包含所需环境变量的文件:

    OPENAI_API_KEY=your_openai_api_key_here
    WORLD_BANK_MCP_SERVER_URL=http://localhost:3001/mcp
    
  3. 开始开发:

    • 在A终端(应用)中:

      pnpm dev
      

      应用程序地址:http://localhost:3000

    • 在B终端(MCP服务器):

      cd mcp-servers/world-bank && pnpm dev
      

      MCP: http://localhost:3001(端点:/mcp)

打开 http://localhost:3000(本地主机上的3000端口) 与AI助手聊天。

资源

架构与数据流

+-------------------------+            +--------------------------------------+            +---------------------------+
|       Browser UI        |            |       Next.js API Route              |            |        MCP Server         |
| `ChatAssistant`         |            | `app/api/agent-with-mcp-tools`       |            |  http://localhost:3001    |
|  - AI Elements UI       |            |  - validate input                    |            |  endpoint: /mcp           |
|  - PromptInput submit   |            |  - AI SDK `streamText` with tools    |            +---------------------------+
+-------------------------+            |  - model: openai('gpt-4o')           |                        |
            |                         +--------------------------------------+                        |
            | 1) User types message                                                                 |
            |--------------------------------------------------------------------------------------->|
            |  POST /api/agent-with-mcp-tools { messages }                                          |
            |                                                                                       |
            |                                         2) MCP tool calls (HTTP /mcp)                 |
            |                                         --------------------------------------------->|
            |                                                                                       |
            |                                         3) World Bank API (data fetch)                |
            |                                         <---------------------------------------------|
            |                                                                                       |
            | 4) Streamed UI message response                                                       |
            |<---------------------------------------------------------------------------------------|
            v

Env:
- `OPENAI_API_KEY` → used by AI SDK OpenAI client
- `WORLD_BANK_MCP_SERVER_URL` → MCP endpoint (default: http://localhost:3001/mcp)

Notes:
- If the app selects an alternate port (e.g., 3002), open that port.
- MCP server must be running; otherwise tools will fail to load.