Skip to main content
When using the Responses API with remote MCP servers, the model provider (OpenAI, Anthropic, etc.) needs to reach the MCP server URL directly. This works great for public MCP servers, but fails for private servers behind firewalls, VPNs, or on local networks. This guide shows you how to use private MCP servers by offloading tool fetching and invocations to the client side — giving you full control while still leveraging the Responses API’s powerful agentic capabilities.

The Problem

Remote MCP Flow (Provider-Managed)Your App → Portkey → OpenAI → ✗ → Private MCP ServerThe provider cannot reach your private server!
When you pass an MCP server URL in your Responses API request, the model provider makes the connection. If your MCP server is:
  • Behind a corporate firewall
  • Running on localhost or a private network
  • Requires VPN access
  • Not exposed to the public internet
…the provider simply cannot reach it, and the request fails.

The Solution: Client-Side MCP Handling

Instead of letting the provider connect to your MCP server, you handle all MCP interactions locally:
Client-Side MCP Flow (You Control Everything)Your App ↔ Private MCP Server (direct connection)Your App → Portkey → Provider (sends function tools, receives tool calls)
1

Fetch tools locally

Your app connects directly to your private MCP server and retrieves available tools
2

Send as function tools

Convert MCP tools to function tool format and include them in your Responses API request
3

Execute tools locally

When the model requests a tool call, your app executes it against your private MCP server
4

Return results

Send tool results back to continue the conversation

Prerequisites

Implementation

Step 1: Create an MCP Client

First, set up a client that connects to your private MCP server.

Step 2: Convert MCP Tools to Function Tools

The Responses API accepts function tools in a specific format. Convert MCP tools to this format:

Step 3: Handle Tool Calls in the Response Loop

When the model wants to call a tool, execute it against your MCP server and return the results:

Step 4: Putting It All Together

Complete Example

Python
TypeScript

Using with Multiple MCP Servers

You can connect to multiple private MCP servers and combine their tools:

Adding Portkey Features

Since you’re using Portkey’s client, you get access to all its enterprise features:

Observability & Logging

Python

Fallbacks & Reliability

Python

Benefits of Client-Side MCP Handling

Access Private Servers

Connect to MCP servers on localhost, internal networks, or behind VPNs.

Full Control

Implement custom authentication, rate limiting, and error handling.

Multiple Servers

Combine tools from multiple MCP servers in a single conversation.

Portkey Features

Get observability, caching, fallbacks, and budget controls on all requests.

When to Use Each Approach

Next Steps

Remote MCP Docs

Learn about provider-managed remote MCP for public servers.

Converting STDIO to HTTP

Convert local MCP servers to remote HTTP servers.

Function Calling

Understand the underlying function calling workflow.

AI Gateway Features

Explore Portkey’s reliability and observability features.
Need help? Join our Discord community or reach out to support.
Last modified on January 9, 2026