-
-
Notifications
You must be signed in to change notification settings - Fork 6
Generate a PRM inside the MCP generated manifest #1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -161,4 +161,68 @@ auto generate_mcp_tools(const sourcemeta::core::URITemplateRouterView &router, | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // TODO: Compose this through a proper RFC 9728 implementation in Core, rather | ||||||||||
| // than assembling the few fields this instance happens to need by hand | ||||||||||
| auto generate_protected_resource_metadata( | ||||||||||
| const sourcemeta::one::Authentication &authentication, | ||||||||||
| const sourcemeta::one::Configuration &configuration, | ||||||||||
| const std::string_view endpoint, sourcemeta::core::JSON &result) -> void { | ||||||||||
| std::string resource{configuration.url}; | ||||||||||
| if (!resource.empty() && resource.back() == '/') { | ||||||||||
| resource.pop_back(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| resource.append(endpoint); | ||||||||||
|
|
||||||||||
| // RFC 9728 Section 1.2 defines a resource identifier as an https URL, and a | ||||||||||
| // client is entitled to reject anything else. Loopback is the exception this | ||||||||||
| // project already makes elsewhere, so that a local instance stays testable | ||||||||||
| const sourcemeta::core::URI resource_uri{resource}; | ||||||||||
| if (!resource_uri.is_https() && | ||||||||||
| !(resource_uri.is_http() && | ||||||||||
| (resource_uri.is_loopback() || resource_uri.is_localhost()))) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // A client that reads this asks its provider for a token bound to the | ||||||||||
| // resource below, so an issuer whose policy expects a different audience | ||||||||||
| // would mint one this instance refuses. Only an issuer whose policy accepts | ||||||||||
| // that audience can be named without sending the client into a rejection | ||||||||||
| auto servers{sourcemeta::core::JSON::make_array()}; | ||||||||||
| for (const auto index : authentication.governing( | ||||||||||
| sourcemeta::one::Authentication::Path::relative(endpoint))) { | ||||||||||
| assert(index < configuration.authentication.size()); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This bounds check relies solely on Prompt for AI agents
Suggested change
|
||||||||||
| const auto &entry{configuration.authentication[index]}; | ||||||||||
| if (entry.type != | ||||||||||
| sourcemeta::one::Configuration::AuthenticationEntry::Type::JWT || | ||||||||||
| entry.audience != resource) { | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // A policy that names its keys outright is never asked to discover | ||||||||||
| // anything, so nothing has established that its issuer is the https | ||||||||||
| // identifier RFC 8414 expects. Advertising it unchecked would publish an | ||||||||||
| // authorization server a client cannot use | ||||||||||
| if (!sourcemeta::core::URI{entry.issuer}.is_https()) { | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| sourcemeta::core::JSON issuer{entry.issuer}; | ||||||||||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||||||||||
| if (!servers.contains(issuer)) { | ||||||||||
| servers.push_back(std::move(issuer)); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (servers.empty()) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| result = sourcemeta::core::JSON::make_object(); | ||||||||||
| result.assign("resource", sourcemeta::core::JSON{std::move(resource)}); | ||||||||||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||||||||||
| result.assign("authorization_servers", std::move(servers)); | ||||||||||
| auto bearer_methods{sourcemeta::core::JSON::make_array()}; | ||||||||||
| bearer_methods.push_back(sourcemeta::core::JSON{"header"}); | ||||||||||
| result.assign("bearer_methods_supported", std::move(bearer_methods)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } // namespace sourcemeta::one | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #ifndef SOURCEMETA_ONE_INDEX_ENDPOINTS_H | ||
| #define SOURCEMETA_ONE_INDEX_ENDPOINTS_H | ||
|
|
||
| #include <string_view> // std::string_view | ||
|
|
||
| namespace sourcemeta::one { | ||
|
|
||
| // Every route this instance serves, as a URI template relative to the instance | ||
| // root. The router is populated from here, and whatever else has to name the | ||
| // same endpoint reads it from here rather than spelling it again | ||
|
|
||
| inline constexpr std::string_view ENDPOINT_LIST_DIRECTORY{ | ||
| "/self/v1/api/list{/path*}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_DEPENDENCIES{ | ||
| "/self/v1/api/schemas/dependencies/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_DEPENDENTS{ | ||
| "/self/v1/api/schemas/dependents/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_HEALTH{ | ||
| "/self/v1/api/schemas/health/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_LOCATIONS{ | ||
| "/self/v1/api/schemas/locations/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_POSITIONS{ | ||
| "/self/v1/api/schemas/positions/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_STATS{ | ||
| "/self/v1/api/schemas/stats/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_METADATA{ | ||
| "/self/v1/api/schemas/metadata/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_EVALUATE{ | ||
| "/self/v1/api/schemas/evaluate/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_RDF{ | ||
| "/self/v1/api/schemas/rdf/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_TRACE{ | ||
| "/self/v1/api/schemas/trace/{+schema}"}; | ||
| inline constexpr std::string_view ENDPOINT_SCHEMA_SEARCH{ | ||
| "/self/v1/api/schemas/search"}; | ||
| inline constexpr std::string_view ENDPOINT_HEALTH{"/self/v1/health"}; | ||
| inline constexpr std::string_view ENDPOINT_AUTH_LOGOUT{"/self/v1/auth/logout"}; | ||
| inline constexpr std::string_view ENDPOINT_AUTH_LOGIN{ | ||
| "/self/v1/auth/login/{policy}"}; | ||
| inline constexpr std::string_view ENDPOINT_AUTH_CALLBACK{ | ||
| "/self/v1/auth/callback/{policy}"}; | ||
| inline constexpr std::string_view ENDPOINT_MCP{"/self/v1/mcp"}; | ||
| // Clients that normalise URLs by appending a slash reach the same handler | ||
| inline constexpr std::string_view ENDPOINT_MCP_TRAILING_SLASH{"/self/v1/mcp/"}; | ||
| inline constexpr std::string_view ENDPOINT_API_NOT_FOUND{"/self/v1/api/{+any}"}; | ||
| inline constexpr std::string_view ENDPOINT_STATIC{"/self/v1/static/{+path}"}; | ||
|
|
||
| } // namespace sourcemeta::one | ||
|
|
||
| #endif |
Uh oh!
There was an error while loading. Please reload this page.