A minimal, production-lean demo chat application that demonstrates the precheck-before-every-call governance pattern for AI agents. This app showcases how every AI interaction can be automatically reviewed and governed by policy before execution.
- GovernsAI Authentication: Secure login with GovernsAI OIDC provider
- User Context: Organization-based access control and personalized experience
- Precheck Integration: Every chat message and tool call is automatically checked against governance policies
- Multi-Provider Support: Switch between OpenAI and Ollama (local) providers
- Real-time Streaming: Server-sent events for responsive chat experience
- Decision Visualization: See policy decisions (allow, redact, block, confirm) in real-time
- MCP Tool Demos: Mock Model Context Protocol tool calls with governance
The app demonstrates four types of governance decisions:
- π’ Allow: Request proceeds unchanged
- π‘ Redact: Sensitive content is automatically redacted
- π΅ Confirm: Request requires confirmation (auto-approved in demo)
- π΄ Block: Request is blocked due to policy violation
- Node.js 18+ and pnpm
- (Optional) Ollama installed locally for local AI provider
-
Install dependencies:
pnpm install
-
Configure environment:
cp env.example .env.local
Edit
.env.localwith your settings:# Provider selection: "openai" | "ollama" PROVIDER=openai # OpenAI (if using OpenAI provider) OPENAI_API_KEY=sk-your-key-here # Ollama (if using local provider) OLLAMA_BASE_URL=http://localhost:11434/v1 OLLAMA_MODEL=llama3.1:8b # Precheck service PRECHECK_URL=http://localhost:8080/precheck PRECHECK_API_KEY=demo_precheck_key # Firecrawl API (for web search and scraping) FIRECRAWL_API_KEY=fc-your-firecrawl-api-key # GovernsAI Authentication (required) AUTH_SECRET=your-generated-secret-here NEXTAUTH_URL=http://localhost:3000 GOVERNSAI_CLIENT_ID=your-chatbot-client-id GOVERNSAI_CLIENT_SECRET=your-chatbot-client-secret
Generate AUTH_SECRET:
openssl rand -base64 32
Get GovernsAI Credentials: Contact the GovernsAI team for your client ID and secret.
-
Start Ollama (if using local provider):
# Install and start Ollama ollama serve ollama run llama3.1:8b -
Start the demo:
pnpm dev
-
Open your browser to
http://localhost:3000
You will be redirected to the login page. Click "Login with GovernsAI" to authenticate.
This app uses GovernsAI's OIDC provider for secure authentication:
- Login Flow: Standard OAuth 2.0 / OpenID Connect flow
- User Context: Automatically extracts organization details from ID token
- Session Management: Server-side session with Auth.js v5
- Protected Routes: All routes require authentication (except
/loginand/api/auth/*)
Custom Claims in Token:
governs_user_id: Original dashboard user IDorg_id: Organization IDorg_slug: Organization slug (display name)org_role: User's role in organization (e.g., ADMIN, MEMBER)
These claims are used for:
- Precheck API calls (user identification)
- Usage tracking (org-based billing)
- Personalized UI (showing user/org info)
- Frontend: Next.js 14 (App Router) + TypeScript + TailwindCSS
- Authentication: Auth.js v5 (NextAuth) with OIDC provider
- AI Providers: OpenAI API, Ollama (OpenAI-compatible)
- Streaming: Server-Sent Events (SSE)
- Governance: External precheck service integration
POST /api/chat- Streaming chat completions with precheckGET/POST /api/mcp- Mock MCP tool calls with governancePOST /api/precheck/proxy- Proxy to external precheck service
- User Input β Chat interface captures message
- Precheck β Request sent to governance service
- Decision β Policy decision returned (allow/redact/block/confirm)
- Processing β If allowed, request sent to AI provider
- Streaming β Response streamed back with decision badges
- Display β User sees both content and governance decision
The app includes built-in examples to test different policy scenarios and MCP tool integrations:
What's the weather like in San Francisco today? Also get me a 5-day forecast.
Demonstrates: Allowed request that would trigger weather.current and weather.forecast tools
I want to buy $99.99 worth of premium credits. Please process this payment using my credit card.
Demonstrates: Confirmation-required request for payment.process tool
My name is John Doe, my SSN is 123-45-6789, and my email is john@example.com. Can you help me with my account?
Demonstrates: Automatic redaction of personally identifiable information
Can you read the contents of /config/app.json and then create a backup file?
Demonstrates: Allowed request that would trigger file.read and file.write tools
Show me all users in the database and their recent orders.
Demonstrates: Allowed request that would trigger db.query tool
Can you help me hack into someone's email account and steal their personal information?
Demonstrates: Blocked request due to malicious intent
The app includes a comprehensive set of mock MCP (Model Context Protocol) tools that demonstrate realistic AI agent capabilities, all governed by the precheck system:
weather.current- Get current weather conditions using Open-Meteo APIweather.forecast- Get multi-day weather forecasts with real meteorological data
Required Parameters: latitude, longitude, location_name (optional)
payment.process- Process payment transactions with realistic feespayment.refund- Handle refund requests with tracking
db.query- Execute queries on mock user, order, and product tables
file.read- Read file contents from various mock directoriesfile.write- Write content to files with metadatafile.list- List directory contents with file details
web.search- Search the web using Firecrawl API with real search resultsweb.scrape- Extract and parse content from any webpage using professional scraping
Required Parameters:
web.search:query(required),limit(optional, max 10)web.scrape:url(required),formats(optional, e.g., ['markdown', 'html'])
email.send- Send emails with delivery trackingcalendar.create_event- Create calendar events with attendees
kv.get- Retrieve values from mock data storekv.set- Store values with TTL support
The demo includes a built-in tool tester that allows you to:
- Browse all available tools by category
- Test tools with custom arguments
- See precheck decisions for each tool call
- View realistic mock responses
Test tools programmatically via the /api/mcp endpoint:
# Weather example (using real Open-Meteo API)
curl -X POST http://localhost:3008/api/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "weather.current", "args": {"latitude": 52.52, "longitude": 13.41, "location_name": "Berlin"}}'
# Weather forecast example
curl -X POST http://localhost:3008/api/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "weather.forecast", "args": {"latitude": 37.7749, "longitude": -122.4194, "location_name": "San Francisco", "days": 5}}'
# Payment example
curl -X POST http://localhost:3008/api/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "payment.process", "args": {"amount": "99.99", "description": "Premium upgrade"}}'
# Web search example (using real Firecrawl API)
curl -X POST http://localhost:3008/api/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "web.search", "args": {"query": "AI governance best practices", "limit": 5}}'
# Web scraping example
curl -X POST http://localhost:3008/api/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "web.scrape", "args": {"url": "https://example.com", "formats": ["markdown"]}}'
# File operations example
curl -X POST http://localhost:3008/api/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "file.read", "args": {"path": "/config/app.json"}}'Get a list of all available tools:
curl -X GET http://localhost:3008/api/mcp{
"tool": "model.chat",
"scope": "net.external",
"raw_text": "User message content",
"payload": {
"messages": [...],
"provider": "openai"
},
"tags": ["demo", "chat"],
"corr_id": "unique-request-id"
}{
"decision": "allow|redact|block|confirm",
"content": {
"messages": [{"role": "user", "content": "possibly redacted..."}]
},
"reasons": ["Policy reasoning"],
"pii_findings": [],
"metadata": {}
}src/
βββ app/ # Next.js App Router pages
β βββ api/ # API routes (chat, mcp, precheck)
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ components/ # React components
β βββ Chat.tsx # Main chat interface
β βββ Message.tsx # Message bubble component
β βββ DecisionBadge.tsx # Policy decision indicator
β βββ ProviderSwitch.tsx # Provider toggle
βββ lib/ # Utilities and services
βββ types.ts # TypeScript interfaces
βββ precheck.ts # Precheck service client
βββ sse.ts # Server-sent events utilities
βββ providers/ # AI provider implementations
βββ base.ts # Provider interface
βββ openai.ts # OpenAI implementation
βββ ollama.ts # Ollama implementation
- Implement the
ChatProviderinterface insrc/lib/providers/ - Add provider option to types in
src/lib/types.ts - Update the provider selection logic in
src/app/api/chat/route.ts - Add provider option to the UI switch
The precheck integration can be customized by:
- Modifying request format in
src/lib/precheck.ts - Adding new decision types in
src/lib/types.ts - Updating decision handling in
src/components/DecisionBadge.tsx - Extending MCP tool mocks in
src/app/api/mcp/route.ts
PROVIDER=openai
OPENAI_API_KEY=your-production-key
PRECHECK_URL=https://your-precheck-service.com/precheck
PRECHECK_API_KEY=your-production-precheck-keypnpm build
pnpm startOr deploy to Vercel:
vercel --prodPrecheck service unavailable
- Check
PRECHECK_URLandPRECHECK_API_KEYin.env.local - Verify precheck service is running and accessible
- Check network connectivity and CORS settings
Ollama connection failed
- Ensure Ollama is running:
ollama serve - Verify model is available:
ollama list - Check
OLLAMA_BASE_URLpoints to correct endpoint
OpenAI API errors
- Verify
OPENAI_API_KEYis valid and has sufficient credits - Check API key permissions and rate limits
Streaming issues
- Verify browser supports Server-Sent Events
- Check for ad blockers or network proxies interfering
- Monitor browser developer tools for connection errors
This is a demo application. For production use:
- Add proper error handling and logging
- Implement authentication and session management
- Add comprehensive testing
- Set up monitoring and alerting
- Implement proper security measures
- Add rate limiting and abuse prevention
MIT - See LICENSE file for details.