AI助手交互协议服务器

Mono MCP服务器是一个支持AI助手与Mono API交互的协议服务器,提供本地stdio和远程HTTP两种传输方式,适用于金融服务和客户数据管理场景。

  • by josephanya
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 josephanya/mono-mcp-server

使用说明

Mono MCP服务器

Mono模型上下文协议(MCP)服务器使人工智能助手能够轻松地与Mono API交互。它旨在支持本地stdio传输和远程StreamableHTTP传输,以实现灵活的部署选项。

需求

  • Node.js 18+(用于本机 fetch 以及现代ESM支持)
  • npm v9+

安装

npm install

配置

将Mono密钥设置为环境变量:

export MONO_SECRET_KEY="your_mono_secret_key"

跑

入口点是 src/index.ts。您可以在开发中运行或在构建后运行:

开发(自动重新加载)

  • 标准(当地):
npm run dev:stdio
  • HTTP(远程):
npm run dev:http

检查员(可选):

npm run dev:inspect

生产(先构建后运行)

npm run build
npm run start:stdio   # or
npm run start:http    # defaults to port 3000

然后访问健康终点 http://0.0.0.0:3000/health 当运行HTTP模式时。

笔记:

  • 如果出现以下情况,应用程序将提前退出 MONO_SECRET_KEY 未设置。

HTTP传输

当以HTTP模式启动时,服务器会公开:

  • GET /health –基本健康检查
  • POST /mcp –客户端到服务器JSON-RPC(初始化和请求)
  • GET /mcp –服务器到客户端通知(需要 mcp-session-id 头球
  • DELETE /mcp –会话终止(需要 mcp-session-id 头球

会话标头:

  • mcp-session-id:用于将后续请求绑定到同一会话。

外露工具

定义如下 src/server/handlers/tools.ts (粗体工具标识符):

  • 获取钱包余额

    • 返回Mono钱包中的可用余额。
  • 获取所有客户

    • 输入(可选): phone?: string, email?: string
    • 列出客户,支持过滤。
  • get_customer_transactions

    • 输入: customerId: string, period: string, page: string, accountId?: string
    • 为客户返回交易记录。
  • get_all_customer_linked_accounts

    • 输入: name?: string, accountNumber?: string
    • 列出带有筛选器的链接帐户。
  • get_count_details

    • 输入: accountId: string
    • 返回帐户详细信息。
  • get_count_identity_info

    • 输入: accountId: string
    • 返回帐户的身份信息。
  • get_count_balance

    • 输入: accountId: string
    • 返回账户余额。
  • get_transaction_history

    • 输入: accountId: string, startDate?: string, endDate?: string, type?: 'debit' | 'credit', narration?: string
    • 返回交易历史记录(默认情况下不分页)。
  • get_account_credits

    • 输入: accountId: string
    • 返回账户的分组流入。
  • get_count_debits

    • 输入: accountId: string
    • 返回账户的分组流出。

与Claude Desktop一起使用

您可以通过stdio(本地)或HTTP(远程)将此MCP服务器连接到Claude Desktop。以下是您可以添加到Claude Desktop的MCP设置中的示例配置。

Stdio(本地)

在stdio模式下运行服务器,让Claude通过stdio进行通信。

  1. 确保 MONO_SECRET_KEY 在您的shell中设置(或传递) env):
export MONO_SECRET_KEY="your_mono_secret_key"
  1. Claude桌面MCP配置条目(JSON):
{
  "mono-mcp-server": {
    "command": "node",
    "args": ["./dist/index.js", "stdio"],
    "env": {
      "MONO_SECRET_KEY": "${MONO_SECRET_KEY}"
    }
  }
}

如果您更喜欢在开发中直接从TypeScript运行,请将command/args替换为您的开发运行器,例如:

{
  "mono-mcp-server": {
    "command": "npx",
    "args": ["tsx", "src/index.ts", "stdio"],
    "env": {
      "MONO_SECRET_KEY": "${MONO_SECRET_KEY}"
    }
  }
}

HTTP(远程)

在HTTP模式下运行服务器,并将Claude指向HTTP端点。

  1. 启动服务器:
npm run dev:http
# or
npm run build && npm run start:http
  1. Claude桌面MCP配置条目(JSON):
{
  "mono-mcp-server-http": {
    "type": "http",
    "url": "http://127.0.0.1:3000/mcp",
    "headers": {
      "content-type": "application/json"
    }
  }
}

笔记:

  • HTTP模式使用会话。克劳德将管理 mcp-session-id 初始化后自动标头。
  • 保持CORS和中配置的允许主机 src/server/transports/http.ts (默认值允许 127.0.0.1 和 localhost).

项目结构

src/
  index.ts                 # Entrypoint: parses args and starts stdio/http
  server/
    mono_mcp.server.ts     # Server wrapper
    setup_handlers.ts      # Registers tools/resources
    handlers/
      tools.ts             # Mono-backed tool implementations (see list above)
      resources.ts         # Resource handlers
    transports/
      http.ts              # Streamable HTTP transport wiring
      stdio.ts             # Stdio transport wiring
    client/
      mono_client.ts       # Minimal client around Mono HTTP API
  utils/
    error.handler.ts       # Global process error handling

环境

  • MONO_SECRET_KEY (必填):您的单声道密钥。如果未设置,则进程退出。

内置于❤️