Connecting MCP Clients and Governing Tool Use
This lesson explains how MCP clients work in Foundry Agent Service and in code, and how to govern which tools agents can use and when people must approve calls.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how an MCP client discovers and calls tools.
- Configure the MCP tool in Foundry Agent Service.
- Govern tools with allowed tools lists, approvals and per-agent connections.
MCP clients in code
An MCP client opens a session with a server, initializes it, lists the available tools and calls them with arguments. Orchestration frameworks wrap this: Agent Framework provides MCP tool classes that connect to a server and expose its tools to an agent, and LangChain provides MCP adapters for LangGraph agents. The raw Python SDK (version 2) client looks like the following example; authentication headers are set on the HTTP client that the transport uses, and the result carries structured_content, text content and an is_error flag.
import httpx2
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
http = httpx2.AsyncClient(headers={"Authorization": f"Bearer {token}"}) # Entra ID token for the server
async with streamable_http_client(MCP_URL, http_client=http) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools() # discover tools at run time
result = await session.call_tool("get_order_status", {"order_id": "ORD-104233"})
order = None if result.is_error else result.structured_contentAn MCP client session
The MCP tool in Foundry Agent Service
Foundry Agent Service includes an MCP tool configured with a server label, the server URL, an optional project connection that holds authentication, a list of allowed tools and an approval setting. When approval is required, the response contains an mcp_approval_request item with the tool name and arguments, and the call proceeds only when the client returns an mcp_approval_response.
mcp_tool = {"type": "mcp", "server_label": "orders", "server_url": ORDERS_MCP_URL,
"allowed_tools": ["get_order_status"], # expose only what this agent needs
"require_approval": "always"}
r = openai.responses.create(model=CHAT, input="Where is order ORD-104233?", tools=[mcp_tool])The Foundry MCP tool
Governing tools
Tool governance answers which agents may use which tools, with which credentials, and under what oversight. The following practices apply.
- Use allowed tools lists so an agent sees only the tools its role needs.
- Require approval for write or high-impact tools, at least until evaluation evidence justifies autonomy.
- Use only trusted servers; a malicious or compromised server can return injected instructions or misleading tool descriptions.
- Put remote servers behind API Management for authentication, rate limits and logs.
- Keep a registry of approved servers and versions, and pin versions in production.
Governing MCP tools
An over-privileged MCP connection
A customer-facing agent connects to an internal MCP server that offers 30 tools, including refunds and account deletion. The agent should only check order status and delivery dates.
Setting allowed tools to the two read-only tools limits the agent to its role, and the server's own authorization should reject write tools for the agent's identity. Requiring approval on all 30 tools would burden staff without reducing the attack surface, and an instruction not to use the other tools is not a control.
Which settings limit an MCP tool in Foundry Agent Service?
Show answer
allowed_tools, which restricts the tools the agent may call, and require_approval, which requires a person to approve calls.
Exam Tips
Remember for the exam
- MCP client: initialize, list_tools, call_tool.
- Foundry MCP tool: allowed_tools plus require_approval.
- Use trusted, versioned servers behind a gateway.