Skip to content

feat: enhance MCP server support with authentication and environment variables #1644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

abhimanyusaxena
Copy link

Summary

  • Add authentication support for remote MCP servers (bearer token, API key, basic auth)
  • Add environment variable expansion in server configurations
  • Enhance error handling and connection resilience

Changes

Authentication Support

  • Added auth_type and auth_config fields to MCP server model
  • Support for three authentication types:
    • Bearer token authentication
    • API key authentication (with configurable header name)
    • Basic authentication (username/password)
  • Authentication headers are automatically added when connecting to remote servers

Environment Variable Support

  • Server configurations can now use environment variables with ${VAR} or $VAR syntax
  • Variables are expanded in:
    • Command and arguments for stdio transport
    • URL and headers for HTTP+SSE transport
    • Authentication configuration values
  • Enables secure configuration without hardcoding sensitive values

Enhanced Error Handling

  • Better error messages for connection failures
  • Timeout handling for HTTP requests (30 seconds)
  • Process startup validation for stdio connections
  • Improved error reporting through WebSocket status updates
  • Connection status now includes error messages

Database Changes

  • Updated MCP server migration to include authentication fields
  • No breaking changes to existing data

Testing

  • Tested with local stdio MCP servers
  • Tested environment variable expansion
  • Tested error scenarios (invalid commands, network failures)

Next Steps

  • Frontend UI updates to support authentication configuration
  • Additional testing with various MCP server implementations

🤖 Generated with Claude Code

User and others added 10 commits May 22, 2025 17:08
Security improvements:
- Implement OAuth CSRF protection with secure state parameter management
- Add proper validation and expiration for OAuth state tokens
- Add security warnings for SECRET_KEY configuration in production
- Sanitize database error logging to prevent sensitive info exposure

Code quality fixes:
- Fix missing import for get_user function in refresh endpoint
- Fix async/await usage in get_current_user_optional
- Standardize is_active default value to True across models
- Add security documentation for shell=True usage
- Update Alembic config to clarify placeholder database URL

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add MCP server models and schemas for storing server configurations
- Implement MCP connection manager supporting both stdio and HTTP+SSE transports
- Create REST API endpoints for managing MCP servers (CRUD operations)
- Add WebSocket endpoint for real-time MCP communication
- Implement tool calling, resource fetching, and prompt retrieval
- Add database migration for mcp_servers table with JSON fields
- Support both local (stdio) and remote (HTTP+SSE) MCP servers
- Add aiohttp dependency for HTTP client functionality

This backend implementation provides a foundation for browser-based MCP hosting,
allowing users to connect to and interact with MCP servers similar to Claude Desktop.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…variables

- Add authentication fields (auth_type, auth_config) to MCP server model
- Support bearer token, API key, and basic authentication for remote servers
- Add environment variable expansion for server configurations
- Enhance error handling and connection resilience
- Improve WebSocket status reporting with error messages
- Add timeout and better error messages for HTTP requests
- Better process management for stdio connections

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant