MCP Server with LangGraph with OpenFGA & Infisical
Complete integration guide for fine-grained authorization and secrets management.🔐 Architecture Overview
🚀 Quick Start
1. Start Infrastructure
- OpenFGA: http://localhost:8080 (API), http://localhost:3000 (Playground)
- Jaeger: http://localhost:16686
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
2. Setup OpenFGA
- Authorization store
- Authorization model (users, organizations, tools, conversations, roles)
- Sample relationship tuples
- Runs verification tests
OPENFGA_STORE_ID and OPENFGA_MODEL_ID to your .env file!
3. Setup Infisical (Optional but Recommended)
- Sign up at https://app.infisical.com
- Create a project
- Generate Universal Auth credentials
- Add to
.env:
4. Install Dependencies
5. Configure Environment
🔑 OpenFGA Authorization Model
Type Definitions
Relations
| Resource | Relation | Description |
|---|---|---|
| organization | member | User is member of organization |
| organization | admin | User is admin of organization |
| tool | executor | User can execute tool |
| tool | owner | User owns tool |
| tool | organization | Tool belongs to organization |
| conversation | owner | User owns conversation |
| conversation | viewer | User can view conversation |
| conversation | editor | User can edit conversation |
| role | assignee | User is assigned role |
Inheritance Rules
-
Tool Execution: Users can execute tools if:
- Directly granted
executorrelation - They own the tool (
owner→executor) - They’re members of the tool’s organization
- Directly granted
-
Conversation Access: Users can view conversations if:
- Directly granted
viewerrelation - They own the conversation (
owner→viewer)
- Directly granted
Example Relationships
🔒 Infisical Secrets Management
Configuration
Secrets are loaded with this priority:- Infisical (if configured)
- Environment variables (fallback)
- Default values (last resort)
Usage in Code
Automatic Loading
Secrets are automatically loaded insrc/mcp_server_langgraph/core/config.py:
🛠️ MCP Server Integration
Running the Server
Available Tools
1. chat
Chat with the AI agent.
Requirements:
- User must have
executorrelation ontool:chat - User must have
editorrelation on target conversation
2. get_conversation
Retrieve conversation history.
Requirements:
- User must have
viewerrelation on target conversation
3. list_conversations
List all accessible conversations.
Requirements:
- Authenticated user
Authorization Flow
📊 Testing
Test Authorization Rules
- Tool access checks
- Conversation ownership/viewing
- Organization-based permissions
- Listing accessible resources
- Adding/removing relationships
- Expanding relationships
Test MCP Server
- Authentication (success/failure)
- Tool execution authorization
- Conversation access control
- Listing conversations
- Unauthorized access attempts
🔧 Adding Users and Permissions
Grant User Access to Tool
Grant User Access to Conversation
Add User to Organization
Remove Permissions
📈 Observability
All authorization checks are traced and logged:Distributed Tracing
Every request creates spans:mcp.call_tool- Tool invocationauth.authenticate- User authenticationauth.authorize- OpenFGA checkopenfga.check- Permission checkagent.chat- Agent execution
Metrics
agent.tool.calls- Tool invocation countauth.failures- Authentication failuresauthz.failures- Authorization failures (by resource)agent.calls.successful- Successful operationsagent.calls.failed- Failed operations
Logs
Structured logs with trace correlation:🏗️ Production Deployment
OpenFGA
Use PostgreSQL backend instead of in-memory:Infisical
- Create production project in Infisical
- Use environment-specific credentials
- Enable secret versioning
- Set up secret rotation
- Use machine identities for service accounts
Security Checklist
- Rotate JWT secret keys
- Use production Infisical project
- Enable OpenFGA audit logs
- Set up secret rotation
- Configure HTTPS for all services
- Enable rate limiting
- Set up monitoring alerts
- Implement backup strategy
- Review and minimize permissions
- Enable MFA for admin accounts
🎯 Use Cases
Multi-Tenant SaaS
Role-Based Access Control
Conversation Sharing
🆘 Troubleshooting
OpenFGA Not Working
Infisical Connection Issues
Authorization Always Fails
- Check OpenFGA relationships exist
- Verify user_id format (
user:alice) - Check resource format (
tool:chat,conversation:thread_1) - Review logs for specific errors
- Test with setup script first
📚 Additional Resources
- OpenFGA Documentation
- Infisical Documentation
- LangGraph Documentation
- MCP Protocol Specification
- OpenTelemetry Python
🤝 Support
For issues or questions:- Check the troubleshooting section
- Review example scripts
- Check observability dashboards
- File an issue with logs and trace IDs