# Copilot CLI

Copilot CLI connects to the hosted [Costfluent MCP server](/developers/mcp) at `https://mcp.costfluent.com` with an API token in a header, from an entry in its `mcp-config.json`. To run the server on your machine instead, `costfluent mcp install` adds an entry that starts it, reading the token from `COSTFLUENT_API_TOKEN` rather than writing it into the file. The Costfluent plugin of [costfluent/agent-skills](https://github.com/costfluent/agent-skills) adds the cost skills.

## Before you start

- An API token from the **Read only** preset, with write capabilities only if Copilot CLI may change objects; see [Create a token](/developers/mcp#create-a-token).
- To run the server on your machine, `costfluent-mcp` and the [command line](/developers/cli#install), `costfluent`, on your `PATH`; both come in the same [release archive](/developers/mcp#install-the-server).

## Connect with an API token

<Stepper>

1. Add the server to `~/.copilot/mcp-config.json`, or to `mcp-config.json` in `COPILOT_HOME` when that is set. The entry reads the token from `COSTFLUENT_API_TOKEN`, so the file holds no token; if `costfluent mcp install` wrote a `costfluent` entry there before, replace it:

   ```json
   {
     "mcpServers": {
       "costfluent": {
         "type": "http",
         "url": "https://mcp.costfluent.com",
         "headers": { "Authorization": "Bearer ${COSTFLUENT_API_TOKEN}" },
         "tools": ["*"]
       }
     }
   }
   ```

2. Set `COSTFLUENT_API_TOKEN` to the token in your shell, and start Copilot CLI from that shell.
3. Ask a question, such as "What did we spend on AWS last month, by service?".

</Stepper>

Instead of step 1, `/mcp add` in Copilot CLI opens a form: choose the **HTTP** server type, enter the URL and, under **HTTP Headers**, the `Authorization` header, and press Ctrl+S to save.

## Run it on your machine

<Stepper>

1. Run `copilot plugin marketplace add costfluent/agent-skills`, then `copilot plugin install costfluent@costfluent`.
2. Run `costfluent mcp install --client copilot --write`. It adds the server to `~/.copilot/mcp-config.json`, or to `mcp-config.json` in `COPILOT_HOME` when that is set.
3. Set `COSTFLUENT_API_TOKEN` to the token in your shell, start Copilot CLI from that shell and ask a question, such as "What did we spend on AWS last month, by service?".

</Stepper>

## How it behaves

- VS Code's agent sessions read the same `mcp-config.json`, so the entry reaches them too.
- The client is `copilot`: `costfluent mcp install` has no `copilot-cli`.
- The entry lets Copilot CLI call every tool the server offers, and the server offers only those the token's capabilities allow.

## Related

- [MCP server](/developers/mcp): the token, the tools and how the server behaves
- [Command line](/developers/cli#connect-an-assistant): every client `costfluent mcp install` writes for
- [Ask good questions](/developers/mcp#ask-good-questions) and [Troubleshooting](/developers/mcp#troubleshooting): asking for the right figures, and what each error means
