Prerequisites
Make sure you have Python 3.11+ and the fastmcp library installed.- Python 3.11+
- fastmcp client library
pip install fastmcp
Set Your Adgentic API Key
# macOS/Linux
export ADGENTIC_API_KEY=<YOUR_KEY>
# Windows
set ADGENTIC_API_KEY=<YOUR_KEY>
If your MCP server is deployed with ADGENTIC_API_KEY in its environment, you can omit api_key in the call.
Run the Sample Script
Python
import asyncio
import json
import os
from fastmcp import Client
MCP_URL = "https://mcp.adgenticplatform.com/mcp/"
API_KEY = "ADGENTIC_API_KEY"
#If it set as an environment variable:
API_KEY = os.environ.get("ADGENTIC_API_KEY")
async def quickstart():
async with Client(MCP_URL) as client:
# List available tools on the MCP server
tools = await client.list_tools()
print("Available tools:", [t.name for t in tools])
# --- Non-shopping example ---
print("\n--- Non-shopping test ---")
response1 = await client.call_tool(
"match_adgentic_products",
{
"prompt": "Write me a poem about summer",
"api_key": API_KEY,
"context": {"country": "US"},
},
)
# Convert the tool's response object into plain text
result1 = (getattr(response1, "text", None)
or (response1.content[0].text if getattr(response1, "content", None) else None)
or str(response1))
# Display it in a clean, readable JSON format
print(json.dumps(json.loads(result1), indent=2))
# --- Shopping example ---
print("\n--- Shopping test ---")
response2 = await client.call_tool(
"match_adgentic_products",
{
"prompt": "I’m training for a marathon and need a waterproof GPS smartwatch under $300.",
"api_key": API_KEY,
"context": {"country": "US"},
},
)
result2 = (getattr(response2, "text", None)
or (response2.content[0].text if getattr(response2, "content", None) else None)
or str(response2))
print(json.dumps(json.loads(result2), indent=2))
if __name__ == "__main__":
asyncio.run(quickstart())
It is recommended to run this script using uv run for consistent dependency management and environment isolation.
Error Handling
| Error | Cause / Fix |
|---|---|
| 401 Unauthorized | Missing or invalid ADGENTIC_API_KEY. Set env var correctly or pass api_key in the tool call. |
| 400 Bad Request | Malformed request (e.g. missing prompt or invalid context). Ensure payload contains prompt and valid JSON. |
| 500 Server Error | Temporary issue on the Adgentic MCP server. Retry; if persists, contact support: support@adgenticplatform.com |
| Timeouts & Connection Errors | Network instability or unreachable server. Verify connectivity and endpoint: https://mcp.adgenticplatform.com/mcp/ |