> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Servers

> Connect MCP servers to Agent Harness with centralized auth, RBAC, guardrails, and zero credential handling in agent code.

MCP servers are how your agent reaches real systems: SaaS apps, internal APIs, data platforms, ticketing tools, and infrastructure controls.

In Agent Harness, MCP connectivity is fully managed through TrueFoundry MCP Gateway. Authentication, access control, guardrails, and observability are centralized — developers building agents never paste API keys or manage per-server credentials.

## Why this matters

In other agent platforms, you must register MCP servers with credential headers per agent or per workspace, and developers handle OAuth tokens or API keys directly:

* **Claude Managed Agents** — register MCP servers with vault credentials per workspace. Developers manage vault IDs and credential matching by URL.
* **LangSmith Managed Deep Agents** — register MCP servers via API with `headers` arrays containing raw bearer tokens.

In TrueFoundry, MCP servers are registered once in the MCP Gateway. Agents reference servers by name — the AI Gateway handles auth, token refresh, and user delegation automatically.

## Gateway-managed MCP access

| Concern                         | How TrueFoundry handles it                                             |
| ------------------------------- | ---------------------------------------------------------------------- |
| Server credentials              | Stored in MCP Gateway. Agents never see tokens or keys.                |
| User-scoped auth (OAuth)        | Gateway manages per-user OAuth flows, stores and refreshes tokens.     |
| Who can use which servers/tools | RBAC — assign MCP server access to teams, users, or agents.            |
| Tool-level restrictions         | Enable/disable individual tools per agent. Exclude destructive tools.  |
| Guardrails                      | Pre-execution and post-execution checks on tool inputs/outputs.        |
| Approval gates                  | Tools marked destructive automatically pause for user confirmation.    |
| Observability                   | Every tool call traced with inputs, outputs, latency, and attribution. |

<Tip>
  Platform teams configure MCP servers and policies once. Agent builders just pick servers from a governed catalog — no credential plumbing required.
</Tip>

## How MCP works in Agent Harness

When an agent run needs a tool:

1. The harness discovers tools from connected MCP servers.
2. The MCP Gateway checks user/team permissions.
3. The AI Gateway applies stored credentials (user-scoped OAuth or service-level tokens).
4. The tool is invoked, traced, and results flow back into the agent context.

```mermaid theme={"dark"}
sequenceDiagram
    participant Agent as Agent Harness
    participant GW as MCP Gateway
    participant MCP as MCP Server

    Agent->>GW: Invoke tool (server name + tool name)
    GW->>GW: Check RBAC, apply credentials
    GW->>MCP: Authenticated tool call
    MCP->>GW: Tool response
    GW->>GW: Apply post-execution guardrails
    GW->>Agent: Filtered response + trace
```

## Server and tool selection

* Attach only the MCP servers an agent needs
* Enable only specific tools required for a use case
* Exclude sensitive or destructive tools from the agent's tool surface
* Use virtual MCP servers to curate and expose a controlled subset of tools

This reduces risk and improves tool-call quality by minimizing irrelevant choices.

## Preload Skill / MCP tools into agent context

For each MCP server, you can configure **Preload Skill / MCP tools into agent context**.

When disabled for an MCP server:

* Tool details are not loaded upfront in the agent's context.
* The agent dynamically discovers available tools at runtime.

This reduces initial context usage and is useful for large tool catalogs. If you need faster first-tool execution for small, frequently used toolsets, preload can be enabled.

See [Preload Tools](/docs/agent-platform/agent-harness/context-engineering/preload-tools) for the detailed flow.

## In-chat authentication

If a user has not yet authenticated to a required MCP server, the agent chat experience prompts authentication inline — the user clicks "Connect", completes the OAuth flow, and continues the conversation without leaving the chat.

<Frame caption="In-chat MCP authentication: the user connects to Slack directly from the agent conversation">
  <img src="https://mintcdn.com/truefoundry/sRJHwFb35bXgeP_o/docs/agent-platform/agent-harness/images/mcp-auth-in-chat.png?fit=max&auto=format&n=sRJHwFb35bXgeP_o&q=85&s=e53ad28a0ffc63ebd494db134eb32415" alt="Agent chat interface showing MCP authentication required for Slack, with a connect button and continue flow inside the conversation" width="1024" height="730" data-path="docs/agent-platform/agent-harness/images/mcp-auth-in-chat.png" />
</Frame>

No credential handling in code, no token pasting, no interruption to the workflow.

## Safety controls

* Mark destructive or non-read-only tools for approval workflows
* Require explicit human confirmation before high-impact actions
* Apply MCP guardrails and gateway policies before and after tool execution

See [Human in the Loop](/docs/agent-platform/agent-harness/human-in-the-loop) and [MCP Guardrails](/docs/ai-gateway/mcp/mcp-overview#5-mcp-guardrails).

## Operational visibility

MCP tool calls are part of end-to-end agent tracing:

* Which server and tool were used
* Inputs and outputs (subject to policy/redaction)
* Latency and error patterns
* User/team attribution and cost impact

For the full MCP Gateway architecture, see [TrueFoundry MCP Gateway](/docs/ai-gateway/mcp/mcp-overview).

## Benchmarking and reliability insights

Server-level benchmarking and comparative MCP reliability analytics are being expanded. This will include side-by-side latency, success-rate, and quality benchmarks across MCP servers and toolsets as these capabilities become generally available.
