Skip to main content

Agent over MCP

This recipe runs a small agent: the tauric model chooses Tauric MCP tools, your code calls them, and the model answers from what they return. It uses the MCP server and model inference with the OpenAI SDK. Install the packages as on Python examples.

python
import asyncio
import json
import os

import httpx
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client
from openai import AsyncOpenAI

KEY = os.environ["TAURIC_API_KEY"]
TOOLS = {"get_security_financials", "list_securities_financials"}
QUESTION = ("Compare Apple's and Microsoft's revenue and net income for each company's last two fiscal years. "
"Cite the filing accession behind each value.")


async def main():
model = AsyncOpenAI(api_key=KEY, base_url="https://api.tauric.ai/v1")
async with httpx.AsyncClient(headers={"Authorization": f"Bearer {KEY}"}, timeout=120) as http:
async with streamable_http_client("https://mcp.tauric.ai/mcp", http_client=http) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = [{"type": "function", "function": {"name": tool.name, "description": tool.description,
"parameters": tool.input_schema}}
for tool in (await session.list_tools()).tools if tool.name in TOOLS]
messages = [{"role": "user", "content": QUESTION}]
while True:
reply = await model.chat.completions.create(model="tauric", messages=messages, tools=tools)
message = reply.choices[0].message
messages.append(message.model_dump(exclude_none=True))
if not message.tool_calls:
print(message.content)
return
for tool_call in message.tool_calls:
arguments = json.loads(tool_call.function.arguments)
print("tool:", tool_call.function.name, arguments)
result = await session.call_tool(tool_call.function.name, arguments)
messages.append({"role": "tool", "tool_call_id": tool_call.id,
"content": json.dumps(result.structured_content)})


asyncio.run(main())

The MCP server lists each tool with its description and input schema; the script offers the model only the tools the question needs, as function tools. Each turn, the model either calls tools or answers, and a tool's structured result goes back to it as JSON.

The answer is model output. Check its figures against the tool results, which are the tool messages in messages.