Skip to main content
Connect your coding agent to CostGraph with the Model Context Protocol (MCP). Your agent can investigate costs, compare infrastructure prices, and read recommendations using data from your selected tenant. The following diagram shows the connection between your agent and tenant data.
An agent connects to CostGraph MCP through browser sign-in or an API key, then reads its authorized tenant's connected cost and resource data.

Prerequisites

  • A CostGraph account with an active billing plan.
  • Access to the tenant you want to query.
  • An MCP client that supports remote HTTP servers.
For a headless client, create a key in API Keys. Use an API key for queries. Install tokens are credentials for installing CostGraph collectors and cannot authorize these queries.

Connect your agent through OAuth or API key

Choose your client. Use browser sign-in for an interactive session or the API key alternative for a headless session. Replace example keys with your own credential and keep them out of shared configuration files.
Add CostGraph to ~/.codex/config.toml.The following image shows the server entry. Copy the configuration from the code block into your file.
Codex configuration example with the costgraph MCP server URL set to https://mcp.costgraph.ai/.
Start browser authorization.
For an API key, use this configuration instead. Set COSTGRAPH_API_KEY in the environment where you run Codex.

Authorize a tenant

During browser sign-in, select the CostGraph tenant you want the agent to use and approve the requested access. Return to your client and confirm that CostGraph appears in its connected MCP servers. A tenant is the CostGraph workspace containing your connected data. A provider’s account or project can appear within that data as a sub-account. Refer to Sub-accounts and tenants for the distinction. API key connections use the access granted to that key. They do not require a browser approval step.

Verify the connection

Check the connection with a read request before asking the agent to make changes.
1

Check the connected server

Open your client’s MCP server list and confirm that CostGraph is connected. If the client reports an authentication error, repeat its sign-in flow or check the API key configuration.
2

Read your cost data

Ask the agent to read the Context map for your authorized tenant.
3

Check the result

Confirm that the agent calls CostGraph tools. The result includes the groups found in your connected data and their costs for the requested window.If the map is empty, check the tenant and connected data sources. Connecting through MCP does not import data. An authentication or billing error means the query did not succeed.
For more tasks, follow Use CostGraph from your agent.

Access and changes

CostGraph scopes queries to the tenant authorized by your connection. Available actions also depend on your credentials and role. An authorized agent can also start or continue a workflow. Open the returned run link to review its plan, approval requests, and outcome. If your connection is read-only, CostGraph returns a link to the relevant dashboard page instead of starting the workflow. Refer to Start workflows from MCP.

Troubleshoot the connection

Check the client status before changing its configuration.
Confirm the server URL is https://mcp.costgraph.ai/. Repeat the client’s OAuth sign-in, or check that its X-API-Key header contains an active personal API key. An install token cannot authenticate a query.
Check your organization’s plan in Billing settings, then retry the request.
Check the selected tenant, date range, and connected data sources. A successful connection does not import infrastructure or billing data by itself.

Revoke access

Revoke an OAuth connection in Connected apps. Deactivate or rotate an API key in API Keys.