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

  1. Install the packages: pip install llama-index llama-index-tools-mcp llama-index-llms-openai-like.
  2. Set ORCAROUTER_API_KEY to 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 through npx.
  3. Turn the server's tools into a tool list and give it to your agent.

Code

A FunctionAgent with the OrcaRouter MCP server
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

© 2026 OrcaRouter

For Providers

Run an inference platform? Get your models on OrcaRouter.

providers@orcarouter.ai

Join our community

Discordsupport@orcarouter.aiXLinkedInGitHubYouTube