Commit 5f62eae
authored
feat: MCPServerIdentity.connect(), ServerBadgeKeeper, stdio credential-in-_meta (#7)
* feat: MCPServerIdentity.connect(), ServerBadgeKeeper, stdio credential-in-_meta
- Add capiscio_mcp/connect.py: MCPServerIdentity dataclass with connect()
and from_env() class methods. Handles idempotent key generation,
registration, badge issuance, and keeper start. "Let's Encrypt" pattern
for one-liner MCP server identity setup (RFC-007).
- Add capiscio_mcp/keeper.py: ServerBadgeKeeper background thread that
monitors badge expiry (exp claim) and calls POST /v1/sdk/servers/{id}/badge
for renewal. Mirrors SDK's BadgeKeeper.
- Update capiscio_mcp/integrations/mcp.py:
* CapiscioMCPServer.__init__: accept identity=MCPServerIdentity shortcut
* _meta injection: patch ServerSession._received_request once (idempotent)
wrapping responder.respond for InitializeRequest to inject identity meta
* _install_credential_extraction: new function wrapping the FastMCP
CallToolRequest handler to extract capiscio_caller_badge /
capiscio_caller_api_key from _meta and set _current_credential contextvar
before the guarded tool runs. Fixes stdio transport where HTTP headers
are not available (RFC-002 ss9.1 equivalent for stdio).
* CapiscioMCPClient.call_tool: forward badge/api_key in JSON-RPC _meta
(meta={"capiscio_caller_badge": ...}) instead of setting a contextvar
in the client process which had no effect on the subprocess server.
* CapiscioMCPClient.connect: send PoP nonce in initialize request _meta,
extract server identity from InitializeResult.meta, verify via
verify_server(), enforce min_trust_level/fail_on_unverified.
- Update capiscio_mcp/__init__.py: export MCPServerIdentity, ServerBadgeKeeper
- Add tests/test_connect.py: 43 tests for MCPServerIdentity
- Add tests/test_keeper.py: 43 tests for ServerBadgeKeeper
- Update tests/test_integrations.py: 13 new tests for
_install_credential_extraction and client meta propagation (346 total)
All 346 tests pass.
* fix: correctly extract badge token from nested data.token response field
The badge endpoint returns the JWS under data.data.token (not data.data.badge).
Update _issue_badge_sync to check both .token and .badge in the nested payload,
and add .domain auto-derivation from the CA URL so the badge request includes
the required domain field.
Also reads CAPISCIO_SERVER_DOMAIN env var in from_env() for user override.
* fix: forward CAPISCIO_* env vars to stdio MCP server subprocess
mcp.client.stdio.get_default_environment() only passes a small whitelist of
vars (HOME, PATH, USER, etc.) to the subprocess. CAPISCIO_* credentials were
being stripped, causing the server subprocess to fail with a missing env var
error.
CapiscioMCPClient now auto-forwards all CAPISCIO_* vars (and MCP_SERVER_COMMAND)
from the parent process via StdioServerParameters.env. An explicit env dict can
also be passed to __init__() for callers that need per-connection overrides.
* feat: env var key injection for ephemeral environments (CAPISCIO_SERVER_PRIVATE_KEY_PEM)
Add support for injecting the server private key via environment variable
for containerised/serverless deployments where ~/.capiscio is ephemeral.
Key priority: env var > local file > generate new keypair.
On first-run keygen, a capture hint is logged to stderr with the
PEM-encoded key for the operator to persist in their secrets manager.
- Add _load_private_key_pem() and _did_from_ed25519_pub_raw() helpers
- Add _log_key_capture_hint() with box-formatted capture hint
- Move cryptography and base58 to base dependencies
- Add 4 unit tests for env var injection and capture hint
* docs: add deployment guide and document env var key injection
- Add new docs/guides/deployment.md covering Docker, Lambda, Cloud Run, K8s
- Update README with MCPServerIdentity.connect() section and env var table
- Update server-registration.md with new env vars and deployment link
- Add Deployment to mkdocs nav
* fix(docs): correct did:key → did:web for production registry usage
The registry assigns did:web when an API key is used. did:key is only
for local dev mode without a registry.
* fix: address Copilot PR review comments
- Remove unused imports (base64, sys, KeyGenerationError, threading, etc.)
- Remove dead code (der_b64 variable)
- Security: write capture hint to stderr instead of logger.warning to
prevent private key leaking into log aggregation pipelines
- Add JSON decode error handling in _issue_badge_sync and keeper._renew
- Fix keeper.stop() to detect still-alive threads after 5s timeout
- Fix session resource leak: call __aexit__ on session before clearing
- Fix fail_on_unverified to enforce regardless of min_trust_level
- Fix ServerVerifyError constructor calls with proper error_code/detail
- Fix registration error handling to only swallow 409/None status codes
All 350 tests passing.1 parent e7a855c commit 5f62eae
12 files changed
Lines changed: 2688 additions & 363 deletions
File tree
- capiscio_mcp
- integrations
- docs/guides
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
200 | 262 | | |
201 | 263 | | |
202 | 264 | | |
| |||
299 | 361 | | |
300 | 362 | | |
301 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
302 | 369 | | |
303 | 370 | | |
304 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
20 | 37 | | |
21 | 38 | | |
22 | 39 | | |
| |||
33 | 50 | | |
34 | 51 | | |
35 | 52 | | |
36 | | - | |
| 53 | + | |
37 | 54 | | |
38 | 55 | | |
39 | 56 | | |
| |||
95 | 112 | | |
96 | 113 | | |
97 | 114 | | |
| 115 | + | |
| 116 | + | |
98 | 117 | | |
99 | 118 | | |
100 | 119 | | |
| |||
154 | 173 | | |
155 | 174 | | |
156 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
157 | 179 | | |
0 commit comments