# LlamaIndex

Load the OrcaRouter MCP server's tools with McpToolSpec and use them in a LlamaIndex FunctionAgent.

|  |  |
| --- | --- |
| Kind | framework |
| Connects through | mcp |
| Docs | <https://docs.llamaindex.ai/en/stable/api_reference/tools/mcp/> |

## Install

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

```python
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

- [Track competitor TikTok accounts](https://www.orcarouter.ai/tools/recipes/track-competitor-tiktok-accounts.md): Pull 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 TikTok](https://www.orcarouter.ai/tools/recipes/monitor-brand-mentions.md): Search 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 list](https://www.orcarouter.ai/tools/recipes/enrich-a-lead-list.md): Turn a list of company domains into firmographics, a contact's work email and a recent news hook, with one API key.

## Related integrations

- [LangChain](https://www.orcarouter.ai/tools/integrations/langchain.md): Load OrcaRouter tools as LangChain tools from the functions export and give them to any LangChain agent; each call runs the tool through OrcaRouter.
- [CrewAI](https://www.orcarouter.ai/tools/integrations/crewai.md): Give a CrewAI agent the OrcaRouter tool catalog through MCPServerAdapter, so it can find and run tools while it works on a task.
- [OpenAI Agents SDK](https://www.orcarouter.ai/tools/integrations/openai-agents-sdk.md): Wrap 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.

---

Markdown version of https://www.orcarouter.ai/tools/integrations/llamaindex
