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

# Codex & OpenAI Agents SDK

> Connect XentFi agent tools to the Codex CLI or the OpenAI Agents SDK.

## Codex CLI

Codex CLI (`codex`) reads MCP server definitions from `~/.codex/config.toml` (or a project-level config, depending on version).

```toml theme={null}
[mcp_servers.xentfi]
command = "npx"
args = ["-y", "@xentfi/mcp-server"]

[mcp_servers.xentfi.env]
XENTFI_AGENT_KEY = "sk_agent_xxx"
```

Run `codex` and ask it to use the tools directly:

> "Use the xentfi tools to show my agent's wallet balances and current spend policy."

Verify the server loaded with whatever `--mcp` / server-listing flag your installed Codex CLI version provides (`codex --help`), or watch stderr on first run for `[xentfi-mcp] MCP server ready over stdio`.

## OpenAI Agents SDK

The Agents SDK has first-class MCP support via `MCPServerStdio`.

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  import os
  from agents import Agent, Runner
  from agents.mcp import MCPServerStdio

  async def main():
      async with MCPServerStdio(
          params={
              "command": "npx",
              "args": ["-y", "@xentfi/mcp-server"],
              "env": {
                  **os.environ,
                  "XENTFI_AGENT_KEY": os.environ["XENTFI_AGENT_KEY"],

              },
          }
      ) as xentfi_server:
          agent = Agent(
              name="Treasury Agent",
              instructions="You manage XentFi agent wallets. Always call xentfi_get_policy before large payments.",
              mcp_servers=[xentfi_server],
          )
          result = await Runner.run(agent, "What wallets do I have and what are their balances?")
          print(result.final_output)

  asyncio.run(main())
  ```

  ```ts TypeScript theme={null}
  import { Agent, run, MCPServerStdio } from "@openai/agents";

  const xentfiServer = new MCPServerStdio({
    name: "xentfi",
    fullCommand: `npx -y @xentfi/mcp-server`,
    env: {
      XENTFI_AGENT_KEY: process.env.XENTFI_AGENT_KEY!,

    },
  });
  await xentfiServer.connect();

  const agent = new Agent({
    name: "Treasury Agent",
    instructions: "You manage XentFi agent wallets. Always check xentfi_get_policy before large payments.",
    mcpServers: [xentfiServer],
  });

  const result = await run(agent, "List my XentFi wallets and their balances.");
  console.log(result.finalOutput);
  await xentfiServer.close();
  ```
</CodeGroup>

<Note>
  Both SDKs cache the tool list from an MCP server at connect time by default — if you rotate the XentFi API key, restart/reconnect the server.
</Note>

<Tip>
  For production agentic-payment workflows, combine the Agents SDK's built-in tool-use approval/guardrails hooks with `xentfi_create_payment`'s `confirm: true` requirement, so a human (or a separate policy-checking function) is in the loop before funds move — on top of XentFi's own server-side Policy enforcement.
</Tip>

## Next steps

<CardGroup cols={2}>
  <Card title="Tools Reference" icon="list" href="/agent/tools-reference">
    See every available tool.
  </Card>

  <Card title="Generic MCP Client" icon="puzzle" href="/agent/generic-client">
    If your runtime isn't covered here.
  </Card>
</CardGroup>
