DEV Community

Lightning Developer
Lightning Developer

Posted on

Making Your Local MCP Server Reach the Outside World with Pinggy

When working with AI-driven systems, connecting models to real tools and data is no longer optional. The Model Context Protocol (MCP) has emerged as a practical way to bridge that gap. It gives AI applications a structured method to interact with APIs, files, and workflows.

But there is a catch. Most MCP servers begin their life on a developer’s machine. That is great for building and debugging, yet it becomes restrictive the moment you want external access.

This is where a tunneling approach becomes useful.

What MCP Really Does Behind the Scenes

At its core, an MCP server acts like a middle layer between an AI system and external capabilities. Instead of hardcoding integrations for every service, MCP standardizes how these connections happen.

Typically, MCP exposes three kinds of functionality:

  • Tools that allow actions such as querying systems or triggering APIs
  • Resources that provide structured context, like documents or datasets
  • Prompts that define reusable interaction patterns

This structure allows AI clients to discover and use capabilities dynamically, rather than relying on tightly coupled integrations.

Why Local Development Becomes a Bottleneck

Running an MCP server locally is convenient. You can quickly iterate, inspect logs, and experiment without worrying about deployment.

However, several real-world scenarios break this setup:

  • A cloud-hosted AI client cannot access your machine
  • Teammates cannot test your prototype remotely
  • Mobile devices fail to reach localhost endpoints
  • External integrations remain untestable

In short, localhost is isolated by design.

Bridging Localhost to the Internet

Instead of deploying your MCP server to the cloud early, you can create a secure tunnel from your machine to a public URL. This allows external systems to communicate with your local server as if it were hosted online.

A typical command to expose a local MCP server looks like this:

ssh -p 443 -R0:localhost:3000 -L4300:localhost:4300 -t free.pinggy.io
Enter fullscreen mode Exit fullscreen mode

Once connected, you receive a temporary HTTPS URL. By appending your MCP endpoint path, you get something like:

https://your-subdomain.pinggy.link/mcp
Enter fullscreen mode Exit fullscreen mode

This URL becomes accessible from anywhere.

Understanding MCP Transport Types Before Exposing

Not every MCP server can be shared the same way. The communication method matters.

Local Process-Based Communication (stdio)

Some MCP servers run as subprocesses and communicate through standard input and output. These are ideal for local environments but cannot be exposed over HTTP directly.

HTTP-Based Communication

Other MCP servers operate as standalone web services. These expose endpoints like /mcp and support HTTP requests. This type is suitable for tunneling and remote access.

Legacy Streaming Approaches

Older implementations may rely on streaming-based transports. These can still work, but compatibility depends on client support.

Getting Your MCP Server Ready

Before creating a tunnel, ensure your server is running locally on a known port.

Example setup:

  • Local server: http://localhost:3000
  • MCP endpoint: http://localhost:3000/mcp

Here is a minimal Node.js example using Express:

const express = require("express");

const app = express();
app.use(express.json());

app.post('/mcp', (req, res) => {
  if (req.method !== 'POST') {
    return res.status(405).json({
      jsonrpc: '2.0',
      error: { code: -32600, message: 'Method not allowed' },
    });
  }

  const { method } = req.body;

  if (method === 'initialize') {
    return res.json({
      jsonrpc: '2.0',
      id: req.body.id,
      result: {
        protocolVersion: '2025-11-25',
        capabilities: {},
        serverInfo: { name: 'minimal-mcp', version: '1.0.0' },
      },
    });
  }

  return res.status(400).json({
    jsonrpc: '2.0',
    error: { code: -32601, message: 'Method not found' },
  });
});

const port = process.env.PORT || 4001;
app.listen(port, () => console.log(`Server running on http://localhost:${port}/mcp`));
Enter fullscreen mode Exit fullscreen mode

Run the server:

node server.js
Enter fullscreen mode Exit fullscreen mode

Verifying the Server Locally

Before exposing anything publicly, confirm that your MCP endpoint responds correctly.

curl -i http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  --data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}'
Enter fullscreen mode Exit fullscreen mode

If this fails, check:

  • Whether the server is running
  • Whether the endpoint path is correct
  • Whether required headers are missing

Creating a Public Tunnel

Keep your server running and open a new terminal:

ssh -p 443 -R0:localhost:3000 -L4300:localhost:4300 -t free.pinggy.io
Enter fullscreen mode Exit fullscreen mode

This does three things:

  • Connects through a commonly open port
  • Maps a public URL to your local server
  • Enables a debugging interface at http://localhost:4300

Testing the Public Endpoint

Once the tunnel is active, test the generated URL:

curl -i https://your-subdomain.pinggy.link/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  --data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"remote-test","version":"1.0.0"}}}'
Enter fullscreen mode Exit fullscreen mode

You can also inspect incoming requests through the local debug panel:

http://localhost:4300
Enter fullscreen mode Exit fullscreen mode

This is useful when debugging connection issues from external clients.

Connecting an AI Client

Most MCP-compatible clients allow you to configure a remote server URL.

Example JavaScript connection:

const mcpUrl = 'https://your-subdomain.pinggy.link/mcp';
const token = 'your-token';

async function init() {
  const response = await fetch(mcpUrl, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json, text/event-stream',
      'Authorization': `Bearer ${token}`,
    },
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: 1,
      method: 'initialize',
      params: {
        protocolVersion: '2025-11-25',
        capabilities: {},
        clientInfo: { name: 'client', version: '1.0.0' },
      },
    }),
  });

  const data = await response.json();
  console.log(data);
}

init();
Enter fullscreen mode Exit fullscreen mode

Make sure your client supports remote HTTP connections. Some tools only work with local processes and will require additional adapters.

Securing Your Exposed MCP Server

Opening a public endpoint without protection is risky. Even for testing, basic safeguards are necessary.

Options include:

  • Simple username and password authentication
  • Token-based access for API clients

Token authentication is generally better for automated systems.

Temporary vs Stable URLs

By default, tunneling generates short-lived URLs. These are fine for quick experiments, but inconvenient for repeated use.

If you need consistency:

  • Use a reserved subdomain
  • Map a custom domain
  • Maintain a stable endpoint for integrations

This helps when sharing with teams or configuring external tools.

Conclusion

Working locally remains the fastest way to build MCP servers, but isolation limits real testing. By exposing your local environment through a secure tunnel, you can simulate real-world usage without committing to early deployment.

The key considerations are simple:

  • Use HTTP-based MCP servers for remote access
  • Verify endpoints locally before exposing them
  • Add authentication before sharing URLs
  • Switch to stable domains when workflows grow

This approach lets you iterate quickly while still testing in conditions that resemble production environments.

Expose Local MCP Servers Securely with Pinggy

Learn how to share a localhost MCP server using Pinggy. This guide covers Streamable HTTP MCP servers, public HTTPS tunnels, testing, authentication, and practical security tips.

favicon pinggy.io

Top comments (0)