> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mcp-use.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LLM providers

> Configure MCPAgent for OpenAI, Anthropic, Google, OpenRouter, Ollama, or an OpenAI-compatible endpoint.

`MCPAgent` supports OpenAI, Anthropic, Google, OpenRouter, Ollama, and OpenAI-compatible endpoints. Configure a provider with a `"provider/model"` string or a `ProviderConfig`.

## Choose a provider

| Provider prefix     | API key lookup                                     | Configuration note                                    |
| ------------------- | -------------------------------------------------- | ----------------------------------------------------- |
| `openai`            | `OPENAI_API_KEY`                                   | Uses the built-in OpenAI provider.                    |
| `anthropic`         | `ANTHROPIC_API_KEY`                                | Uses the built-in Anthropic provider.                 |
| `google`            | `GOOGLE_API_KEY` or `GOOGLE_GENERATIVE_AI_API_KEY` | Uses the built-in Google provider.                    |
| `openrouter`        | `OPENROUTER_API_KEY`                               | Model names may contain `/`, such as `openai/gpt-4o`. |
| `ollama`            | No key required                                    | Defaults to `http://localhost:11434`.                 |
| `openai-compatible` | `OPENAI_API_KEY` or `llmConfig.apiKey`             | Requires the endpoint in `llmConfig.baseUrl`.         |

## Configure a provider string

Set the provider's environment variable before starting the process. The agent resolves the key when it initializes.

```typescript theme={null}
import { MCPAgent } from "@mcp-use/agent";

async function main() {
  const agent = new MCPAgent({
    llm: "anthropic/claude-sonnet-4-6",
    llmConfig: {
      temperature: 0.2,
      maxTokens: 1_000,
    },
    mcpServers: {
      filesystem: {
        command: "npx",
        args: ["-y", "@modelcontextprotocol/server-filesystem", "./"],
      },
    },
  });

  try {
    await agent.initialize();
    const result = await agent.run({
      prompt: "Read package.json and list the available scripts.",
    });
    console.log(result);
  } finally {
    await agent.close();
  }
}

main().catch(console.error);
```

A successful run prints scripts found through the filesystem MCP server.

The string parser accepts model names that contain `/`. For example, `openrouter/openai/gpt-4o` selects the `openrouter` provider and passes `openai/gpt-4o` as the model name.

## Connect an OpenAI-compatible endpoint

Use `openai-compatible` for an endpoint that implements OpenAI chat-completions semantics. Supply the full API base URL and any required headers.

```typescript theme={null}
import { MCPAgent, type ProviderConfig } from "@mcp-use/agent";

const provider: ProviderConfig = {
  provider: "openai-compatible",
  model: "my-tool-calling-model",
  apiKey: process.env.COMPATIBLE_API_KEY ?? "local",
  baseUrl: "http://localhost:8000/v1",
  extraHeaders: {
    "X-Workspace": "docs-example",
  },
};

const agent = new MCPAgent({ llm: provider, mcpServers });

try {
  await agent.initialize();
  const result = await agent.run({
    prompt: "Call one available tool and report its result.",
  });
  console.log(result);
} finally {
  await agent.close();
}
```

Verify that the selected model supports tool calling. A reachable text-only model cannot use MCP tools.

## Handle configuration errors

Initialization throws when:

* a provider string is not in `provider/model` form;
* the provider prefix is unsupported;
* a required API key is missing; or
* no model driver can be created.

Keep provider-specific tuning in `llmConfig` or `ProviderConfig`. See the [MCPAgent API reference](https://mcp-use-typescript-api-reference.vercel.app/modules/_mcp-use_agent.index.html#mcpagent) for the complete option types.

## Next steps

* [Build an MCP agent](/v2/typescript/agent/index)
* [Stream agent output](/v2/typescript/agent/streaming)
