Overview

You can use the official Python/TypeScript MCP SDK to connect to MCP Servers that have been added to the TrueFoundry Gateway. The Gateway handles authorization for those servers - you only need to provide authentication for the Gateway itself.

Transport Support:

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

Get your code snippet from the AI Gateway UI

Copy the code snippet from the UI for quick integration


Installation

npm install @modelcontextprotocol/sdk

Usage

Below are complete examples of how to use the SDK to connect, list tools, and call tools on an MCP Server. Just copy the code, update your credentials and tool names, and you’re ready to go!

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 integration ID
  • <tfy-api-token> with your TrueFoundry API token
  • <tool-name> with the name of the tool you want to use

Tips

  • Make sure your API token has the necessary permissions for the MCP server and tools you want to access.