Skip to main content

Overview

This recipe shows how to wire Civic MCP tools to the OpenAI Node SDK using manual function calling.
Want a simpler approach? The OpenAI Agents SDK recipe uses hostedMcpTool() — no manual tool looping required. Use this page if you need full control over the tool loop.

Prerequisites

Installation

Authentication

Generate a Civic Token

  1. Log in to app.civic.com
  2. Click your account name in the bottom left
  3. Go to Install → MCP URL
  4. Click Generate Token and copy it immediately — it won’t be shown again
Never commit your token to source control. Store it in environment variables or a secrets manager. Tokens expire after 30 days.

Set Environment Variables

For production agents, lock to a specific toolkit by appending a profile parameter:

Use the Token

Pass the token as a Bearer token in the Authorization header:

Full credentials guide

Token generation, URL parameters, OAuth vs token comparison

Create an MCP Client

Call with Tool Functions

This example handles a single round of tool calling. Real agent loops need to iterate until the model stops requesting tools — see the multi-turn loop below.

Usage

OpenAI Agents SDK

Simpler approach — hostedMcpTool() handles the loop for you

Get Help

Developer Slack