NexBank MCP Server
MCP server for interacting with NexBank API v2, providing six business tools and supporting Bearer Token or OAuth authentication.
README
NexBank MCP Server
独立的 NexBank API v2 MCP Server。提供 Stateless Streamable HTTP、Bearer Token、可选 OAuth 授权码接入、MySQL Connection 解析和六个业务工具。
准备
- 使用 Node.js 20 或更高版本安装依赖:
npm install。 - 数据库执行唯一脚本
sql/001_init.sql。脚本第一部分会删除旧表及其全部数据,第二部分创建统一使用nxb_mcp_前缀的新表;执行前必须确认旧数据无需保留或已完成备份。 - 复制
config/application.example.yaml为部署配置,并填写 MySQL 与两个环境的 API Base URL。 - 通过
--config <文件>或NEXBANK_MCP_CONFIG_FILE指定配置文件。
不要把真实 AppSecret、Bearer Token 或生产配置提交到仓库。
Token 有效期使用可读 Duration 配置,支持 s(秒)、m(分钟)、h(小时)、d(天)。Access Token 默认 1 小时,Refresh Token 默认 365 天:
auth:
accessTokenTtl: "1h"
refreshTokenTtl: "365d"
OAuth /token 响应中的 expires_in 始终按秒返回。验证自动刷新时,可在重新授权前暂时设置 accessTokenTtl: "30s" 和 refreshTokenTtl: "10m"。
运行
npm run build
npm start -- --config ./config/application.yaml
开发模式:
npm run dev -- --config ./config/application.yaml
日志默认同时输出到控制台和 ./logs,并按照服务所在时区的自然日写入
nexbank-mcp-server-YYYY-MM-DD.log。可以通过部署配置调整文件日志:
logging:
level: "info"
file:
enabled: true
directory: "./logs"
prefix: "nexbank-mcp-server"
设置 file.enabled: false 可以只保留控制台日志。日志滚动不会改变既有敏感字段脱敏规则。
MCP 入口默认为 POST /mcp,请求必须包含:
Authorization: Bearer <26-character-ULID>.<22-character-random-secret>
完整 Token 固定为 49 个字符。第一部分是 26 字符 ULID,第二部分是 16 字节密码学安全随机数的 Base64URL 编码。
Stateless 模式不提供 GET/SSE 会话,GET /mcp 和 DELETE /mcp 返回 405。
OAuth 简易绑定
在配置中增加 oauth 后,Server 同时支持原有 Bearer Token 和 OAuth 2.1 授权码流程:
oauth:
issuerUrl: "https://mcp.example.com"
bindingEnvironment: "sandbox"
issuerUrl必须是对外可访问的 HTTPS Origin;仅本机开发允许localhost、127.0.0.1或[::1]使用 HTTP。bindingEnvironment决定授权页凭证绑定到沙盒还是正式环境。页面本身只填写App ID、AppSecret、customerCode,不要求用户登录。- 服务端保留 PKCE、OAuth state、redirect URI 和 resource 校验。授权成功后在同一个数据库事务中创建 Bearer Token 与
nxb_mcp_connection,OAuth/token返回的expires_in与数据库expires_at的剩余有效期一致。 - OAuth 公共客户端注册信息持久化在
nxb_mcp_oauth_client;未完成授权请求和授权码仍只在进程内短期保存。 - 授权码交换同时返回 Access Token、
expires_in和 Refresh Token。Refresh Token 只保存 SHA-256 哈希,并绑定client_id、scope 和 resource;每次刷新都会同时轮换 Access Token 与 Refresh Token。 - 已使用 Refresh Token 被再次提交时,服务端会撤销整个 Token Family 及当前 Access Token,客户端必须重新授权。
- OAuth 请求参数会写入结构化日志。
AppSecret、授权码、PKCE verifier、token 不记录原值,appId、customerCode只记录脱敏值。
启用 OAuth 的部署必须通过 HTTPS 暴露授权端点。删除整个 oauth 配置块即可继续只使用手工生成的 Bearer Token。
Token 与 Connection
生成 Token:
npm run token:generate -- --name "调用方名称" --config ./config/application.yaml
完整 Token 只显示一次,同时会显示过期时间。随后在 nxb_mcp_connection 中按生成记录的数据库主键维护 Sandbox Connection;付费并取得正式配置后,为同一 access_token_id 增加 Production Connection。
只有未过期、enabled=1 且 status='active' 的 Connection 能调用 NexBank。停用 Token 可直接把 nxb_mcp_access_token.enabled 更新为 0。
测试
npm test
npm run test:e2e
MySQL 集成测试只允许连接专用测试库:
NEXBANK_MCP_TEST_CONFIG_FILE=./config/application.test.yaml
NEXBANK_MCP_ALLOW_DB_TESTS=true
npm run test:integration
集成测试不会创建或删除数据库。真实 Sandbox 联调仅执行只读工具;签约链接生成不属于默认自动化测试。
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.