Overview
Integrate Civic Nexus with OpenAI Agents SDK using thehostedMcpTool()
approach. This is the simplest way to use Nexus with OpenAI - no manual tool looping or conversion code required.
Updated for OpenAI Agents SDK: This guide uses the new hosted MCP tool feature. For the older function calling approach, see OpenAI SDK (Node.js).
Prerequisites
Prerequisites:
- Node.js 18+ project (Next.js 14+ or any Node.js framework)
- Civic account - Create account
- Connect services at nexus.civic.com (GitHub, Slack, etc.)
- OpenAI API Key - Get yours at platform.openai.com
- Complete Civic Auth setup (see Access Token Setup below)
Access Token Setup (Next.js + Civic Auth)
Why Civic Auth? Nexus needs to identify which user is accessing tools and authorize their permissions. Civic Auth provides the secure access token. (Support for additional identity providers coming soon.)- 1. next.config.ts
- 2. API Route
- 3. Middleware
- 4. Get Token
Full Integration Guide
Complete Next.js setup with frontend components, configuration options, and deployment details
AI Prompt for Next.js
Use Claude, ChatGPT, or other AI assistants to automatically set up Civic Auth
Get your Client ID at auth.civic.com
Environment Variables
Create a.env.local
file in your project root:
Getting your Civic Client ID:
- Visit auth.civic.com
- Create a new application or use an existing one
- Copy the Client ID from your application settings
Installation
Install the required packages:Basic Setup
Step 1: Create Agent with Hosted MCP Tool
Step 2: Run the Agent
- Discovers available tools from Nexus
- Selects the appropriate tool to use
- Calls the tool with the right parameters
- Returns the result to you
Complete Example: Next.js API Route
Streaming Responses
For real-time streaming:Tool Approval
Control which tools require approval before execution. Configure this in the hostedMcpTool:Key Advantages
Simplest Setup
Minimal code - just hostedMcpTool() configuration
Automatic Tools
Agent discovers and calls tools automatically
Remote Execution
Tools run through OpenAI’s Responses API
Built-in Streaming
Easy streaming support with stream: true option
Nexus Authentication
Required Authorization
Required Authorization
Getting the Access Token
Getting the Access Token
Nexus Endpoint
Nexus Endpoint
Comparison with Other Approaches
Feature | OpenAI Agents SDK (hostedMcpTool) | OpenAI SDK (function calling) | Vercel AI SDK |
---|---|---|---|
Setup Complexity | Low | Medium | Medium |
Tool Looping | No (automatic) | Yes (manual) | Yes (manual) |
Tool Conversion | No | Yes | Yes |
Best For | Quick prototypes | Full control | Next.js apps |
Streaming | Yes | Yes | Yes |
Next Steps
1
Test with Simple Queries
Try “list my GitHub repos” or “search Slack messages about X”
2
Connect More Services
Visit nexus.civic.com to connect additional tools
3
Add Streaming
Implement real-time responses with the stream option
4
Deploy
Deploy your agent to production