The Problem
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
localhostor a private network - Requires VPN access
- Not exposed to the public internet
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
Full Python Implementation
Full Python Implementation
Python
Full TypeScript Implementation
Full TypeScript Implementation
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
| Approach | Use When |
|---|---|
| Remote MCP (provider-managed) | MCP server is publicly accessible, you want simplicity |
| Client-Side MCP (this guide) | MCP server is private, you need custom auth/routing, you want more control |
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.

