Skip to content

Commit 067f3ef

Browse files
ctronclaude
andcommitted
feat: add MCP server subcommand for AI-assisted token retrieval
Add `oidc mcp` subcommand that starts a stdio-based MCP server using the rmcp crate, exposing `list_clients` and `get_token` tools. This allows AI assistants like Claude Code to retrieve OIDC tokens for configured clients. The MCP functionality is behind a default-enabled `mcp` feature flag so it can be excluded when not needed. Also adds cargo-all-features to CI to verify all feature combinations compile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 669bd1a commit 067f3ef

6 files changed

Lines changed: 333 additions & 0 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,29 @@ jobs:
9696
- name: Test
9797
run: cargo +${{ matrix.rust }} test --workspace ${{ matrix.args }} -- --nocapture
9898

99+
features:
100+
needs: fmt
101+
runs-on: ubuntu-24.04
102+
steps:
103+
- uses: actions/checkout@v7
104+
105+
- uses: Swatinem/rust-cache@v2
106+
107+
- name: Install dependencies
108+
run: sudo apt install -y libssl-dev
109+
110+
- name: Install cargo-all-features
111+
run: cargo install cargo-all-features
112+
113+
- name: Check all feature combinations
114+
run: cargo check-all-features
115+
99116
ci:
100117
runs-on: ubuntu-latest
101118
needs:
102119
- fmt
103120
- test
121+
- features
104122
if: always()
105123
steps:
106124
- name: Success

Cargo.lock

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ openidconnect = { version = "4", features = ["accept-rfc3339-timestamps"] }
3737
oauth2 = "5"
3838
pretty-hex = "0.4.1"
3939
reqwest = "0.12" # keep aligned with openidconnect
40+
rmcp = { version = "2", features = ["server", "transport-io", "macros"], optional = true }
41+
schemars = { version = "1", optional = true }
4042
serde = { version = "1", features = ["derive"] }
4143
serde_json = "1"
4244
serde_yaml = "0.9"
@@ -48,6 +50,8 @@ url = "2"
4850
openssl = "0.10" # transient dependency, required for vendoring
4951

5052
[features]
53+
default = ["mcp"]
54+
mcp = ["dep:rmcp", "dep:schemars"]
5155
vendored = [
5256
"openssl/vendored"
5357
]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,31 @@ This also works with `curl`:
7979
curl http://example.com/api -H $(oidc token -H my-client)
8080
```
8181

82+
## MCP Server
83+
84+
`oidc-cli` includes a built-in [MCP](https://modelcontextprotocol.io/) server that lets AI assistants retrieve OIDC
85+
tokens for configured clients. This is useful when you want AI-powered tools to make authenticated API calls on your
86+
behalf.
87+
88+
First, set up your OIDC clients as usual (see above). Then start the MCP server:
89+
90+
```bash
91+
oidc mcp
92+
```
93+
94+
The server communicates over stdio and exposes two tools:
95+
96+
* **`list_clients`** — lists all configured OIDC clients with their issuer URL and token status
97+
* **`get_token`** — retrieves a valid token for a named client, automatically refreshing if expired
98+
99+
### Claude Code
100+
101+
To register the MCP server with [Claude Code](https://docs.anthropic.com/en/docs/claude-code):
102+
103+
```bash
104+
claude mcp add oidc -- oidc mcp
105+
```
106+
82107
## More examples
83108

84109
Create a public client from an initial refresh token. This can be useful if you have a frontend application, but no

0 commit comments

Comments
 (0)