Turn Any REST API Into a Multi-Tenant AI Tool Server
MCP Gateway bridges your existing backend APIs (REST, OpenAPI, SaaS, internal microservices) to AI clients like Claude Desktop, ChatGPT, Cursor, or your own custom web/mobile chatbot using the Model Context Protocol (MCP) over HTTP.
Instead of writing and hosting a custom MCP server for every API, register your API once in the Control Plane, define or import tools from OpenAPI, and serve them immediately on a tenant-isolated MCP Gateway endpoint (https://<tenant>.gateway.khanalmilan.com.np/mcp/<service>).
Why Use MCP Gateway?
Multi-Tenant Isolation
Every organization gets isolated services, Bearer keys, encrypted secrets, and subdomain routing (<tenant>.gateway.khanalmilan.com.np/mcp/<service>).
Zero Secret Exposure to LLMs
API keys and per-user Bearer tokens are AES-256-GCM encrypted at rest and injected server-side—AI models never see credentials.
End-User Auth & RBAC
Supports per-caller login (?return_url callback, password, or Google OAuth) + /me role checks so users only access their own authorized data.
SSRF Guard & Audit Trail
Blocks private/metadata IPs automatically, validates tool arguments against JSON Schema, and logs latency/status for every call.
4-Step Quickstart
- 1. Create an MCP Service — Go to /dashboard/services/new to create a service (e.g.
milan-mcp) and get yourmcp_live_...Bearer key. - 2. Register Your API Connection — Go to /dashboard/apis, enter your Base URL (e.g.
https://api.khanalmilan.com.np), choose an Auth Type (none,bearer,api_key,basic, orend_user), and click Test. - 3. Build & Publish Tools — Go to /dashboard/tools, link your API Connection, set HTTP method & path (e.g.
GET /api/v1/ledgers), and click Publish. - 4. Connect Any AI Client — Copy your endpoint URL and Bearer key from /dashboard/gateway into Claude Desktop, ChatGPT Desktop, or your own chatbot.
MCP Request & Response Examples
Endpoint: POST https://<tenant>.gateway.khanalmilan.com.np/mcp/<service_slug> with header Authorization: Bearer <service_api_key>.
1. Initialize Handshake (returns Mcp-Session-Id header)
// Request
POST https://milan-khanals-workspace-1.gateway.khanalmilan.com.np/mcp/milan-mcp
Authorization: Bearer mcp_live_xxx
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": { "name": "my-chatbot", "version": "1.0.0" }
}
}
// Response (Header: Mcp-Session-Id: <uuid>)
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": { "tools": { "listChanged": false }, "resources": {}, "prompts": {} },
"serverInfo": { "name": "mcp-gateway/milan-khanals-workspace-1", "version": "1.0.0" }
}
}2. List Published Tools (tools/list)
// Request
{ "jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {} }
// Response
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "get_ledgers",
"description": "Fetch ledgers for the authenticated user.",
"inputSchema": { "type": "object", "properties": {} }
}
]
}
}3. Execute Tool (tools/call)
// Request (include Mcp-Session-Id or X-Caller-Id for per-user auth)
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get_ledgers",
"arguments": {}
}
}
// Response (when authenticated)
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{ "type": "text", "text": "[{\"id\": 1, \"name\": \"Cash Ledger\", \"balance\": 12500}]" }],
"isError": false
}
}
// Response (when end-user login is required first)
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{
"type": "text",
"text": "Authentication required for Milan API. Ask the user to open this link in their browser to sign in (never ask for passwords in chat): https://mcpgateway.khanalmilan.com.np/connect/<state> — once they confirm they have signed in, retry 'get_ledgers'."
}],
"isError": false
}
}Use MCP Gateway in Your Own Chatbot or App
Your own AI chatbot backend (FastAPI, Next.js, LangChain, OpenAI Agents) can call MCP Gateway over standard HTTP. Pass a unique X-Caller-Id (e.g. your app's user ID or chat session ID) so every end user gets isolated auth tokens and RBAC enforcement.
# Python example (your chatbot backend calling MCP Gateway)
import httpx
GATEWAY_URL = "https://milan-khanals-workspace-1.gateway.khanalmilan.com.np/mcp/milan-mcp"
HEADERS = {
"Authorization": "Bearer mcp_live_YOUR_SERVICE_KEY",
"X-Caller-Id": "end-user-42", # isolates per-user OAuth/login tokens
"Content-Type": "application/json",
}
# 1. Discover available tools to pass to OpenAI / Anthropic / Gemini
tools_resp = httpx.post(GATEWAY_URL, headers=HEADERS, json={
"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}
}).json()
tools = tools_resp["result"]["tools"]
# 2. When your LLM chooses a tool, execute it via MCP Gateway
call_resp = httpx.post(GATEWAY_URL, headers=HEADERS, json={
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {"name": "get_ledgers", "arguments": {}},
}).json()
print(call_resp["result"]["content"][0]["text"])// TypeScript / Node.js example
const res = await fetch("https://milan-khanals-workspace-1.gateway.khanalmilan.com.np/mcp/milan-mcp", {
method: "POST",
headers: {
"Authorization": "Bearer mcp_live_YOUR_SERVICE_KEY",
"X-Caller-Id": currentUserId,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: { name: "get_ledgers", arguments: {} },
}),
});
const data = await res.json();End-User Authentication & RBAC Setup
When your API (e.g. /api/v1/ledgers) requires each end user's own Bearer token instead of a single shared API key, set Auth Type to End-User Auth (Login / Google) in /dashboard/apis.
Option A: External Login Redirect (?return_url)
Set External Login URL to your app's login page (e.g. https://khanalmilan.com.np/login). After your user signs in (via password, Google, SSO, or 2FA), redirect them back to return_url with &token=<JWT>:
const returnUrl = new URLSearchParams(window.location.search).get("return_url");
if (returnUrl) {
const target = new URL(returnUrl);
target.searchParams.set("token", accessToken);
window.location.href = target.toString();
}Option B: Direct Login & Google OAuth + /me RBAC
- Password Login Path: e.g.
/api/v1/auth/login— Gateway posts credentials from/connect/<state>and extracts the Bearer token. - Google Exchange Path: e.g.
/api/v1/auth/google— Gateway redirects to/connect/google/callback, exchanges the code with Google, and postsid_tokento your backend (supporting JSON orhttpOnlycookie tokens). - Profile /me Path: e.g.
/api/v1/auth/me— Gateway fetches{id, email, role}and enforcesrole_restrictedandown_data_onlypolicies before calling your API withAuthorization: Bearer <user_token>.