Overview

TrueFoundry AI Gateway enables you to expose integrated MCP Servers to developers in a secure manner.
Diagram showing TrueFoundry AI Gateway architecture with MCP Servers integration
This allows you to:
  • Manage who can use the registered MCP Servers.
  • Avoid exposing MCP Server credentials directly to the developers.
  • Monitor usage metrics (latency, execution per second) of the tools across all registered MCP Servers. (Coming soon.)
  • Rate-limit tool calls. (Coming soon.)
    • This is useful for expensive tools like search, code-execution, etc.

Quickstart

1

Copy the code snippet

TrueFoundry Dashboard showing where to find the MCP server code snippet in AI Gateway UI

Get your code snippet from the AI Gateway UI

TrueFoundry Dashboard showing code snippet interface for MCP server integration

Copy the code snippet from the UI for quick integration

2

Copy PAT or VAT

Check out the Authentication page more details.
3

Call the MCP Server from your code

At this point, we can use the code snippet we copied at Step 1.Below is an example showing how to connect, list tools, and call tools on an MCP Server. Update the placeholders with your actual credentials and tool names.
Install the library:
npm install @modelcontextprotocol/sdk
Code:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

// Example usage (runs if this file is executed directly)
// Run with: npx ts-node typescript-mcp-client.ts
(async () => {
    const url = 'https://<controlPlaneUrl>/api/llm/mcp-server/<integrationId>/server';
    const authToken = '<tfy-api-token>'; // Replace with your actual TFY API token (PAT or Service account token)
    const toolName = '<tool-name>';      // Replace with your actual tool name
    const args = {};                     // Replace with your actual tool arguments

    const requestInit: RequestInit = {
        headers: { Authorization: `Bearer ${authToken}` }
    };
    const baseUrl = new URL(url);
    const client = new Client({ name: "streamable-http-client", version: "1.0.0" });
    await client.connect(new StreamableHTTPClientTransport(baseUrl, { requestInit }));

    const tools = await client.listTools();
    console.log("Available tools:", tools);

    const result = await client.callTool({ name: toolName, arguments: args });
    console.log("Tool result:", result);
})();

Configuration

Required Parameters

ParameterDescription
urlThe MCP server URL (e.g., https://<controlPlaneUrl>/api/llm/mcp-server/<integrationId>/server)
authTokenYour TrueFoundry API token (PAT or user token)
toolNameThe name of the tool you want to invoke
argsThe arguments to pass to the tool
Replace the placeholders in the example:
  • <controlPlaneUrl> with your TrueFoundry control plane URL
  • <integrationId> with your MCP server ID
  • <tfy-api-token> with your TrueFoundry API token
  • <tool-name> with the name of the tool you want to use

Supported Transports

  • Only MCP servers that use streamable-http transport (stateful/stateless) are supported for connection via Gateway proxy
  • Older SSE-based MCP servers will work on /agent/responses endpoint but are not compatible with the proxy connection method described here