[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ABH3F2P2ZJ839MAFW9AECN":3,"skill-same:01M7ABH3F2P2ZJ839MAFW9AECN":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":14,"repositoryHtmlUrl":29,"repositoryHomepageUrl":30,"ownerHtmlUrl":31,"ownerBlogUrl":32,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7ABH3F2P2ZJ839MAFW9AECN","mcp-auth",null,"Authorize MCP SDK v2 resource servers with bearer validation, service clients with credentials, or host-session exchanges; browser authorization_code flows use mcp-client.","j0hanz\u002Fj0hanz-marketplace","j0hanz","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F159924955?v=4","01M7ABFK415CKHXYV9GZRJ16T7","Linus Johansson","01M7ABFK52FCPP2PNBH1YR7ZPA",0,"MIT","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fmcp-hub\u002Fskills\u002Fmcp-auth\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: mcp-auth\ndescription: 'Authorize MCP SDK v2 resource servers with bearer validation, service clients with credentials, or host-session exchanges; browser authorization_code flows use mcp-client.'\nuser-invocable: false\nmetadata:\n  category: technique\n---\n\n# MCP SDK v2 authorization\n\nRef: https:\u002F\u002Fts.sdk.modelcontextprotocol.io\u002Fv2\u002F\n\n**Server = Resource Server: IdP issue\u002Frevoke token, server validate.**\n\n> v1 Authorization Server helpers (`mcpAuthRouter`, `OAuthServerProvider`) frozen in `@modelcontextprotocol\u002Fserver-legacy\u002Fauth`. Resource Server helpers come from `@modelcontextprotocol\u002Fexpress` (Node: `requireBearerAuth`, `mcpAuthMetadataRouter`) or `@modelcontextprotocol\u002Fserver` (web-standard hosts: `requireBearerAuth`, `oauthMetadataResponse`). Migrate AS role to dedicated IdP.\n\nBrowser\u002FSPA login (`connect`, `finishAuth`, `IssuerMismatchError`) belongs in [mcp-client](..\u002Fmcp-client\u002FSKILL.md) \"Authenticate the client.\" Mock `authInfo` with [mcp-test](..\u002Fmcp-test\u002FSKILL.md).\n\n## Protect a resource server\n\n```ts\nimport {\n  getOAuthProtectedResourceMetadataUrl,\n  mcpAuthMetadataRouter,\n  requireBearerAuth,\n} from '@modelcontextprotocol\u002Fexpress';\nimport { OAuthError, OAuthErrorCode } from '@modelcontextprotocol\u002Fserver';\n\nconst auth = requireBearerAuth({\n  verifier: {\n    verifyAccessToken: async (token) => {\n      try {\n        const payload = await verifyJwt(token);\n        return { token, clientId: payload.sub, scopes: payload.scopes, expiresAt: payload.exp };\n      } catch {\n        throw new OAuthError(OAuthErrorCode.InvalidToken, 'Invalid or expired token'); \u002F\u002F a plain Error here becomes HTTP 500\n      }\n    },\n  },\n  requiredScopes: ['mcp'],\n  resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(mcpServerUrl),\n});\n\napp.all('\u002Fmcp', auth, (req, res) => void node(req, res, req.body));\napp.use(mcpAuthMetadataRouter({ oauthMetadata, resourceServerUrl: mcpServerUrl }));\n```\n\nVerify signature, issuer, audience against IdP keys. Decoded JWT claims alone not enough. `requireBearerAuth` extracts header, attaches verified `AuthInfo` to `req.auth`. `toNodeHandler` forwards it to `ctx.http.authInfo`.\n\n- [ ] `requireBearerAuth` protects MCP route before tool dispatch; `mcpAuthMetadataRouter` serves resource metadata.\n- [ ] `verifyAccessToken` supplies `expiresAt`, rejects bad tokens with `OAuthError(OAuthErrorCode.InvalidToken)`. Plain exception becomes HTTP 500.\n- [ ] Tool callbacks get tenant\u002Fuser permissions from `ctx.http?.authInfo`, return `{ isError: true, content: [...] }` on authorization failure.\n- [ ] Express hosts use `@modelcontextprotocol\u002Fexpress` (`requireBearerAuth`, `mcpAuthMetadataRouter`); web-standard fetch hosts use `requireBearerAuth` + `oauthMetadataResponse` from `@modelcontextprotocol\u002Fserver`.\n\n```ts\n\u002F\u002F web-standard fetch host (Cloudflare Workers, Hono, Bun, Deno)\nimport { oauthMetadataResponse, requireBearerAuth } from '@modelcontextprotocol\u002Fserver';\n\nexport default {\n  async fetch(req: Request): Promise\u003CResponse> {\n    const meta = await oauthMetadataResponse(req, {\n      oauthMetadata,\n      resourceServerUrl: mcpServerUrl,\n    });\n    if (meta) return meta; \u002F\u002F RFC 9728 protected-resource \u002F RFC 8414 AS metadata\n    \u002F\u002F ...route to handler; requireBearerAuth(req) returns AuthInfo or a 401 challenge Response\n  },\n};\n```\n\n## Authenticate a service client\n\nUse `ClientCredentialsProvider` for service with client secret. Use `PrivateKeyJwtProvider` when authorization server requires private-key client authentication:\n\n```ts\nnew ClientCredentialsProvider({ clientId, clientSecret, expectedIssuer });\nnew PrivateKeyJwtProvider({\n  clientId,\n  privateKey,\n  algorithm: 'RS256',\n  jwtLifetimeSeconds: 300,\n});\n```\n\n`expectedIssuer` pins `ClientCredentialsProvider` credentials; mismatched discovery throws `AuthorizationServerMismatchError`. Other two providers take none.\n\nFor authenticated host session, exchange its assertion with `CrossAppAccessProvider`:\n\n```ts\nnew CrossAppAccessProvider({\n  assertion: async (ctx) =>\n    (await discoverAndRequestJwtAuthGrant({\u002F* issuer\u002Faudience *\u002F})).jwtAuthGrant,\n  clientId,\n  clientSecret,\n});\n```\n\nFor other grant model, implement `OAuthClientProvider` with static `clientMetadata`\u002F`redirectUrl` plus `tokens`\u002F`saveTokens`, `clientInformation`\u002F`saveClientInformation`, `codeVerifier`\u002F`saveCodeVerifier`, `state`, `redirectToAuthorization`, and `saveDiscoveryState`\u002F`discoveryState`. Only `clientInformation(ctx?)` and `saveClientInformation(info, ctx?)` accept optional `ctx`; `saveTokens(tokens)` and `tokens()` take no `ctx` — tokens not issuer-partitioned. Override `validateResourceURL(serverUrl, resource?)` for RFC 8707 resource pinning. Use **Client ID Metadata Document** — stable HTTPS `clientMetadata` URL passed as `clientId` — instead of deprecated `registerClient` (SEP-991).\n\n- [ ] `ClientCredentialsProvider` sets `expectedIssuer` (mismatched discovery throws `AuthorizationServerMismatchError`); `PrivateKeyJwtProvider` and `CrossAppAccessProvider` don't accept it.\n- [ ] `clientInformation` and `saveClientInformation` accept optional `ctx`; `tokens` and `saveTokens` not issuer-partitioned.\n- [ ] Custom provider implements every listed persistence and redirect method, plus resource URL validation when RFC 8707 pinning applies.\n\n## Handle authorization errors\n\n- **OAuth consolidation**: v1 `Invalid*Error` family and `OAUTH_ERRORS` replaced by `OAuthError` + `OAuthErrorCode`; switch `instanceof` to `error.code`.\n- **`InsufficientScopeError`** — two distinct classes: **OAuth** one (`OAuthError(OAuthErrorCode.InsufficientScope)`, surfaced as 403 by `requireBearerAuth` scope enforcement) and separate **transport** class (client-side, SEP-2350), covered in [mcp-client](..\u002Fmcp-client\u002FSKILL.md).\n\n- [ ] Error handling uses `error.code` for consolidated OAuth errors, distinguishes OAuth vs transport `InsufficientScopeError` classes.\n- [ ] Tests use mock issuers from [mcp-test](..\u002Fmcp-test\u002FSKILL.md).\n","# MCP SDK v2 authorization\n\nRef: https:\u002F\u002Fts.sdk.modelcontextprotocol.io\u002Fv2\u002F\n\n**Server = Resource Server: IdP issue\u002Frevoke token, server validate.**\n\n> v1 Authorization Server helpers (`mcpAuthRouter`, `OAuthServerProvider`) frozen in `@modelcontextprotocol\u002Fserver-legacy\u002Fauth`. Resource Server helpers come from `@modelcontextprotocol\u002Fexpress` (Node: `requireBearerAuth`, `mcpAuthMetadataRouter`) or `@modelcontextprotocol\u002Fserver` (web-standard hosts: `requireBearerAuth`, `oauthMetadataResponse`). Migrate AS role to dedicated IdP.\n\nBrowser\u002FSPA login (`connect`, `finishAuth`, `IssuerMismatchError`) belongs in [mcp-client](..\u002Fmcp-client\u002FSKILL.md) \"Authenticate the client.\" Mock `authInfo` with [mcp-test](..\u002Fmcp-test\u002FSKILL.md).\n\n## Protect a resource server\n\n```ts\nimport {\n  getOAuthProtectedResourceMetadataUrl,\n  mcpAuthMetadataRouter,\n  requireBearerAuth,\n} from '@modelcontextprotocol\u002Fexpress';\nimport { OAuthError, OAuthErrorCode } from '@modelcontextprotocol\u002Fserver';\n\nconst auth = requireBearerAuth({\n  verifier: {\n    verifyAccessToken: async (token) => {\n      try {\n        const payload = await verifyJwt(token);\n        return { token, clientId: payload.sub, scopes: payload.scopes, expiresAt: payload.exp };\n      } catch {\n        throw new OAuthError(OAuthErrorCode.InvalidToken, 'Invalid or expired token'); \u002F\u002F a plain Error here becomes HTTP 500\n      }\n    },\n  },\n  requiredScopes: ['mcp'],\n  resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(mcpServerUrl),\n});\n\napp.all('\u002Fmcp', auth, (req, res) => void node(req, res, req.body));\napp.use(mcpAuthMetadataRouter({ oauthMetadata, resourceServerUrl: mcpServerUrl }));\n```\n\nVerify signature, issuer, audience against IdP keys. Decoded JWT claims alone not enough. `requireBearerAuth` extracts header, attaches verified `AuthInfo` to `req.auth`. `toNodeHandler` forwards it to `ctx.http.authInfo`.\n\n- [ ] `requireBearerAuth` protects MCP route before tool dispatch; `mcpAuthMetadataRouter` serves resource metadata.\n- [ ] `verifyAccessToken` supplies `expiresAt`, rejects bad tokens with `OAuthError(OAuthErrorCode.InvalidToken)`. Plain exception becomes HTTP 500.\n- [ ] Tool callbacks get tenant\u002Fuser permissions from `ctx.http?.authInfo`, return `{ isError: true, content: [...] }` on authorization failure.\n- [ ] Express hosts use `@modelcontextprotocol\u002Fexpress` (`requireBearerAuth`, `mcpAuthMetadataRouter`); web-standard fetch hosts use `requireBearerAuth` + `oauthMetadataResponse` from `@modelcontextprotocol\u002Fserver`.\n\n```ts\n\u002F\u002F web-standard fetch host (Cloudflare Workers, Hono, Bun, Deno)\nimport { oauthMetadataResponse, requireBearerAuth } from '@modelcontextprotocol\u002Fserver';\n\nexport default {\n  async fetch(req: Request): Promise\u003CResponse> {\n    const meta = await oauthMetadataResponse(req, {\n      oauthMetadata,\n      resourceServerUrl: mcpServerUrl,\n    });\n    if (meta) return meta; \u002F\u002F RFC 9728 protected-resource \u002F RFC 8414 AS metadata\n    \u002F\u002F ...route to handler; requireBearerAuth(req) returns AuthInfo or a 401 challenge Response\n  },\n};\n```\n\n## Authenticate a service client\n\nUse `ClientCredentialsProvider` for service with client secret. Use `PrivateKeyJwtProvider` when authorization server requires private-key client authentication:\n\n```ts\nnew ClientCredentialsProvider({ clientId, clientSecret, expectedIssuer });\nnew PrivateKeyJwtProvider({\n  clientId,\n  privateKey,\n  algorithm: 'RS256',\n  jwtLifetimeSeconds: 300,\n});\n```\n\n`expectedIssuer` pins `ClientCredentialsProvider` credentials; mismatched discovery throws `AuthorizationServerMismatchError`. Other two providers take none.\n\nFor authenticated host session, exchange its assertion with `CrossAppAccessProvider`:\n\n```ts\nnew CrossAppAccessProvider({\n  assertion: async (ctx) =>\n    (await discoverAndRequestJwtAuthGrant({\u002F* issuer\u002Faudience *\u002F})).jwtAuthGrant,\n  clientId,\n  clientSecret,\n});\n```\n\nFor other grant model, implement `OAuthClientProvider` with static `clientMetadata`\u002F`redirectUrl` plus `tokens`\u002F`saveTokens`, `clientInformation`\u002F`saveClientInformation`, `codeVerifier`\u002F`saveCodeVerifier`, `state`, `redirectToAuthorization`, and `saveDiscoveryState`\u002F`discoveryState`. Only `clientInformation(ctx?)` and `saveClientInformation(info, ctx?)` accept optional `ctx`; `saveTokens(tokens)` and `tokens()` take no `ctx` — tokens not issuer-partitioned. Override `validateResourceURL(serverUrl, resource?)` for RFC 8707 resource pinning. Use **Client ID Metadata Document** — stable HTTPS `clientMetadata` URL passed as `clientId` — instead of deprecated `registerClient` (SEP-991).\n\n- [ ] `ClientCredentialsProvider` sets `expectedIssuer` (mismatched discovery throws `AuthorizationServerMismatchError`); `PrivateKeyJwtProvider` and `CrossAppAccessProvider` don't accept it.\n- [ ] `clientInformation` and `saveClientInformation` accept optional `ctx`; `tokens` and `saveTokens` not issuer-partitioned.\n- [ ] Custom provider implements every listed persistence and redirect method, plus resource URL validation when RFC 8707 pinning applies.\n\n## Handle authorization errors\n\n- **OAuth consolidation**: v1 `Invalid*Error` family and `OAUTH_ERRORS` replaced by `OAuthError` + `OAuthErrorCode`; switch `instanceof` to `error.code`.\n- **`InsufficientScopeError`** — two distinct classes: **OAuth** one (`OAuthError(OAuthErrorCode.InsufficientScope)`, surfaced as 403 by `requireBearerAuth` scope enforcement) and separate **transport** class (client-side, SEP-2350), covered in [mcp-client](..\u002Fmcp-client\u002FSKILL.md).\n\n- [ ] Error handling uses `error.code` for consolidated OAuth errors, distinguishes OAuth vs transport `InsufficientScopeError` classes.\n- [ ] Tests use mock issuers from [mcp-test](..\u002Fmcp-test\u002FSKILL.md).\n",{"name":5,"metadata":24,"description":7,"user-invocable":20},{"category":25},"technique","main","534498267dccbe415f22f31fceac9da6771c195f","plugins\u002Fmcp-hub\u002Fskills\u002Fmcp-auth","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace","https:\u002F\u002Fj0hanz-marketplace.vercel.app","https:\u002F\u002Fgithub.com\u002Fj0hanz","linus-johansson-cv-d308be9b73e1.herokuapp.com","2026-11-15 02:42:07",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add j0hanz\u002Fj0hanz-marketplace --skill mcp-auth",{"tool":40,"command":41},"bunx","bunx skills add j0hanz\u002Fj0hanz-marketplace --skill mcp-auth",{"tool":43,"command":44},"pnpm","pnpm dlx skills add j0hanz\u002Fj0hanz-marketplace --skill mcp-auth","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fmcp-hub\u002Fskills\u002Fmcp-auth\u002FSKILL.md",true,[],[49,56,63,70,77,84],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":19},"01M7ABP78JFYBMCXJ9GMETCYZM","unslop","Use when writing or editing prose a person will read, or when text sounds AI-generated.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Funslop\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M7ABP52BNV7NRPNBR6PCNZWC","show-me","Use when asked to show, diagram, or walk through how code fits together or what a change does, or before explaining a multi-file flow in prose.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Fshow-me\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M7ABP3EPN4KFB4HPJNMY31NR","pr","Use when writing or updating a pull request description, or before running `gh pr create`.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Fpr\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7ABP08MXTHPZYTG4HKEP7WQ","commit","Use when writing a commit message, or before running `git commit`.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Fcommit\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M7ABNV9J7DN1AFRBGDBHVBY2","write-specs","Spec a feature's observable behavior. Use when asked for requirements, when a request says what the system should do but not how, or to capture what a built system already guarantees. Not for how to build it (write-plan).","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkbench\u002Fskills\u002Fwrite-specs\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M7ABNPK2GVG8EB3SSEAMK4FZ","write-skills","Write, fix, or audit a skill's frontmatter, trigger description, and body. Use when a skill is asked for, never fires, or fires at the wrong moment. Not for a hook (write-hooks) or the plugin manifest and catalog.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkbench\u002Fskills\u002Fwrite-skills\u002FSKILL.md",[],[]]