Build and Ship Any MCP Server in MINUTES (Full Guide)

Cole MedinAbout 5 min readJul 10, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

  • Model Context Protocol (MCP): A standard for connecting AI agents to external tools and systems.
  • Streamable HTTP: A scalable transport layer for MCP.
  • OAUTH (GitHub OAUTH): Authentication and authorization protocol used to secure MCP servers, specifically using GitHub accounts.
  • Cloudflare Workers: A serverless platform for deploying and scaling MCP servers.
  • Sentry: An application monitoring platform for tracking errors and performance in production MCP servers.
  • Lifespan (Lifecycle Management): Managing resources like database connections within the MCP server and closing them down gracefully.
  • Tool Descriptions: Clear and concise descriptions for each tool in the MCP server, used by the LLM to understand when and how to use the tool.
  • KV (Key-Value Store): A database used to keep track of users authenticated with GitHub.

Building Production-Ready MCP Servers

Introduction

The video addresses the increasing use of MCP servers and the lack of knowledge on building and deploying them for production. It highlights Anthropic's advancements in MCP infrastructure, including streamable HTTP, OAUTH, security documentation, and remote deployments via platforms like Cloudflare. The video provides a comprehensive template for building production-ready MCP servers, covering authentication, monitoring, security, and deployment.

What We're Building

The video demonstrates building a TypeScript MCP server with the following features:

  • Authentication: GitHub OAUTH integration for secure access.
  • Monitoring: Sentry integration for production monitoring.
  • Deployment: Cloudflare Workers for remote deployment.
  • Transport Layers: Streamable HTTP (new) and SSE (legacy).
  • Database Integration: A basic "chat with your database" MCP server using Postgress.
  • Tools:
    • List all tables in the database.
    • Execute read-only queries.
    • Execute write operations (protected by GitHub OAUTH).

Prerequisites

The following prerequisites are required to set up the MCP server:

  1. Node.js: Installed on your local machine.
  2. Cloudflare Account: A free tier account is sufficient.
  3. GitHub Account: Required for OAUTH authentication.
  4. Postgress Database: For the "chat with your database" functionality.
  5. Wrangler CLI: Cloudflare's command-line interface. Installation: npm install -g wrangler. Login: wrangler login.
  6. Clone the Repository: Clone the provided GitHub repository.
  7. Install Dependencies: Run npm install in the cloned repository.

Understanding MCP Core

The video emphasizes understanding the core functionality of MCP before adding complexity. A basic example is provided, based on the TypeScript MCP SDK documentation.

  • Import MCP Server: Import MCP Server and the transport layer (e.g., Standard IO).
  • Create Instance: Create an instance of the MCP server.
  • Register Tools: Register functionalities as tools.
  • Define Transport: Define the transport layer.
  • Spin Up Server: Start the MCP server.

The video highlights that MCP is essentially an API endpoint for AI agents, repackaged in a standard.

Simple Math MCP Server Example

A basic MCP server example (simplemath.ts) is provided to demonstrate the core concepts:

  • Import MCP Agent: Import MCP Agent from Cloudflare's agents offering.
  • Define Server: Define the MCP server.
  • Initialize Tools: Define tools with names, arguments, descriptions, and function definitions.
  • Serve MCP Server: Serve the server with SSE and streamable HTTP endpoints.

The example includes a calculate tool that performs basic math operations. The server is run using wrangler dev --config simplemath.ts, making it accessible via localhost:8789.

Setting Up the Main MCP Server

The video outlines the steps to get the main MCP server up and running:

  1. Clone the Repository: (Already done in prerequisites)
  2. Set Up Environment Variables: Copy .dev.vars.example to .dev.vars and set the following variables:
    • GITHUB_CLIENT_ID: GitHub OAUTH client ID.
    • GITHUB_CLIENT_SECRET: GitHub OAUTH client secret.
    • ENCRYPTION_KEY: Encryption key for OAUTH.
    • DATABASE_URL: Connection string for the Postgress database.
  3. Run Wrangler Dev: Execute wrangler dev to start the MCP server locally.

GitHub OAUTH Setup

The video explains how to set up GitHub OAUTH:

  1. GitHub Developer Settings: Go to GitHub settings -> Developer settings -> OAUTH apps.
  2. Create New App: Create a new OAUTH app to obtain the client ID and secret.
  3. Configure Redirect URI: Set the redirect URI to your Cloudflare worker URL.

MCP Server Implementation Details

The video walks through the key aspects of the MCP server implementation:

  • Allowed GitHub Users: A list of GitHub usernames allowed to use sensitive tools (e.g., write queries).
  • Lifespan Management: Database connection is initialized when the server starts and closed gracefully when the server exits.
  • Tool Descriptions: Clear and concise descriptions for each tool, used by the LLM to understand when and how to use the tool.
  • Security Best Practices:
    • SQL Query Validation: Validating SQL queries for dangerous patterns.
    • Role-Based Access Control: Using GitHub OAUTH to protect sensitive tools.
  • GitHub OAUTH Integration: Using Cloudflare's OAUTH provider to handle server-side authentication.
  • API Handlers: Handlers for SSE and streamable HTTP endpoints.

Monitoring with Sentry

The video demonstrates integrating Sentry for production monitoring:

  1. Create Sentry Project: Create a new Cloudflare Workers JavaScript project in Sentry.
  2. Get DSN: Obtain the DSN (Data Source Name) from the Sentry project.
  3. Set Environment Variable: Add the DSN as an environment variable.
  4. Enable Sentry: Swap the index.ts file with the index_sentry.ts file.
  5. Configure Sentry: Configure Sentry in the index.ts file, following the provided guide.
  6. Wrap OAUTH Provider: Wrap the OAUTH provider with Sentry's withEntry function.

Deploying to Cloudflare

The video outlines the steps to deploy the MCP server to Cloudflare Workers:

  1. Create KV Namespace: Create a KV namespace to store OAUTH data: wrangler kv namespace create oath_kv.
  2. Update Wrangler.toml: Replace the placeholder KV ID in wrangler.toml with the actual KV ID.
  3. Deploy: Run wrangler deploy to deploy the MCP server to Cloudflare Workers.
  4. Set Environment Variables: Set the environment variables (client ID, client secret, encryption key, database URL) in the Cloudflare dashboard or using the Wrangler CLI: wrangler secret put <secret_name>.

Using AI Coding Assistants

The video suggests using AI coding assistants like Cloud Code or Cursor to customize the MCP server. The GitHub repository and security checklist can be used as context for the AI coding assistant to generate new tools, modify authentication methods, or implement other features.

Conclusion

The video provides a comprehensive guide and template for building and deploying production-ready MCP servers. It covers essential aspects like authentication, security, monitoring, and deployment, enabling developers to create robust and scalable MCP solutions. The use of AI coding assistants is also highlighted as a way to further customize and extend the functionality of the MCP server.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.