Skip to main content
Servers Are Up
Virtual Datacenter
PricingFree Tools
Sign inBrowse catalog
Servers Are Up
Virtual Datacenter
PricingFree Tools
Sign inBrowse catalog

Loading…

Servers Are Up

Your apps, automation and data on hardware we own. Build a private stack with predictable capacity and access through your dashboard, API or SSH.

SLA with service creditsOwned hardwareUS-based

Make room for your next idea

Explore the capacity, apps and access options that fit your workload. Check current availability and your total before you buy.

Sign up freeView Pricing

Products

  • Linux VPS
  • Windows VPS
  • Cloud & SaaS Services
  • Cloud Storage (Azure)
  • Virtual Datacenter
  • AI & Agent Hosting
  • Containers
  • Instant Apps
  • Software Platforms
  • Network builder
  • Game Servers
  • Free Game Servers
  • Pricing

Resources

  • Free Network Tools
  • 2026 Pricing Benchmark
  • Live SVG Badges
  • Latency & Speed Test
  • Guides & Tutorials
  • Documentation
  • API Reference
  • MCP Server
  • CLI & SDKs
  • OpenAPI & llms.txt
  • Use Cases
  • Free Migration
  • Uptime & Reliability
  • Datacenter
  • System Status
  • Network
  • Provider Comparisons Hub
  • Compare Providers

Company

  • About Us
  • Enterprise
  • Security Architecture
  • Trust Center
  • Blog
  • FAQ
  • Compliance
  • Startup Program
  • Open-Source Sponsorship
  • Press & Media Kit
  • Referral Program
  • Help Center
  • Contact Us
© Servers Are Up
TermsPrivacySLARefund PolicyDPAAcceptable Use
Service information
Docs
  • Documentation Hub
  • Technical Knowledge Library
    Runbooks & 187 Blueprints
  • Choose a Product
    VMs, Containers & Cloud
  • First Linux Server
    SSH, Firewall & Apps
  • Windows Server 2025
    BYOL & Remote Desktop
  • Remote Access
  • Troubleshooting
  • FAQ
  • All Product Guides
    29 Step-by-Step Guides
  • Cloud & SaaS Catalog
    112 Cloud & SaaS Offerings
  • Azure Cloud Storage
    Hot/Cool/Archive & WORM
  • Resource Manager & RBAC
    Groups, Tags & Locks
  • Multi-Model Cloud DB
    JSONB, SQL & pgvector
  • Cloud Identity & ZTNA
    OIDC, SCIM & PIM
  • Key Vault & KMS
    Secrets & Envelope Keys
  • Cloud SIEM, SOAR & DLP
    Posture & Threat Response
  • API Gateway & Cloud DNS
    Edge WAF & DNS Zones
  • Serverless, Workflows & IoT
    Functions, Queues & DAGs
  • SaaS, Governance & Vault
    Budgets & Off-Host GRS
  • Linux Systems & Kernel
    SSH, UFW, sysctl & OOM
  • Self-Hosted Apps & Stacks
    Caddy, Nextcloud & Auth
  • Build Web Apps with AI
  • Next.js and React
  • TypeScript and Node.js
  • npm and Tooling
  • Data and APIs
  • Deploy and Operate
  • Tutorials
  • Infrastructure
  • Automation & Regions
  • API Overview
  • API v1 Reference
    Endpoints & 23 Scopes
  • MCP Server
    129 AI Agent Tools
  • Swagger / OpenAPI 3.1
  • API Playground
  • Versioning & Sunset
  • API Token Security
    Authentication & Tokens
  • Instances API
    Compute Resources
  • Networking API
    Networks & Ports
  • Storage API Availability
    Volumes & Backups
  • Webhooks & Events
    Event Notifications
  • Rate Limits & Best Practices
    Throttling & Retries
  • sau CLI Reference
    34 Commands (v0.2)
  • Browser Web CLI
  • SDKs
  • Infrastructure as Code
    Terraform & Ansible
  • Code Examples
  • CLI & SDK Guides
  • Security Guides
  • Security at a Glance
  • Zero Trust Architecture
  • Live Trust Center
  • Compliance
Need help?

Loading documentation...

Documentation/ai web apps

Build a secure Streamable HTTP MCP server for your API

Expose tools safely over Model Context Protocol Streamable HTTP with token scoping, JSON schema validation, anti-poisoning checks, and audit logs.

Advanced
30 min
Updated 2026-11-23

Deploy Ready-to-Run Infrastructure in Seconds

Linux VMs from $6/mo · Pooled Virtual Datacenters from $12/mo · Use code WELCOME20 for 20% off your first order.

Browse ServersView Pricing

Commands checked on 2026-11-23 with MCP SDK 1.x, Streamable HTTP, Node.js 24, TypeScript 5.

What you will have at the end

A production-hardened Model Context Protocol (MCP) server speaking Streamable HTTP JSON-RPC (POST /api/mcp/v1), defending against tool poisoning, rug-pull schema mutations, excessive agency, SSRF, and cross-tenant data leakage aligned with OWASP Top 10 for LLM Applications 2025.

Before you start

  • Familiarity with TypeScript REST API routes and Bearer token auth; see Add a first AI feature to a Next.js app.
  • Review how Servers Are Up organizes scoped PAT and tenant tokens on MCP Server Guide and Connect an AI agent through MCP.

Steps

1. Enforce Streamable HTTP authentication and server-derived identity

Never rely on client-supplied userId or tenantId tool parameters as authorization proof. Derive the caller identity exclusively from a hashed Bearer token (SHA-256) or OAuth 2.1 access token tied to exact allowed scopes:

import crypto from 'node:crypto';

export interface VerifiedMcpPrincipal {
  userId: string;
  environmentId: string;
  scopes: ReadonlySet<string>;
}

export function hashBearerToken(rawHeader: string | null): string | null {
  if (!rawHeader?.startsWith('Bearer ')) return null;
  const token = rawHeader.slice('Bearer '.length).trim();
  if (token.length < 24) return null;
  return crypto.createHash('sha256').update(token, 'utf8').digest('hex');
}

Reject tools/call immediately with JSON-RPC error -32001 (401) if no valid scoped principal exists, while optionally keeping initialize and read-only catalog discovery inspectable.

2. Validate every tool argument strictly with Zod before dispatch

Treat all LLM tool arguments as hostile untrusted input (LLM06: Excessive Agency). Validate types, enums, string length ceilings, and URL/path constraints explicitly:

import { z } from 'zod';

export const SafeSearchSchema = z.object({
  query: z.string().trim().min(2).max(300),
  limit: z.number().int().min(1).max(15).default(6),
});

Never interpolate tool inputs directly into shell strings (exec) or raw SQL templates—use parameterized queries and argument arrays (execFile).

3. Pin tool descriptions and guard against indirect tool poisoning

Attackers often hide malicious directives inside tool descriptions ("rug pulls") or downstream ticket/document strings read by an MCP tool (LLM01: Prompt Injection):

  • Pin immutable tool manifest arrays in version-controlled code rather than dynamically loading tool definitions from user-editable database fields.
  • Sanitize or XML-wrap every string fetched from databases, customer notes, or external docs before returning JSON results to the LLM (<untrusted_external_data>).
  • Enforce read-only / confirmation guardrails (READ_ONLY, PIM_GATED_WRITE, CanNotDelete / ReadOnly locks) so destructive actions require human-verified elevation rather than silent single-step tool execution.

4. Write immutable SHA-256 hash-chained tool audit records

Log every MCP invocation with timestamp, principal ID, environment ID, tool name, sanitized argument summary, latency, and prevHash -> entryHash chaining so forensic review detects any tampering or anomalous tool probing.

Check that it works

Verify unauthenticated tools/call rejection and tools/list schema stability over HTTP:

curl -s -X POST https://YOUR_DOMAIN/api/mcp/v1 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | head -c 300

curl -s -o /dev/null -w "Unauth mutating tools/call -> %{http_code}\n" \
  -X POST https://YOUR_DOMAIN/api/mcp/v1 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"create_resource","arguments":{}}}'

Protected tool calls must return 401 (or JSON-RPC auth error) without an authorized Bearer token.

What can go wrong

  • MCP clients loop or stall after upgrading from legacy HTTP+SSE to Streamable HTTP. Modern clients send JSON-RPC POST directly with Accept: application/json, text/event-stream and expect deterministic JSON-RPC 2.0 envelopes with matching id.
  • Agent invents arguments for another tenant (env_id: "ENV-OTHER"). Your handler trusted args.environmentId without checking membership. Always validate args.environmentId against the token's bound tenant set first.
  • Tool outputs leak stack traces or internal .env hostnames into agent context. Catch unexpected exceptions cleanly and return generic public error codes rather than raw err.stack.

Good practice

  • Keep MCP write modes opt-in (READ_ONLY by default) and gate destructive mutations behind short-lived privilege elevation or explicit customer confirmation.
  • Test SSRF rules on every tool that touches hostnames, webhooks, or external URLs.
  • Apply strict per-token rate limits so a runaway agent retry loop cannot DoS your API or exhaust database pools.

Where to go next

  • Input and output guardrails for AI applications
  • Build RAG with PostgreSQL 17 and pgvector HNSW safely
  • Connect an AI agent through MCP

Related Articles

Choose a model for your app by measuring it

Read more

Run Dify, Flowise, and Langflow workflows cleanly in Docker

Read more

Add a first AI feature to a Next.js app

Read more

Frequently Asked Questions

What does the Build a secure Streamable HTTP MCP server for your API documentation guide cover?
Expose tools safely over Model Context Protocol Streamable HTTP with token scoping, JSON schema validation, anti-poisoning checks, and audit logs. It is rated advanced difficulty (30 min) and applies to Servers Are Up infrastructure and workflows.
Can I manage or automate these steps through the Servers Are Up dashboard, REST API v1, or MCP server?
Yes. Every Servers Are Up server includes browser-based SSH, WebRDP, and VNC console access in the dashboard, plus programmatic control via the REST API v1 (/api/v1) and hosted Model Context Protocol server (/api/mcp/v1) using a scoped Personal Access Token.

Need hands-on help with Build a secure Streamable HTTP MCP server for your API?

Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.

Was this article helpful?

On this page

What you will have at the endBefore you startSteps1. Enforce Streamable HTTP authentication and server-derived identity2. Validate every tool argument strictly with Zod before dispatch3. Pin tool descriptions and guard against indirect tool poisoning4. Write immutable SHA-256 hash-chained tool audit recordsCheck that it worksWhat can go wrongGood practiceWhere to go next
Need Live Commands?

Open Aria in Wide Engineering Mode for distro-specific commands, compose tweaks, and isolated environment troubleshooting.

Knowledge Library