keycardai-hermes
Keycard plugin for Hermes Agent:
delegated, per-tool-call access with brokered credentials. Before each tool
runs, the plugin acquires a credential for the actor the turn acts as and hands
it to the tool as a non-throwing AccessContext; surfaces the tool-call
boundary does not reach (MCP servers, CLIs, scripts) get the same credentials
through a stdio MCP relay and hermes keycard token.
The contract is the Hermes Agent integration spec. The package is experimental: it writes down what a reference deployment already runs, and ships only what works without upstream Hermes changes.
Install
Hermes Agent is not on PyPI, so the plugin installs into Hermes's own
virtualenv, where hermes_agent.plugins entry points are discovered:
# from the Hermes checkout, with its venv active
pip install keycardai-hermes
Requires Python 3.11 (Hermes's floor) and keycardai-oauth>=0.36.0.
The plugin registers a tool_execution middleware, a secret source and the
hermes keycard command group. None of them needs a declared Hermes
capability, so there is no consent step.
Enable the plugin
One settings block per Hermes profile, in that profile's config.yaml:
plugins:
enabled:
- keycardai-hermes
entries:
keycardai-hermes:
settings:
zone_url: https://your-zone.keycard.cloud
application_credential:
type: client_secret
client_id: app_...
secret_name: KEYCARD_CLIENT_SECRET # read through Hermes's get_secret, from .env
sign_in_resource: urn:hermes:assistant # a resource the application owns
owner_actor: alice # the actor for CLI, TUI, cron and the relay
tool_resources:
calendar_search: [https://calendar.example.com]
# resources: [...] # granted for every tool, built-ins included
# request_scopes: ...
# default_pattern: on_behalf_of | impersonate | as_self
# actor_aliases: {athena: alice}
# actors: {alice: alice@example.com} # for impersonate and verify_sign_in
# secrets: {CALENDAR_KEY: https://calendar.example.com}
# block_without_sign_in: true
# sign_in_on_admission: false # answer a sender with no sign-in before the turn
# authorization_url: https://...
# verify_sign_in: false
Put the secret in the profile's .env as KEYCARD_CLIENT_SECRET=...; the
settings file never holds it. A workload_identity block
({type: workload_identity, client_id: ..., token_file: ...}) reads a
platform-projected token file instead.
plugins.isolation: host is not supported: the plugin refuses to load there,
including inside the plugin host child (HERMES_PLUGIN_HOST_PROCESS=1),
because a ContextVar set in the plugin host process cannot reach a tool.
Sign in an actor
hermes keycard login --actor alice
Registers a public client in the zone on first use (device code and refresh
token grants, no client authentication), runs the device flow for
sign_in_resource, and stores the sign-in under the actor in a 0600 file under
the profile's Hermes home. Without --actor the sign-in is stored under
owner_actor. With verify_sign_in: true, the zone's UserInfo must match
actors[alice] (its sub, or its email when the value is an email and the zone marks it
verified) or
nothing is stored. Each sign-in file is named by a readable prefix of the actor plus a digest of
the full id, so two actors never share one, and the directories are 0700.
In a gateway turn the actor is the sender (HERMES_SESSION_ACTOR_ID). A turn
with an empty actor acts as owner_actor unless Hermes's
session_is_messaging_surface() reports it as a messaging turn: API server,
CLI, TUI, cron and kanban turns use the owner, while a messaging turn with an
empty actor (Hermes clears it when a second sender's message joins a running
turn) gets no actor, never the owner's. Hermes counts any surface it doesn't
list as messaging, so an unknown surface gets no actor either. A tool call that needs a
sign-in and has none is answered with a tool result naming the login command,
and the tool does not run (block_without_sign_in: false records the error on
the context and runs the tool instead). With sign_in_on_admission: true, a
message from a sender with no sign-in is answered with the login command before
the turn starts, whether or not the turn would have called a tool.
Read the credential in a tool
from keycardai.hermes import get_access_context
def calendar_search(query: str) -> str:
access = get_access_context()
if access.has_resource_error("https://calendar.example.com"):
return f"calendar unavailable: {access.get_resource_error('https://calendar.example.com')['message']}"
token = access.access("https://calendar.example.com").access_token
...
Errors are data: a denied grant, an expired sign-in or a failed refresh is on
the AccessContext, never an exception out of the middleware. Outside a tool
call, grant() and agrant() install the same context:
from keycardai.hermes import grant
with grant(tool_name="calendar_search") as access:
...
A token for anything else
hermes keycard token https://calendar.example.com # as owner_actor
hermes keycard token https://model.example.com --as-self # as the application
Writes only the token to standard output and exits non-zero with the error on
standard error. It is the route for scripts and CLIs the terminal tool runs,
and the key_cmd of a model provider registered through
providers.register_provider (off unless configured). Note that the command
acts as owner_actor (or as the application) whichever sender's turn runs it,
and a token printed by the terminal tool lands in the session transcript; a
wrapper that writes it where the next command reads it keeps it out.
MCP servers behind a gateway: the relay
keycardai-hermes-mcp is a stdio MCP server that relays to a streamable HTTP
endpoint, attaching a token for the endpoint (or --resource) acquired as
owner_actor. It retries once on a 401 with a new token and once on a 404 by
replaying initialize; anything that still fails is a JSON-RPC error on that
request naming the resource. Requests run concurrently, so a slow tool call
holds up nothing else, and a reply may take up to five minutes. In the profile's config.yaml:
mcp_servers:
calendar:
command: keycardai-hermes-mcp
args: ["https://gateway.example.com/mcp/calendar"]
env:
KEYCARD_CLIENT_SECRET: "${KEYCARD_CLIENT_SECRET}"
The relay runs outside Hermes, so it reads the application secret from the
environment variable named by secret_name. Hermes strips a stdio MCP server's
environment to a baseline, so the env block has to pass it through as above;
HERMES_HOME is set by Hermes to the profile's home, which is where the relay
reads the settings and the sign-in store. Like the token command, the relay
acts as owner_actor.
Static secrets
secrets maps names to resources; the plugin's secret source answers each
name with an as-itself token for its resource once per process, when Hermes
hydrates secret sources. Anything that rotates goes through the middleware,
the relay or the token command instead.
Testing
keycardai.hermes.testing.mock_access_context serves a synthetic context to a
tool without a zone:
from keycardai.hermes.testing import mock_access_context
with mock_access_context(resource_tokens={"https://calendar.example.com": "tok"}):
assert "tok" in calendar_search("standup")
See TESTING.md for the test matrix against the spec and examples/profile
for a complete profile.
Metadata
Release files for keycardai-hermes 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| keycardai_hermes-0.1.1.tar.gz | 101.6 kB | Without provenance | Details for keycardai_hermes-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| keycardai_hermes-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for keycardai_hermes-0.1.1-py3-none-any.whl |
Total release size: 134.6 kB
Release files / keycardai_hermes-0.1.1.tar.gz
| Download URL | keycardai_hermes-0.1.1.tar.gz |
|---|---|
| Size | 101.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cc17226fe4277d593c56cda4f0de9d3f1bc7524f97354d3b826d90a4c36dfdd
|
|
BLAKE2b-256 checksum How to use checksums |
7ade8ed3f7b8532fdbde14a663a81074dee26f52ed410b127e3fdf0e5e6a3590
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / keycardai_hermes-0.1.1-py3-none-any.whl
| Download URL | keycardai_hermes-0.1.1-py3-none-any.whl |
|---|---|
| Size | 32.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ab70f306a6e6f3e8756c9a58ef51bf09d1069611f274feb227f71dbc965ea6d
|
|
BLAKE2b-256 checksum How to use checksums |
9a554a79057293a42df4691bce83c39fd8fabb860e750566d66c66c27f8d30a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for keycardai-hermes 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.