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
- Civic account at app.civic.com with at least one MCP server connected
- OpenAI API key from platform.openai.com
Installation
Authentication
- Backend / Script (Civic Token)
- Next.js App (Civic Auth)
Generate a Civic Token
- Log in to app.civic.com
- Click your account name in the bottom left
- Go to Install → MCP URL
- Click Generate Token and copy it immediately — it won’t be shown again
Set Environment Variables
profile parameter:Use the Token
Pass the token as a Bearer token in theAuthorization 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

