stacklok / stacklok/toolhive

Enhancement: Support Remote Auth for Docker Containers

Open
#2,323 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

authentication cli enhancement
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Enhancement: Support Remote Auth (--remote-auth-*) for Docker Containers

Summary

Enable --remote-auth-* flags to work with containerized MCP servers, allowing ToolHive to acquire OAuth/OIDC tokens and inject them into requests to Docker containers, not just remote URLs.

Current Behavior

The --remote-auth-* flags currently only work when connecting to remote MCP servers via HTTP/HTTPS URLs. When running containerized MCP servers locally, remote authentication is disabled by design.

Current limitation in pkg/transport/http.go:314:

// Add OAuth token injection middleware for remote authentication if we have a token source
if t.remoteURL != "" && t.tokenSource != nil {
    tokenMiddleware := t.createTokenInjectionMiddleware()
    middlewares = append(middlewares, types.NamedMiddleware{
        Name:     "oauth-token-injection",
        Function: tokenMiddleware,
    })
}

The check t.remoteURL != "" prevents token injection for containers since remoteURL is only set for remote URLs, not container images.

Desired Behavior

Allow users to acquire OAuth/OIDC tokens via the --remote-auth-* flags and have ToolHive inject those tokens into HTTP requests to containerized MCP servers running with HTTP/SSE transport.

Example command:

thv run ghcr.io/example/github-mcp-server \
  --transport sse \
  --remote-auth-issuer https://github.com/login/oauth \
  --remote-auth-client-id <client-id> \
  --remote-auth-scopes "repo,user"

Expected flow:

  1. ToolHive initiates OAuth flow with GitHub
  2. User authenticates in browser
  3. ToolHive acquires access token
  4. Container starts with HTTP/SSE transport
  5. ToolHive injects Authorization: Bearer <token> into all requests to the container
  6. Container can use the token to make authenticated GitHub API calls

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/transport/http.go:314 and trace how remoteURL and tokenSource control OAuth token injection for HTTP/SSE transports. Verify the container startup and transport path, then ensure the acquired Bearer token is injected into requests made to containerized MCP servers when the remote-auth flags are used.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
authentication, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.