authn-authz-with-mcps
This MCP server provides authentication via wallet sign-in (SIWE) and authorization with scoped access to read and trade portfolios, enabling secure portfolio management through natural language.
README
authn-authz-with-mcps
Prototyping authentication & authorization for a per-portfolio MCP server.
A portfolio owner signs in with their wallet (AuthN), grants scopes (consent), and then operates their portfolio through tools that are scope- and policy-bounded (AuthZ).
The shape
One backend, two front doors over a single policy-enforced tool core:
Browser UI ──SIWE login──▶ Backend ──┐
(the human) ──REST tools──▶ ├─▶ tool core ─┬─ read_portfolio ─▶ YDS (live)
│ (scopes + └─ set_target_allocation ─▶ local (simulated)
MCP client ──MCP + Bearer──▶ /mcp ─┘ policy bounds)
The human UI calls /api/*; an MCP client calls /mcp. Both resolve a
Principal from the session token and call the same tools.ts, so authorization
is identical no matter who connects.
Run
The UI is a Vite + React app (ui/ workspace) that connects to a real browser
wallet (MetaMask / Rabby / Coinbase extension) via wagmi. You need a browser
wallet to sign in.
yarn install
yarn dev # terminal 1 — backend (http://localhost:8799)
yarn ui # terminal 2 — React dev server (http://localhost:5173)
Open http://localhost:5173 — Connect your wallet → Sign-In With Ethereum
(your wallet pops up to sign) → view your portfolio → re-target the allocation.
Tick portfolio:trade before signing for write access; leave it off to see a
read-only session refused at trade time. (Vite proxies /api and /mcp to the
backend.)
To see live data, connect a wallet that has a real Ymax portfolio — a wallet
with none gets a not_found (there is no fake fallback).
Scripts: yarn dev / yarn start (backend), yarn ui / yarn ui:build (React),
yarn typecheck, yarn format / yarn format:check.
The three layers (and where each lives)
| Layer | Question | In this repo |
|---|---|---|
| [1] AuthN — login/identity | who are you? | backend/auth.ts — SIWE / EIP-4361 → session JWT bound to the proven wallet address |
| [2] AuthZ — capability + bounds | what may you do, within what limits? | backend/tools.ts (scope gate) + backend/policy.ts (instrument allowlist, concentration cap, portions sum to 100) |
| [3] Execution | who signs the money move? | reads are LIVE from YDS for the connected wallet (not_found if it has none); writes are simulated in memory (the backend holds no key). In production: a delegated on-chain key that can't drain |
How auth flows
- AuthN (login):
POST /api/nonce(server mints a one-time nonce + the EIP-4361 message) → wallet signs it locally →POST /api/login(server verifies signature + nonce) → a session JWT bound to the wallet address + the consented scopes. - Session: every later request carries
Authorization: Bearer <jwt>; the server derives thePrincipalfrom it (requireAuth). - AuthZ: each tool first checks its required scope
(
portfolio:read/portfolio:trade), then runs policy bounds before touching the portfolio. Both the REST routes and the MCP tools go through the sametools.ts.
Honest gaps (this is a prototype)
- MCP transport auth:
/mcpis Bearer-gated with the SIWE session JWT. Real MCP clients (Cowork / claude.ai) connect by URL with OAuth, not a custom Bearer — wiring OAuth at the MCP boundary is the open next step. - Replay: a JWT/Bearer is replayable within its lifetime — fine for reads, but real money-moving writes want per-request signing or on-chain enforcement.
- Reads are live, writes are simulated:
read_portfoliofetches the wallet's real portfolio from YDS (https://main1.ymax.app/portfolios/by-wallet/<address>);set_target_allocationis validated against that live state but recorded locally (no on-chain signing). The real write path is a delegated, low-authority on-chain key that cannot withdraw — not built here. - Nonce/session stores are in-memory; production uses Redis / Cloudflare KV.
- Cosmos/Keplr wallets use a different signature standard (ADR-036 /
signArbitrary), not SIWE — out of scope.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。