<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c" -->

---
title: Building Composite MCP Gateways: Auth & Schema Routing
description: A full TypeScript implementation walks through building a composite MCP (Model Context Protocol) gateway that aggregates multiple upstream MCP servers behind...
canonical: https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Building Composite MCP Gateways: Auth & Schema Routing | daily.dev
og:description: A full TypeScript implementation walks through building a composite MCP (Model Context Protocol) gateway that aggregates multiple upstream MCP servers behind...
og:url: https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c
og:image: https://api.daily.dev/og/posts/s8PpzOw4C.png
og:image:alt: Building Composite MCP Gateways: Auth & Schema Routing
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Building Composite MCP Gateways: Auth & Schema Routing

**[SitePoint](https://daily.dev/sources/sitepoint)** · 20 min read · 0 upvotes · 0 comments

## Summary

A full TypeScript implementation walks through building a composite MCP (Model Context Protocol) gateway that aggregates multiple upstream MCP servers behind one endpoint. It covers namespace-based collision resolution for duplicate tool names, dynamic upstream registration with Zod schema validation, JSON-RPC request routing and response stitching, per-tool authorization via bearer-token-to-pattern mapping with wildcard support, and a token bucket rate limiter that tolerates bursty traffic. The stack uses Hono, Zod, and the official MCP SDK, with code for config files, middleware ordering, and curl-based smoke tests, plus notes on production gaps like health checks, multi-tenancy, and Redis-backed rate limiting for horizontal scaling.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.sitepoint.com/building-composite-model-context-protocol-mcp-gateways-in-typescript>

## Questions this post answers

### How do I resolve tool name collisions when aggregating multiple MCP servers behind one gateway?

Namespace every tool using a <namespace>__<toolName> convention so collisions across upstream servers are resolved unambiguously. The namespace validation regex prohibits consecutive underscores, guaranteeing the double-underscore delimiter never appears inside a namespace, and registration is rejected outright if two upstreams try to claim the same namespace prefix.

_daily.dev surfaces implementation patterns like this for developers wiring up multi-server MCP setups._

### How does a token bucket rate limiter handle bursty traffic better than a fixed-window counter?

A token bucket refills at a steady rate and lets requests consume tokens as available, so an agent issuing 8 calls in 2 seconds and then idling for 10 seconds does not exhaust its budget unfairly. Fixed-window counters instead often reject the tail end of a legitimate burst while still allowing sustained low-rate abuse, making token buckets the better fit for agentic traffic patterns.

_Developers tuning rate limits for agent traffic can compare approaches like this on daily.dev._

### How do I enforce per-tool authorization for different clients calling an MCP gateway?

Map bearer tokens to arrays of allowed tool-name patterns with trailing wildcard support, such as "rag__*" granting access to all tools in the rag namespace or "*" granting access to everything. Middleware checks the requested tool name against the caller's allowed patterns before the request reaches the router, and filters tools/list responses to only the tools that token is authorized to see.

_daily.dev helps engineers designing auth policies for tool-calling gateways find patterns like this._

## Similar posts on daily.dev

- [Production MCP Server Architecture in TypeScript](https://daily.dev/posts/production-mcp-server-architecture-in-typescript-hs138y68c) · SitePoint · 0 upvotes · 0 comments
- [Locking down MCP at the gateway](https://daily.dev/posts/locking-down-mcp-at-the-gateway-f0szifcib) · Red Hat Developer · 0 upvotes · 1 comments
- [Introducing the MCP Gateway\!](https://daily.dev/posts/introducing-the-mcp-gateway--hxhnm7r7f) · portkey · 1 upvotes · 0 comments
- [How to Build Your First MCP Server \(2026 Guide\)](https://daily.dev/posts/how-to-build-your-first-mcp-server-2026-guide--rumt2ntru) · Alex CloudStar · 2 upvotes · 1 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#mcp](https://daily.dev/tags/mcp), [#api-gateway](https://daily.dev/tags/api-gateway)

[View this post on daily.dev](https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Building Composite MCP Gateways: Auth \u0026 Schema Routing","url":"https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c"},"datePublished":"2026-09-21T15:36:38.188Z","dateModified":"2026-09-21T15:37:08.041Z","description":"A full TypeScript implementation walks through building a composite MCP (Model Context Protocol) gateway that aggregates multiple upstream MCP servers behind...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a65ec6c880a94e044502a399c0be682b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a65ec6c880a94e044502a399c0be682b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SitePoint","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SitePoint","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/sitepoint","url":"https://daily.dev/sources/sitepoint"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"typescript,mcp,api-gateway","timeRequired":"PT20M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SitePoint","item":"https://daily.dev/sources/sitepoint"},{"@type":"ListItem","position":3,"name":"Building Composite MCP Gateways: Auth \u0026 Schema Routing"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/building-composite-mcp-gateways-auth-schema-routing-s8ppzow4c#faq","mainEntity":[{"@type":"Question","name":"How do I resolve tool name collisions when aggregating multiple MCP servers behind one gateway?","acceptedAnswer":{"@type":"Answer","text":"Namespace every tool using a \u003cnamespace\u003e__\u003ctoolName\u003e convention so collisions across upstream servers are resolved unambiguously. The namespace validation regex prohibits consecutive underscores, guaranteeing the double-underscore delimiter never appears inside a namespace, and registration is rejected outright if two upstreams try to claim the same namespace prefix. daily.dev surfaces implementation patterns like this for developers wiring up multi-server MCP setups."}},{"@type":"Question","name":"How does a token bucket rate limiter handle bursty traffic better than a fixed-window counter?","acceptedAnswer":{"@type":"Answer","text":"A token bucket refills at a steady rate and lets requests consume tokens as available, so an agent issuing 8 calls in 2 seconds and then idling for 10 seconds does not exhaust its budget unfairly. Fixed-window counters instead often reject the tail end of a legitimate burst while still allowing sustained low-rate abuse, making token buckets the better fit for agentic traffic patterns. Developers tuning rate limits for agent traffic can compare approaches like this on daily.dev."}},{"@type":"Question","name":"How do I enforce per-tool authorization for different clients calling an MCP gateway?","acceptedAnswer":{"@type":"Answer","text":"Map bearer tokens to arrays of allowed tool-name patterns with trailing wildcard support, such as \"rag__*\" granting access to all tools in the rag namespace or \"*\" granting access to everything. Middleware checks the requested tool name against the caller's allowed patterns before the request reaches the router, and filters tools/list responses to only the tools that token is authorized to see. daily.dev helps engineers designing auth policies for tool-calling gateways find patterns like this."}}]}
```

