ccowan190/terraform-mcp-server-oauth2
If you are the rightful owner of terraform-mcp-server-oauth2 and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A HashiCorp Terraform MCP server with OAuth2 authentication for Claude.ai integration.
Terraform MCP Server with OAuth2 Authentication
A HashiCorp Terraform MCP (Model Context Protocol) server enhanced with OAuth2 authentication support for seamless Claude.ai integration.
๐ Features
- OAuth2 Authentication: Google OAuth2 integration for Claude.ai
- Dual Authentication: OAuth2 with Cloud Run IAM fallback
- HundredX Integration: Domain validation for @hundredxinc.com accounts
- Claude.ai Ready: Direct integration with Claude.ai remote MCP servers
- Secure: Session token management with expiration
- Monitoring: Health and authentication status endpoints
๐๏ธ Architecture
Claude.ai โ OAuth2 Flow โ Terraform MCP Server โ Terraform Registry
โ
Google Authentication
โ
HundredX Domain Validation
๐ฆ Installation
Prerequisites
- Docker
- Google Cloud SDK (
gcloud
) - Google Cloud project with OAuth2 credentials
Quick Start
-
Clone the repository:
git clone https://github.com/ccowan190/terraform-mcp-server-oauth2.git cd terraform-mcp-server-oauth2
-
Set up OAuth2 credentials:
./create-oauth2-credentials.sh
-
Configure environment variables:
export OAUTH2_CLIENT_ID="your-google-client-id" export OAUTH2_CLIENT_SECRET="your-google-client-secret"
-
Deploy to Google Cloud Run:
./deploy-oauth2.sh
๐ง Configuration
Environment Variables
Variable | Description | Required |
---|---|---|
OAUTH2_CLIENT_ID | Google OAuth2 Client ID | Optional* |
OAUTH2_CLIENT_SECRET | Google OAuth2 Client Secret | Optional* |
OAUTH2_REDIRECT_URL | OAuth2 callback URL | Optional |
MODE | Server mode (http or stdio ) | No |
TRANSPORT_PORT | HTTP server port | No |
*If not provided, server falls back to Cloud Run IAM authentication
OAuth2 Setup
-
Create OAuth2 Credentials in Google Cloud Console:
- Application type: Web application
- Name: Terraform MCP Server for Claude.ai
- Authorized origins:
https://claude.ai
,https://api.anthropic.com
- Redirect URIs:
https://claude.ai/oauth/callback
,https://api.anthropic.com/oauth/callback
-
Configure OAuth Consent Screen:
- User Type: Internal (for organization use)
- App name: Terraform MCP Server
- Scopes: email, profile, openid
๐ API Endpoints
Health Check
GET /health
Response:
{
"status": "ok",
"service": "terraform-mcp-server",
"transport": "streamable-http",
"auth": "oauth2|iam"
}
Authentication Status
GET /auth/status
Response:
{
"auth_type": "oauth2|iam",
"auth_enabled": true,
"login_url": "/oauth/login"
}
OAuth2 Authentication (when enabled)
GET /oauth/login # Initiates OAuth2 flow
GET /oauth/callback # Handles OAuth2 callback
MCP Protocol
POST /mcp # Terraform MCP operations (requires auth)
๐ Claude.ai Integration
Option 1: OAuth2 Authentication (Recommended)
- Deploy with OAuth2 credentials configured
- In Claude.ai integration settings:
- Service URL:
https://your-service-url/mcp
- OAuth Client ID: Your Google OAuth2 Client ID
- Service URL:
Option 2: Proxy Method (Development)
# Start authenticated proxy
gcloud run services proxy terraform-mcp-server --region=us-central1 --project=your-project --port=8080
# Configure Claude Desktop
# URL: http://localhost:8080/mcp
๐งช Testing
Run the comprehensive test suite:
./test-oauth2.sh
Tests include:
- Health check endpoint
- Authentication status
- MCP endpoint protection
- OAuth2 flow (when enabled)
๐ก๏ธ Security Features
- Domain Validation: Only @hundredxinc.com email addresses allowed
- Token Expiration: Session tokens expire after 1 hour
- HTTPS Only: All OAuth2 flows use secure connections
- IAM Fallback: Cloud Run IAM security when OAuth2 not configured
๐ Project Structure
โโโ cmd/terraform-mcp-server/ # Main server code
โ โโโ main.go # Server entry point with OAuth2 support
โ โโโ init.go # Initialization and configuration
โโโ pkg/oauth2/ # OAuth2 authentication package
โ โโโ oauth2.go # OAuth2 handler implementation
โโโ deploy-oauth2.sh # Deployment script
โโโ test-oauth2.sh # Testing script
โโโ create-oauth2-credentials.sh # OAuth2 setup guide
โโโ README.md # This file
๐ Deployment
Google Cloud Run
# Build and deploy
./deploy-oauth2.sh
# Or manually:
docker build -t gcr.io/your-project/terraform-mcp-server:oauth2 .
docker push gcr.io/your-project/terraform-mcp-server:oauth2
gcloud run deploy terraform-mcp-server \
--image=gcr.io/your-project/terraform-mcp-server:oauth2 \
--set-env-vars="OAUTH2_CLIENT_ID=your-id,OAUTH2_CLIENT_SECRET=your-secret"
Local Development
# Run locally with OAuth2
docker run -p 8080:8080 \
-e MODE=http \
-e OAUTH2_CLIENT_ID=your-id \
-e OAUTH2_CLIENT_SECRET=your-secret \
terraform-mcp-server:oauth2
๐ Authentication Modes
OAuth2 Mode
- Enabled: When
OAUTH2_CLIENT_ID
andOAUTH2_CLIENT_SECRET
are set - Flow: Google OAuth2 โ Domain validation โ Session token
- Claude.ai: Direct integration with OAuth Client ID
IAM Mode (Fallback)
- Enabled: When OAuth2 credentials are not configured
- Flow: Google Cloud IAM authentication
- Claude.ai: Requires proxy or service account
๐ Monitoring
Monitor your deployment:
# Check health
curl https://your-service-url/health
# Check auth status
curl https://your-service-url/auth/status
# View logs
gcloud run services logs read terraform-mcp-server --region=us-central1
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
This project is based on HashiCorp's terraform-mcp-server and includes OAuth2 enhancements.
๐ Support
- Issues: GitHub Issues
- Documentation: See
/docs
folder for detailed guides - Contact: File an issue or reach out via GitHub
๐ฏ Roadmap
- JWT token signing for enhanced security
- Multiple OAuth2 provider support
- Advanced session management
- Audit logging
- Rate limiting
- Custom domain validation rules
Built with โค๏ธ for the Claude.ai and Terraform communities.