java.lang.Object
com.agentforge4j.testkit.tool.ScriptedToolProvider
- All Implemented Interfaces:
ToolProvider
A deterministic, in-process
ToolProvider for tests: it advertises a single capability and
— depending on the factory — returns a fixed ToolResult, throws, or blocks until
interrupted, with no network transport. Use it to drive the runtime tool-governance path
(resolve → validate → policy → invoke, the approval / decision suspend-resume branches, and the
provider-crash / authoritative-timeout failure arms) without standing up an MCP server.-
Constructor Summary
ConstructorsConstructorDescriptionScriptedToolProvider(String providerId, String capability, ToolResult result, String inputSchema) Creates a provider serving one capability with a fixed result and an explicit input schema (used to drive the argument-validation branch of the governance chokepoint). -
Method Summary
Modifier and TypeMethodDescriptionstatic ScriptedToolProviderCreates a provider whose capability fails with the given message (drives the decision-on-failure path toAWAITING_TOOL_DECISION).static ScriptedToolProviderCreates a provider whose capability blocks until interrupted — driving the authoritative-timeout arm of the governance chokepoint.health()invoke(ToolDescriptor descriptor, String arguments, ToolInvocationContext ctx, ToolExecutionOptions options) Invokes the resolved tool.static ScriptedToolProviderCreates a succeeding provider that advertisesrequiredPropertyas a required top-level input field, so aTOOL_INVOCATIONwhose arguments omit it fails argument validation and drives the run toAWAITING_TOOL_DECISIONbefore the provider is ever invoked.static ScriptedToolProvidersucceeding(String providerId, String capability, String output) Creates a provider whose capability succeeds with the given output.static ScriptedToolProviderthrowing(String providerId, String capability, RuntimeException failure) Creates a provider whose capability throws frominvokeinstead of returning a result — driving the execution-exception arm of the governance chokepoint (a provider bug or transport crash), which a result-failure cannot reach.
-
Constructor Details
-
ScriptedToolProvider
public ScriptedToolProvider(String providerId, String capability, ToolResult result, String inputSchema) Creates a provider serving one capability with a fixed result and an explicit input schema (used to drive the argument-validation branch of the governance chokepoint).- Parameters:
providerId- stable provider id; must not be blankcapability- the capability id; must not be blankresult- the result returned on every invocation; must not benullinputSchema- the JSON-schema text advertised for the capability; must not be blank
-
-
Method Details
-
succeeding
Creates a provider whose capability succeeds with the given output.- Parameters:
providerId- stable provider idcapability- the capability idoutput- the success output payload- Returns:
- a succeeding provider
-
requiring
public static ScriptedToolProvider requiring(String providerId, String capability, String output, String requiredProperty) Creates a succeeding provider that advertisesrequiredPropertyas a required top-level input field, so aTOOL_INVOCATIONwhose arguments omit it fails argument validation and drives the run toAWAITING_TOOL_DECISIONbefore the provider is ever invoked.- Parameters:
providerId- stable provider idcapability- the capability idoutput- the success output payload (returned only if validation passed)requiredProperty- the input property the capability requires- Returns:
- a succeeding provider with a required-field input schema
-
failing
public static ScriptedToolProvider failing(String providerId, String capability, String errorMessage) Creates a provider whose capability fails with the given message (drives the decision-on-failure path toAWAITING_TOOL_DECISION).- Parameters:
providerId- stable provider idcapability- the capability iderrorMessage- the failure message- Returns:
- a failing provider
-
throwing
public static ScriptedToolProvider throwing(String providerId, String capability, RuntimeException failure) Creates a provider whose capability throws frominvokeinstead of returning a result — driving the execution-exception arm of the governance chokepoint (a provider bug or transport crash), which a result-failure cannot reach.- Parameters:
providerId- stable provider idcapability- the capability idfailure- the exception thrown on every invocation; must not benull- Returns:
- a throwing provider
-
hanging
Creates a provider whose capability blocks until interrupted — driving the authoritative-timeout arm of the governance chokepoint. Pair it with a shortToolExecutionOptionstimeout on the harness so the test stays fast; the execution service cancels the invocation, which interrupts and releases the blocked call.- Parameters:
providerId- stable provider idcapability- the capability id- Returns:
- a hanging provider
-
providerId
- Specified by:
providerIdin interfaceToolProvider- Returns:
- stable, non-blank provider id, for example
"mcp:github-official"
-
listTools
- Specified by:
listToolsin interfaceToolProvider- Returns:
- descriptors for every tool this provider currently exposes
-
invoke
public ToolResult invoke(ToolDescriptor descriptor, String arguments, ToolInvocationContext ctx, ToolExecutionOptions options) Description copied from interface:ToolProviderInvokes the resolved tool.- Specified by:
invokein interfaceToolProvider- Parameters:
descriptor- resolved descriptor; useToolSource.remoteToolName()for the remote namearguments- tool arguments as JSON text, ornullctx- invocation contextoptions- tunables; the provider may honour these best-effort, but the authoritative timeout is enforced by the execution service- Returns:
- the invocation result
-
health
- Specified by:
healthin interfaceToolProvider- Returns:
- current provider health
-