nsmcp::ToolRegistry method questionSnapshot (public)

 <instance of nsmcp::ToolRegistry[i]> questionSnapshot context \
    authorizer

Defined in /usr/local/ns/tcl/nsmcp/01-tools.tcl

Pin the permitted tool inventory for a new question. Apply request authorization and question allowlists; outbound upstream comparison additionally requires its configured provider and switches.

Parameters:
context (required)
Authenticated request context carrying the principal, grants and selected server.
authorizer (required)
Authorizer used to enforce the request context's permissions and targets.
Returns:
A dictionary mapping allowed tool names to descriptor fingerprints.

Testcases:
No testcase defined.
Source code:
set pins {}
set listed [:list $context $authorizer]
foreach {index type members} [ns_json triples getvalue -output triples -path tools -- $listed] {
    set metadata [ns_json parse [ns_json value -- [list {} object $members]]]
    if {![dict exists $metadata annotations readOnlyHint] || ![dict get $metadata annotations readOnlyHint]} {
        continue
    }
    set name [dict get $metadata name]
    if {$name ni [::nsmcp::questionAllowedTools]} {
        continue
    }
    if {![dict exists $metadata annotations destructiveHint] || [dict get $metadata annotations destructiveHint]
        || ![dict exists $metadata annotations openWorldHint]} {
        continue
    }
    if {[dict get $metadata annotations openWorldHint]} {
        # This one outbound tool has a fixed GitHub transport and
        # administrator-owned repository mappings. All other external
        # tools remain excluded from question execution.
        if {$name ne "code_upstream_compare"
            || ![nsf::is object,type=::nsmcp::CodeUpstreamTool [dict get ${:tools} $name]]
            || ![ns_config -bool ns/server/[ns_info server]/module/nsmcp enableCodeTools false]
            || ![ns_config -bool ns/server/[ns_info server]/module/nsmcp enableCodeUpstream false]} {
            continue
        }
    }
    if {[dict size $pins]>=256 || [string bytelength $name]>128} {
        error "Question tool inventory exceeds limit"
    }
    dict set pins $name [:fingerprint $name]
}
if {$pins eq {}} {
    error "No permitted read-only question tools are available"
}
return $pins
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: