Support Skills authorization without cross-package dependencies

未關閉
#1,990 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
csharp

研究方向

Start by reading the Core hosting primitive-filter composition and the existing AddAuthorizationFilters policy evaluator, then trace how Skills composes skills/list and skills/get handlers. The issue requires a shared hook that preserves existing authorization checkpoints, request services, and Tasks dispatch order while avoiding package dependency changes. Done means the acceptance criteria pass, including Native AOT compatibility and no new package dependency.

由索引模型根據 Issue 內容生成。

描述

P3

Problem

The registered-Skills/typed-handler design associated with #1863 should participate in AddAuthorizationFilters. Authorizing the file resources alone does not protect the frontmatter and manifests exposed by skills/list and skills/get. Wrapping the optional custom Skills handlers is insufficient: registered entries augment the list afterward, and matched registered gets take precedence over the fallback.

Applications should be able to use WithSkills(...) plus AddAuthorizationFilters() with their existing ASP.NET authorization services, without a separate integration registration or package. ModelContextProtocol.AspNetCore must not reference Skills, and Skills must not acquire an ASP.NET authorization dependency.

Recommended approach

Add a small, experimental, policy-neutral primitive-filter seam in Core/hosting over IMcpServerPrimitive and its server-local metadata. It needs a typed invocation hook around the complete composed handler after matching, plus a listing-visibility hook for entries mapped to registered primitives. A McpServerPrimitiveFilter-style contract is illustrative; this does not require a new catalog abstraction or a large generic framework.

AddAuthorizationFilters registers an adapter that reuses its existing policy evaluator. Skills owns the protocol-specific matching and list projection and consumes the shared hook automatically. Keep the existing tool/prompt/resource typed adapters at their current checkpoints rather than replacing them with a single outer filter: intervening filters can change the principal or matched primitive, and tool authorization must still precede Tasks dispatch.

Expected behavior and acceptance criteria

  • WithSkills and AddAuthorizationFilters work in either registration order, with no additional application integration step or cross-package dependency.
  • Protected registered entries are omitted from the complete composed listing. Registered gets are matched and authorized before dispatch, including URI-equivalent requests; denial never falls through to the custom handler. Authorized direct get/read does not depend on listing membership.
  • Reuse the existing IAuthorizeData, explicit AuthorizationPolicy, IAuthorizationRequirementData, and IAllowAnonymous behavior. Unprotected/anonymous entries remain usable; missing authorization services or filters produce actionable local diagnostics rather than silently exposing protected entries.
  • Preserve repeated authorization checkpoints around changes to the user or matched primitive, existing typed-filter order, and denial before task creation.
  • Resolve authorization services from context.Services and use context.User. Reuse stateless HTTP's HttpContext.RequestServices and existing MCP request scopes/disposal; do not manufacture scopes or capture request services in shared filters.
  • Preserve Skills snapshots, validation, initial-null-cursor augmentation, registered-get precedence, conservative get defaults, protocol-version handling, and source-generated/Native AOT compatibility.

Boundaries and open decision

Custom database entries without registered primitive metadata remain application-owned: authorize before pagination and cursor construction, and authorize direct get/read independently. A generic post-page filter cannot sanitize an arbitrary application cursor. Do not load a whole database source or mutate shared registrations per caller to compensate.

Skill files remain ordinary resources with separately applied corresponding policies, especially when files are shared. Do not implicitly copy/merge skill metadata onto files or add automatic file revocation when a skill is removed.

The prototype preserves handler-supplied cache hints. Caller-dependent results must not be reused through public caching; decide whether authorization filtering should constrain/reject public hints or leave that enforcement with the application.

A local-only prototype exercised composed Skills list/get, stateless HTTP service identity and async disposal, policy/guard parity, repeated checkpoints, and pre-Tasks authorization, and built and ran under Native AOT without changing the package dependency graph. The recommendation is the small shared seam, not shipping the prototype verbatim. Related: #1941 for request-service integration and #1704 for broader extension-handler composition.

[!NOTE]
This issue was generated by GitHub Copilot from a local prototype at the maintainer's request.

主要語言
C#
星號
4.6k
分支
849
平均合併
1 天 16 小時
30 天內合併 PR
24

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/csharp-sdk 的其他 Issue

查看 modelcontextprotocol/csharp-sdk 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。