mcp: OAuth for HTTP servers (discovery, DCR, PKCE, refresh, hx mcp login/logout)

This commit is contained in:
hermes committed 2026-10-06 10:17:18 +00:00
1 parent aa72ab664d
commit 6ae6758836
10 files changed
+621 -23

No files matched your search

+36 -2
View File
@@ -62,11 +62,22 @@ enum Cmd {
/// Token size of the fixed request prefix (system prompt parts, tool schemas, MCP index).
Prefix,
/// Connect to configured MCP servers and print tools + index/eager token cost.
Mcp,
Mcp {
#[command(subcommand)]
action: Option<McpAction>,
},
/// Serve lens diagnostics + LSP navigation as an MCP server over stdio.
McpServe,
}
#[derive(Subcommand)]
enum McpAction {
/// OAuth login for an HTTP MCP server from mcp.json.
Login { server: String },
/// Forget the stored OAuth token for an HTTP MCP server.
Logout { server: String },
}
/// `~/.hx/config.toml`, overridden by `.hx/config.toml` in the project.
#[derive(Default, serde::Deserialize)]
#[serde(default, deny_unknown_fields)]
@@ -372,7 +383,30 @@ async fn main() -> Result<()> {
mgr.shutdown().await;
return Ok(());
}
Some(Cmd::Mcp) => {
Some(Cmd::Mcp { action: Some(a) }) => {
let cwd = std::env::current_dir()?;
let cfgs =
hx_mcp::config::load(&context::hx_home(), &cwd).map_err(anyhow::Error::msg)?;
let (McpAction::Login { server } | McpAction::Logout { server }) = &a;
let s = cfgs
.get(server)
.filter(|s| s.url.is_some())
.ok_or_else(|| anyhow::anyhow!("no HTTP MCP server `{server}` in mcp.json"))?;
if matches!(a, McpAction::Logout { .. }) {
hx_mcp::oauth::logout(s).map_err(anyhow::Error::msg)?;
return Ok(());
}
hx_mcp::oauth::login(s, |u| {
eprintln!(
"Open this URL to log in (or paste the final redirect URL here):\n\n{u}\n"
)
})
.await
.map_err(anyhow::Error::msg)?;
eprintln!("logged in to {server}");
return Ok(());
}
Some(Cmd::Mcp { action: None }) => {
let cwd = std::env::current_dir()?;
let hub = hx_mcp::Hub::start(
hx_mcp::config::load(&context::hx_home(), &cwd).map_err(anyhow::Error::msg)?,