Agent framework
OrcaRouter tools in LlamaIndex
Load the OrcaRouter MCP server's tools with McpToolSpec and use them in a LlamaIndex FunctionAgent.
Details
- Kind
- Agent framework
- Connects through
- MCP server
Set it up
- Install the packages:
pip install llama-index llama-index-tools-mcp llama-index-llms-openai-like. - Set
ORCAROUTER_API_KEYto an API key from your OrcaRouter console. It pays for the agent's model, reached through OrcaRouter's OpenAI-compatible API, and for the tools; Node.js 18 or later runs the MCP server throughnpx. - Turn the server's tools into a tool list and give it to your agent.
Code
import asyncio
import os
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai_like import OpenAILike
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec
async def main():
client = BasicMCPClient(
"npx",
args=["-y", "@orcarouter/mcp"],
env={"ORCAROUTER_API_KEY": os.environ["ORCAROUTER_API_KEY"]},
)
tools = await McpToolSpec(client=client).to_tool_list_async()
# The agent's model, through OrcaRouter's OpenAI-compatible API, on the same key.
llm = OpenAILike(
model="openai/gpt-5-mini",
api_base="https://api.orcarouter.ai/v1",
api_key=os.environ["ORCAROUTER_API_KEY"],
context_window=128000,
is_chat_model=True,
is_function_calling_model=True,
)
agent = FunctionAgent(
tools=tools,
llm=llm,
system_prompt="Find a tool in the OrcaRouter catalog for each question, then run it.",
)
print(await agent.run("How many followers does @nasa have on TikTok?"))
asyncio.run(main())Recipes to try with LlamaIndex
- Track competitor TikTok accountsPull each competitor's TikTok profile, find its latest videos and read what viewers say, in three tool calls an agent can repeat every week.
- Monitor brand mentions on the web and TikTokSearch the web and TikTok for your brand, then read the comments under the posts that mention it: a daily brand check an agent can run on its own.
- Enrich a lead listTurn a list of company domains into firmographics, a contact's work email and a recent news hook, with one API key.
Other integrations
- LangChainLoad OrcaRouter tools as LangChain tools from the functions export and give them to any LangChain agent; each call runs the tool through OrcaRouter.
- CrewAIGive a CrewAI agent the OrcaRouter tool catalog through MCPServerAdapter, so it can find and run tools while it works on a task.
- OpenAI Agents SDKWrap each OrcaRouter tool in a FunctionTool with its own JSON schema and run it from an Agents SDK agent, with the model served through OrcaRouter too.
