nsmcp::ToolRegistry method call (public)

 <instance of nsmcp::ToolRegistry[i]> call context authorizer name \
    arguments

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

Authorize, validate and invoke a registered tool. Check enable state, permissions and question pins before handing arguments to the tool.

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.
name (required)
Name of the configured or registered item to resolve.
arguments (required)
Rooted ns_json typed triples for the tool's JSON argument object.
Returns:
The tool's rooted JSON result; policy and validation failures raise RPC errors.

Testcases:
No testcase defined.
Source code:
:refreshProviders
if {![dict exists ${:tools} $name]} {
    return -code error -errorcode {NSMCP RPC -32602} "Unknown tool"
}
set tool [dict get ${:tools} $name]
if {![$tool dependenciesPresent]} {
    return -code error -errorcode {NSMCP RPC -32602} "Unknown tool"
}
$authorizer require $context [$tool permission]
if {![:readEnabled $name]} {
    return -code error -errorcode {NSMCP RPC -32602} "Tool is disabled on this server"
}
:verifyQuestionPin $context $name
$tool validate $arguments
if {[catch {
    set saved {}
    if {$name eq "log_results" && [$context cget -questionRestricted]
        && [$context cget -questionEvent] ne {}
        && [llength [lindex $arguments 2]] == 3
        && [lrange [lindex $arguments 2] 0 1] eq {jobHandle string}} {
        set callback [$context cget -questionEvent]
        set saved [{*}$callback [dict create type retainedSummary jobHandle [lindex $arguments 2 2]]]
    }
    if {[llength $saved] == 3 && [lindex $saved 1] eq "object"} {
        set saved
    } else {
        $tool execute $context $arguments
    }
} result options]} {
    if {[lrange [dict get $options -errorcode] 0 1] eq {NSMCP RPC}} {
        return -options $options $result
    }
    set diagnostic [dict create tool $name message $result  errorCode [dict get $options -errorcode] errorInfo [dict get $options -errorinfo]]
    ns_log error "nsmcp: tool execution failed: $name [string map [list \r {\r} \n {\n}] $diagnostic]"
    return [list {} object {content array {0 object {type string text text string {Tool execution failed; consult the server log.}}} isError boolean true}]
}
if {$name eq "episode_overview" && [info exists ::nsmcp::buildHash]} {
    lset result 2 [concat [lindex $result 2] [list buildHash string $::nsmcp::buildHash]]
}
# A full overview has large native-event and disk arrays. Sending it
# as structuredContent alongside a second JSON text block can exhaust
# a question model's tool-result budget before it sees the pool arrays.
# Give question models one compact, standard MCP text result. Direct
# MCP clients continue to receive both complete representations.
if {$name eq "episode_overview" && [$context cget -questionRestricted]} {
    set fallback [ns_json value -- [:episodeQuestionResult $result]]
    return [list {} object [list content array [list 0 object [list type string text text string $fallback]]  isError boolean false]]
}
set fallback [ns_json value -- $result]
return [list {} object [list structuredContent object [lindex $result 2]  content array [list 0 object [list type string text text string $fallback]]  isError boolean false]]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: