MarzbanSDK

Introduction

The Marzban toolkit — marzban-sdk, a complete typed TypeScript client, and marzban-mcp, an MCP server built on it for AI agents. Node.js, Bun, Deno, and the browser.

MarzbanSDK is a toolkit for building on Marzban: a complete, production-grade TypeScript SDK for your own integrations, and an MCP server built on that same SDK for AI agents. Same auth, same retries, same typed errors underneath either one — pick whichever fits how you're building.

marzban-sdk

A complete, production-grade TypeScript SDK for building Marzban integrations. Beyond fully typed coverage of the entire API, it bundles the infrastructure a real integration needs — authentication with transparent token refresh, retries, WebSocket log streaming, webhook verification, and runtime validation — and behaves identically in Node.js, Bun, Deno, and the browser.

Features

Module overview

ModuleAccessDescription
Userssdk.userCreate, update, query, and manage users
Adminssdk.adminManage admin accounts
Nodessdk.nodeAdd, configure, and monitor nodes
Systemsdk.systemStats, inbounds, and proxy host config
Coresdk.coreXray core stats, config, and restart
Subscriptionssdk.subscriptionPublic subscription endpoints
User Templatessdk.userTemplateReusable user configuration templates
Webhookssdk.webhookIncoming event handling and verification
Logssdk.logsReal-time WebSocket log streaming

Quick example

import { createMarzbanSDK, formatBytes, humanRemaining } from 'marzban-sdk'

const sdk = await createMarzbanSDK({
  baseUrl: 'https://vpn.example.com',
  username: 'admin',
  password: 'secret',
})

// List active users
const { users, total } = await sdk.user.getUsers({ status: 'active' })
console.log(`${total} active users`)

for (const user of users) {
  const dataLeft = formatBytes((user.data_limit ?? 0) - user.used_traffic)
  const timeLeft = user.expire ? humanRemaining(user.expire * 1000) : '∞'
  console.log(`${user.username} — ${dataLeft} left, expires ${timeLeft}`)
}

marzban-mcp

An MCP server built on marzban-sdk that gives an AI agent — Claude, Cursor, or any other MCP client — a set of tools to manage a Marzban panel directly: users, subscriptions, nodes, and the core config. It's a separate, published package (marzban-mcp), not a mode of the SDK.

  • 21 tools, 3 prompts — the full user lifecycle plus config, hosts, nodes, system stats, and subscriptions, and ready-made prompts that chain several tools into one investigation.
  • Profile-gated access — a tool outside the active profile never appears in tools/list at all.
  • Confirmation on every destructive action — a first call only describes the consequences and returns a one-time token; nothing runs until a second, explicitly confirmed call repeats it.
  • Credentials only from environment variables, masked by default in tool output.
claude_desktop_config.json / .mcp.json
{
  "mcpServers": {
    "marzban": {
      "command": "npx",
      "args": ["-y", "marzban-mcp"],
      "env": {
        "MARZBAN_BASE_URL": "https://panel.example.com",
        "MARZBAN_USERNAME": "admin",
        "MARZBAN_PASSWORD": "secret"
      }
    }
  }
}

On this page