Build a custom MCP client for AgentFlow
Learn how to build a custom client to interface with the Reltio AgentFlow MCP Server for tool orchestration and AI agent integration.
This topic shows you how to integrate with the Reltio AgentFlow MCP Server using a custom MCP client, following the Model Context Protocol specification. Although the MCP Server adheres to the protocol and OAuth 2.0 standards, you'll need to handle a few key integration details explicitly when building your client.
- Interface with the MCP server for tool orchestration
- Build a lightweight utility to call MCP tools
- Implement custom clients beyond pre-configured options
What you can accomplish
- Sends requests to Reltio AgentFlow MCP server
- Handles tool invocations
- Processes responses from the server
Prerequisites
- Python 3.10+
- A valid access token
- MCP server endpoint URL
- The requests library (or
httpx
forasync
)
- Install dependencies
- Authenticate with the MCP server
Install dependencies
Install the required Python library:pip install requests
Authenticate with the MCP Server
To connect your custom MCP client, you must first obtain an access token using OAuth 2.0 authentication.
For more information about supported authentication flows, header formats, and endpoint discovery, see Get an access token using OAuth 2.0.
Configure the client
MCP_SERVER_URL = "https://<namespace>.reltio.com/ai/tools/mcp/"
ACCESS_TOKEN = "Bearer <ACCESS_TOKEN>"
Replace <namespace>
with your assigned Reltio namespace.Error Handling
- HTTP error response
- Your client implementation must include appropriate error handling logic to catch and report failed requests.
Result
Your custom MCP client can now send requests to the MCP AgentFlow server and handle responses.
Best practices
- Always tokenize sensitive context values before logging.
- Implement circuit breakers or retries for long-running tools.
- Use activity logging to trace tool execution with timestamps and trace IDs.
- Store access tokens securely and reuse until expiration. Refresh tokens are not supported.
Use streamable HTTP using Anthropic python SDK for MCP
from typing import Optional
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
class MCPClient:
def __init__(self):
self.session: Optional[ClientSession] = None
async def connect_to_streamable_http_server(self, server_url: str, headers: Optional[dict] = None) -> None:
self._streams_context = streamablehttp_client(url=server_url, headers=headers or {})
read_stream, write_stream, _ = await self._streams_context.__aenter__()
self._session_context = ClientSession(read_stream, write_stream)
self.session = await self._session_context.__aenter__()
await self.session.initialize()
response = await self.session.list_tools()
tool_names = [tool.name for tool in response.tools]
print("Initialized Streamable HTTP client...")
print("Connected tools:", tool_names)
For more information, see python-sdk.