Loading…
Loading documentation...
Expose tools safely over Model Context Protocol Streamable HTTP with token scoping, JSON schema validation, anti-poisoning checks, and audit logs.
Commands checked on 2026-11-23 with MCP SDK 1.x, Streamable HTTP, Node.js 24, TypeScript 5.
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.
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.
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).
Attackers often hide malicious directives inside tool descriptions ("rug pulls") or downstream ticket/document strings read by an MCP tool (LLM01: Prompt Injection):
<untrusted_external_data>).READ_ONLY, PIM_GATED_WRITE, CanNotDelete / ReadOnly locks) so destructive actions require human-verified elevation rather than silent single-step tool execution.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.
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.
POST directly with Accept: application/json, text/event-stream and expect deterministic JSON-RPC 2.0 envelopes with matching id.env_id: "ENV-OTHER"). Your handler trusted args.environmentId without checking membership. Always validate args.environmentId against the token's bound tenant set first..env hostnames into agent context. Catch unexpected exceptions cleanly and return generic public error codes rather than raw err.stack.READ_ONLY by default) and gate destructive mutations behind short-lived privilege elevation or explicit customer confirmation.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.