- Home
- Skills
- APIs & Backend
- MCP / API Resource-Server Hardening
MCP / API Resource-Server Hardening
Signature verification proves a token came from your issuer.
$29
Works with the AI Agents you already use
MCP / API Resource-Server Hardening
Example session with this skill installed
Our MCP server verifies Keycloak JWTs and then trusts them. Review it against the hardening checklist and fix what's missing: it's multi-tenant and the realm is shared with our customer-facing apps.
- Read your context and instructions
- Compiled the mcp api resource-server
Summary
Four gaps found; all four are the defects the checklist exists for. Fixed in the store layer and the single handler, with tests that attack both transports.
| Gap | Before | After |
|---|---|---|
| Any valid realm token accepted | signature + iss + exp only | authorizeClient against OIDC_ALLOWED_CLIENTS=agent-runner; customer-app tokens now 403 CLIENT_NOT_ALLOWED |
| No audience | tokens for the web app replayable here | audience: https://mcp.example.com required (RFC 8707) |
Unmapped app key fell back to tenant default | silent cross-tenant read | tenantFor returns null, 403 TENANT_NOT_CONFIGURED; escape:../x mapping dropped at parse |
author taken from the request body | any key holder could write as anyone | derived from the credential; body value kept as claimedAuthor only |
Tests added (hardening.test.mjs pattern): 12 pass.
SERVER_DERIVEDinjection on REST and MCP: author, version, bytes, createdAt, scope all ignored or labelled- isolation: beta cannot read, list or see versions of alpha's scope; cross-tenant read is 404, same as never existed
- audit: a distinctive scope name appears nowhere in 4 logged exits (write, MCP read, unauthenticated, unmapped)
Audit line now (families only):
{"event":"request","caller":"oidc:agent-runner","tenant":"acme","route":"/v1/context/:scope","tool":"context_write","scope":"project","status":200,"ms":3}
Also added: /.well-known/oauth-protected-resource and WWW-Authenticate: Bearer resource_metadata=... on 401, so MCP clients discover the authorization server without configuration.
Next steps
- Register the audience with the identity provider and roll the new tokens.
- Keep
OIDC_ALLOWED_CLIENTSin configuration; it starts empty and stays explicit. - If a future fix makes one of these tests fail, change the test and say why; do not fix it back.
Connects securely to your tools. The creator never sees your data.
About this skill
Signature verification proves a token came from your issuer. It does not prove the token was meant for your service, that the client it was issued to may use this surface, that the credential is assigned a tenant, or that the request body can be trusted for fields the server owns. Each of those gaps shipped once as a real defect; this skill is the code and the tests that keep them closed.
token-verifier.mjs
RS256/ES256 against the issuer's JWKS with node:crypto only; discovery or explicit JWKS URI; kid required and key type matched to the algorithm; one refetch on an unknown kid; iss, exp, nbf and audience (RFC 8707); every failure is { ok: false } with no fallback, including an unreachable JWKS.
authorization.mjs
Client from azp/client_id only (never username or sub); explicit allow-list where an empty list rejects everyone; tenant mapping that drops unsafe ids at parse and returns null for an unmapped credential (403 TENANT_NOT_CONFIGURED, never a default); applyServerDerived so author, version, size, timestamps and the URL scope never come from the body and a caller's value is kept only as a labelled claim; audit helpers that log scope families and route templates, describe batched JSON-RPC, and never carry names; RFC 9728 metadata and WWW-Authenticate.
example-server.mjs
A loopback resource server with REST and MCP Streamable HTTP surfaces applying every rule: 401 vs 403 semantics, 404 for cross-tenant reads, one audit line per request at the single handler.
12 tests
A fake authorization server with generated keys; every verifier failure; rotation; allow-list; fail-closed tenancy; a SERVER_DERIVED injection test on both transports; isolation for read, list and versions on REST and MCP; the negative audit test that a distinctive scope name appears nowhere.
reference/checklist.md
Each rule with the defect it came from, the status-code table, and the instrument-verification habits that caught false readings.
Node 20+, no packages. Network only to the issuer's discovery and JWKS URLs you configure.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Bearer tokens only; no DPoP/mTLS. Built-in scope parsing assumes family/name format. Node 20+ required.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 19 days ago
- Software
Node.js 20+OIDC authorization server
The authorization server needs a JWKS endpoint.
Permissions
Shell runs node for the tests and the example server. Read files: your server source when adapting the pattern. Write files: test and source files you add. Network: the verifier fetches the issuer's discovery document and JWKS at the URLs you configure; the example server listens on 127.0.0.1. Tests make no network calls. Configuration (issuer, allowed clients, tenant map, app keys) is read from environment variables you set for the example server.