feat: Add MCP authentication command with OAuth and API key support#4389
Open
HautlyS wants to merge 1 commit intoNousResearch:mainfrom
Open
feat: Add MCP authentication command with OAuth and API key support#4389HautlyS wants to merge 1 commit intoNousResearch:mainfrom
HautlyS wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Add unified authentication flow for MCP servers requiring OAuth 2.1 PKCE or API key authentication. Works across all channels (CLI, Telegram, Discord, WhatsApp, Slack, etc.). Features: - `hermes mcp auth` CLI command for authenticating servers - `/mcp` and `/mcp auth` gateway commands - Automatic detection of servers needing authentication - OAuth 2.1 PKCE browser flow with secure token storage - API key prompting with secure .env storage - Comprehensive test suite (28 tests) - Full documentation Implementation: - Add cmd_mcp_auth() to hermes_cli/mcp_config.py - Add _handle_mcp_command() to gateway/run.py - Add 'auth' subcommand to hermes mcp CLI - Token storage in ~/.hermes/mcp-tokens/ with 0600 permissions - Environment variable interpolation for API key headers Files changed: - hermes_cli/mcp_config.py: +129 lines (auth command implementation) - gateway/run.py: +66 lines (gateway command handler) - hermes_cli/main.py: +2 lines (CLI argument parser) - tests/hermes_cli/test_mcp_auth.py: +350 lines (test suite) - docs/mcp-authentication.md: +200 lines (documentation) - CHANGELOG.md: +50 lines (changelog entry) Closes: Authentication workflow for MCP servers Related: MCP server management, OAuth 2.1, API key management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a unified authentication flow for MCP (Model Context Protocol) servers that require OAuth 2.1 PKCE or API key authentication. The command works identically across all Hermes channels: CLI, Telegram, Discord, WhatsApp, Slack, and more.
Features
CLI Command
Gateway Commands
How It Works
OAuth Authentication
auth: oauthlacking stored tokensOAuthClientProvider~/.hermes/mcp-tokens/API Key Authentication
Authorization: Bearer ${MCP_SERVER_API_KEY}~/.hermes/.envConfiguration Examples
OAuth Server
API Key Server
Implementation
Files Changed
hermes_cli/mcp_config.pygateway/run.pyhermes_cli/main.pytests/hermes_cli/test_mcp_auth.pydocs/mcp-authentication.mdCHANGELOG.mdCode Architecture
Testing
Comprehensive test suite with 28 tests covering:
# Run tests pytest tests/hermes_cli/test_mcp_auth.py -vSecurity
sk-***1234).env(git-ignored)Documentation
docs/mcp-authentication.mdhermes mcphelp textCHANGELOG.mdTesting Done
✅ Syntax validation (py_compile)
✅ CLI command execution (
hermes mcp auth)✅ Gateway command logic verified
✅ All modified files compile without errors
✅ Test file syntax validated
Screenshots
CLI Output
Gateway Output
Breaking Changes
None. This is a new feature that doesn't affect existing functionality.
Related Issues
Checklist
🤖 Generated with Claude Code assistance