@mcpc-tech/cli 0.1.29 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mcpc.cjs +395 -2947
- package/bin/mcpc.mjs +393 -2945
- package/package.json +2 -1
package/bin/mcpc.cjs
CHANGED
|
@@ -502,7 +502,7 @@ var require_cross_spawn = __commonJS({
|
|
|
502
502
|
var cp = require("child_process");
|
|
503
503
|
var parse = require_parse();
|
|
504
504
|
var enoent = require_enoent();
|
|
505
|
-
function
|
|
505
|
+
function spawn2(command, args, options) {
|
|
506
506
|
const parsed = parse(command, args, options);
|
|
507
507
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
508
508
|
enoent.hookChildProcess(spawned, parsed);
|
|
@@ -514,8 +514,8 @@ var require_cross_spawn = __commonJS({
|
|
|
514
514
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
515
515
|
return result;
|
|
516
516
|
}
|
|
517
|
-
module2.exports =
|
|
518
|
-
module2.exports.spawn =
|
|
517
|
+
module2.exports = spawn2;
|
|
518
|
+
module2.exports.spawn = spawn2;
|
|
519
519
|
module2.exports.sync = spawnSync;
|
|
520
520
|
module2.exports._parse = parse;
|
|
521
521
|
module2.exports._enoent = enoent;
|
|
@@ -5085,17 +5085,17 @@ var Client = class extends Protocol {
|
|
|
5085
5085
|
this._cachedToolOutputValidators.clear();
|
|
5086
5086
|
this._cachedKnownTaskTools.clear();
|
|
5087
5087
|
this._cachedRequiredTaskTools.clear();
|
|
5088
|
-
for (const
|
|
5089
|
-
if (
|
|
5090
|
-
const toolValidator = this._jsonSchemaValidator.getValidator(
|
|
5091
|
-
this._cachedToolOutputValidators.set(
|
|
5088
|
+
for (const tool2 of tools) {
|
|
5089
|
+
if (tool2.outputSchema) {
|
|
5090
|
+
const toolValidator = this._jsonSchemaValidator.getValidator(tool2.outputSchema);
|
|
5091
|
+
this._cachedToolOutputValidators.set(tool2.name, toolValidator);
|
|
5092
5092
|
}
|
|
5093
|
-
const taskSupport =
|
|
5093
|
+
const taskSupport = tool2.execution?.taskSupport;
|
|
5094
5094
|
if (taskSupport === "required" || taskSupport === "optional") {
|
|
5095
|
-
this._cachedKnownTaskTools.add(
|
|
5095
|
+
this._cachedKnownTaskTools.add(tool2.name);
|
|
5096
5096
|
}
|
|
5097
5097
|
if (taskSupport === "required") {
|
|
5098
|
-
this._cachedRequiredTaskTools.add(
|
|
5098
|
+
this._cachedRequiredTaskTools.add(tool2.name);
|
|
5099
5099
|
}
|
|
5100
5100
|
}
|
|
5101
5101
|
}
|
|
@@ -7420,14 +7420,14 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
7420
7420
|
acquiredKeys.push(defKey);
|
|
7421
7421
|
allClients[serverId] = client;
|
|
7422
7422
|
const { tools } = await client.listTools();
|
|
7423
|
-
tools.forEach((
|
|
7424
|
-
const toolNameWithScope = `${name}.${
|
|
7425
|
-
const internalToolName =
|
|
7423
|
+
tools.forEach((tool2) => {
|
|
7424
|
+
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
7425
|
+
const internalToolName = tool2.name;
|
|
7426
7426
|
const rawToolId = `${serverId}_${internalToolName}`;
|
|
7427
7427
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
7428
7428
|
if (filterIn && !filterIn({
|
|
7429
7429
|
action: internalToolName,
|
|
7430
|
-
tool:
|
|
7430
|
+
tool: tool2,
|
|
7431
7431
|
mcpName: name,
|
|
7432
7432
|
toolNameWithScope,
|
|
7433
7433
|
internalToolName,
|
|
@@ -7442,7 +7442,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
7442
7442
|
timeout: def.toolCallTimeout
|
|
7443
7443
|
});
|
|
7444
7444
|
allTools[toolId] = {
|
|
7445
|
-
...
|
|
7445
|
+
...tool2,
|
|
7446
7446
|
execute,
|
|
7447
7447
|
_originalName: toolNameWithScope
|
|
7448
7448
|
};
|
|
@@ -7505,13 +7505,13 @@ var createConfigPlugin = () => ({
|
|
|
7505
7505
|
name: "built-in-config",
|
|
7506
7506
|
version: "1.0.0",
|
|
7507
7507
|
enforce: "pre",
|
|
7508
|
-
transformTool: (
|
|
7508
|
+
transformTool: (tool2, context2) => {
|
|
7509
7509
|
const server = context2.server;
|
|
7510
7510
|
const config = server.findToolConfig?.(context2.toolName);
|
|
7511
7511
|
if (config?.description) {
|
|
7512
|
-
|
|
7512
|
+
tool2.description = config.description;
|
|
7513
7513
|
}
|
|
7514
|
-
return
|
|
7514
|
+
return tool2;
|
|
7515
7515
|
}
|
|
7516
7516
|
});
|
|
7517
7517
|
var config_plugin_default = createConfigPlugin();
|
|
@@ -7521,10 +7521,10 @@ var createToolNameMappingPlugin = () => ({
|
|
|
7521
7521
|
name: "built-in-tool-name-mapping",
|
|
7522
7522
|
version: "1.0.0",
|
|
7523
7523
|
enforce: "pre",
|
|
7524
|
-
transformTool: (
|
|
7524
|
+
transformTool: (tool2, context2) => {
|
|
7525
7525
|
const server = context2.server;
|
|
7526
7526
|
const toolName = context2.toolName;
|
|
7527
|
-
const originalName =
|
|
7527
|
+
const originalName = tool2._originalName || toolName;
|
|
7528
7528
|
const dotNotation = originalName.replace(/_/g, ".");
|
|
7529
7529
|
const underscoreNotation = originalName.replace(/\./g, "_");
|
|
7530
7530
|
if (dotNotation !== originalName && server.toolNameMapping) {
|
|
@@ -7536,7 +7536,7 @@ var createToolNameMappingPlugin = () => ({
|
|
|
7536
7536
|
if (originalName !== toolName && server.toolNameMapping) {
|
|
7537
7537
|
server.toolNameMapping.set(originalName, toolName);
|
|
7538
7538
|
}
|
|
7539
|
-
return
|
|
7539
|
+
return tool2;
|
|
7540
7540
|
}
|
|
7541
7541
|
});
|
|
7542
7542
|
var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
|
|
@@ -7687,7 +7687,7 @@ You must follow the <manual/>, obey the <rules/>, and use the <format/>.
|
|
|
7687
7687
|
|
|
7688
7688
|
<parameters>
|
|
7689
7689
|
\`tool\` - Which tool to execute: "man" to get schemas, or a tool name to execute
|
|
7690
|
-
\`args\` - For "man":
|
|
7690
|
+
\`args\` - For "man": { tools: ["tool1", "tool2"] }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.
|
|
7691
7691
|
</parameters>
|
|
7692
7692
|
|
|
7693
7693
|
<rules>
|
|
@@ -7702,7 +7702,7 @@ Get tool schemas:
|
|
|
7702
7702
|
\`\`\`json
|
|
7703
7703
|
{
|
|
7704
7704
|
"tool": "man",
|
|
7705
|
-
"args": ["tool1", "tool2"]
|
|
7705
|
+
"args": { "tools": ["tool1", "tool2"] }
|
|
7706
7706
|
}
|
|
7707
7707
|
\`\`\`
|
|
7708
7708
|
|
|
@@ -7714,80 +7714,6 @@ Execute a tool:
|
|
|
7714
7714
|
}
|
|
7715
7715
|
\`\`\`
|
|
7716
7716
|
</format>`,
|
|
7717
|
-
/**
|
|
7718
|
-
* Tool-based execution system prompt for autonomous sampling mode with native tools
|
|
7719
|
-
*
|
|
7720
|
-
* Note: Used when client supports sampling.tools capability
|
|
7721
|
-
*/
|
|
7722
|
-
SAMPLING_EXECUTION_TOOLS: `Agent \`{toolName}\` that completes tasks by calling tools.
|
|
7723
|
-
|
|
7724
|
-
<manual>
|
|
7725
|
-
{description}
|
|
7726
|
-
</manual>
|
|
7727
|
-
|
|
7728
|
-
<rules>
|
|
7729
|
-
1. Execute one action per iteration
|
|
7730
|
-
2. Adapt based on results from previous actions
|
|
7731
|
-
3. Continue until task is complete
|
|
7732
|
-
</rules>
|
|
7733
|
-
|
|
7734
|
-
<tools>
|
|
7735
|
-
{toolList}
|
|
7736
|
-
</tools>`,
|
|
7737
|
-
/**
|
|
7738
|
-
* JSON-only execution system prompt for autonomous sampling mode
|
|
7739
|
-
*
|
|
7740
|
-
* Note: Sampling mode runs an internal LLM loop that autonomously calls tools until complete.
|
|
7741
|
-
*/
|
|
7742
|
-
SAMPLING_EXECUTION: `Agent \`{toolName}\` that completes tasks by calling tools in an autonomous loop.
|
|
7743
|
-
|
|
7744
|
-
<manual>
|
|
7745
|
-
{description}
|
|
7746
|
-
</manual>
|
|
7747
|
-
|
|
7748
|
-
<rules>
|
|
7749
|
-
1. **YOUR ENTIRE RESPONSE MUST BE A SINGLE JSON OBJECT** - no text before or after
|
|
7750
|
-
2. Execute one tool per iteration
|
|
7751
|
-
3. Specify which tool to use with \`useTool\`
|
|
7752
|
-
4. Adapt based on results from previous actions
|
|
7753
|
-
5. Continue until task is complete
|
|
7754
|
-
</rules>
|
|
7755
|
-
|
|
7756
|
-
<format>
|
|
7757
|
-
CORRECT:
|
|
7758
|
-
\`\`\`json
|
|
7759
|
-
{"useTool": "tool_name", "decision": "proceed", "tool_name": {...}}
|
|
7760
|
-
\`\`\`
|
|
7761
|
-
|
|
7762
|
-
WRONG - No explanations:
|
|
7763
|
-
\`\`\`
|
|
7764
|
-
I will list the directory
|
|
7765
|
-
{"useTool": "list_directory", ...}
|
|
7766
|
-
\`\`\`
|
|
7767
|
-
|
|
7768
|
-
During execution:
|
|
7769
|
-
\`\`\`json
|
|
7770
|
-
{
|
|
7771
|
-
"useTool": "tool_name",
|
|
7772
|
-
"decision": "proceed",
|
|
7773
|
-
"tool_name": { /* tool parameters */ }
|
|
7774
|
-
}
|
|
7775
|
-
\`\`\`
|
|
7776
|
-
|
|
7777
|
-
When complete:
|
|
7778
|
-
\`\`\`json
|
|
7779
|
-
{ "decision": "complete" }
|
|
7780
|
-
\`\`\`
|
|
7781
|
-
|
|
7782
|
-
Decisions:
|
|
7783
|
-
- \`proceed\` = action succeeded, continue
|
|
7784
|
-
- \`retry\` = action failed, try again
|
|
7785
|
-
- \`complete\` = task finished
|
|
7786
|
-
</format>
|
|
7787
|
-
|
|
7788
|
-
<tools>
|
|
7789
|
-
{toolList}
|
|
7790
|
-
</tools>`,
|
|
7791
7717
|
/**
|
|
7792
7718
|
* Tool description for sampling tools (shown in MCP tools list)
|
|
7793
7719
|
* Explains how to use prompt and context parameters
|
|
@@ -7809,7 +7735,21 @@ You must follow the <manual/>, obey the <rules/>, and use the <format/>.
|
|
|
7809
7735
|
1. Always provide both \`prompt\` and \`context\` parameters
|
|
7810
7736
|
2. \`prompt\` must be a clear, actionable description
|
|
7811
7737
|
3. \`context\` must include relevant environment info (e.g., working directory)
|
|
7812
|
-
</rules
|
|
7738
|
+
</rules>`,
|
|
7739
|
+
/**
|
|
7740
|
+
* System prompt for AI sampling loop (ai_sampling/ai_acp modes)
|
|
7741
|
+
* Used inside the execution loop when AI calls native tools.
|
|
7742
|
+
* Note: Tool schemas are passed via AI SDK native tool calling, not in prompt.
|
|
7743
|
+
*/
|
|
7744
|
+
AI_LOOP_SYSTEM: `Agent \`{toolName}\` that completes tasks by calling tools.
|
|
7745
|
+
|
|
7746
|
+
<manual>
|
|
7747
|
+
{description}
|
|
7748
|
+
</manual>
|
|
7749
|
+
|
|
7750
|
+
<rules>
|
|
7751
|
+
{rules}
|
|
7752
|
+
</rules>{context}`
|
|
7813
7753
|
};
|
|
7814
7754
|
var ResponseTemplates = {
|
|
7815
7755
|
/**
|
|
@@ -7850,9 +7790,8 @@ Adjust parameters and retry.`,
|
|
|
7850
7790
|
};
|
|
7851
7791
|
var CompiledPrompts = {
|
|
7852
7792
|
autonomousExecution: p(SystemPrompts.AUTONOMOUS_EXECUTION),
|
|
7853
|
-
samplingExecution: p(SystemPrompts.SAMPLING_EXECUTION),
|
|
7854
|
-
samplingExecutionTools: p(SystemPrompts.SAMPLING_EXECUTION_TOOLS),
|
|
7855
7793
|
samplingToolDescription: p(SystemPrompts.SAMPLING_TOOL_DESCRIPTION),
|
|
7794
|
+
aiLoopSystem: p(SystemPrompts.AI_LOOP_SYSTEM),
|
|
7856
7795
|
actionSuccess: p(ResponseTemplates.ACTION_SUCCESS),
|
|
7857
7796
|
planningPrompt: p(ResponseTemplates.PLANNING_PROMPT),
|
|
7858
7797
|
errorResponse: p(ResponseTemplates.ERROR_RESPONSE),
|
|
@@ -7862,6 +7801,106 @@ var CompiledPrompts = {
|
|
|
7862
7801
|
completionMessage: () => ResponseTemplates.COMPLETION_MESSAGE
|
|
7863
7802
|
};
|
|
7864
7803
|
|
|
7804
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/factories/args-def-factory.js
|
|
7805
|
+
function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps, _ensureStepActions) {
|
|
7806
|
+
return {
|
|
7807
|
+
forSampling: function() {
|
|
7808
|
+
return {
|
|
7809
|
+
type: "object",
|
|
7810
|
+
description: "Provide prompt for autonomous tool execution",
|
|
7811
|
+
properties: {
|
|
7812
|
+
prompt: {
|
|
7813
|
+
type: "string",
|
|
7814
|
+
description: "The task to be completed autonomously by the agentic system using available tools"
|
|
7815
|
+
},
|
|
7816
|
+
context: {
|
|
7817
|
+
type: "object",
|
|
7818
|
+
description: "Execution context, e.g., { cwd: '/path/to/dir' }. Any relevant fields allowed.",
|
|
7819
|
+
additionalProperties: true
|
|
7820
|
+
}
|
|
7821
|
+
},
|
|
7822
|
+
required: [
|
|
7823
|
+
"prompt",
|
|
7824
|
+
"context"
|
|
7825
|
+
],
|
|
7826
|
+
errorMessage: {
|
|
7827
|
+
required: {
|
|
7828
|
+
prompt: "Missing required field 'prompt'. Please provide a clear task description.",
|
|
7829
|
+
context: "Missing required field 'context'. Please provide relevant context (e.g., { cwd: '...' })."
|
|
7830
|
+
}
|
|
7831
|
+
}
|
|
7832
|
+
};
|
|
7833
|
+
},
|
|
7834
|
+
/**
|
|
7835
|
+
* Agentic schema - simplified Unix-style interface
|
|
7836
|
+
*
|
|
7837
|
+
* Only two fields:
|
|
7838
|
+
* - `tool`: which tool to execute (enum includes "man" + all tool names)
|
|
7839
|
+
* - `args`: object with parameters. For "man": { tools: ["a", "b"] }. For others: tool parameters.
|
|
7840
|
+
*/
|
|
7841
|
+
forAgentic: function(allToolNames) {
|
|
7842
|
+
const toolEnum = [
|
|
7843
|
+
"man",
|
|
7844
|
+
...allToolNames
|
|
7845
|
+
];
|
|
7846
|
+
return {
|
|
7847
|
+
type: "object",
|
|
7848
|
+
properties: {
|
|
7849
|
+
tool: {
|
|
7850
|
+
type: "string",
|
|
7851
|
+
enum: toolEnum,
|
|
7852
|
+
description: 'Which tool to execute. Use "man" to get tool schemas, or a tool name to execute.',
|
|
7853
|
+
errorMessage: {
|
|
7854
|
+
enum: `Invalid tool. Available: ${toolEnum.join(", ")}`
|
|
7855
|
+
}
|
|
7856
|
+
},
|
|
7857
|
+
args: {
|
|
7858
|
+
type: "object",
|
|
7859
|
+
description: `For "man": { tools: ["tool1", "tool2"] }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
|
|
7860
|
+
}
|
|
7861
|
+
},
|
|
7862
|
+
required: [
|
|
7863
|
+
"tool"
|
|
7864
|
+
],
|
|
7865
|
+
additionalProperties: false
|
|
7866
|
+
};
|
|
7867
|
+
},
|
|
7868
|
+
/**
|
|
7869
|
+
* Schema for "man" command args validation
|
|
7870
|
+
* Expected format: { tools: ["tool1", "tool2"] }
|
|
7871
|
+
*/
|
|
7872
|
+
forMan: function(allToolNames) {
|
|
7873
|
+
return {
|
|
7874
|
+
type: "object",
|
|
7875
|
+
properties: {
|
|
7876
|
+
tools: {
|
|
7877
|
+
type: "array",
|
|
7878
|
+
items: {
|
|
7879
|
+
type: "string",
|
|
7880
|
+
enum: allToolNames,
|
|
7881
|
+
errorMessage: {
|
|
7882
|
+
enum: `Invalid tool name. Available: ${allToolNames.join(", ")}`
|
|
7883
|
+
}
|
|
7884
|
+
},
|
|
7885
|
+
minItems: 1,
|
|
7886
|
+
errorMessage: {
|
|
7887
|
+
minItems: "At least one tool name is required"
|
|
7888
|
+
}
|
|
7889
|
+
}
|
|
7890
|
+
},
|
|
7891
|
+
required: [
|
|
7892
|
+
"tools"
|
|
7893
|
+
],
|
|
7894
|
+
errorMessage: {
|
|
7895
|
+
required: {
|
|
7896
|
+
tools: 'Missing "tools" field. Expected: { tools: ["tool1", "tool2"] }'
|
|
7897
|
+
}
|
|
7898
|
+
}
|
|
7899
|
+
};
|
|
7900
|
+
}
|
|
7901
|
+
};
|
|
7902
|
+
}
|
|
7903
|
+
|
|
7865
7904
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/schema-validator.js
|
|
7866
7905
|
var import_ajv2 = require("ajv");
|
|
7867
7906
|
var import_ajv_formats2 = __toESM(require("ajv-formats"), 1);
|
|
@@ -8031,24 +8070,11 @@ var AgenticExecutor = class {
|
|
|
8031
8070
|
isError: true
|
|
8032
8071
|
};
|
|
8033
8072
|
}
|
|
8034
|
-
const
|
|
8035
|
-
if (
|
|
8036
|
-
const
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
type: "string",
|
|
8040
|
-
enum: this.allToolNames,
|
|
8041
|
-
errorMessage: {
|
|
8042
|
-
enum: `Invalid tool name. Available: ${this.allToolNames.join(", ")}`
|
|
8043
|
-
}
|
|
8044
|
-
},
|
|
8045
|
-
minItems: 1,
|
|
8046
|
-
errorMessage: {
|
|
8047
|
-
type: 'Expected an array of tool names, e.g. ["tool1", "tool2"]',
|
|
8048
|
-
minItems: "At least one tool name is required"
|
|
8049
|
-
}
|
|
8050
|
-
};
|
|
8051
|
-
const manValidation = validateSchema(args.args ?? [], manSchema);
|
|
8073
|
+
const tool2 = args.tool;
|
|
8074
|
+
if (tool2 === "man") {
|
|
8075
|
+
const createArgsDef = createArgsDefFactory(this.name, this.allToolNames, {});
|
|
8076
|
+
const manSchema = createArgsDef.forMan(this.allToolNames);
|
|
8077
|
+
const manValidation = validateSchema(args.args ?? {}, manSchema);
|
|
8052
8078
|
if (!manValidation.valid) {
|
|
8053
8079
|
return {
|
|
8054
8080
|
content: [
|
|
@@ -8060,10 +8086,11 @@ var AgenticExecutor = class {
|
|
|
8060
8086
|
isError: true
|
|
8061
8087
|
};
|
|
8062
8088
|
}
|
|
8063
|
-
|
|
8089
|
+
const argsObj = args.args;
|
|
8090
|
+
return this.handleManCommand(argsObj.tools, executeSpan);
|
|
8064
8091
|
}
|
|
8065
8092
|
const toolArgs = args.args || {};
|
|
8066
|
-
return await this.executeTool(
|
|
8093
|
+
return await this.executeTool(tool2, toolArgs, executeSpan);
|
|
8067
8094
|
} catch (error) {
|
|
8068
8095
|
if (executeSpan) {
|
|
8069
8096
|
endSpan(executeSpan, error);
|
|
@@ -8123,14 +8150,14 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8123
8150
|
/**
|
|
8124
8151
|
* Execute a tool with runtime validation
|
|
8125
8152
|
*/
|
|
8126
|
-
async executeTool(
|
|
8127
|
-
const externalTool = this.toolNameToDetailList.find(([name]) => name ===
|
|
8153
|
+
async executeTool(tool2, toolArgs, executeSpan) {
|
|
8154
|
+
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
8128
8155
|
if (externalTool) {
|
|
8129
8156
|
const [, toolDetail] = externalTool;
|
|
8130
8157
|
if (executeSpan) {
|
|
8131
8158
|
executeSpan.setAttributes({
|
|
8132
8159
|
toolType: "external",
|
|
8133
|
-
selectedTool:
|
|
8160
|
+
selectedTool: tool2
|
|
8134
8161
|
});
|
|
8135
8162
|
}
|
|
8136
8163
|
if (toolDetail.inputSchema) {
|
|
@@ -8148,7 +8175,7 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8148
8175
|
content: [
|
|
8149
8176
|
{
|
|
8150
8177
|
type: "text",
|
|
8151
|
-
text: `Parameter validation failed for "${
|
|
8178
|
+
text: `Parameter validation failed for "${tool2}": ${validation.error}`
|
|
8152
8179
|
}
|
|
8153
8180
|
],
|
|
8154
8181
|
isError: true
|
|
@@ -8157,7 +8184,7 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8157
8184
|
}
|
|
8158
8185
|
this.logger.debug({
|
|
8159
8186
|
message: "Executing external tool",
|
|
8160
|
-
tool:
|
|
8187
|
+
tool: tool2
|
|
8161
8188
|
});
|
|
8162
8189
|
const result = await toolDetail.execute(toolArgs);
|
|
8163
8190
|
if (executeSpan) {
|
|
@@ -8170,19 +8197,19 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8170
8197
|
}
|
|
8171
8198
|
return result;
|
|
8172
8199
|
}
|
|
8173
|
-
if (this.allToolNames.includes(
|
|
8200
|
+
if (this.allToolNames.includes(tool2)) {
|
|
8174
8201
|
if (executeSpan) {
|
|
8175
8202
|
executeSpan.setAttributes({
|
|
8176
8203
|
toolType: "internal",
|
|
8177
|
-
selectedTool:
|
|
8204
|
+
selectedTool: tool2
|
|
8178
8205
|
});
|
|
8179
8206
|
}
|
|
8180
8207
|
this.logger.debug({
|
|
8181
8208
|
message: "Executing internal tool",
|
|
8182
|
-
tool:
|
|
8209
|
+
tool: tool2
|
|
8183
8210
|
});
|
|
8184
8211
|
try {
|
|
8185
|
-
const result = await this.server.callTool(
|
|
8212
|
+
const result = await this.server.callTool(tool2, toolArgs);
|
|
8186
8213
|
const callToolResult = result ?? {
|
|
8187
8214
|
content: []
|
|
8188
8215
|
};
|
|
@@ -8201,14 +8228,14 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8201
8228
|
}
|
|
8202
8229
|
this.logger.error({
|
|
8203
8230
|
message: "Error executing internal tool",
|
|
8204
|
-
tool:
|
|
8231
|
+
tool: tool2,
|
|
8205
8232
|
error: String(error)
|
|
8206
8233
|
});
|
|
8207
8234
|
return {
|
|
8208
8235
|
content: [
|
|
8209
8236
|
{
|
|
8210
8237
|
type: "text",
|
|
8211
|
-
text: `Error executing tool "${
|
|
8238
|
+
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
8212
8239
|
}
|
|
8213
8240
|
],
|
|
8214
8241
|
isError: true
|
|
@@ -8218,7 +8245,7 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8218
8245
|
if (executeSpan) {
|
|
8219
8246
|
executeSpan.setAttributes({
|
|
8220
8247
|
toolType: "not_found",
|
|
8221
|
-
tool:
|
|
8248
|
+
tool: tool2
|
|
8222
8249
|
});
|
|
8223
8250
|
endSpan(executeSpan);
|
|
8224
8251
|
}
|
|
@@ -8226,7 +8253,7 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8226
8253
|
content: [
|
|
8227
8254
|
{
|
|
8228
8255
|
type: "text",
|
|
8229
|
-
text: `Tool "${
|
|
8256
|
+
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
8230
8257
|
}
|
|
8231
8258
|
],
|
|
8232
8259
|
isError: true
|
|
@@ -8237,72 +8264,6 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8237
8264
|
}
|
|
8238
8265
|
};
|
|
8239
8266
|
|
|
8240
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/factories/args-def-factory.js
|
|
8241
|
-
function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps, _ensureStepActions) {
|
|
8242
|
-
return {
|
|
8243
|
-
forSampling: function() {
|
|
8244
|
-
return {
|
|
8245
|
-
type: "object",
|
|
8246
|
-
description: "Provide prompt for autonomous tool execution",
|
|
8247
|
-
properties: {
|
|
8248
|
-
prompt: {
|
|
8249
|
-
type: "string",
|
|
8250
|
-
description: "The task to be completed autonomously by the agentic system using available tools"
|
|
8251
|
-
},
|
|
8252
|
-
context: {
|
|
8253
|
-
type: "object",
|
|
8254
|
-
description: "Execution context, e.g., { cwd: '/path/to/dir' }. Any relevant fields allowed.",
|
|
8255
|
-
additionalProperties: true
|
|
8256
|
-
}
|
|
8257
|
-
},
|
|
8258
|
-
required: [
|
|
8259
|
-
"prompt",
|
|
8260
|
-
"context"
|
|
8261
|
-
],
|
|
8262
|
-
errorMessage: {
|
|
8263
|
-
required: {
|
|
8264
|
-
prompt: "Missing required field 'prompt'. Please provide a clear task description.",
|
|
8265
|
-
context: "Missing required field 'context'. Please provide relevant context (e.g., { cwd: '...' })."
|
|
8266
|
-
}
|
|
8267
|
-
}
|
|
8268
|
-
};
|
|
8269
|
-
},
|
|
8270
|
-
/**
|
|
8271
|
-
* Agentic schema - simplified Unix-style interface
|
|
8272
|
-
*
|
|
8273
|
-
* Only two fields:
|
|
8274
|
-
* - `tool`: which tool to execute (enum includes "man" + all tool names)
|
|
8275
|
-
* - `args`: parameters for the tool (array for "man", object for others)
|
|
8276
|
-
*/
|
|
8277
|
-
forAgentic: function(allToolNames) {
|
|
8278
|
-
const toolEnum = [
|
|
8279
|
-
"man",
|
|
8280
|
-
...allToolNames
|
|
8281
|
-
];
|
|
8282
|
-
return {
|
|
8283
|
-
type: "object",
|
|
8284
|
-
properties: {
|
|
8285
|
-
tool: {
|
|
8286
|
-
type: "string",
|
|
8287
|
-
enum: toolEnum,
|
|
8288
|
-
description: 'Which tool to execute. Use "man" to get tool schemas, or a tool name to execute.',
|
|
8289
|
-
errorMessage: {
|
|
8290
|
-
enum: `Invalid tool. Available: ${toolEnum.join(", ")}`
|
|
8291
|
-
}
|
|
8292
|
-
},
|
|
8293
|
-
args: {
|
|
8294
|
-
description: 'For "man": array of tool names ["tool1", "tool2"]. For other tools: object with parameters.'
|
|
8295
|
-
}
|
|
8296
|
-
},
|
|
8297
|
-
required: [
|
|
8298
|
-
"tool"
|
|
8299
|
-
],
|
|
8300
|
-
additionalProperties: false
|
|
8301
|
-
};
|
|
8302
|
-
}
|
|
8303
|
-
};
|
|
8304
|
-
}
|
|
8305
|
-
|
|
8306
8267
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-tool-registrar.js
|
|
8307
8268
|
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList }) {
|
|
8308
8269
|
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
@@ -8396,6 +8357,7 @@ function convertMCPStopReasonToAISDK(stopReason) {
|
|
|
8396
8357
|
}
|
|
8397
8358
|
|
|
8398
8359
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
|
|
8360
|
+
var DEFAULT_MAX_TOKENS = 128e3;
|
|
8399
8361
|
var MCPSamplingLanguageModel = class {
|
|
8400
8362
|
specificationVersion = "v2";
|
|
8401
8363
|
provider;
|
|
@@ -8403,11 +8365,13 @@ var MCPSamplingLanguageModel = class {
|
|
|
8403
8365
|
supportedUrls = {};
|
|
8404
8366
|
server;
|
|
8405
8367
|
modelPreferences;
|
|
8368
|
+
maxTokens;
|
|
8406
8369
|
constructor(config) {
|
|
8407
8370
|
this.server = config.server;
|
|
8408
8371
|
this.modelId = "";
|
|
8409
8372
|
this.provider = "mcp-client";
|
|
8410
8373
|
this.modelPreferences = config.modelPreferences;
|
|
8374
|
+
this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
8411
8375
|
}
|
|
8412
8376
|
/**
|
|
8413
8377
|
* Generate a response using MCP's createMessage capability
|
|
@@ -8439,7 +8403,7 @@ var MCPSamplingLanguageModel = class {
|
|
|
8439
8403
|
const createMessageParams = {
|
|
8440
8404
|
systemPrompt,
|
|
8441
8405
|
messages,
|
|
8442
|
-
maxTokens: options.maxOutputTokens ??
|
|
8406
|
+
maxTokens: options.maxOutputTokens ?? this.maxTokens,
|
|
8443
8407
|
modelPreferences: this.modelPreferences
|
|
8444
8408
|
};
|
|
8445
8409
|
if (useNativeTools && options.tools && options.tools.length > 0) {
|
|
@@ -8662,11 +8626,11 @@ var MCPSamplingLanguageModel = class {
|
|
|
8662
8626
|
*/
|
|
8663
8627
|
convertAISDKToolsToMCP(tools) {
|
|
8664
8628
|
if (!tools || tools.length === 0) return [];
|
|
8665
|
-
return tools.filter((
|
|
8666
|
-
const toolAny =
|
|
8629
|
+
return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
|
|
8630
|
+
const toolAny = tool2;
|
|
8667
8631
|
return {
|
|
8668
|
-
name:
|
|
8669
|
-
description: toolAny.description || `Tool: ${
|
|
8632
|
+
name: tool2.name,
|
|
8633
|
+
description: toolAny.description || `Tool: ${tool2.name}`,
|
|
8670
8634
|
inputSchema: {
|
|
8671
8635
|
type: "object",
|
|
8672
8636
|
...toolAny.inputSchema || toolAny.parameters
|
|
@@ -8744,18 +8708,18 @@ Follow the JSON schema definition for each tool's parameters.
|
|
|
8744
8708
|
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
8745
8709
|
|
|
8746
8710
|
Tools:`;
|
|
8747
|
-
const toolDescriptions = tools.map((
|
|
8748
|
-
if (
|
|
8749
|
-
const toolAny =
|
|
8711
|
+
const toolDescriptions = tools.map((tool2) => {
|
|
8712
|
+
if (tool2.type === "function") {
|
|
8713
|
+
const toolAny = tool2;
|
|
8750
8714
|
const description = toolAny.description || "No description provided";
|
|
8751
8715
|
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
8752
8716
|
const params = schema ? `
|
|
8753
8717
|
JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
|
|
8754
8718
|
return `
|
|
8755
|
-
- ${
|
|
8756
|
-
} else if (
|
|
8719
|
+
- ${tool2.name}: ${description}${params}`;
|
|
8720
|
+
} else if (tool2.type === "provider-defined") {
|
|
8757
8721
|
return `
|
|
8758
|
-
- ${
|
|
8722
|
+
- ${tool2.name}: ${tool2.id || "No description provided"}`;
|
|
8759
8723
|
}
|
|
8760
8724
|
return "";
|
|
8761
8725
|
}).filter(Boolean).join("");
|
|
@@ -8817,7 +8781,8 @@ var MCPSamplingProvider = class {
|
|
|
8817
8781
|
languageModel(options) {
|
|
8818
8782
|
return new MCPSamplingLanguageModel({
|
|
8819
8783
|
server: this.config.server,
|
|
8820
|
-
modelPreferences: options?.modelPreferences
|
|
8784
|
+
modelPreferences: options?.modelPreferences,
|
|
8785
|
+
maxTokens: this.config.maxTokens
|
|
8821
8786
|
});
|
|
8822
8787
|
}
|
|
8823
8788
|
/**
|
|
@@ -8887,2722 +8852,208 @@ var BaseAIExecutor = class {
|
|
|
8887
8852
|
isEnabled: true,
|
|
8888
8853
|
functionId: `mcpc.${this.config.name}`,
|
|
8889
8854
|
tracer: this.tracer
|
|
8890
|
-
} : void 0,
|
|
8891
|
-
onStepFinish: (step) => {
|
|
8892
|
-
if (span) {
|
|
8893
|
-
span.addEvent("step", {
|
|
8894
|
-
tools: step.toolCalls?.length ?? 0,
|
|
8895
|
-
reason: step.finishReason ?? ""
|
|
8896
|
-
});
|
|
8897
|
-
}
|
|
8898
|
-
}
|
|
8899
|
-
});
|
|
8900
|
-
return {
|
|
8901
|
-
content: [
|
|
8902
|
-
{
|
|
8903
|
-
type: "text",
|
|
8904
|
-
text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
|
|
8905
|
-
}
|
|
8906
|
-
],
|
|
8907
|
-
isError: false
|
|
8908
|
-
};
|
|
8909
|
-
} catch (error) {
|
|
8910
|
-
this.logger.error({
|
|
8911
|
-
message: "Execution error",
|
|
8912
|
-
error
|
|
8913
|
-
});
|
|
8914
|
-
return {
|
|
8915
|
-
content: [
|
|
8916
|
-
{
|
|
8917
|
-
type: "text",
|
|
8918
|
-
text: `Error: ${error instanceof Error ? error.message : String(error)}`
|
|
8919
|
-
}
|
|
8920
|
-
],
|
|
8921
|
-
isError: true
|
|
8922
|
-
};
|
|
8923
|
-
}
|
|
8924
|
-
}
|
|
8925
|
-
buildSystemPrompt(args) {
|
|
8926
|
-
return `Agent \`${this.config.name}\` that completes tasks by calling tools.
|
|
8927
|
-
|
|
8928
|
-
<manual>
|
|
8929
|
-
${this.config.description}
|
|
8930
|
-
</manual>
|
|
8931
|
-
|
|
8932
|
-
<rules>
|
|
8933
|
-
${this.getRules()}
|
|
8934
|
-
</rules>
|
|
8935
|
-
|
|
8936
|
-
<tools>
|
|
8937
|
-
${this.getToolListDescription()}
|
|
8938
|
-
</tools>${args.context ? this.formatContext(args.context) : ""}`;
|
|
8939
|
-
}
|
|
8940
|
-
getRules() {
|
|
8941
|
-
return `1. Use tools to complete the user's request
|
|
8942
|
-
2. Review results after each tool call
|
|
8943
|
-
3. Adapt your approach based on outcomes
|
|
8944
|
-
4. Continue until task is complete
|
|
8945
|
-
5. When complete, provide a summary WITHOUT calling more tools`;
|
|
8946
|
-
}
|
|
8947
|
-
getToolListDescription() {
|
|
8948
|
-
return "Tools will be provided by AI SDK";
|
|
8949
|
-
}
|
|
8950
|
-
formatContext(context2) {
|
|
8951
|
-
return `
|
|
8952
|
-
|
|
8953
|
-
<context>
|
|
8954
|
-
${JSON.stringify(context2, null, 2)}
|
|
8955
|
-
</context>`;
|
|
8956
|
-
}
|
|
8957
|
-
convertToAISDKTool(name, toolDetail, execute) {
|
|
8958
|
-
const cleanedSchema = toolDetail.inputSchema ? cleanToolSchema(toolDetail.inputSchema) : {
|
|
8959
|
-
type: "object"
|
|
8960
|
-
};
|
|
8961
|
-
return (0, import_ai.tool)({
|
|
8962
|
-
description: toolDetail.description || `Tool: ${name}`,
|
|
8963
|
-
inputSchema: (0, import_ai.jsonSchema)(cleanedSchema),
|
|
8964
|
-
execute
|
|
8965
|
-
});
|
|
8966
|
-
}
|
|
8967
|
-
};
|
|
8968
|
-
|
|
8969
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-executor.js
|
|
8970
|
-
var AISamplingExecutor = class extends BaseAIExecutor {
|
|
8971
|
-
server;
|
|
8972
|
-
tools;
|
|
8973
|
-
providerOptions;
|
|
8974
|
-
model = null;
|
|
8975
|
-
constructor(config) {
|
|
8976
|
-
super(config, "callTool" in config.server ? config.server : void 0);
|
|
8977
|
-
this.server = config.server;
|
|
8978
|
-
this.tools = config.tools;
|
|
8979
|
-
this.providerOptions = config.providerOptions;
|
|
8980
|
-
}
|
|
8981
|
-
initProvider() {
|
|
8982
|
-
if (!this.model) {
|
|
8983
|
-
const provider = new MCPSamplingProvider({
|
|
8984
|
-
server: this.server
|
|
8985
|
-
});
|
|
8986
|
-
this.model = provider.languageModel(this.providerOptions);
|
|
8987
|
-
}
|
|
8988
|
-
return this.model;
|
|
8989
|
-
}
|
|
8990
|
-
getModel() {
|
|
8991
|
-
if (!this.model) throw new Error("Model not initialized");
|
|
8992
|
-
return this.model;
|
|
8993
|
-
}
|
|
8994
|
-
getExecutorType() {
|
|
8995
|
-
return "mcp";
|
|
8996
|
-
}
|
|
8997
|
-
getToolListDescription() {
|
|
8998
|
-
return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
8999
|
-
}
|
|
9000
|
-
buildTools() {
|
|
9001
|
-
const aiTools = {};
|
|
9002
|
-
for (const [name, detail] of this.tools) {
|
|
9003
|
-
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
9004
|
-
const result = await this.callTool(name, input);
|
|
9005
|
-
return this.formatResult(result);
|
|
9006
|
-
});
|
|
9007
|
-
}
|
|
9008
|
-
return aiTools;
|
|
9009
|
-
}
|
|
9010
|
-
async callTool(name, input) {
|
|
9011
|
-
if ("callTool" in this.server) {
|
|
9012
|
-
return await this.server.callTool(name, input);
|
|
9013
|
-
}
|
|
9014
|
-
const detail = this.tools.find(([n]) => n === name)?.[1];
|
|
9015
|
-
if (detail?.execute) return await detail.execute(input);
|
|
9016
|
-
throw new Error(`Cannot call tool "${name}"`);
|
|
9017
|
-
}
|
|
9018
|
-
formatResult(result) {
|
|
9019
|
-
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
9020
|
-
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
9021
|
-
}
|
|
9022
|
-
execute(args) {
|
|
9023
|
-
this.initProvider();
|
|
9024
|
-
return super.execute(args);
|
|
9025
|
-
}
|
|
9026
|
-
};
|
|
9027
|
-
|
|
9028
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-registrar.js
|
|
9029
|
-
function registerAISamplingTool(server, params) {
|
|
9030
|
-
const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false } = params;
|
|
9031
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
9032
|
-
const executor = new AISamplingExecutor({
|
|
9033
|
-
name,
|
|
9034
|
-
description,
|
|
9035
|
-
server,
|
|
9036
|
-
tools: toolNameToDetailList,
|
|
9037
|
-
providerOptions,
|
|
9038
|
-
maxSteps,
|
|
9039
|
-
tracingEnabled
|
|
9040
|
-
});
|
|
9041
|
-
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
9042
|
-
toolName: name,
|
|
9043
|
-
description,
|
|
9044
|
-
toolList: allToolNames.map((n) => `- ${n}`).join("\n")
|
|
9045
|
-
});
|
|
9046
|
-
const argsDef = createArgsDef.forSampling();
|
|
9047
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
9048
|
-
type: "object",
|
|
9049
|
-
properties: {}
|
|
9050
|
-
};
|
|
9051
|
-
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
9052
|
-
const validationResult = validateSchema(args, schema);
|
|
9053
|
-
if (!validationResult.valid) {
|
|
9054
|
-
return {
|
|
9055
|
-
content: [
|
|
9056
|
-
{
|
|
9057
|
-
type: "text",
|
|
9058
|
-
text: CompiledPrompts.errorResponse({
|
|
9059
|
-
errorMessage: validationResult.error || "Validation failed"
|
|
9060
|
-
})
|
|
9061
|
-
}
|
|
9062
|
-
],
|
|
9063
|
-
isError: true
|
|
9064
|
-
};
|
|
9065
|
-
}
|
|
9066
|
-
const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
|
|
9067
|
-
return executor.execute({
|
|
9068
|
-
prompt,
|
|
9069
|
-
context: args.context
|
|
9070
|
-
});
|
|
9071
|
-
});
|
|
9072
|
-
}
|
|
9073
|
-
|
|
9074
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-sampling-plugin.js
|
|
9075
|
-
var createAISamplingModePlugin = () => ({
|
|
9076
|
-
name: "mode-ai-sampling",
|
|
9077
|
-
version: "1.0.0",
|
|
9078
|
-
apply: "ai_sampling",
|
|
9079
|
-
registerAgentTool: (context2) => {
|
|
9080
|
-
const opts = context2.options;
|
|
9081
|
-
registerAISamplingTool(context2.server, {
|
|
9082
|
-
description: context2.description,
|
|
9083
|
-
name: context2.name,
|
|
9084
|
-
allToolNames: context2.allToolNames,
|
|
9085
|
-
depGroups: context2.depGroups,
|
|
9086
|
-
toolNameToDetailList: context2.toolNameToDetailList,
|
|
9087
|
-
providerOptions: opts.providerOptions,
|
|
9088
|
-
maxSteps: opts.maxSteps,
|
|
9089
|
-
tracingEnabled: opts.tracingEnabled
|
|
9090
|
-
});
|
|
9091
|
-
}
|
|
9092
|
-
});
|
|
9093
|
-
var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
|
|
9094
|
-
|
|
9095
|
-
// __mcpc__cli_latest/node_modules/@agentclientprotocol/sdk/dist/acp.js
|
|
9096
|
-
var import_zod3 = require("zod");
|
|
9097
|
-
|
|
9098
|
-
// __mcpc__cli_latest/node_modules/@agentclientprotocol/sdk/dist/schema.js
|
|
9099
|
-
var import_zod2 = require("zod");
|
|
9100
|
-
var AGENT_METHODS = {
|
|
9101
|
-
authenticate: "authenticate",
|
|
9102
|
-
initialize: "initialize",
|
|
9103
|
-
session_cancel: "session/cancel",
|
|
9104
|
-
session_load: "session/load",
|
|
9105
|
-
session_new: "session/new",
|
|
9106
|
-
session_prompt: "session/prompt",
|
|
9107
|
-
session_set_mode: "session/set_mode",
|
|
9108
|
-
session_set_model: "session/set_model"
|
|
9109
|
-
};
|
|
9110
|
-
var CLIENT_METHODS = {
|
|
9111
|
-
fs_read_text_file: "fs/read_text_file",
|
|
9112
|
-
fs_write_text_file: "fs/write_text_file",
|
|
9113
|
-
session_request_permission: "session/request_permission",
|
|
9114
|
-
session_update: "session/update",
|
|
9115
|
-
terminal_create: "terminal/create",
|
|
9116
|
-
terminal_kill: "terminal/kill",
|
|
9117
|
-
terminal_output: "terminal/output",
|
|
9118
|
-
terminal_release: "terminal/release",
|
|
9119
|
-
terminal_wait_for_exit: "terminal/wait_for_exit"
|
|
9120
|
-
};
|
|
9121
|
-
var PROTOCOL_VERSION = 1;
|
|
9122
|
-
var writeTextFileRequestSchema = import_zod2.z.object({
|
|
9123
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9124
|
-
content: import_zod2.z.string(),
|
|
9125
|
-
path: import_zod2.z.string(),
|
|
9126
|
-
sessionId: import_zod2.z.string()
|
|
9127
|
-
});
|
|
9128
|
-
var readTextFileRequestSchema = import_zod2.z.object({
|
|
9129
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9130
|
-
limit: import_zod2.z.number().optional().nullable(),
|
|
9131
|
-
line: import_zod2.z.number().optional().nullable(),
|
|
9132
|
-
path: import_zod2.z.string(),
|
|
9133
|
-
sessionId: import_zod2.z.string()
|
|
9134
|
-
});
|
|
9135
|
-
var terminalOutputRequestSchema = import_zod2.z.object({
|
|
9136
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9137
|
-
sessionId: import_zod2.z.string(),
|
|
9138
|
-
terminalId: import_zod2.z.string()
|
|
9139
|
-
});
|
|
9140
|
-
var releaseTerminalRequestSchema = import_zod2.z.object({
|
|
9141
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9142
|
-
sessionId: import_zod2.z.string(),
|
|
9143
|
-
terminalId: import_zod2.z.string()
|
|
9144
|
-
});
|
|
9145
|
-
var waitForTerminalExitRequestSchema = import_zod2.z.object({
|
|
9146
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9147
|
-
sessionId: import_zod2.z.string(),
|
|
9148
|
-
terminalId: import_zod2.z.string()
|
|
9149
|
-
});
|
|
9150
|
-
var killTerminalCommandRequestSchema = import_zod2.z.object({
|
|
9151
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9152
|
-
sessionId: import_zod2.z.string(),
|
|
9153
|
-
terminalId: import_zod2.z.string()
|
|
9154
|
-
});
|
|
9155
|
-
var extMethodRequestSchema = import_zod2.z.record(import_zod2.z.unknown());
|
|
9156
|
-
var roleSchema = import_zod2.z.union([import_zod2.z.literal("assistant"), import_zod2.z.literal("user")]);
|
|
9157
|
-
var textResourceContentsSchema = import_zod2.z.object({
|
|
9158
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9159
|
-
mimeType: import_zod2.z.string().optional().nullable(),
|
|
9160
|
-
text: import_zod2.z.string(),
|
|
9161
|
-
uri: import_zod2.z.string()
|
|
9162
|
-
});
|
|
9163
|
-
var blobResourceContentsSchema = import_zod2.z.object({
|
|
9164
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9165
|
-
blob: import_zod2.z.string(),
|
|
9166
|
-
mimeType: import_zod2.z.string().optional().nullable(),
|
|
9167
|
-
uri: import_zod2.z.string()
|
|
9168
|
-
});
|
|
9169
|
-
var toolKindSchema = import_zod2.z.union([
|
|
9170
|
-
import_zod2.z.literal("read"),
|
|
9171
|
-
import_zod2.z.literal("edit"),
|
|
9172
|
-
import_zod2.z.literal("delete"),
|
|
9173
|
-
import_zod2.z.literal("move"),
|
|
9174
|
-
import_zod2.z.literal("search"),
|
|
9175
|
-
import_zod2.z.literal("execute"),
|
|
9176
|
-
import_zod2.z.literal("think"),
|
|
9177
|
-
import_zod2.z.literal("fetch"),
|
|
9178
|
-
import_zod2.z.literal("switch_mode"),
|
|
9179
|
-
import_zod2.z.literal("other")
|
|
9180
|
-
]);
|
|
9181
|
-
var toolCallStatusSchema = import_zod2.z.union([
|
|
9182
|
-
import_zod2.z.literal("pending"),
|
|
9183
|
-
import_zod2.z.literal("in_progress"),
|
|
9184
|
-
import_zod2.z.literal("completed"),
|
|
9185
|
-
import_zod2.z.literal("failed")
|
|
9186
|
-
]);
|
|
9187
|
-
var writeTextFileResponseSchema = import_zod2.z.object({
|
|
9188
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional()
|
|
9189
|
-
});
|
|
9190
|
-
var readTextFileResponseSchema = import_zod2.z.object({
|
|
9191
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9192
|
-
content: import_zod2.z.string()
|
|
9193
|
-
});
|
|
9194
|
-
var requestPermissionResponseSchema = import_zod2.z.object({
|
|
9195
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9196
|
-
outcome: import_zod2.z.union([
|
|
9197
|
-
import_zod2.z.object({
|
|
9198
|
-
outcome: import_zod2.z.literal("cancelled")
|
|
9199
|
-
}),
|
|
9200
|
-
import_zod2.z.object({
|
|
9201
|
-
optionId: import_zod2.z.string(),
|
|
9202
|
-
outcome: import_zod2.z.literal("selected")
|
|
9203
|
-
})
|
|
9204
|
-
])
|
|
9205
|
-
});
|
|
9206
|
-
var createTerminalResponseSchema = import_zod2.z.object({
|
|
9207
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9208
|
-
terminalId: import_zod2.z.string()
|
|
9209
|
-
});
|
|
9210
|
-
var releaseTerminalResponseSchema = import_zod2.z.object({
|
|
9211
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional()
|
|
9212
|
-
});
|
|
9213
|
-
var waitForTerminalExitResponseSchema = import_zod2.z.object({
|
|
9214
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9215
|
-
exitCode: import_zod2.z.number().optional().nullable(),
|
|
9216
|
-
signal: import_zod2.z.string().optional().nullable()
|
|
9217
|
-
});
|
|
9218
|
-
var killTerminalResponseSchema = import_zod2.z.object({
|
|
9219
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional()
|
|
9220
|
-
});
|
|
9221
|
-
var extMethodResponseSchema = import_zod2.z.record(import_zod2.z.unknown());
|
|
9222
|
-
var cancelNotificationSchema = import_zod2.z.object({
|
|
9223
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9224
|
-
sessionId: import_zod2.z.string()
|
|
9225
|
-
});
|
|
9226
|
-
var extNotificationSchema = import_zod2.z.record(import_zod2.z.unknown());
|
|
9227
|
-
var authenticateRequestSchema = import_zod2.z.object({
|
|
9228
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9229
|
-
methodId: import_zod2.z.string()
|
|
9230
|
-
});
|
|
9231
|
-
var setSessionModeRequestSchema = import_zod2.z.object({
|
|
9232
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9233
|
-
modeId: import_zod2.z.string(),
|
|
9234
|
-
sessionId: import_zod2.z.string()
|
|
9235
|
-
});
|
|
9236
|
-
var setSessionModelRequestSchema = import_zod2.z.object({
|
|
9237
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9238
|
-
modelId: import_zod2.z.string(),
|
|
9239
|
-
sessionId: import_zod2.z.string()
|
|
9240
|
-
});
|
|
9241
|
-
var extMethodRequest1Schema = import_zod2.z.record(import_zod2.z.unknown());
|
|
9242
|
-
var httpHeaderSchema = import_zod2.z.object({
|
|
9243
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9244
|
-
name: import_zod2.z.string(),
|
|
9245
|
-
value: import_zod2.z.string()
|
|
9246
|
-
});
|
|
9247
|
-
var annotationsSchema = import_zod2.z.object({
|
|
9248
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9249
|
-
audience: import_zod2.z.array(roleSchema).optional().nullable(),
|
|
9250
|
-
lastModified: import_zod2.z.string().optional().nullable(),
|
|
9251
|
-
priority: import_zod2.z.number().optional().nullable()
|
|
9252
|
-
});
|
|
9253
|
-
var embeddedResourceResourceSchema = import_zod2.z.union([
|
|
9254
|
-
textResourceContentsSchema,
|
|
9255
|
-
blobResourceContentsSchema
|
|
9256
|
-
]);
|
|
9257
|
-
var authenticateResponseSchema = import_zod2.z.object({
|
|
9258
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional()
|
|
9259
|
-
});
|
|
9260
|
-
var setSessionModeResponseSchema = import_zod2.z.object({
|
|
9261
|
-
meta: import_zod2.z.unknown().optional()
|
|
9262
|
-
});
|
|
9263
|
-
var promptResponseSchema = import_zod2.z.object({
|
|
9264
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9265
|
-
stopReason: import_zod2.z.union([
|
|
9266
|
-
import_zod2.z.literal("end_turn"),
|
|
9267
|
-
import_zod2.z.literal("max_tokens"),
|
|
9268
|
-
import_zod2.z.literal("max_turn_requests"),
|
|
9269
|
-
import_zod2.z.literal("refusal"),
|
|
9270
|
-
import_zod2.z.literal("cancelled")
|
|
9271
|
-
])
|
|
9272
|
-
});
|
|
9273
|
-
var setSessionModelResponseSchema = import_zod2.z.object({
|
|
9274
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional()
|
|
9275
|
-
});
|
|
9276
|
-
var extMethodResponse1Schema = import_zod2.z.record(import_zod2.z.unknown());
|
|
9277
|
-
var sessionModeIdSchema = import_zod2.z.string();
|
|
9278
|
-
var extNotification1Schema = import_zod2.z.record(import_zod2.z.unknown());
|
|
9279
|
-
var unstructuredCommandInputSchema = import_zod2.z.object({
|
|
9280
|
-
hint: import_zod2.z.string()
|
|
9281
|
-
});
|
|
9282
|
-
var permissionOptionSchema = import_zod2.z.object({
|
|
9283
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9284
|
-
kind: import_zod2.z.union([
|
|
9285
|
-
import_zod2.z.literal("allow_once"),
|
|
9286
|
-
import_zod2.z.literal("allow_always"),
|
|
9287
|
-
import_zod2.z.literal("reject_once"),
|
|
9288
|
-
import_zod2.z.literal("reject_always")
|
|
9289
|
-
]),
|
|
9290
|
-
name: import_zod2.z.string(),
|
|
9291
|
-
optionId: import_zod2.z.string()
|
|
9292
|
-
});
|
|
9293
|
-
var toolCallContentSchema = import_zod2.z.union([
|
|
9294
|
-
import_zod2.z.object({
|
|
9295
|
-
content: import_zod2.z.union([
|
|
9296
|
-
import_zod2.z.object({
|
|
9297
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9298
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9299
|
-
text: import_zod2.z.string(),
|
|
9300
|
-
type: import_zod2.z.literal("text")
|
|
9301
|
-
}),
|
|
9302
|
-
import_zod2.z.object({
|
|
9303
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9304
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9305
|
-
data: import_zod2.z.string(),
|
|
9306
|
-
mimeType: import_zod2.z.string(),
|
|
9307
|
-
type: import_zod2.z.literal("image"),
|
|
9308
|
-
uri: import_zod2.z.string().optional().nullable()
|
|
9309
|
-
}),
|
|
9310
|
-
import_zod2.z.object({
|
|
9311
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9312
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9313
|
-
data: import_zod2.z.string(),
|
|
9314
|
-
mimeType: import_zod2.z.string(),
|
|
9315
|
-
type: import_zod2.z.literal("audio")
|
|
9316
|
-
}),
|
|
9317
|
-
import_zod2.z.object({
|
|
9318
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9319
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9320
|
-
description: import_zod2.z.string().optional().nullable(),
|
|
9321
|
-
mimeType: import_zod2.z.string().optional().nullable(),
|
|
9322
|
-
name: import_zod2.z.string(),
|
|
9323
|
-
size: import_zod2.z.number().optional().nullable(),
|
|
9324
|
-
title: import_zod2.z.string().optional().nullable(),
|
|
9325
|
-
type: import_zod2.z.literal("resource_link"),
|
|
9326
|
-
uri: import_zod2.z.string()
|
|
9327
|
-
}),
|
|
9328
|
-
import_zod2.z.object({
|
|
9329
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9330
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9331
|
-
resource: embeddedResourceResourceSchema,
|
|
9332
|
-
type: import_zod2.z.literal("resource")
|
|
9333
|
-
})
|
|
9334
|
-
]),
|
|
9335
|
-
type: import_zod2.z.literal("content")
|
|
9336
|
-
}),
|
|
9337
|
-
import_zod2.z.object({
|
|
9338
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9339
|
-
newText: import_zod2.z.string(),
|
|
9340
|
-
oldText: import_zod2.z.string().optional().nullable(),
|
|
9341
|
-
path: import_zod2.z.string(),
|
|
9342
|
-
type: import_zod2.z.literal("diff")
|
|
9343
|
-
}),
|
|
9344
|
-
import_zod2.z.object({
|
|
9345
|
-
terminalId: import_zod2.z.string(),
|
|
9346
|
-
type: import_zod2.z.literal("terminal")
|
|
9347
|
-
})
|
|
9348
|
-
]);
|
|
9349
|
-
var toolCallLocationSchema = import_zod2.z.object({
|
|
9350
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9351
|
-
line: import_zod2.z.number().optional().nullable(),
|
|
9352
|
-
path: import_zod2.z.string()
|
|
9353
|
-
});
|
|
9354
|
-
var envVariableSchema = import_zod2.z.object({
|
|
9355
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9356
|
-
name: import_zod2.z.string(),
|
|
9357
|
-
value: import_zod2.z.string()
|
|
9358
|
-
});
|
|
9359
|
-
var terminalExitStatusSchema = import_zod2.z.object({
|
|
9360
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9361
|
-
exitCode: import_zod2.z.number().optional().nullable(),
|
|
9362
|
-
signal: import_zod2.z.string().optional().nullable()
|
|
9363
|
-
});
|
|
9364
|
-
var fileSystemCapabilitySchema = import_zod2.z.object({
|
|
9365
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9366
|
-
readTextFile: import_zod2.z.boolean().optional(),
|
|
9367
|
-
writeTextFile: import_zod2.z.boolean().optional()
|
|
9368
|
-
});
|
|
9369
|
-
var stdioSchema = import_zod2.z.object({
|
|
9370
|
-
args: import_zod2.z.array(import_zod2.z.string()),
|
|
9371
|
-
command: import_zod2.z.string(),
|
|
9372
|
-
env: import_zod2.z.array(envVariableSchema),
|
|
9373
|
-
name: import_zod2.z.string()
|
|
9374
|
-
});
|
|
9375
|
-
var mcpServerSchema = import_zod2.z.union([
|
|
9376
|
-
import_zod2.z.object({
|
|
9377
|
-
headers: import_zod2.z.array(httpHeaderSchema),
|
|
9378
|
-
name: import_zod2.z.string(),
|
|
9379
|
-
type: import_zod2.z.literal("http"),
|
|
9380
|
-
url: import_zod2.z.string()
|
|
9381
|
-
}),
|
|
9382
|
-
import_zod2.z.object({
|
|
9383
|
-
headers: import_zod2.z.array(httpHeaderSchema),
|
|
9384
|
-
name: import_zod2.z.string(),
|
|
9385
|
-
type: import_zod2.z.literal("sse"),
|
|
9386
|
-
url: import_zod2.z.string()
|
|
9387
|
-
}),
|
|
9388
|
-
stdioSchema
|
|
9389
|
-
]);
|
|
9390
|
-
var contentBlockSchema = import_zod2.z.union([
|
|
9391
|
-
import_zod2.z.object({
|
|
9392
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9393
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9394
|
-
text: import_zod2.z.string(),
|
|
9395
|
-
type: import_zod2.z.literal("text")
|
|
9396
|
-
}),
|
|
9397
|
-
import_zod2.z.object({
|
|
9398
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9399
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9400
|
-
data: import_zod2.z.string(),
|
|
9401
|
-
mimeType: import_zod2.z.string(),
|
|
9402
|
-
type: import_zod2.z.literal("image"),
|
|
9403
|
-
uri: import_zod2.z.string().optional().nullable()
|
|
9404
|
-
}),
|
|
9405
|
-
import_zod2.z.object({
|
|
9406
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9407
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9408
|
-
data: import_zod2.z.string(),
|
|
9409
|
-
mimeType: import_zod2.z.string(),
|
|
9410
|
-
type: import_zod2.z.literal("audio")
|
|
9411
|
-
}),
|
|
9412
|
-
import_zod2.z.object({
|
|
9413
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9414
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9415
|
-
description: import_zod2.z.string().optional().nullable(),
|
|
9416
|
-
mimeType: import_zod2.z.string().optional().nullable(),
|
|
9417
|
-
name: import_zod2.z.string(),
|
|
9418
|
-
size: import_zod2.z.number().optional().nullable(),
|
|
9419
|
-
title: import_zod2.z.string().optional().nullable(),
|
|
9420
|
-
type: import_zod2.z.literal("resource_link"),
|
|
9421
|
-
uri: import_zod2.z.string()
|
|
9422
|
-
}),
|
|
9423
|
-
import_zod2.z.object({
|
|
9424
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9425
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
9426
|
-
resource: embeddedResourceResourceSchema,
|
|
9427
|
-
type: import_zod2.z.literal("resource")
|
|
9428
|
-
})
|
|
9429
|
-
]);
|
|
9430
|
-
var authMethodSchema = import_zod2.z.object({
|
|
9431
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9432
|
-
description: import_zod2.z.string().optional().nullable(),
|
|
9433
|
-
id: import_zod2.z.string(),
|
|
9434
|
-
name: import_zod2.z.string()
|
|
9435
|
-
});
|
|
9436
|
-
var mcpCapabilitiesSchema = import_zod2.z.object({
|
|
9437
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9438
|
-
http: import_zod2.z.boolean().optional(),
|
|
9439
|
-
sse: import_zod2.z.boolean().optional()
|
|
9440
|
-
});
|
|
9441
|
-
var promptCapabilitiesSchema = import_zod2.z.object({
|
|
9442
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9443
|
-
audio: import_zod2.z.boolean().optional(),
|
|
9444
|
-
embeddedContext: import_zod2.z.boolean().optional(),
|
|
9445
|
-
image: import_zod2.z.boolean().optional()
|
|
9446
|
-
});
|
|
9447
|
-
var modelInfoSchema = import_zod2.z.object({
|
|
9448
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9449
|
-
description: import_zod2.z.string().optional().nullable(),
|
|
9450
|
-
modelId: import_zod2.z.string(),
|
|
9451
|
-
name: import_zod2.z.string()
|
|
9452
|
-
});
|
|
9453
|
-
var sessionModeSchema = import_zod2.z.object({
|
|
9454
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9455
|
-
description: import_zod2.z.string().optional().nullable(),
|
|
9456
|
-
id: sessionModeIdSchema,
|
|
9457
|
-
name: import_zod2.z.string()
|
|
9458
|
-
});
|
|
9459
|
-
var sessionModelStateSchema = import_zod2.z.object({
|
|
9460
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9461
|
-
availableModels: import_zod2.z.array(modelInfoSchema),
|
|
9462
|
-
currentModelId: import_zod2.z.string()
|
|
9463
|
-
});
|
|
9464
|
-
var sessionModeStateSchema = import_zod2.z.object({
|
|
9465
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9466
|
-
availableModes: import_zod2.z.array(sessionModeSchema),
|
|
9467
|
-
currentModeId: import_zod2.z.string()
|
|
9468
|
-
});
|
|
9469
|
-
var planEntrySchema = import_zod2.z.object({
|
|
9470
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9471
|
-
content: import_zod2.z.string(),
|
|
9472
|
-
priority: import_zod2.z.union([import_zod2.z.literal("high"), import_zod2.z.literal("medium"), import_zod2.z.literal("low")]),
|
|
9473
|
-
status: import_zod2.z.union([
|
|
9474
|
-
import_zod2.z.literal("pending"),
|
|
9475
|
-
import_zod2.z.literal("in_progress"),
|
|
9476
|
-
import_zod2.z.literal("completed")
|
|
9477
|
-
])
|
|
9478
|
-
});
|
|
9479
|
-
var availableCommandInputSchema = unstructuredCommandInputSchema;
|
|
9480
|
-
var clientNotificationSchema = import_zod2.z.union([
|
|
9481
|
-
cancelNotificationSchema,
|
|
9482
|
-
extNotificationSchema
|
|
9483
|
-
]);
|
|
9484
|
-
var createTerminalRequestSchema = import_zod2.z.object({
|
|
9485
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9486
|
-
args: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
9487
|
-
command: import_zod2.z.string(),
|
|
9488
|
-
cwd: import_zod2.z.string().optional().nullable(),
|
|
9489
|
-
env: import_zod2.z.array(envVariableSchema).optional(),
|
|
9490
|
-
outputByteLimit: import_zod2.z.number().optional().nullable(),
|
|
9491
|
-
sessionId: import_zod2.z.string()
|
|
9492
|
-
});
|
|
9493
|
-
var terminalOutputResponseSchema = import_zod2.z.object({
|
|
9494
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9495
|
-
exitStatus: terminalExitStatusSchema.optional().nullable(),
|
|
9496
|
-
output: import_zod2.z.string(),
|
|
9497
|
-
truncated: import_zod2.z.boolean()
|
|
9498
|
-
});
|
|
9499
|
-
var newSessionRequestSchema = import_zod2.z.object({
|
|
9500
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9501
|
-
cwd: import_zod2.z.string(),
|
|
9502
|
-
mcpServers: import_zod2.z.array(mcpServerSchema)
|
|
9503
|
-
});
|
|
9504
|
-
var loadSessionRequestSchema = import_zod2.z.object({
|
|
9505
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9506
|
-
cwd: import_zod2.z.string(),
|
|
9507
|
-
mcpServers: import_zod2.z.array(mcpServerSchema),
|
|
9508
|
-
sessionId: import_zod2.z.string()
|
|
9509
|
-
});
|
|
9510
|
-
var promptRequestSchema = import_zod2.z.object({
|
|
9511
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9512
|
-
prompt: import_zod2.z.array(contentBlockSchema),
|
|
9513
|
-
sessionId: import_zod2.z.string()
|
|
9514
|
-
});
|
|
9515
|
-
var newSessionResponseSchema = import_zod2.z.object({
|
|
9516
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9517
|
-
models: sessionModelStateSchema.optional().nullable(),
|
|
9518
|
-
modes: sessionModeStateSchema.optional().nullable(),
|
|
9519
|
-
sessionId: import_zod2.z.string()
|
|
9520
|
-
});
|
|
9521
|
-
var loadSessionResponseSchema = import_zod2.z.object({
|
|
9522
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9523
|
-
models: sessionModelStateSchema.optional().nullable(),
|
|
9524
|
-
modes: sessionModeStateSchema.optional().nullable()
|
|
9525
|
-
});
|
|
9526
|
-
var toolCallUpdateSchema = import_zod2.z.object({
|
|
9527
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9528
|
-
content: import_zod2.z.array(toolCallContentSchema).optional().nullable(),
|
|
9529
|
-
kind: toolKindSchema.optional().nullable(),
|
|
9530
|
-
locations: import_zod2.z.array(toolCallLocationSchema).optional().nullable(),
|
|
9531
|
-
rawInput: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9532
|
-
rawOutput: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9533
|
-
status: toolCallStatusSchema.optional().nullable(),
|
|
9534
|
-
title: import_zod2.z.string().optional().nullable(),
|
|
9535
|
-
toolCallId: import_zod2.z.string()
|
|
9536
|
-
});
|
|
9537
|
-
var clientCapabilitiesSchema = import_zod2.z.object({
|
|
9538
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9539
|
-
fs: fileSystemCapabilitySchema.optional(),
|
|
9540
|
-
terminal: import_zod2.z.boolean().optional()
|
|
9541
|
-
});
|
|
9542
|
-
var agentCapabilitiesSchema = import_zod2.z.object({
|
|
9543
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9544
|
-
loadSession: import_zod2.z.boolean().optional(),
|
|
9545
|
-
mcpCapabilities: mcpCapabilitiesSchema.optional(),
|
|
9546
|
-
promptCapabilities: promptCapabilitiesSchema.optional()
|
|
9547
|
-
});
|
|
9548
|
-
var availableCommandSchema = import_zod2.z.object({
|
|
9549
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9550
|
-
description: import_zod2.z.string(),
|
|
9551
|
-
input: availableCommandInputSchema.optional().nullable(),
|
|
9552
|
-
name: import_zod2.z.string()
|
|
9553
|
-
});
|
|
9554
|
-
var clientResponseSchema = import_zod2.z.union([
|
|
9555
|
-
writeTextFileResponseSchema,
|
|
9556
|
-
readTextFileResponseSchema,
|
|
9557
|
-
requestPermissionResponseSchema,
|
|
9558
|
-
createTerminalResponseSchema,
|
|
9559
|
-
terminalOutputResponseSchema,
|
|
9560
|
-
releaseTerminalResponseSchema,
|
|
9561
|
-
waitForTerminalExitResponseSchema,
|
|
9562
|
-
killTerminalResponseSchema,
|
|
9563
|
-
extMethodResponseSchema
|
|
9564
|
-
]);
|
|
9565
|
-
var requestPermissionRequestSchema = import_zod2.z.object({
|
|
9566
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9567
|
-
options: import_zod2.z.array(permissionOptionSchema),
|
|
9568
|
-
sessionId: import_zod2.z.string(),
|
|
9569
|
-
toolCall: toolCallUpdateSchema
|
|
9570
|
-
});
|
|
9571
|
-
var initializeRequestSchema = import_zod2.z.object({
|
|
9572
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9573
|
-
clientCapabilities: clientCapabilitiesSchema.optional(),
|
|
9574
|
-
protocolVersion: import_zod2.z.number()
|
|
9575
|
-
});
|
|
9576
|
-
var initializeResponseSchema = import_zod2.z.object({
|
|
9577
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9578
|
-
agentCapabilities: agentCapabilitiesSchema.optional(),
|
|
9579
|
-
authMethods: import_zod2.z.array(authMethodSchema).optional(),
|
|
9580
|
-
protocolVersion: import_zod2.z.number()
|
|
9581
|
-
});
|
|
9582
|
-
var sessionNotificationSchema = import_zod2.z.object({
|
|
9583
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9584
|
-
sessionId: import_zod2.z.string(),
|
|
9585
|
-
update: import_zod2.z.union([
|
|
9586
|
-
import_zod2.z.object({
|
|
9587
|
-
content: contentBlockSchema,
|
|
9588
|
-
sessionUpdate: import_zod2.z.literal("user_message_chunk")
|
|
9589
|
-
}),
|
|
9590
|
-
import_zod2.z.object({
|
|
9591
|
-
content: contentBlockSchema,
|
|
9592
|
-
sessionUpdate: import_zod2.z.literal("agent_message_chunk")
|
|
9593
|
-
}),
|
|
9594
|
-
import_zod2.z.object({
|
|
9595
|
-
content: contentBlockSchema,
|
|
9596
|
-
sessionUpdate: import_zod2.z.literal("agent_thought_chunk")
|
|
9597
|
-
}),
|
|
9598
|
-
import_zod2.z.object({
|
|
9599
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9600
|
-
content: import_zod2.z.array(toolCallContentSchema).optional(),
|
|
9601
|
-
kind: import_zod2.z.union([
|
|
9602
|
-
import_zod2.z.literal("read"),
|
|
9603
|
-
import_zod2.z.literal("edit"),
|
|
9604
|
-
import_zod2.z.literal("delete"),
|
|
9605
|
-
import_zod2.z.literal("move"),
|
|
9606
|
-
import_zod2.z.literal("search"),
|
|
9607
|
-
import_zod2.z.literal("execute"),
|
|
9608
|
-
import_zod2.z.literal("think"),
|
|
9609
|
-
import_zod2.z.literal("fetch"),
|
|
9610
|
-
import_zod2.z.literal("switch_mode"),
|
|
9611
|
-
import_zod2.z.literal("other")
|
|
9612
|
-
]).optional(),
|
|
9613
|
-
locations: import_zod2.z.array(toolCallLocationSchema).optional(),
|
|
9614
|
-
rawInput: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9615
|
-
rawOutput: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9616
|
-
sessionUpdate: import_zod2.z.literal("tool_call"),
|
|
9617
|
-
status: import_zod2.z.union([
|
|
9618
|
-
import_zod2.z.literal("pending"),
|
|
9619
|
-
import_zod2.z.literal("in_progress"),
|
|
9620
|
-
import_zod2.z.literal("completed"),
|
|
9621
|
-
import_zod2.z.literal("failed")
|
|
9622
|
-
]).optional(),
|
|
9623
|
-
title: import_zod2.z.string(),
|
|
9624
|
-
toolCallId: import_zod2.z.string()
|
|
9625
|
-
}),
|
|
9626
|
-
import_zod2.z.object({
|
|
9627
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9628
|
-
content: import_zod2.z.array(toolCallContentSchema).optional().nullable(),
|
|
9629
|
-
kind: toolKindSchema.optional().nullable(),
|
|
9630
|
-
locations: import_zod2.z.array(toolCallLocationSchema).optional().nullable(),
|
|
9631
|
-
rawInput: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9632
|
-
rawOutput: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9633
|
-
sessionUpdate: import_zod2.z.literal("tool_call_update"),
|
|
9634
|
-
status: toolCallStatusSchema.optional().nullable(),
|
|
9635
|
-
title: import_zod2.z.string().optional().nullable(),
|
|
9636
|
-
toolCallId: import_zod2.z.string()
|
|
9637
|
-
}),
|
|
9638
|
-
import_zod2.z.object({
|
|
9639
|
-
_meta: import_zod2.z.record(import_zod2.z.unknown()).optional(),
|
|
9640
|
-
entries: import_zod2.z.array(planEntrySchema),
|
|
9641
|
-
sessionUpdate: import_zod2.z.literal("plan")
|
|
9642
|
-
}),
|
|
9643
|
-
import_zod2.z.object({
|
|
9644
|
-
availableCommands: import_zod2.z.array(availableCommandSchema),
|
|
9645
|
-
sessionUpdate: import_zod2.z.literal("available_commands_update")
|
|
9646
|
-
}),
|
|
9647
|
-
import_zod2.z.object({
|
|
9648
|
-
currentModeId: sessionModeIdSchema,
|
|
9649
|
-
sessionUpdate: import_zod2.z.literal("current_mode_update")
|
|
9650
|
-
})
|
|
9651
|
-
])
|
|
9652
|
-
});
|
|
9653
|
-
var clientRequestSchema = import_zod2.z.union([
|
|
9654
|
-
writeTextFileRequestSchema,
|
|
9655
|
-
readTextFileRequestSchema,
|
|
9656
|
-
requestPermissionRequestSchema,
|
|
9657
|
-
createTerminalRequestSchema,
|
|
9658
|
-
terminalOutputRequestSchema,
|
|
9659
|
-
releaseTerminalRequestSchema,
|
|
9660
|
-
waitForTerminalExitRequestSchema,
|
|
9661
|
-
killTerminalCommandRequestSchema,
|
|
9662
|
-
extMethodRequestSchema
|
|
9663
|
-
]);
|
|
9664
|
-
var agentRequestSchema = import_zod2.z.union([
|
|
9665
|
-
initializeRequestSchema,
|
|
9666
|
-
authenticateRequestSchema,
|
|
9667
|
-
newSessionRequestSchema,
|
|
9668
|
-
loadSessionRequestSchema,
|
|
9669
|
-
setSessionModeRequestSchema,
|
|
9670
|
-
promptRequestSchema,
|
|
9671
|
-
setSessionModelRequestSchema,
|
|
9672
|
-
extMethodRequest1Schema
|
|
9673
|
-
]);
|
|
9674
|
-
var agentResponseSchema = import_zod2.z.union([
|
|
9675
|
-
initializeResponseSchema,
|
|
9676
|
-
authenticateResponseSchema,
|
|
9677
|
-
newSessionResponseSchema,
|
|
9678
|
-
loadSessionResponseSchema,
|
|
9679
|
-
setSessionModeResponseSchema,
|
|
9680
|
-
promptResponseSchema,
|
|
9681
|
-
setSessionModelResponseSchema,
|
|
9682
|
-
extMethodResponse1Schema
|
|
9683
|
-
]);
|
|
9684
|
-
var agentNotificationSchema = import_zod2.z.union([
|
|
9685
|
-
sessionNotificationSchema,
|
|
9686
|
-
extNotification1Schema
|
|
9687
|
-
]);
|
|
9688
|
-
var agentClientProtocolSchema = import_zod2.z.union([
|
|
9689
|
-
clientRequestSchema,
|
|
9690
|
-
clientResponseSchema,
|
|
9691
|
-
clientNotificationSchema,
|
|
9692
|
-
agentRequestSchema,
|
|
9693
|
-
agentResponseSchema,
|
|
9694
|
-
agentNotificationSchema
|
|
9695
|
-
]);
|
|
9696
|
-
|
|
9697
|
-
// __mcpc__cli_latest/node_modules/@agentclientprotocol/sdk/dist/stream.js
|
|
9698
|
-
function ndJsonStream(output, input) {
|
|
9699
|
-
const textEncoder = new TextEncoder();
|
|
9700
|
-
const textDecoder = new TextDecoder();
|
|
9701
|
-
const readable = new ReadableStream({
|
|
9702
|
-
async start(controller) {
|
|
9703
|
-
let content = "";
|
|
9704
|
-
const reader = input.getReader();
|
|
9705
|
-
try {
|
|
9706
|
-
while (true) {
|
|
9707
|
-
const { value, done } = await reader.read();
|
|
9708
|
-
if (done) {
|
|
9709
|
-
break;
|
|
9710
|
-
}
|
|
9711
|
-
if (!value) {
|
|
9712
|
-
continue;
|
|
9713
|
-
}
|
|
9714
|
-
content += textDecoder.decode(value, { stream: true });
|
|
9715
|
-
const lines = content.split("\n");
|
|
9716
|
-
content = lines.pop() || "";
|
|
9717
|
-
for (const line of lines) {
|
|
9718
|
-
const trimmedLine = line.trim();
|
|
9719
|
-
if (trimmedLine) {
|
|
9720
|
-
try {
|
|
9721
|
-
const message = JSON.parse(trimmedLine);
|
|
9722
|
-
controller.enqueue(message);
|
|
9723
|
-
} catch (err) {
|
|
9724
|
-
console.error("Failed to parse JSON message:", trimmedLine, err);
|
|
9725
|
-
}
|
|
9726
|
-
}
|
|
9727
|
-
}
|
|
9728
|
-
}
|
|
9729
|
-
} finally {
|
|
9730
|
-
reader.releaseLock();
|
|
9731
|
-
controller.close();
|
|
9732
|
-
}
|
|
9733
|
-
}
|
|
9734
|
-
});
|
|
9735
|
-
const writable = new WritableStream({
|
|
9736
|
-
async write(message) {
|
|
9737
|
-
const content = JSON.stringify(message) + "\n";
|
|
9738
|
-
const writer = output.getWriter();
|
|
9739
|
-
try {
|
|
9740
|
-
await writer.write(textEncoder.encode(content));
|
|
9741
|
-
} finally {
|
|
9742
|
-
writer.releaseLock();
|
|
9743
|
-
}
|
|
9744
|
-
}
|
|
9745
|
-
});
|
|
9746
|
-
return { readable, writable };
|
|
9747
|
-
}
|
|
9748
|
-
|
|
9749
|
-
// __mcpc__cli_latest/node_modules/@agentclientprotocol/sdk/dist/acp.js
|
|
9750
|
-
var ClientSideConnection = class {
|
|
9751
|
-
#connection;
|
|
9752
|
-
/**
|
|
9753
|
-
* Creates a new client-side connection to an agent.
|
|
9754
|
-
*
|
|
9755
|
-
* This establishes the communication channel between a client and agent
|
|
9756
|
-
* following the ACP specification.
|
|
9757
|
-
*
|
|
9758
|
-
* @param toClient - A function that creates a Client handler to process incoming agent requests
|
|
9759
|
-
* @param stream - The bidirectional message stream for communication. Typically created using
|
|
9760
|
-
* {@link ndJsonStream} for stdio-based connections.
|
|
9761
|
-
*
|
|
9762
|
-
* See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
|
|
9763
|
-
*/
|
|
9764
|
-
constructor(toClient, stream) {
|
|
9765
|
-
const client = toClient(this);
|
|
9766
|
-
const requestHandler = async (method, params) => {
|
|
9767
|
-
switch (method) {
|
|
9768
|
-
case CLIENT_METHODS.fs_write_text_file: {
|
|
9769
|
-
const validatedParams = writeTextFileRequestSchema.parse(params);
|
|
9770
|
-
return client.writeTextFile?.(validatedParams);
|
|
9771
|
-
}
|
|
9772
|
-
case CLIENT_METHODS.fs_read_text_file: {
|
|
9773
|
-
const validatedParams = readTextFileRequestSchema.parse(params);
|
|
9774
|
-
return client.readTextFile?.(validatedParams);
|
|
9775
|
-
}
|
|
9776
|
-
case CLIENT_METHODS.session_request_permission: {
|
|
9777
|
-
const validatedParams = requestPermissionRequestSchema.parse(params);
|
|
9778
|
-
return client.requestPermission(validatedParams);
|
|
9779
|
-
}
|
|
9780
|
-
case CLIENT_METHODS.terminal_create: {
|
|
9781
|
-
const validatedParams = createTerminalRequestSchema.parse(params);
|
|
9782
|
-
return client.createTerminal?.(validatedParams);
|
|
9783
|
-
}
|
|
9784
|
-
case CLIENT_METHODS.terminal_output: {
|
|
9785
|
-
const validatedParams = terminalOutputRequestSchema.parse(params);
|
|
9786
|
-
return client.terminalOutput?.(validatedParams);
|
|
9787
|
-
}
|
|
9788
|
-
case CLIENT_METHODS.terminal_release: {
|
|
9789
|
-
const validatedParams = releaseTerminalRequestSchema.parse(params);
|
|
9790
|
-
const result = await client.releaseTerminal?.(validatedParams);
|
|
9791
|
-
return result ?? {};
|
|
9792
|
-
}
|
|
9793
|
-
case CLIENT_METHODS.terminal_wait_for_exit: {
|
|
9794
|
-
const validatedParams = waitForTerminalExitRequestSchema.parse(params);
|
|
9795
|
-
return client.waitForTerminalExit?.(validatedParams);
|
|
9796
|
-
}
|
|
9797
|
-
case CLIENT_METHODS.terminal_kill: {
|
|
9798
|
-
const validatedParams = killTerminalCommandRequestSchema.parse(params);
|
|
9799
|
-
const result = await client.killTerminal?.(validatedParams);
|
|
9800
|
-
return result ?? {};
|
|
9801
|
-
}
|
|
9802
|
-
default:
|
|
9803
|
-
if (method.startsWith("_")) {
|
|
9804
|
-
const customMethod = method.substring(1);
|
|
9805
|
-
if (!client.extMethod) {
|
|
9806
|
-
throw RequestError.methodNotFound(method);
|
|
9807
|
-
}
|
|
9808
|
-
return client.extMethod(customMethod, params);
|
|
9809
|
-
}
|
|
9810
|
-
throw RequestError.methodNotFound(method);
|
|
9811
|
-
}
|
|
9812
|
-
};
|
|
9813
|
-
const notificationHandler = async (method, params) => {
|
|
9814
|
-
switch (method) {
|
|
9815
|
-
case CLIENT_METHODS.session_update: {
|
|
9816
|
-
const validatedParams = sessionNotificationSchema.parse(params);
|
|
9817
|
-
return client.sessionUpdate(validatedParams);
|
|
9818
|
-
}
|
|
9819
|
-
default:
|
|
9820
|
-
if (method.startsWith("_")) {
|
|
9821
|
-
const customMethod = method.substring(1);
|
|
9822
|
-
if (!client.extNotification) {
|
|
9823
|
-
return;
|
|
9824
|
-
}
|
|
9825
|
-
return client.extNotification(customMethod, params);
|
|
9826
|
-
}
|
|
9827
|
-
throw RequestError.methodNotFound(method);
|
|
9828
|
-
}
|
|
9829
|
-
};
|
|
9830
|
-
this.#connection = new Connection(requestHandler, notificationHandler, stream);
|
|
9831
|
-
}
|
|
9832
|
-
/**
|
|
9833
|
-
* Establishes the connection with a client and negotiates protocol capabilities.
|
|
9834
|
-
*
|
|
9835
|
-
* This method is called once at the beginning of the connection to:
|
|
9836
|
-
* - Negotiate the protocol version to use
|
|
9837
|
-
* - Exchange capability information between client and agent
|
|
9838
|
-
* - Determine available authentication methods
|
|
9839
|
-
*
|
|
9840
|
-
* The agent should respond with its supported protocol version and capabilities.
|
|
9841
|
-
*
|
|
9842
|
-
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
9843
|
-
*/
|
|
9844
|
-
async initialize(params) {
|
|
9845
|
-
return await this.#connection.sendRequest(AGENT_METHODS.initialize, params);
|
|
9846
|
-
}
|
|
9847
|
-
/**
|
|
9848
|
-
* Creates a new conversation session with the agent.
|
|
9849
|
-
*
|
|
9850
|
-
* Sessions represent independent conversation contexts with their own history and state.
|
|
9851
|
-
*
|
|
9852
|
-
* The agent should:
|
|
9853
|
-
* - Create a new session context
|
|
9854
|
-
* - Connect to any specified MCP servers
|
|
9855
|
-
* - Return a unique session ID for future requests
|
|
9856
|
-
*
|
|
9857
|
-
* May return an `auth_required` error if the agent requires authentication.
|
|
9858
|
-
*
|
|
9859
|
-
* See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
|
|
9860
|
-
*/
|
|
9861
|
-
async newSession(params) {
|
|
9862
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_new, params);
|
|
9863
|
-
}
|
|
9864
|
-
/**
|
|
9865
|
-
* Loads an existing session to resume a previous conversation.
|
|
9866
|
-
*
|
|
9867
|
-
* This method is only available if the agent advertises the `loadSession` capability.
|
|
9868
|
-
*
|
|
9869
|
-
* The agent should:
|
|
9870
|
-
* - Restore the session context and conversation history
|
|
9871
|
-
* - Connect to the specified MCP servers
|
|
9872
|
-
* - Stream the entire conversation history back to the client via notifications
|
|
9873
|
-
*
|
|
9874
|
-
* See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
|
|
9875
|
-
*/
|
|
9876
|
-
async loadSession(params) {
|
|
9877
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_load, params) ?? {};
|
|
9878
|
-
}
|
|
9879
|
-
/**
|
|
9880
|
-
* Sets the operational mode for a session.
|
|
9881
|
-
*
|
|
9882
|
-
* Allows switching between different agent modes (e.g., "ask", "architect", "code")
|
|
9883
|
-
* that affect system prompts, tool availability, and permission behaviors.
|
|
9884
|
-
*
|
|
9885
|
-
* The mode must be one of the modes advertised in `availableModes` during session
|
|
9886
|
-
* creation or loading. Agents may also change modes autonomously and notify the
|
|
9887
|
-
* client via `current_mode_update` notifications.
|
|
9888
|
-
*
|
|
9889
|
-
* This method can be called at any time during a session, whether the Agent is
|
|
9890
|
-
* idle or actively generating a turn.
|
|
9891
|
-
*
|
|
9892
|
-
* See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
|
|
9893
|
-
*/
|
|
9894
|
-
async setSessionMode(params) {
|
|
9895
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_set_mode, params) ?? {};
|
|
9896
|
-
}
|
|
9897
|
-
/**
|
|
9898
|
-
* **UNSTABLE**
|
|
9899
|
-
*
|
|
9900
|
-
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
9901
|
-
*
|
|
9902
|
-
* Select a model for a given session.
|
|
9903
|
-
*/
|
|
9904
|
-
async setSessionModel(params) {
|
|
9905
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_set_model, params) ?? {};
|
|
9906
|
-
}
|
|
9907
|
-
/**
|
|
9908
|
-
* Authenticates the client using the specified authentication method.
|
|
9909
|
-
*
|
|
9910
|
-
* Called when the agent requires authentication before allowing session creation.
|
|
9911
|
-
* The client provides the authentication method ID that was advertised during initialization.
|
|
9912
|
-
*
|
|
9913
|
-
* After successful authentication, the client can proceed to create sessions with
|
|
9914
|
-
* `newSession` without receiving an `auth_required` error.
|
|
9915
|
-
*
|
|
9916
|
-
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
9917
|
-
*/
|
|
9918
|
-
async authenticate(params) {
|
|
9919
|
-
return await this.#connection.sendRequest(AGENT_METHODS.authenticate, params) ?? {};
|
|
9920
|
-
}
|
|
9921
|
-
/**
|
|
9922
|
-
* Processes a user prompt within a session.
|
|
9923
|
-
*
|
|
9924
|
-
* This method handles the whole lifecycle of a prompt:
|
|
9925
|
-
* - Receives user messages with optional context (files, images, etc.)
|
|
9926
|
-
* - Processes the prompt using language models
|
|
9927
|
-
* - Reports language model content and tool calls to the Clients
|
|
9928
|
-
* - Requests permission to run tools
|
|
9929
|
-
* - Executes any requested tool calls
|
|
9930
|
-
* - Returns when the turn is complete with a stop reason
|
|
9931
|
-
*
|
|
9932
|
-
* See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
|
|
9933
|
-
*/
|
|
9934
|
-
async prompt(params) {
|
|
9935
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_prompt, params);
|
|
9936
|
-
}
|
|
9937
|
-
/**
|
|
9938
|
-
* Cancels ongoing operations for a session.
|
|
9939
|
-
*
|
|
9940
|
-
* This is a notification sent by the client to cancel an ongoing prompt turn.
|
|
9941
|
-
*
|
|
9942
|
-
* Upon receiving this notification, the Agent SHOULD:
|
|
9943
|
-
* - Stop all language model requests as soon as possible
|
|
9944
|
-
* - Abort all tool call invocations in progress
|
|
9945
|
-
* - Send any pending `session/update` notifications
|
|
9946
|
-
* - Respond to the original `session/prompt` request with `StopReason::Cancelled`
|
|
9947
|
-
*
|
|
9948
|
-
* See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
|
|
9949
|
-
*/
|
|
9950
|
-
async cancel(params) {
|
|
9951
|
-
return await this.#connection.sendNotification(AGENT_METHODS.session_cancel, params);
|
|
9952
|
-
}
|
|
9953
|
-
/**
|
|
9954
|
-
* Extension method
|
|
9955
|
-
*
|
|
9956
|
-
* Allows the Client to send an arbitrary request that is not part of the ACP spec.
|
|
9957
|
-
*/
|
|
9958
|
-
async extMethod(method, params) {
|
|
9959
|
-
return await this.#connection.sendRequest(`_${method}`, params);
|
|
9960
|
-
}
|
|
9961
|
-
/**
|
|
9962
|
-
* Extension notification
|
|
9963
|
-
*
|
|
9964
|
-
* Allows the Client to send an arbitrary notification that is not part of the ACP spec.
|
|
9965
|
-
*/
|
|
9966
|
-
async extNotification(method, params) {
|
|
9967
|
-
return await this.#connection.sendNotification(`_${method}`, params);
|
|
9968
|
-
}
|
|
9969
|
-
};
|
|
9970
|
-
var Connection = class {
|
|
9971
|
-
#pendingResponses = /* @__PURE__ */ new Map();
|
|
9972
|
-
#nextRequestId = 0;
|
|
9973
|
-
#requestHandler;
|
|
9974
|
-
#notificationHandler;
|
|
9975
|
-
#stream;
|
|
9976
|
-
#writeQueue = Promise.resolve();
|
|
9977
|
-
constructor(requestHandler, notificationHandler, stream) {
|
|
9978
|
-
this.#requestHandler = requestHandler;
|
|
9979
|
-
this.#notificationHandler = notificationHandler;
|
|
9980
|
-
this.#stream = stream;
|
|
9981
|
-
this.#receive();
|
|
9982
|
-
}
|
|
9983
|
-
async #receive() {
|
|
9984
|
-
const reader = this.#stream.readable.getReader();
|
|
9985
|
-
try {
|
|
9986
|
-
while (true) {
|
|
9987
|
-
const { value: message, done } = await reader.read();
|
|
9988
|
-
if (done) {
|
|
9989
|
-
break;
|
|
9990
|
-
}
|
|
9991
|
-
if (!message) {
|
|
9992
|
-
continue;
|
|
9993
|
-
}
|
|
9994
|
-
try {
|
|
9995
|
-
this.#processMessage(message);
|
|
9996
|
-
} catch (err) {
|
|
9997
|
-
console.error("Unexpected error during message processing:", message, err);
|
|
9998
|
-
if ("id" in message && message.id !== void 0) {
|
|
9999
|
-
this.#sendMessage({
|
|
10000
|
-
jsonrpc: "2.0",
|
|
10001
|
-
id: message.id,
|
|
10002
|
-
error: {
|
|
10003
|
-
code: -32700,
|
|
10004
|
-
message: "Parse error"
|
|
10005
|
-
}
|
|
10006
|
-
});
|
|
10007
|
-
}
|
|
10008
|
-
}
|
|
10009
|
-
}
|
|
10010
|
-
} finally {
|
|
10011
|
-
reader.releaseLock();
|
|
10012
|
-
}
|
|
10013
|
-
}
|
|
10014
|
-
async #processMessage(message) {
|
|
10015
|
-
if ("method" in message && "id" in message) {
|
|
10016
|
-
const response = await this.#tryCallRequestHandler(message.method, message.params);
|
|
10017
|
-
if ("error" in response) {
|
|
10018
|
-
console.error("Error handling request", message, response.error);
|
|
10019
|
-
}
|
|
10020
|
-
await this.#sendMessage({
|
|
10021
|
-
jsonrpc: "2.0",
|
|
10022
|
-
id: message.id,
|
|
10023
|
-
...response
|
|
10024
|
-
});
|
|
10025
|
-
} else if ("method" in message) {
|
|
10026
|
-
const response = await this.#tryCallNotificationHandler(message.method, message.params);
|
|
10027
|
-
if ("error" in response) {
|
|
10028
|
-
console.error("Error handling notification", message, response.error);
|
|
10029
|
-
}
|
|
10030
|
-
} else if ("id" in message) {
|
|
10031
|
-
this.#handleResponse(message);
|
|
10032
|
-
} else {
|
|
10033
|
-
console.error("Invalid message", { message });
|
|
10034
|
-
}
|
|
10035
|
-
}
|
|
10036
|
-
async #tryCallRequestHandler(method, params) {
|
|
10037
|
-
try {
|
|
10038
|
-
const result = await this.#requestHandler(method, params);
|
|
10039
|
-
return { result: result ?? null };
|
|
10040
|
-
} catch (error) {
|
|
10041
|
-
if (error instanceof RequestError) {
|
|
10042
|
-
return error.toResult();
|
|
10043
|
-
}
|
|
10044
|
-
if (error instanceof import_zod3.z.ZodError) {
|
|
10045
|
-
return RequestError.invalidParams(error.format()).toResult();
|
|
10046
|
-
}
|
|
10047
|
-
let details;
|
|
10048
|
-
if (error instanceof Error) {
|
|
10049
|
-
details = error.message;
|
|
10050
|
-
} else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
|
|
10051
|
-
details = error.message;
|
|
10052
|
-
}
|
|
10053
|
-
try {
|
|
10054
|
-
return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
|
|
10055
|
-
} catch {
|
|
10056
|
-
return RequestError.internalError({ details }).toResult();
|
|
10057
|
-
}
|
|
10058
|
-
}
|
|
10059
|
-
}
|
|
10060
|
-
async #tryCallNotificationHandler(method, params) {
|
|
10061
|
-
try {
|
|
10062
|
-
await this.#notificationHandler(method, params);
|
|
10063
|
-
return { result: null };
|
|
10064
|
-
} catch (error) {
|
|
10065
|
-
if (error instanceof RequestError) {
|
|
10066
|
-
return error.toResult();
|
|
10067
|
-
}
|
|
10068
|
-
if (error instanceof import_zod3.z.ZodError) {
|
|
10069
|
-
return RequestError.invalidParams(error.format()).toResult();
|
|
10070
|
-
}
|
|
10071
|
-
let details;
|
|
10072
|
-
if (error instanceof Error) {
|
|
10073
|
-
details = error.message;
|
|
10074
|
-
} else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
|
|
10075
|
-
details = error.message;
|
|
10076
|
-
}
|
|
10077
|
-
try {
|
|
10078
|
-
return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
|
|
10079
|
-
} catch {
|
|
10080
|
-
return RequestError.internalError({ details }).toResult();
|
|
10081
|
-
}
|
|
10082
|
-
}
|
|
10083
|
-
}
|
|
10084
|
-
#handleResponse(response) {
|
|
10085
|
-
const pendingResponse = this.#pendingResponses.get(response.id);
|
|
10086
|
-
if (pendingResponse) {
|
|
10087
|
-
if ("result" in response) {
|
|
10088
|
-
pendingResponse.resolve(response.result);
|
|
10089
|
-
} else if ("error" in response) {
|
|
10090
|
-
pendingResponse.reject(response.error);
|
|
10091
|
-
}
|
|
10092
|
-
this.#pendingResponses.delete(response.id);
|
|
10093
|
-
} else {
|
|
10094
|
-
console.error("Got response to unknown request", response.id);
|
|
10095
|
-
}
|
|
10096
|
-
}
|
|
10097
|
-
async sendRequest(method, params) {
|
|
10098
|
-
const id = this.#nextRequestId++;
|
|
10099
|
-
const responsePromise = new Promise((resolve3, reject) => {
|
|
10100
|
-
this.#pendingResponses.set(id, { resolve: resolve3, reject });
|
|
10101
|
-
});
|
|
10102
|
-
await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
|
|
10103
|
-
return responsePromise;
|
|
10104
|
-
}
|
|
10105
|
-
async sendNotification(method, params) {
|
|
10106
|
-
await this.#sendMessage({ jsonrpc: "2.0", method, params });
|
|
10107
|
-
}
|
|
10108
|
-
async #sendMessage(message) {
|
|
10109
|
-
this.#writeQueue = this.#writeQueue.then(async () => {
|
|
10110
|
-
const writer = this.#stream.writable.getWriter();
|
|
10111
|
-
try {
|
|
10112
|
-
await writer.write(message);
|
|
10113
|
-
} finally {
|
|
10114
|
-
writer.releaseLock();
|
|
10115
|
-
}
|
|
10116
|
-
}).catch((error) => {
|
|
10117
|
-
console.error("ACP write error:", error);
|
|
10118
|
-
});
|
|
10119
|
-
return this.#writeQueue;
|
|
10120
|
-
}
|
|
10121
|
-
};
|
|
10122
|
-
var RequestError = class _RequestError extends Error {
|
|
10123
|
-
code;
|
|
10124
|
-
data;
|
|
10125
|
-
constructor(code, message, data) {
|
|
10126
|
-
super(message);
|
|
10127
|
-
this.code = code;
|
|
10128
|
-
this.name = "RequestError";
|
|
10129
|
-
this.data = data;
|
|
10130
|
-
}
|
|
10131
|
-
/**
|
|
10132
|
-
* Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
|
|
10133
|
-
*/
|
|
10134
|
-
static parseError(data) {
|
|
10135
|
-
return new _RequestError(-32700, "Parse error", data);
|
|
10136
|
-
}
|
|
10137
|
-
/**
|
|
10138
|
-
* The JSON sent is not a valid Request object.
|
|
10139
|
-
*/
|
|
10140
|
-
static invalidRequest(data) {
|
|
10141
|
-
return new _RequestError(-32600, "Invalid request", data);
|
|
10142
|
-
}
|
|
10143
|
-
/**
|
|
10144
|
-
* The method does not exist / is not available.
|
|
10145
|
-
*/
|
|
10146
|
-
static methodNotFound(method) {
|
|
10147
|
-
return new _RequestError(-32601, "Method not found", { method });
|
|
10148
|
-
}
|
|
10149
|
-
/**
|
|
10150
|
-
* Invalid method parameter(s).
|
|
10151
|
-
*/
|
|
10152
|
-
static invalidParams(data) {
|
|
10153
|
-
return new _RequestError(-32602, "Invalid params", data);
|
|
10154
|
-
}
|
|
10155
|
-
/**
|
|
10156
|
-
* Internal JSON-RPC error.
|
|
10157
|
-
*/
|
|
10158
|
-
static internalError(data) {
|
|
10159
|
-
return new _RequestError(-32603, "Internal error", data);
|
|
10160
|
-
}
|
|
10161
|
-
/**
|
|
10162
|
-
* Authentication required.
|
|
10163
|
-
*/
|
|
10164
|
-
static authRequired(data) {
|
|
10165
|
-
return new _RequestError(-32e3, "Authentication required", data);
|
|
10166
|
-
}
|
|
10167
|
-
/**
|
|
10168
|
-
* Resource, such as a file, was not found
|
|
10169
|
-
*/
|
|
10170
|
-
static resourceNotFound(uri) {
|
|
10171
|
-
return new _RequestError(-32002, "Resource not found", uri && { uri });
|
|
10172
|
-
}
|
|
10173
|
-
toResult() {
|
|
10174
|
-
return {
|
|
10175
|
-
error: {
|
|
10176
|
-
code: this.code,
|
|
10177
|
-
message: this.message,
|
|
10178
|
-
data: this.data
|
|
10179
|
-
}
|
|
10180
|
-
};
|
|
10181
|
-
}
|
|
10182
|
-
toErrorResponse() {
|
|
10183
|
-
return {
|
|
10184
|
-
code: this.code,
|
|
10185
|
-
message: this.message,
|
|
10186
|
-
data: this.data
|
|
10187
|
-
};
|
|
10188
|
-
}
|
|
10189
|
-
};
|
|
10190
|
-
|
|
10191
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/language-model.js
|
|
10192
|
-
var import_node_child_process = require("node:child_process");
|
|
10193
|
-
var import_node_process8 = __toESM(require("node:process"), 1);
|
|
10194
|
-
var import_node_stream2 = require("node:stream");
|
|
10195
|
-
var import_zod4 = __toESM(require("zod"), 1);
|
|
10196
|
-
|
|
10197
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/format-tool-error.js
|
|
10198
|
-
function formatToolError(toolResult) {
|
|
10199
|
-
if (!toolResult || toolResult.length === 0) return "Unknown tool error";
|
|
10200
|
-
const parts = [];
|
|
10201
|
-
for (const blk of toolResult) {
|
|
10202
|
-
if (blk.type === "content") {
|
|
10203
|
-
if (blk.content.type === "text") {
|
|
10204
|
-
parts.push(blk.content.text);
|
|
10205
|
-
}
|
|
10206
|
-
}
|
|
10207
|
-
}
|
|
10208
|
-
return parts.join("\n");
|
|
10209
|
-
}
|
|
10210
|
-
|
|
10211
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/tool-proxy-host.js
|
|
10212
|
-
var import_node_net = require("node:net");
|
|
10213
|
-
|
|
10214
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/json-rpc.js
|
|
10215
|
-
function createResponse(id, result) {
|
|
10216
|
-
return {
|
|
10217
|
-
jsonrpc: "2.0",
|
|
10218
|
-
id,
|
|
10219
|
-
result
|
|
10220
|
-
};
|
|
10221
|
-
}
|
|
10222
|
-
function createErrorResponse(id, code, message, data) {
|
|
10223
|
-
const error = {
|
|
10224
|
-
code,
|
|
10225
|
-
message
|
|
10226
|
-
};
|
|
10227
|
-
if (data !== void 0) {
|
|
10228
|
-
error.data = data;
|
|
10229
|
-
}
|
|
10230
|
-
return {
|
|
10231
|
-
jsonrpc: "2.0",
|
|
10232
|
-
id,
|
|
10233
|
-
error
|
|
10234
|
-
};
|
|
10235
|
-
}
|
|
10236
|
-
function parseMessage(line) {
|
|
10237
|
-
try {
|
|
10238
|
-
const parsed = JSON.parse(line);
|
|
10239
|
-
if (parsed.jsonrpc !== "2.0") return null;
|
|
10240
|
-
return parsed;
|
|
10241
|
-
} catch {
|
|
10242
|
-
return null;
|
|
10243
|
-
}
|
|
10244
|
-
}
|
|
10245
|
-
function serializeMessage2(message) {
|
|
10246
|
-
return JSON.stringify(message);
|
|
10247
|
-
}
|
|
10248
|
-
|
|
10249
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/types.js
|
|
10250
|
-
var JsonRpcErrorCode = {
|
|
10251
|
-
PARSE_ERROR: -32700,
|
|
10252
|
-
INVALID_REQUEST: -32600,
|
|
10253
|
-
METHOD_NOT_FOUND: -32601,
|
|
10254
|
-
INVALID_PARAMS: -32602,
|
|
10255
|
-
INTERNAL_ERROR: -32603
|
|
10256
|
-
};
|
|
10257
|
-
var ProxyMethod = {
|
|
10258
|
-
// Host -> Proxy
|
|
10259
|
-
REGISTER_TOOLS: "registerTools",
|
|
10260
|
-
// Proxy -> Host
|
|
10261
|
-
CALL_HANDLER: "callHandler"
|
|
10262
|
-
};
|
|
10263
|
-
|
|
10264
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/tool-proxy-runtime.js
|
|
10265
|
-
var RUNTIME_CODE = `
|
|
10266
|
-
/* MCP Protocol Version 2024-11-05 */
|
|
10267
|
-
const isDeno=typeof Deno!=="undefined",MCP_VER="2024-11-05";
|
|
10268
|
-
let tools=[],host=null,pending=new Map,buf="",hbuf="",rid=0;
|
|
10269
|
-
const env=k=>isDeno?Deno.env.get(k):process.env[k];
|
|
10270
|
-
const write=async m=>{
|
|
10271
|
-
const s=JSON.stringify(m)+"\\n";
|
|
10272
|
-
if(isDeno)await Deno.stdout.write(new TextEncoder().encode(s));
|
|
10273
|
-
else process.stdout.write(s);
|
|
10274
|
-
};
|
|
10275
|
-
const send=(id,r,e)=>write({jsonrpc:"2.0",id,...(e?{error:e}:{result:r})});
|
|
10276
|
-
const hostReq=(m,p)=>new Promise((res,rej)=>{
|
|
10277
|
-
const id="r-"+ ++rid;
|
|
10278
|
-
const s=JSON.stringify({jsonrpc:"2.0",id,method:m,params:p})+"\\n";
|
|
10279
|
-
if(isDeno)host.write(new TextEncoder().encode(s));
|
|
10280
|
-
else host.write(s);
|
|
10281
|
-
const t=setTimeout(()=>{pending.delete(id);rej(new Error("timeout"))},30000);
|
|
10282
|
-
pending.set(id,{resolve:v=>{clearTimeout(t);res(v)},reject:e=>{clearTimeout(t);rej(e)}});
|
|
10283
|
-
});
|
|
10284
|
-
const init=async()=>{
|
|
10285
|
-
const p=parseInt(env("ACP_TOOL_PROXY_PORT")||"0",10);
|
|
10286
|
-
if(p){
|
|
10287
|
-
if(isDeno){
|
|
10288
|
-
host=await Deno.connect({hostname:"127.0.0.1",port:p});
|
|
10289
|
-
(async()=>{
|
|
10290
|
-
const d=new TextDecoder(),b=new Uint8Array(65536);
|
|
10291
|
-
while(true){const n=await host.read(b);if(!n)break;
|
|
10292
|
-
hbuf+=d.decode(b.subarray(0,n));let ls=hbuf.split("\\n");hbuf=ls.pop();
|
|
10293
|
-
for(let l of ls)if(l.trim())onHostMsg(l)}})();
|
|
10294
|
-
}else{
|
|
10295
|
-
host=require("net").createConnection({host:"127.0.0.1",port:p});
|
|
10296
|
-
await new Promise(r=>host.on("connect",r));
|
|
10297
|
-
host.on("data",d=>{hbuf+=d;let ls=hbuf.split("\\n");hbuf=ls.pop();
|
|
10298
|
-
for(let l of ls)if(l.trim())onHostMsg(l)});
|
|
10299
|
-
}
|
|
10300
|
-
try{tools=await hostReq("getTools")}catch(e){
|
|
10301
|
-
const m="Failed to get tools: "+e.message+"\\n";
|
|
10302
|
-
if(isDeno)Deno.stderr.write(new TextEncoder().encode(m));
|
|
10303
|
-
else process.stderr.write(m);
|
|
10304
|
-
}
|
|
10305
|
-
}
|
|
10306
|
-
};
|
|
10307
|
-
const onHostMsg=l=>{try{let r=JSON.parse(l),h=pending.get(r.id);
|
|
10308
|
-
if(h){pending.delete(r.id);r.error?h.reject(new Error(r.error.message)):h.resolve(r.result)}}catch{}};
|
|
10309
|
-
const handle=async l=>{let m;try{m=JSON.parse(l)}catch{return}if(m.jsonrpc!=="2.0")return;
|
|
10310
|
-
if(m.method==="initialize")send(m.id,{protocolVersion:MCP_VER,capabilities:{tools:{}},serverInfo:{name:"proxy",version:"1.0"}});
|
|
10311
|
-
else if(m.method==="notifications/initialized");
|
|
10312
|
-
else if(m.method==="tools/list")send(m.id,{tools:tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema}))});
|
|
10313
|
-
else if(m.method==="tools/call"){let p=m.params,t=tools.find(x=>x.name===p.name);
|
|
10314
|
-
if(!t)send(m.id,null,{code:-32601,message:"Not found"});
|
|
10315
|
-
else try{let r=await hostReq("callHandler",{name:p.name,args:p.arguments||{}});send(m.id,r)}
|
|
10316
|
-
catch(e){send(m.id,{content:[{type:"text",text:"Error: "+e.message}],isError:true})}}
|
|
10317
|
-
else send(m.id,null,{code:-32601,message:"Unknown"});
|
|
10318
|
-
};
|
|
10319
|
-
init().then(async()=>{
|
|
10320
|
-
if(isDeno){
|
|
10321
|
-
const d=new TextDecoder(),b=new Uint8Array(65536);
|
|
10322
|
-
while(true){const n=await Deno.stdin.read(b);if(!n)break;
|
|
10323
|
-
buf+=d.decode(b.subarray(0,n));let ls=buf.split("\\n");buf=ls.pop();for(let l of ls)if(l.trim())handle(l)}
|
|
10324
|
-
}else{
|
|
10325
|
-
process.stdin.setEncoding("utf8");
|
|
10326
|
-
process.stdin.on("data",c=>{buf+=c;let ls=buf.split("\\n");buf=ls.pop();for(let l of ls)if(l.trim())handle(l)});
|
|
10327
|
-
}
|
|
10328
|
-
});
|
|
10329
|
-
`.trim().replace(/\n/g, "");
|
|
10330
|
-
|
|
10331
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/tool-proxy-host.js
|
|
10332
|
-
var ToolProxyHost = class {
|
|
10333
|
-
server = null;
|
|
10334
|
-
connections = [];
|
|
10335
|
-
tools = /* @__PURE__ */ new Map();
|
|
10336
|
-
serverName;
|
|
10337
|
-
port = 0;
|
|
10338
|
-
constructor(name = "acp-tool-proxy") {
|
|
10339
|
-
this.serverName = name;
|
|
10340
|
-
}
|
|
10341
|
-
/**
|
|
10342
|
-
* Register an AI SDK tool to be exposed through the proxy
|
|
10343
|
-
*/
|
|
10344
|
-
registerTool(name, tool3) {
|
|
10345
|
-
this.tools.set(name, tool3);
|
|
10346
|
-
}
|
|
10347
|
-
/**
|
|
10348
|
-
* Register multiple tools at once
|
|
10349
|
-
*/
|
|
10350
|
-
registerTools(tools) {
|
|
10351
|
-
for (const [name, tool3] of Object.entries(tools)) {
|
|
10352
|
-
this.registerTool(name, tool3);
|
|
10353
|
-
}
|
|
10354
|
-
}
|
|
10355
|
-
/**
|
|
10356
|
-
* Get tool definitions for the runtime
|
|
10357
|
-
*/
|
|
10358
|
-
getToolDefinitions() {
|
|
10359
|
-
const definitions = [];
|
|
10360
|
-
for (const [name, tool3] of this.tools.entries()) {
|
|
10361
|
-
definitions.push({
|
|
10362
|
-
name,
|
|
10363
|
-
description: tool3.description || `Tool: ${name}`,
|
|
10364
|
-
// inputSchema from Tool can be Zod or JSON schema, cast to JSON schema format
|
|
10365
|
-
inputSchema: tool3.inputSchema || {
|
|
10366
|
-
type: "object",
|
|
10367
|
-
properties: {}
|
|
10368
|
-
}
|
|
10369
|
-
});
|
|
10370
|
-
}
|
|
10371
|
-
return definitions;
|
|
10372
|
-
}
|
|
10373
|
-
/**
|
|
10374
|
-
* Start TCP server and return MCP server config for ACP
|
|
10375
|
-
*/
|
|
10376
|
-
async start() {
|
|
10377
|
-
if (!this.server) {
|
|
10378
|
-
await this.startServer();
|
|
10379
|
-
}
|
|
10380
|
-
return this.getServerConfig();
|
|
10381
|
-
}
|
|
10382
|
-
/**
|
|
10383
|
-
* Get MCP server configuration
|
|
10384
|
-
*/
|
|
10385
|
-
getServerConfig() {
|
|
10386
|
-
return {
|
|
10387
|
-
name: this.serverName,
|
|
10388
|
-
command: "node",
|
|
10389
|
-
args: [
|
|
10390
|
-
"-e",
|
|
10391
|
-
RUNTIME_CODE
|
|
10392
|
-
],
|
|
10393
|
-
env: [
|
|
10394
|
-
{
|
|
10395
|
-
name: "ACP_TOOL_PROXY_PORT",
|
|
10396
|
-
value: String(this.port)
|
|
10397
|
-
}
|
|
10398
|
-
]
|
|
10399
|
-
};
|
|
10400
|
-
}
|
|
10401
|
-
/**
|
|
10402
|
-
* Start TCP server to receive tool execution requests
|
|
10403
|
-
*/
|
|
10404
|
-
startServer() {
|
|
10405
|
-
return new Promise((resolve3, reject) => {
|
|
10406
|
-
this.server = (0, import_node_net.createServer)((socket) => {
|
|
10407
|
-
this.handleConnection(socket);
|
|
10408
|
-
});
|
|
10409
|
-
this.server.on("error", (err) => {
|
|
10410
|
-
reject(err);
|
|
10411
|
-
});
|
|
10412
|
-
this.server.listen(0, "127.0.0.1", () => {
|
|
10413
|
-
const address = this.server.address();
|
|
10414
|
-
if (typeof address === "object" && address) {
|
|
10415
|
-
this.port = address.port;
|
|
10416
|
-
resolve3();
|
|
10417
|
-
} else {
|
|
10418
|
-
reject(new Error("Failed to get server address"));
|
|
10419
|
-
}
|
|
10420
|
-
});
|
|
10421
|
-
});
|
|
10422
|
-
}
|
|
10423
|
-
/**
|
|
10424
|
-
* Handle incoming connection from runtime
|
|
10425
|
-
*/
|
|
10426
|
-
handleConnection(socket) {
|
|
10427
|
-
this.connections.push(socket);
|
|
10428
|
-
let buffer = "";
|
|
10429
|
-
socket.on("data", (data) => {
|
|
10430
|
-
buffer += data.toString();
|
|
10431
|
-
const lines = buffer.split("\n");
|
|
10432
|
-
buffer = lines.pop() || "";
|
|
10433
|
-
for (const line of lines) {
|
|
10434
|
-
if (!line.trim()) continue;
|
|
10435
|
-
const message = parseMessage(line);
|
|
10436
|
-
if (!message) continue;
|
|
10437
|
-
if ("method" in message) {
|
|
10438
|
-
this.handleRequest(socket, message).catch((err) => console.error("[ToolProxy] Error handling request:", err));
|
|
10439
|
-
}
|
|
10440
|
-
}
|
|
10441
|
-
});
|
|
10442
|
-
socket.on("close", () => {
|
|
10443
|
-
this.connections = this.connections.filter((c) => c !== socket);
|
|
10444
|
-
});
|
|
10445
|
-
socket.on("error", (err) => {
|
|
10446
|
-
console.error("[ToolProxy] Socket error:", err);
|
|
10447
|
-
});
|
|
10448
|
-
}
|
|
10449
|
-
/**
|
|
10450
|
-
* Handle JSON-RPC request from runtime
|
|
10451
|
-
*/
|
|
10452
|
-
async handleRequest(socket, request) {
|
|
10453
|
-
try {
|
|
10454
|
-
if (request.method === ProxyMethod.CALL_HANDLER) {
|
|
10455
|
-
const params = request.params;
|
|
10456
|
-
const tool3 = this.tools.get(params.name);
|
|
10457
|
-
if (!tool3) {
|
|
10458
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.METHOD_NOT_FOUND, `Tool not found: ${params.name}`));
|
|
10459
|
-
return;
|
|
10460
|
-
}
|
|
10461
|
-
if (!tool3.execute) {
|
|
10462
|
-
const clientToolResult = {
|
|
10463
|
-
content: [
|
|
10464
|
-
{
|
|
10465
|
-
type: "text",
|
|
10466
|
-
text: JSON.stringify({
|
|
10467
|
-
isClientTool: true,
|
|
10468
|
-
toolName: params.name,
|
|
10469
|
-
args: params.args
|
|
10470
|
-
})
|
|
10471
|
-
}
|
|
10472
|
-
],
|
|
10473
|
-
isError: false
|
|
10474
|
-
};
|
|
10475
|
-
this.sendResponse(socket, createResponse(request.id, clientToolResult));
|
|
10476
|
-
return;
|
|
10477
|
-
}
|
|
10478
|
-
const result = await tool3.execute(params.args, {
|
|
10479
|
-
toolCallId: params.name,
|
|
10480
|
-
messages: []
|
|
10481
|
-
});
|
|
10482
|
-
let toolResult;
|
|
10483
|
-
const parseResult = CallToolResultSchema.safeParse(result);
|
|
10484
|
-
if (parseResult.success) {
|
|
10485
|
-
toolResult = parseResult.data;
|
|
10486
|
-
} else {
|
|
10487
|
-
toolResult = {
|
|
10488
|
-
content: [
|
|
10489
|
-
{
|
|
10490
|
-
type: "text",
|
|
10491
|
-
text: typeof result === "string" ? result : JSON.stringify(result)
|
|
10492
|
-
}
|
|
10493
|
-
]
|
|
10494
|
-
};
|
|
10495
|
-
}
|
|
10496
|
-
this.sendResponse(socket, createResponse(request.id, toolResult));
|
|
10497
|
-
} else if (request.method === "getTools") {
|
|
10498
|
-
const definitions = this.getToolDefinitions();
|
|
10499
|
-
this.sendResponse(socket, createResponse(request.id, definitions));
|
|
10500
|
-
} else {
|
|
10501
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.METHOD_NOT_FOUND, `Unknown method: ${request.method}`));
|
|
10502
|
-
}
|
|
10503
|
-
} catch (error) {
|
|
10504
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.INTERNAL_ERROR, error instanceof Error ? error.message : String(error)));
|
|
10505
|
-
}
|
|
10506
|
-
}
|
|
10507
|
-
/**
|
|
10508
|
-
* Send response to runtime
|
|
10509
|
-
*/
|
|
10510
|
-
sendResponse(socket, response) {
|
|
10511
|
-
socket.write(serializeMessage2(response) + "\n");
|
|
10512
|
-
}
|
|
10513
|
-
/**
|
|
10514
|
-
* Stop the TCP server
|
|
10515
|
-
*/
|
|
10516
|
-
stop() {
|
|
10517
|
-
for (const socket of this.connections) {
|
|
10518
|
-
socket.destroy();
|
|
10519
|
-
}
|
|
10520
|
-
this.connections = [];
|
|
10521
|
-
if (this.server) {
|
|
10522
|
-
this.server.close();
|
|
10523
|
-
this.server = null;
|
|
10524
|
-
}
|
|
10525
|
-
this.port = 0;
|
|
10526
|
-
}
|
|
10527
|
-
};
|
|
10528
|
-
|
|
10529
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/acp-tool.js
|
|
10530
|
-
var import_ai2 = require("ai");
|
|
10531
|
-
var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME = "acp.acp_provider_agent_dynamic_tool";
|
|
10532
|
-
var executeRegistry = /* @__PURE__ */ new Map();
|
|
10533
|
-
function acpTools(tools) {
|
|
10534
|
-
for (const [name, toolDef] of Object.entries(tools)) {
|
|
10535
|
-
executeRegistry.set(name, toolDef.execute);
|
|
10536
|
-
}
|
|
10537
|
-
return {
|
|
10538
|
-
...tools,
|
|
10539
|
-
...getACPDynamicTool()
|
|
10540
|
-
};
|
|
10541
|
-
}
|
|
10542
|
-
function getACPDynamicTool() {
|
|
10543
|
-
return {
|
|
10544
|
-
[ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME]: (0, import_ai2.tool)({
|
|
10545
|
-
type: "provider-defined",
|
|
10546
|
-
id: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME,
|
|
10547
|
-
name: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME,
|
|
10548
|
-
args: {},
|
|
10549
|
-
inputSchema: (0, import_ai2.jsonSchema)({})
|
|
10550
|
-
})
|
|
10551
|
-
};
|
|
10552
|
-
}
|
|
10553
|
-
function getExecuteByName(name) {
|
|
10554
|
-
return executeRegistry.get(name);
|
|
10555
|
-
}
|
|
10556
|
-
function hasRegisteredExecute(name) {
|
|
10557
|
-
return executeRegistry.has(name);
|
|
10558
|
-
}
|
|
10559
|
-
|
|
10560
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/utils.js
|
|
10561
|
-
function extractBase64Data(data) {
|
|
10562
|
-
return data.includes(",") ? data.split(",")[1] : data;
|
|
10563
|
-
}
|
|
10564
|
-
|
|
10565
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/convert-utils.js
|
|
10566
|
-
var import_ai3 = require("ai");
|
|
10567
|
-
function convertAiSdkMessagesToAcp(options, isFreshSession) {
|
|
10568
|
-
const messages = !isFreshSession ? options.prompt.filter((m) => m.role === "user").slice(-1) : options.prompt;
|
|
10569
|
-
const contentBlocks = [];
|
|
10570
|
-
for (const msg of messages) {
|
|
10571
|
-
let prefix = "";
|
|
10572
|
-
if (msg.role === "system") prefix = "System: ";
|
|
10573
|
-
else if (msg.role === "assistant") prefix = "Assistant: ";
|
|
10574
|
-
else if (msg.role === "tool") prefix = "Result: ";
|
|
10575
|
-
if (Array.isArray(msg.content)) {
|
|
10576
|
-
let isFirst = true;
|
|
10577
|
-
for (const part of msg.content) {
|
|
10578
|
-
if (part.type === "text") {
|
|
10579
|
-
const text = isFirst ? `${prefix}${part.text} ` : part.text;
|
|
10580
|
-
contentBlocks.push({
|
|
10581
|
-
type: "text",
|
|
10582
|
-
text
|
|
10583
|
-
});
|
|
10584
|
-
isFirst = false;
|
|
10585
|
-
} else if (part.type === "tool-call") {
|
|
10586
|
-
const toolCallText = `[Tool Call: ${part.toolName}(${JSON.stringify(part.input)})]`;
|
|
10587
|
-
const text = isFirst ? `${prefix}${toolCallText} ` : toolCallText;
|
|
10588
|
-
contentBlocks.push({
|
|
10589
|
-
type: "text",
|
|
10590
|
-
text
|
|
10591
|
-
});
|
|
10592
|
-
isFirst = false;
|
|
10593
|
-
} else if (part.type === "tool-result") {
|
|
10594
|
-
const resultData = part.result ?? part.output;
|
|
10595
|
-
const resultText = JSON.stringify(resultData) ?? "null";
|
|
10596
|
-
const text = isFirst ? `${prefix}${resultText} ` : resultText;
|
|
10597
|
-
contentBlocks.push({
|
|
10598
|
-
type: "text",
|
|
10599
|
-
text
|
|
10600
|
-
});
|
|
10601
|
-
isFirst = false;
|
|
10602
|
-
} else if (part.type === "file" && typeof part.data === "string") {
|
|
10603
|
-
const type = part.mediaType.startsWith("image/") ? "image" : part.mediaType.startsWith("audio/") ? "audio" : null;
|
|
10604
|
-
if (type) {
|
|
10605
|
-
contentBlocks.push({
|
|
10606
|
-
type,
|
|
10607
|
-
mimeType: part.mediaType,
|
|
10608
|
-
data: extractBase64Data(part.data)
|
|
10609
|
-
});
|
|
10610
|
-
}
|
|
10611
|
-
}
|
|
10612
|
-
}
|
|
10613
|
-
} else if (typeof msg.content === "string") {
|
|
10614
|
-
contentBlocks.push({
|
|
10615
|
-
type: "text",
|
|
10616
|
-
text: `${prefix}${msg.content} `
|
|
10617
|
-
});
|
|
10618
|
-
}
|
|
10619
|
-
}
|
|
10620
|
-
return contentBlocks;
|
|
10621
|
-
}
|
|
10622
|
-
function extractACPTools(tools, prepared = true) {
|
|
10623
|
-
const acpTools2 = [];
|
|
10624
|
-
if (!tools) {
|
|
10625
|
-
return acpTools2;
|
|
10626
|
-
}
|
|
10627
|
-
const toolsArray = Array.isArray(tools) ? tools : Object.entries(tools).map(([name, tool3]) => ({
|
|
10628
|
-
type: "function",
|
|
10629
|
-
name,
|
|
10630
|
-
...tool3
|
|
10631
|
-
}));
|
|
10632
|
-
for (const t of toolsArray) {
|
|
10633
|
-
if (t.type === "function") {
|
|
10634
|
-
const toolWithSchema = t;
|
|
10635
|
-
const toolInputSchema = toolWithSchema.inputSchema;
|
|
10636
|
-
if (hasRegisteredExecute(t.name) && toolInputSchema) {
|
|
10637
|
-
const execute = getExecuteByName(t.name);
|
|
10638
|
-
acpTools2.push({
|
|
10639
|
-
...t,
|
|
10640
|
-
name: t.name,
|
|
10641
|
-
inputSchema: prepared ? toolInputSchema : (0, import_ai3.asSchema)(toolInputSchema).jsonSchema,
|
|
10642
|
-
execute
|
|
10643
|
-
});
|
|
10644
|
-
}
|
|
10645
|
-
}
|
|
10646
|
-
}
|
|
10647
|
-
return acpTools2;
|
|
10648
|
-
}
|
|
10649
|
-
|
|
10650
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/language-model.js
|
|
10651
|
-
var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2 = "acp.acp_provider_agent_dynamic_tool";
|
|
10652
|
-
var providerAgentDynamicToolSchema = import_zod4.default.object({
|
|
10653
|
-
toolCallId: import_zod4.default.string().describe("The unique ID of the tool call."),
|
|
10654
|
-
toolName: import_zod4.default.string().describe("The name of the tool being called."),
|
|
10655
|
-
args: import_zod4.default.record(import_zod4.default.unknown()).describe("The input arguments for the tool call.")
|
|
10656
|
-
});
|
|
10657
|
-
var ACPAISDKClient = class {
|
|
10658
|
-
onSessionUpdateCallback;
|
|
10659
|
-
onPermissionRequestCallback;
|
|
10660
|
-
setSessionUpdateHandler(handler) {
|
|
10661
|
-
this.onSessionUpdateCallback = handler;
|
|
10662
|
-
}
|
|
10663
|
-
setPermissionRequestHandler(handler) {
|
|
10664
|
-
this.onPermissionRequestCallback = handler;
|
|
10665
|
-
}
|
|
10666
|
-
sessionUpdate(params) {
|
|
10667
|
-
if (this.onSessionUpdateCallback) {
|
|
10668
|
-
this.onSessionUpdateCallback(params);
|
|
10669
|
-
}
|
|
10670
|
-
return Promise.resolve();
|
|
10671
|
-
}
|
|
10672
|
-
async requestPermission(params) {
|
|
10673
|
-
if (this.onPermissionRequestCallback) {
|
|
10674
|
-
return await this.onPermissionRequestCallback(params);
|
|
10675
|
-
}
|
|
10676
|
-
return {
|
|
10677
|
-
outcome: {
|
|
10678
|
-
outcome: "selected",
|
|
10679
|
-
optionId: params.options[0]?.optionId || "allow"
|
|
10680
|
-
}
|
|
10681
|
-
};
|
|
10682
|
-
}
|
|
10683
|
-
writeTextFile(_params) {
|
|
10684
|
-
throw new Error("File operations not implemented in language model client");
|
|
10685
|
-
}
|
|
10686
|
-
readTextFile(_params) {
|
|
10687
|
-
throw new Error("File operations not implemented in language model client");
|
|
10688
|
-
}
|
|
10689
|
-
};
|
|
10690
|
-
var ACPLanguageModel = class {
|
|
10691
|
-
specificationVersion = "v2";
|
|
10692
|
-
provider = "acp";
|
|
10693
|
-
modelId;
|
|
10694
|
-
modeId;
|
|
10695
|
-
supportedUrls = {};
|
|
10696
|
-
config;
|
|
10697
|
-
agentProcess = null;
|
|
10698
|
-
connection = null;
|
|
10699
|
-
sessionId = null;
|
|
10700
|
-
sessionResponse = null;
|
|
10701
|
-
client = null;
|
|
10702
|
-
currentModelId = null;
|
|
10703
|
-
currentModeId = null;
|
|
10704
|
-
isFreshSession = true;
|
|
10705
|
-
// State for managing stream conversion
|
|
10706
|
-
textBlockIndex = 0;
|
|
10707
|
-
thinkBlockIndex = 0;
|
|
10708
|
-
currentTextId = null;
|
|
10709
|
-
currentThinkingId = null;
|
|
10710
|
-
toolCallsMap = /* @__PURE__ */ new Map();
|
|
10711
|
-
// Tool proxy for host-side tool execution
|
|
10712
|
-
toolProxyHost = null;
|
|
10713
|
-
// Client tool interrupt mechanism
|
|
10714
|
-
clientToolAbort = null;
|
|
10715
|
-
constructor(modelId, modeId, config) {
|
|
10716
|
-
this.modelId = modelId;
|
|
10717
|
-
this.modeId = modeId;
|
|
10718
|
-
this.config = config;
|
|
10719
|
-
}
|
|
10720
|
-
/**
|
|
10721
|
-
* Resets the internal state used for stream conversion.
|
|
10722
|
-
*/
|
|
10723
|
-
resetStreamState() {
|
|
10724
|
-
this.textBlockIndex = 0;
|
|
10725
|
-
this.thinkBlockIndex = 0;
|
|
10726
|
-
this.currentTextId = null;
|
|
10727
|
-
this.currentThinkingId = null;
|
|
10728
|
-
this.toolCallsMap.clear();
|
|
10729
|
-
this.clientToolAbort = null;
|
|
10730
|
-
}
|
|
10731
|
-
/**
|
|
10732
|
-
* Parses a 'tool_call' notification update into a structured object.
|
|
10733
|
-
* Note: We only use rawInput for tool input (content is for UI display).
|
|
10734
|
-
*/
|
|
10735
|
-
parseToolCall(update) {
|
|
10736
|
-
if (update.sessionUpdate !== "tool_call") {
|
|
10737
|
-
throw new Error("Invalid update type for parseToolCall");
|
|
10738
|
-
}
|
|
10739
|
-
const toolCallId = update.toolCallId;
|
|
10740
|
-
const toolName = update.title || update.toolCallId;
|
|
10741
|
-
const toolInput = update.rawInput ?? {};
|
|
10742
|
-
return {
|
|
10743
|
-
toolCallId,
|
|
10744
|
-
toolName,
|
|
10745
|
-
toolInput
|
|
10746
|
-
};
|
|
10747
|
-
}
|
|
10748
|
-
/**
|
|
10749
|
-
* Parses a 'tool_call_update' notification update into a structured object.
|
|
10750
|
-
* Note: We only use rawOutput for tool result (content is for UI display).
|
|
10751
|
-
*/
|
|
10752
|
-
parseToolResult(update) {
|
|
10753
|
-
if (update.sessionUpdate !== "tool_call_update") {
|
|
10754
|
-
throw new Error("Invalid update type for parseToolResult");
|
|
10755
|
-
}
|
|
10756
|
-
const toolCallId = update.toolCallId;
|
|
10757
|
-
const toolName = update.title || update.toolCallId;
|
|
10758
|
-
const toolResult = update.rawOutput ?? update.content ?? null;
|
|
10759
|
-
const isError = update.status === "failed";
|
|
10760
|
-
return {
|
|
10761
|
-
toolCallId,
|
|
10762
|
-
toolName,
|
|
10763
|
-
toolResult,
|
|
10764
|
-
isError,
|
|
10765
|
-
status: update.status
|
|
10766
|
-
};
|
|
10767
|
-
}
|
|
10768
|
-
/**
|
|
10769
|
-
* Checks if a tool result is from a client-side tool (no execute function).
|
|
10770
|
-
* Client tools return a special response with `isClientTool: true`.
|
|
10771
|
-
* Handles both MCP format (type: "text") and ACP ToolCallContent format (type: "content").
|
|
10772
|
-
*/
|
|
10773
|
-
isClientToolResult(toolResult) {
|
|
10774
|
-
if (!Array.isArray(toolResult) || toolResult.length === 0) {
|
|
10775
|
-
return {
|
|
10776
|
-
isClientTool: false
|
|
10777
|
-
};
|
|
10778
|
-
}
|
|
10779
|
-
const content = toolResult[0];
|
|
10780
|
-
if (!content?.type) {
|
|
10781
|
-
return {
|
|
10782
|
-
isClientTool: false
|
|
10783
|
-
};
|
|
10784
|
-
}
|
|
10785
|
-
const textContent = content.type === "text" && typeof content.text === "string" ? content.text : content.type === "content" && content.content?.type === "text" ? content.content.text : void 0;
|
|
10786
|
-
if (!textContent) {
|
|
10787
|
-
return {
|
|
10788
|
-
isClientTool: false
|
|
10789
|
-
};
|
|
10790
|
-
}
|
|
10791
|
-
try {
|
|
10792
|
-
const parsed = JSON.parse(textContent);
|
|
10793
|
-
if (parsed.isClientTool === true) {
|
|
10794
|
-
return {
|
|
10795
|
-
isClientTool: true,
|
|
10796
|
-
toolName: parsed.toolName,
|
|
10797
|
-
args: parsed.args
|
|
10798
|
-
};
|
|
10799
|
-
}
|
|
10800
|
-
} catch {
|
|
10801
|
-
}
|
|
10802
|
-
return {
|
|
10803
|
-
isClientTool: false
|
|
10804
|
-
};
|
|
10805
|
-
}
|
|
10806
|
-
/**
|
|
10807
|
-
* Converts AI SDK prompt messages into ACP ContentBlock objects.
|
|
10808
|
-
* When session exists, only extracts the last user message (history is in session).
|
|
10809
|
-
* Prefixes text with role since ACP ContentBlock has no role field.
|
|
10810
|
-
*/
|
|
10811
|
-
/**
|
|
10812
|
-
* Ensures the ACP agent process is running and a session is established.
|
|
10813
|
-
* @param acpTools - Tools from streamText options to proxy
|
|
10814
|
-
*/
|
|
10815
|
-
/**
|
|
10816
|
-
* Connects to the ACP agent process and initializes the protocol connection.
|
|
10817
|
-
* Does NOT start a session.
|
|
10818
|
-
*/
|
|
10819
|
-
async connectClient() {
|
|
10820
|
-
if (this.connection) {
|
|
10821
|
-
return;
|
|
10822
|
-
}
|
|
10823
|
-
if (!this.agentProcess) {
|
|
10824
|
-
const sessionCwd = this.config.session?.cwd || (typeof import_node_process8.default.cwd === "function" ? import_node_process8.default.cwd() : "/");
|
|
10825
|
-
this.agentProcess = (0, import_node_child_process.spawn)(this.config.command, this.config.args ?? [], {
|
|
10826
|
-
stdio: [
|
|
10827
|
-
"pipe",
|
|
10828
|
-
"pipe",
|
|
10829
|
-
"inherit"
|
|
10830
|
-
],
|
|
10831
|
-
env: {
|
|
10832
|
-
...import_node_process8.default.env,
|
|
10833
|
-
...this.config.env
|
|
10834
|
-
},
|
|
10835
|
-
cwd: sessionCwd
|
|
10836
|
-
});
|
|
10837
|
-
if (!this.agentProcess.stdout || !this.agentProcess.stdin) {
|
|
10838
|
-
throw new Error("Failed to spawn agent process with stdio");
|
|
10839
|
-
}
|
|
10840
|
-
const input = import_node_stream2.Writable.toWeb(this.agentProcess.stdin);
|
|
10841
|
-
const output = import_node_stream2.Readable.toWeb(this.agentProcess.stdout);
|
|
10842
|
-
this.client = new ACPAISDKClient();
|
|
10843
|
-
this.connection = new ClientSideConnection(() => this.client, ndJsonStream(input, output));
|
|
10844
|
-
}
|
|
10845
|
-
if (!this.connection) {
|
|
10846
|
-
throw new Error("Connection not initialized");
|
|
10847
|
-
}
|
|
10848
|
-
const initConfig = {
|
|
10849
|
-
...this.config.initialize,
|
|
10850
|
-
protocolVersion: this.config.initialize?.protocolVersion ?? PROTOCOL_VERSION,
|
|
10851
|
-
clientCapabilities: this.config.initialize?.clientCapabilities ?? {
|
|
10852
|
-
fs: {
|
|
10853
|
-
readTextFile: false,
|
|
10854
|
-
writeTextFile: false
|
|
10855
|
-
},
|
|
10856
|
-
terminal: false
|
|
10857
|
-
}
|
|
10858
|
-
};
|
|
10859
|
-
const initResult = await this.connection.initialize(initConfig);
|
|
10860
|
-
const validAuthMethods = initResult.authMethods?.find((a) => a.id === this.config.authMethodId)?.id;
|
|
10861
|
-
if ((initResult.authMethods?.length ?? 0) > 0) {
|
|
10862
|
-
if (!this.config.authMethodId || !validAuthMethods) {
|
|
10863
|
-
console.log("[acp-ai-provider] Warning: No authMethodId specified in config, skipping authentication step. If this is not desired, please set one of the authMethodId in the ACPProviderSettings.", JSON.stringify(initResult.authMethods, null, 2));
|
|
10864
|
-
}
|
|
10865
|
-
if (this.config.authMethodId && validAuthMethods) {
|
|
10866
|
-
await this.connection.authenticate({
|
|
10867
|
-
methodId: this.config.authMethodId ?? initResult.authMethods?.[0].id
|
|
10868
|
-
});
|
|
10869
|
-
}
|
|
10870
|
-
}
|
|
10871
|
-
}
|
|
10872
|
-
/**
|
|
10873
|
-
* Starts a new session or updates the existing one.
|
|
10874
|
-
* Assumes connectClient() has been called.
|
|
10875
|
-
*/
|
|
10876
|
-
async startSession(acpTools2) {
|
|
10877
|
-
if (!this.connection) {
|
|
10878
|
-
throw new Error("Not connected");
|
|
10879
|
-
}
|
|
10880
|
-
const mcpServers = [
|
|
10881
|
-
...this.config.session?.mcpServers ?? []
|
|
10882
|
-
];
|
|
10883
|
-
let toolsAdded = false;
|
|
10884
|
-
if (acpTools2 && acpTools2.length > 0 && !this.toolProxyHost) {
|
|
10885
|
-
console.log("[acp-ai-provider] Setting up tool proxy for client-side tools...", acpTools2.map((t) => t.name));
|
|
10886
|
-
this.toolProxyHost = new ToolProxyHost("acp-ai-sdk-tools");
|
|
10887
|
-
for (const t of acpTools2) {
|
|
10888
|
-
this.toolProxyHost.registerTool(t.name, t);
|
|
10889
|
-
}
|
|
10890
|
-
toolsAdded = true;
|
|
10891
|
-
}
|
|
10892
|
-
if (this.toolProxyHost) {
|
|
10893
|
-
const proxyConfig = await this.toolProxyHost.start();
|
|
10894
|
-
mcpServers.push(proxyConfig);
|
|
10895
|
-
}
|
|
10896
|
-
if (this.sessionId && toolsAdded) {
|
|
10897
|
-
this.sessionResponse = await this.connection.newSession({
|
|
10898
|
-
...this.config.session,
|
|
10899
|
-
cwd: this.config.session?.cwd ?? import_node_process8.default.cwd(),
|
|
10900
|
-
mcpServers
|
|
10901
|
-
});
|
|
10902
|
-
this.sessionId = this.sessionResponse.sessionId;
|
|
10903
|
-
this.isFreshSession = true;
|
|
10904
|
-
await this.applySessionDelay();
|
|
10905
|
-
return;
|
|
10906
|
-
}
|
|
10907
|
-
if (this.sessionId) {
|
|
10908
|
-
return;
|
|
10909
|
-
}
|
|
10910
|
-
if (this.config.existingSessionId) {
|
|
10911
|
-
await this.connection.loadSession({
|
|
10912
|
-
sessionId: this.config.existingSessionId,
|
|
10913
|
-
cwd: this.config.session?.cwd ?? import_node_process8.default.cwd(),
|
|
10914
|
-
mcpServers
|
|
10915
|
-
});
|
|
10916
|
-
this.sessionId = this.config.existingSessionId;
|
|
10917
|
-
this.sessionResponse = {
|
|
10918
|
-
sessionId: this.config.existingSessionId
|
|
10919
|
-
};
|
|
10920
|
-
this.isFreshSession = false;
|
|
10921
|
-
} else {
|
|
10922
|
-
this.sessionResponse = await this.connection.newSession({
|
|
10923
|
-
...this.config.session,
|
|
10924
|
-
cwd: this.config.session?.cwd ?? import_node_process8.default.cwd(),
|
|
10925
|
-
mcpServers
|
|
10926
|
-
});
|
|
10927
|
-
this.sessionId = this.sessionResponse.sessionId;
|
|
10928
|
-
this.isFreshSession = true;
|
|
10929
|
-
}
|
|
10930
|
-
const { models, modes } = this.sessionResponse ?? {};
|
|
10931
|
-
if (models?.currentModelId) {
|
|
10932
|
-
this.currentModelId = models.currentModelId;
|
|
10933
|
-
}
|
|
10934
|
-
if (modes?.currentModeId) {
|
|
10935
|
-
this.currentModeId = modes.currentModeId;
|
|
10936
|
-
}
|
|
10937
|
-
if (this.modelId && this.modelId !== this.currentModelId) {
|
|
10938
|
-
await this.setModel(this.modelId);
|
|
10939
|
-
this.currentModelId = this.modelId;
|
|
10940
|
-
}
|
|
10941
|
-
if (this.modeId && this.modeId !== this.currentModeId) {
|
|
10942
|
-
await this.setMode(this.modeId);
|
|
10943
|
-
this.currentModeId = this.modeId;
|
|
10944
|
-
}
|
|
10945
|
-
await this.applySessionDelay();
|
|
10946
|
-
}
|
|
10947
|
-
async applySessionDelay() {
|
|
10948
|
-
if (this.config.sessionDelayMs) {
|
|
10949
|
-
console.log(`[acp-ai-provider] Waiting ${this.config.sessionDelayMs}ms after session setup...`);
|
|
10950
|
-
await new Promise((resolve3) => setTimeout(resolve3, this.config.sessionDelayMs));
|
|
10951
|
-
}
|
|
10952
|
-
}
|
|
10953
|
-
/**
|
|
10954
|
-
* Ensures the ACP agent process is running and a session is established.
|
|
10955
|
-
* @param acpTools - Tools from streamText options to proxy
|
|
10956
|
-
*/
|
|
10957
|
-
async ensureConnected(acpTools2) {
|
|
10958
|
-
await this.connectClient();
|
|
10959
|
-
await this.startSession(acpTools2);
|
|
10960
|
-
}
|
|
10961
|
-
/**
|
|
10962
|
-
* Clears connection state. Skips if persistSession is enabled.
|
|
10963
|
-
*/
|
|
10964
|
-
cleanup() {
|
|
10965
|
-
if (this.config.persistSession) return;
|
|
10966
|
-
this.forceCleanup();
|
|
10967
|
-
}
|
|
10968
|
-
/**
|
|
10969
|
-
* Returns the current session ID.
|
|
10970
|
-
*/
|
|
10971
|
-
getSessionId() {
|
|
10972
|
-
return this.sessionId;
|
|
10973
|
-
}
|
|
10974
|
-
/**
|
|
10975
|
-
* Initializes the session and returns session info (models, modes, meta).
|
|
10976
|
-
* Call this before prompting to discover available options.
|
|
10977
|
-
*/
|
|
10978
|
-
/**
|
|
10979
|
-
* Initializes the session and returns session info (models, modes, meta).
|
|
10980
|
-
* Call this before prompting to discover available options.
|
|
10981
|
-
*
|
|
10982
|
-
* @param acpTools - Optional list of tools to register during session initialization.
|
|
10983
|
-
*/
|
|
10984
|
-
async initSession(tools) {
|
|
10985
|
-
const acpTools2 = extractACPTools(tools, false);
|
|
10986
|
-
await this.ensureConnected(acpTools2.length > 0 ? acpTools2 : void 0);
|
|
10987
|
-
return this.sessionResponse;
|
|
10988
|
-
}
|
|
10989
|
-
/**
|
|
10990
|
-
* Sets the session mode (e.g., "ask", "plan").
|
|
10991
|
-
*/
|
|
10992
|
-
async setMode(modeId) {
|
|
10993
|
-
if (!this.connection || !this.sessionId) {
|
|
10994
|
-
throw new Error("Not connected. Call preconnect() first.");
|
|
10995
|
-
}
|
|
10996
|
-
const availableModes = this.sessionResponse?.modes?.availableModes;
|
|
10997
|
-
if (availableModes) {
|
|
10998
|
-
const foundMode = availableModes.find((m) => m.id === modeId);
|
|
10999
|
-
if (!foundMode) {
|
|
11000
|
-
const availableList = availableModes.map((m) => m.id).join(", ");
|
|
11001
|
-
const currentInfo = this.sessionResponse?.modes?.currentModeId ? ` (Current: "${this.sessionResponse.modes.currentModeId}")` : "";
|
|
11002
|
-
throw new Error(`Mode "${modeId}" is not available${currentInfo}. Available modes: ${availableList}`);
|
|
11003
|
-
}
|
|
11004
|
-
}
|
|
11005
|
-
await this.connection.setSessionMode({
|
|
11006
|
-
sessionId: this.sessionId,
|
|
11007
|
-
modeId
|
|
11008
|
-
});
|
|
11009
|
-
this.currentModeId = modeId;
|
|
11010
|
-
}
|
|
11011
|
-
/**
|
|
11012
|
-
* Sets the session model.
|
|
11013
|
-
*/
|
|
11014
|
-
async setModel(modelId) {
|
|
11015
|
-
if (!this.connection || !this.sessionId) {
|
|
11016
|
-
throw new Error("Not connected. Call preconnect() first.");
|
|
11017
|
-
}
|
|
11018
|
-
const { models } = this.sessionResponse ?? {};
|
|
11019
|
-
if (models?.availableModels) {
|
|
11020
|
-
if (!models.availableModels.some((m) => m.modelId === modelId)) {
|
|
11021
|
-
const availableList = models.availableModels.map((m) => m.modelId).join(", ");
|
|
11022
|
-
const currentInfo = this.currentModelId ? ` (Current: "${this.currentModelId}")` : "";
|
|
11023
|
-
throw new Error(`Model "${modelId}" is not available${currentInfo}. Available models: ${availableList}`);
|
|
11024
|
-
}
|
|
11025
|
-
}
|
|
11026
|
-
await this.connection.setSessionModel({
|
|
11027
|
-
sessionId: this.sessionId,
|
|
11028
|
-
modelId
|
|
11029
|
-
});
|
|
11030
|
-
this.currentModelId = modelId;
|
|
11031
|
-
}
|
|
11032
|
-
/**
|
|
11033
|
-
* Forces cleanup regardless of persistSession setting.
|
|
11034
|
-
*/
|
|
11035
|
-
forceCleanup() {
|
|
11036
|
-
if (this.toolProxyHost) {
|
|
11037
|
-
this.toolProxyHost.stop();
|
|
11038
|
-
this.toolProxyHost = null;
|
|
11039
|
-
}
|
|
11040
|
-
if (this.agentProcess) {
|
|
11041
|
-
this.agentProcess.kill();
|
|
11042
|
-
this.agentProcess.stdin?.end();
|
|
11043
|
-
this.agentProcess.stdout?.destroy();
|
|
11044
|
-
this.agentProcess = null;
|
|
11045
|
-
}
|
|
11046
|
-
this.connection = null;
|
|
11047
|
-
this.sessionId = null;
|
|
11048
|
-
this.sessionResponse = null;
|
|
11049
|
-
this.client = null;
|
|
11050
|
-
}
|
|
11051
|
-
/**
|
|
11052
|
-
* Emits raw content (plan, diffs, terminals) as raw stream parts.
|
|
11053
|
-
* Plan data is emitted directly, while diffs and terminals are bound to a toolCallId.
|
|
11054
|
-
*/
|
|
11055
|
-
emitRawContent(controller, data) {
|
|
11056
|
-
if ("entries" in data) {
|
|
11057
|
-
controller.enqueue({
|
|
11058
|
-
type: "raw",
|
|
11059
|
-
rawValue: JSON.stringify({
|
|
11060
|
-
type: "plan",
|
|
11061
|
-
entries: data.entries
|
|
11062
|
-
})
|
|
11063
|
-
});
|
|
11064
|
-
return;
|
|
11065
|
-
}
|
|
11066
|
-
for (const item of data.content) {
|
|
11067
|
-
if (item.type === "diff" || item.type === "terminal") {
|
|
11068
|
-
controller.enqueue({
|
|
11069
|
-
type: "raw",
|
|
11070
|
-
rawValue: JSON.stringify({
|
|
11071
|
-
...item,
|
|
11072
|
-
toolCallId: data.toolCallId
|
|
11073
|
-
})
|
|
11074
|
-
});
|
|
11075
|
-
}
|
|
11076
|
-
}
|
|
11077
|
-
}
|
|
11078
|
-
/**
|
|
11079
|
-
* Flushes any pending tool calls that haven't emitted tool-call yet.
|
|
11080
|
-
* This handles the case where a tool emits {} first, then the next message is a different type.
|
|
11081
|
-
*/
|
|
11082
|
-
flushPendingToolCalls(controller) {
|
|
11083
|
-
for (const [toolCallId, toolInfo] of this.toolCallsMap.entries()) {
|
|
11084
|
-
if (!toolInfo.inputAvailable) {
|
|
11085
|
-
toolInfo.inputAvailable = true;
|
|
11086
|
-
controller.enqueue({
|
|
11087
|
-
type: "tool-call",
|
|
11088
|
-
toolCallId,
|
|
11089
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11090
|
-
input: JSON.stringify({
|
|
11091
|
-
toolCallId,
|
|
11092
|
-
toolName: toolInfo.name,
|
|
11093
|
-
args: {}
|
|
11094
|
-
})
|
|
11095
|
-
});
|
|
11096
|
-
}
|
|
11097
|
-
}
|
|
11098
|
-
}
|
|
11099
|
-
/**
|
|
11100
|
-
* Standardized handler for converting SessionNotifications into
|
|
11101
|
-
* LanguageModelV2StreamPart objects, pushing them onto a stream controller.
|
|
11102
|
-
*/
|
|
11103
|
-
handleStreamNotification(controller, notification) {
|
|
11104
|
-
const update = notification.update;
|
|
11105
|
-
switch (update.sessionUpdate) {
|
|
11106
|
-
case "plan":
|
|
11107
|
-
this.flushPendingToolCalls(controller);
|
|
11108
|
-
this.emitRawContent(controller, {
|
|
11109
|
-
type: "plan",
|
|
11110
|
-
entries: update.entries
|
|
11111
|
-
});
|
|
11112
|
-
break;
|
|
11113
|
-
case "agent_thought_chunk":
|
|
11114
|
-
this.flushPendingToolCalls(controller);
|
|
11115
|
-
if (!this.currentThinkingId) {
|
|
11116
|
-
this.currentThinkingId = `reasoning - ${this.thinkBlockIndex++} `;
|
|
11117
|
-
controller.enqueue({
|
|
11118
|
-
type: "reasoning-start",
|
|
11119
|
-
id: this.currentThinkingId
|
|
11120
|
-
});
|
|
11121
|
-
}
|
|
11122
|
-
controller.enqueue({
|
|
11123
|
-
type: "reasoning-delta",
|
|
11124
|
-
id: this.currentThinkingId,
|
|
11125
|
-
delta: update.content.type === "text" ? update.content.text : ""
|
|
11126
|
-
});
|
|
11127
|
-
break;
|
|
11128
|
-
case "agent_message_chunk":
|
|
11129
|
-
this.flushPendingToolCalls(controller);
|
|
11130
|
-
if (this.currentThinkingId) {
|
|
11131
|
-
controller.enqueue({
|
|
11132
|
-
type: "reasoning-end",
|
|
11133
|
-
id: this.currentThinkingId
|
|
11134
|
-
});
|
|
11135
|
-
this.currentThinkingId = null;
|
|
11136
|
-
}
|
|
11137
|
-
if (update.content.type === "text") {
|
|
11138
|
-
const textChunk = update.content.text;
|
|
11139
|
-
if (!this.currentTextId) {
|
|
11140
|
-
this.currentTextId = `text - ${this.textBlockIndex++} `;
|
|
11141
|
-
controller.enqueue({
|
|
11142
|
-
type: "text-start",
|
|
11143
|
-
id: this.currentTextId
|
|
11144
|
-
});
|
|
11145
|
-
}
|
|
11146
|
-
controller.enqueue({
|
|
11147
|
-
type: "text-delta",
|
|
11148
|
-
id: this.currentTextId,
|
|
11149
|
-
delta: textChunk
|
|
11150
|
-
});
|
|
11151
|
-
}
|
|
11152
|
-
break;
|
|
11153
|
-
case "tool_call": {
|
|
11154
|
-
if (this.currentTextId) {
|
|
11155
|
-
controller.enqueue({
|
|
11156
|
-
type: "text-end",
|
|
11157
|
-
id: this.currentTextId
|
|
11158
|
-
});
|
|
11159
|
-
this.currentTextId = null;
|
|
11160
|
-
}
|
|
11161
|
-
if (this.currentThinkingId) {
|
|
11162
|
-
controller.enqueue({
|
|
11163
|
-
type: "reasoning-end",
|
|
11164
|
-
id: this.currentThinkingId
|
|
11165
|
-
});
|
|
11166
|
-
this.currentThinkingId = null;
|
|
11167
|
-
}
|
|
11168
|
-
const { toolCallId, toolName, toolInput } = this.parseToolCall(update);
|
|
11169
|
-
const existingToolCall = this.toolCallsMap.get(toolCallId);
|
|
11170
|
-
const hasInput = toolInput && typeof toolInput === "object" && Object.keys(toolInput).length > 0;
|
|
11171
|
-
if (!existingToolCall) {
|
|
11172
|
-
this.toolCallsMap.set(toolCallId, {
|
|
11173
|
-
index: this.toolCallsMap.size,
|
|
11174
|
-
name: toolName,
|
|
11175
|
-
inputStarted: true,
|
|
11176
|
-
inputAvailable: !!hasInput
|
|
11177
|
-
});
|
|
11178
|
-
controller.enqueue({
|
|
11179
|
-
type: "tool-input-start",
|
|
11180
|
-
id: toolCallId,
|
|
11181
|
-
toolName
|
|
11182
|
-
});
|
|
11183
|
-
if (hasInput) {
|
|
11184
|
-
controller.enqueue({
|
|
11185
|
-
type: "tool-call",
|
|
11186
|
-
toolCallId,
|
|
11187
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11188
|
-
input: JSON.stringify({
|
|
11189
|
-
toolCallId,
|
|
11190
|
-
toolName,
|
|
11191
|
-
args: toolInput
|
|
11192
|
-
})
|
|
11193
|
-
});
|
|
11194
|
-
}
|
|
11195
|
-
} else if (!existingToolCall.inputAvailable && hasInput) {
|
|
11196
|
-
existingToolCall.inputAvailable = true;
|
|
11197
|
-
if (update.title && existingToolCall.name !== update.title && update.title !== toolCallId) {
|
|
11198
|
-
existingToolCall.name = update.title;
|
|
11199
|
-
}
|
|
11200
|
-
controller.enqueue({
|
|
11201
|
-
type: "tool-call",
|
|
11202
|
-
toolCallId,
|
|
11203
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11204
|
-
input: JSON.stringify({
|
|
11205
|
-
toolCallId,
|
|
11206
|
-
toolName: existingToolCall.name,
|
|
11207
|
-
args: toolInput
|
|
11208
|
-
})
|
|
11209
|
-
});
|
|
11210
|
-
}
|
|
11211
|
-
break;
|
|
11212
|
-
}
|
|
11213
|
-
case "tool_call_update": {
|
|
11214
|
-
const { toolCallId, toolName, toolResult, isError, status } = this.parseToolResult(update);
|
|
11215
|
-
let toolInfo = this.toolCallsMap.get(toolCallId);
|
|
11216
|
-
if (status === "in_progress") {
|
|
11217
|
-
if (!toolInfo) {
|
|
11218
|
-
toolInfo = {
|
|
11219
|
-
index: this.toolCallsMap.size,
|
|
11220
|
-
name: toolName,
|
|
11221
|
-
inputStarted: true,
|
|
11222
|
-
inputAvailable: true
|
|
11223
|
-
};
|
|
11224
|
-
this.toolCallsMap.set(toolCallId, toolInfo);
|
|
11225
|
-
controller.enqueue({
|
|
11226
|
-
type: "tool-input-start",
|
|
11227
|
-
id: toolCallId,
|
|
11228
|
-
toolName
|
|
11229
|
-
});
|
|
11230
|
-
}
|
|
11231
|
-
if (!toolInfo.inputAvailable) {
|
|
11232
|
-
toolInfo.inputAvailable = true;
|
|
11233
|
-
if (update.title && toolInfo.name !== update.title && update.title !== toolCallId) {
|
|
11234
|
-
toolInfo.name = update.title;
|
|
11235
|
-
}
|
|
11236
|
-
controller.enqueue({
|
|
11237
|
-
type: "tool-call",
|
|
11238
|
-
toolCallId,
|
|
11239
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11240
|
-
input: JSON.stringify({
|
|
11241
|
-
toolCallId,
|
|
11242
|
-
toolName: toolInfo.name,
|
|
11243
|
-
args: {}
|
|
11244
|
-
})
|
|
11245
|
-
});
|
|
11246
|
-
}
|
|
11247
|
-
const content2 = update.content ?? [];
|
|
11248
|
-
if (content2.length > 0) {
|
|
11249
|
-
this.emitRawContent(controller, {
|
|
11250
|
-
content: content2,
|
|
11251
|
-
toolCallId
|
|
11252
|
-
});
|
|
11253
|
-
}
|
|
11254
|
-
break;
|
|
11255
|
-
}
|
|
11256
|
-
if (![
|
|
11257
|
-
"completed",
|
|
11258
|
-
"failed"
|
|
11259
|
-
].includes(status)) {
|
|
11260
|
-
break;
|
|
11261
|
-
}
|
|
11262
|
-
if (!toolInfo) {
|
|
11263
|
-
toolInfo = {
|
|
11264
|
-
index: this.toolCallsMap.size,
|
|
11265
|
-
name: toolName,
|
|
11266
|
-
inputAvailable: true
|
|
11267
|
-
};
|
|
11268
|
-
this.toolCallsMap.set(toolCallId, toolInfo);
|
|
11269
|
-
controller.enqueue({
|
|
11270
|
-
type: "tool-call",
|
|
11271
|
-
toolCallId,
|
|
11272
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11273
|
-
input: JSON.stringify({
|
|
11274
|
-
toolCallId,
|
|
11275
|
-
toolName
|
|
11276
|
-
})
|
|
11277
|
-
});
|
|
11278
|
-
} else if (!toolInfo.inputAvailable) {
|
|
11279
|
-
toolInfo.inputAvailable = true;
|
|
11280
|
-
if (update.title && toolInfo.name !== update.title && update.title !== toolCallId) {
|
|
11281
|
-
toolInfo.name = update.title;
|
|
11282
|
-
}
|
|
11283
|
-
controller.enqueue({
|
|
11284
|
-
type: "tool-call",
|
|
11285
|
-
toolCallId,
|
|
11286
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11287
|
-
input: JSON.stringify({
|
|
11288
|
-
toolCallId,
|
|
11289
|
-
toolName: toolInfo.name,
|
|
11290
|
-
args: {}
|
|
11291
|
-
})
|
|
11292
|
-
});
|
|
11293
|
-
}
|
|
11294
|
-
const clientToolInfo = this.isClientToolResult(toolResult);
|
|
11295
|
-
if (clientToolInfo.isClientTool) {
|
|
11296
|
-
console.log(`[acp-ai-provider] Detected client tool: ${clientToolInfo.toolName}, stopping stream`);
|
|
11297
|
-
const content2 = update.content ?? [];
|
|
11298
|
-
if (content2.length > 0) {
|
|
11299
|
-
this.emitRawContent(controller, {
|
|
11300
|
-
content: content2,
|
|
11301
|
-
toolCallId
|
|
11302
|
-
});
|
|
11303
|
-
}
|
|
11304
|
-
if (this.clientToolAbort) {
|
|
11305
|
-
controller.enqueue({
|
|
11306
|
-
type: "finish",
|
|
11307
|
-
finishReason: "tool-calls",
|
|
11308
|
-
usage: {
|
|
11309
|
-
inputTokens: void 0,
|
|
11310
|
-
outputTokens: void 0,
|
|
11311
|
-
totalTokens: void 0
|
|
11312
|
-
}
|
|
8855
|
+
} : void 0,
|
|
8856
|
+
onStepFinish: (step) => {
|
|
8857
|
+
if (span) {
|
|
8858
|
+
span.addEvent("step", {
|
|
8859
|
+
tools: step.toolCalls?.length ?? 0,
|
|
8860
|
+
reason: step.finishReason ?? ""
|
|
11313
8861
|
});
|
|
11314
|
-
controller.close();
|
|
11315
|
-
this.clientToolAbort.resolve();
|
|
11316
|
-
this.cleanup();
|
|
11317
|
-
}
|
|
11318
|
-
break;
|
|
11319
|
-
}
|
|
11320
|
-
controller.enqueue({
|
|
11321
|
-
type: "tool-result",
|
|
11322
|
-
toolCallId,
|
|
11323
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
11324
|
-
result: toolResult,
|
|
11325
|
-
providerExecuted: true,
|
|
11326
|
-
// https://github.com/vercel/ai/blob/282f062922cb59167dd3a11e3af67cfa0b75f317/packages/ai/src/generate-text/run-tools-transformation.ts#L316
|
|
11327
|
-
...isError && {
|
|
11328
|
-
isError: true,
|
|
11329
|
-
result: new Error(formatToolError(toolResult))
|
|
11330
8862
|
}
|
|
11331
|
-
});
|
|
11332
|
-
const content = update.content ?? [];
|
|
11333
|
-
if (content.length > 0) {
|
|
11334
|
-
this.emitRawContent(controller, {
|
|
11335
|
-
content,
|
|
11336
|
-
toolCallId
|
|
11337
|
-
});
|
|
11338
8863
|
}
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
*/
|
|
11346
|
-
async doGenerate(options) {
|
|
11347
|
-
try {
|
|
11348
|
-
await this.ensureConnected();
|
|
11349
|
-
const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession);
|
|
11350
|
-
this.isFreshSession = false;
|
|
11351
|
-
let accumulatedText = "";
|
|
11352
|
-
const toolCalls = [];
|
|
11353
|
-
const toolResults = /* @__PURE__ */ new Map();
|
|
11354
|
-
const mockController = {
|
|
11355
|
-
enqueue: (part) => {
|
|
11356
|
-
switch (part.type) {
|
|
11357
|
-
case "text-delta":
|
|
11358
|
-
accumulatedText += part.delta;
|
|
11359
|
-
break;
|
|
11360
|
-
case "tool-call": {
|
|
11361
|
-
const inputData = JSON.parse(part.input);
|
|
11362
|
-
toolCalls.push({
|
|
11363
|
-
id: part.toolCallId,
|
|
11364
|
-
name: inputData.toolName,
|
|
11365
|
-
input: inputData.args
|
|
11366
|
-
});
|
|
11367
|
-
break;
|
|
11368
|
-
}
|
|
11369
|
-
case "tool-result": {
|
|
11370
|
-
const matchingToolCall = toolCalls.find((tc) => tc.id === part.toolCallId);
|
|
11371
|
-
toolResults.set(part.toolCallId, {
|
|
11372
|
-
name: matchingToolCall?.name || part.toolCallId,
|
|
11373
|
-
result: part.result,
|
|
11374
|
-
isError: part.isError
|
|
11375
|
-
});
|
|
11376
|
-
break;
|
|
11377
|
-
}
|
|
11378
|
-
// Other stream parts (reasoning, start/end blocks, etc.)
|
|
11379
|
-
// are ignored in non-streaming mode
|
|
11380
|
-
default:
|
|
11381
|
-
break;
|
|
8864
|
+
});
|
|
8865
|
+
return {
|
|
8866
|
+
content: [
|
|
8867
|
+
{
|
|
8868
|
+
type: "text",
|
|
8869
|
+
text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
|
|
11382
8870
|
}
|
|
11383
|
-
|
|
8871
|
+
],
|
|
8872
|
+
isError: false
|
|
11384
8873
|
};
|
|
11385
|
-
|
|
11386
|
-
this.
|
|
11387
|
-
|
|
11388
|
-
|
|
11389
|
-
streamHandler(mockController, notification);
|
|
11390
|
-
});
|
|
11391
|
-
}
|
|
11392
|
-
const response = await this.connection.prompt({
|
|
11393
|
-
sessionId: this.sessionId,
|
|
11394
|
-
prompt: promptContent
|
|
8874
|
+
} catch (error) {
|
|
8875
|
+
this.logger.error({
|
|
8876
|
+
message: "Execution error",
|
|
8877
|
+
error
|
|
11395
8878
|
});
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
content.push({
|
|
11405
|
-
type: "tool-call",
|
|
11406
|
-
toolCallId: toolCall.id,
|
|
11407
|
-
toolName: toolCall.name,
|
|
11408
|
-
args: JSON.stringify(toolCall.input),
|
|
11409
|
-
input: toolCall.input,
|
|
11410
|
-
output: toolResults.get(toolCall.id)?.result
|
|
11411
|
-
});
|
|
11412
|
-
}
|
|
11413
|
-
const result = {
|
|
11414
|
-
content,
|
|
11415
|
-
finishReason: response.stopReason === "end_turn" ? "stop" : "other",
|
|
11416
|
-
usage: {
|
|
11417
|
-
inputTokens: 0,
|
|
11418
|
-
outputTokens: 0,
|
|
11419
|
-
totalTokens: 0
|
|
11420
|
-
},
|
|
11421
|
-
warnings: []
|
|
8879
|
+
return {
|
|
8880
|
+
content: [
|
|
8881
|
+
{
|
|
8882
|
+
type: "text",
|
|
8883
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`
|
|
8884
|
+
}
|
|
8885
|
+
],
|
|
8886
|
+
isError: true
|
|
11422
8887
|
};
|
|
11423
|
-
this.cleanup();
|
|
11424
|
-
return result;
|
|
11425
|
-
} catch (error) {
|
|
11426
|
-
this.cleanup();
|
|
11427
|
-
throw error;
|
|
11428
8888
|
}
|
|
11429
8889
|
}
|
|
11430
|
-
|
|
11431
|
-
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
|
|
11435
|
-
|
|
11436
|
-
const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession);
|
|
11437
|
-
this.isFreshSession = false;
|
|
11438
|
-
const connection = this.connection;
|
|
11439
|
-
const sessionId = this.sessionId;
|
|
11440
|
-
const client = this.client;
|
|
11441
|
-
const cleanup = () => this.cleanup();
|
|
11442
|
-
const streamHandler = this.handleStreamNotification.bind(this);
|
|
11443
|
-
const stream = new ReadableStream({
|
|
11444
|
-
start: async (controller) => {
|
|
11445
|
-
controller.enqueue({
|
|
11446
|
-
type: "stream-start",
|
|
11447
|
-
warnings: []
|
|
11448
|
-
});
|
|
11449
|
-
this.resetStreamState();
|
|
11450
|
-
const clientToolPromise = new Promise((resolve3) => {
|
|
11451
|
-
this.clientToolAbort = {
|
|
11452
|
-
controller,
|
|
11453
|
-
resolve: resolve3
|
|
11454
|
-
};
|
|
11455
|
-
});
|
|
11456
|
-
try {
|
|
11457
|
-
if (client) {
|
|
11458
|
-
client.setSessionUpdateHandler((notification) => {
|
|
11459
|
-
streamHandler(controller, notification);
|
|
11460
|
-
});
|
|
11461
|
-
}
|
|
11462
|
-
const promptPromise = connection.prompt({
|
|
11463
|
-
sessionId,
|
|
11464
|
-
prompt: promptContent
|
|
11465
|
-
});
|
|
11466
|
-
const result = await Promise.race([
|
|
11467
|
-
promptPromise.then((response2) => ({
|
|
11468
|
-
type: "response",
|
|
11469
|
-
response: response2
|
|
11470
|
-
})),
|
|
11471
|
-
clientToolPromise.then(() => ({
|
|
11472
|
-
type: "client-tool"
|
|
11473
|
-
}))
|
|
11474
|
-
]);
|
|
11475
|
-
if (result.type === "client-tool") {
|
|
11476
|
-
return;
|
|
11477
|
-
}
|
|
11478
|
-
const response = result.response;
|
|
11479
|
-
controller.enqueue({
|
|
11480
|
-
type: "finish",
|
|
11481
|
-
finishReason: response.stopReason === "end_turn" ? "stop" : "other",
|
|
11482
|
-
usage: {
|
|
11483
|
-
inputTokens: 0,
|
|
11484
|
-
outputTokens: 0,
|
|
11485
|
-
totalTokens: 0
|
|
11486
|
-
}
|
|
11487
|
-
});
|
|
11488
|
-
controller.close();
|
|
11489
|
-
cleanup();
|
|
11490
|
-
} catch (error) {
|
|
11491
|
-
cleanup();
|
|
11492
|
-
controller.enqueue({
|
|
11493
|
-
type: "error",
|
|
11494
|
-
error
|
|
11495
|
-
});
|
|
11496
|
-
}
|
|
11497
|
-
},
|
|
11498
|
-
cancel: () => {
|
|
11499
|
-
cleanup();
|
|
11500
|
-
}
|
|
8890
|
+
buildSystemPrompt(args) {
|
|
8891
|
+
return CompiledPrompts.aiLoopSystem({
|
|
8892
|
+
toolName: this.config.name,
|
|
8893
|
+
description: this.config.description,
|
|
8894
|
+
rules: this.getRules(),
|
|
8895
|
+
context: this.formatContext(args.context)
|
|
11501
8896
|
});
|
|
11502
|
-
return {
|
|
11503
|
-
stream,
|
|
11504
|
-
warnings: []
|
|
11505
|
-
};
|
|
11506
8897
|
}
|
|
11507
|
-
|
|
11508
|
-
return
|
|
8898
|
+
getRules() {
|
|
8899
|
+
return `1. Use tools to complete the user's request
|
|
8900
|
+
2. Review results after each tool call
|
|
8901
|
+
3. Adapt your approach based on outcomes
|
|
8902
|
+
4. Continue until task is complete
|
|
8903
|
+
5. When complete, provide a summary WITHOUT calling more tools`;
|
|
8904
|
+
}
|
|
8905
|
+
formatContext(context2) {
|
|
8906
|
+
if (!context2 || Object.keys(context2).length === 0) {
|
|
8907
|
+
return "";
|
|
8908
|
+
}
|
|
8909
|
+
return `
|
|
8910
|
+
|
|
8911
|
+
<context>
|
|
8912
|
+
${JSON.stringify(context2, null, 2)}
|
|
8913
|
+
</context>`;
|
|
8914
|
+
}
|
|
8915
|
+
convertToAISDKTool(name, toolDetail, execute) {
|
|
8916
|
+
const cleanedSchema = toolDetail.inputSchema ? cleanToolSchema(toolDetail.inputSchema) : {
|
|
8917
|
+
type: "object"
|
|
8918
|
+
};
|
|
8919
|
+
return (0, import_ai.tool)({
|
|
8920
|
+
description: toolDetail.description || `Tool: ${name}`,
|
|
8921
|
+
inputSchema: (0, import_ai.jsonSchema)(cleanedSchema),
|
|
8922
|
+
execute
|
|
8923
|
+
});
|
|
11509
8924
|
}
|
|
11510
8925
|
};
|
|
11511
8926
|
|
|
11512
|
-
// __mcpc__cli_latest/node_modules/@jsr/
|
|
11513
|
-
var
|
|
11514
|
-
|
|
8927
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-executor.js
|
|
8928
|
+
var AISamplingExecutor = class extends BaseAIExecutor {
|
|
8929
|
+
server;
|
|
8930
|
+
tools;
|
|
8931
|
+
providerOptions;
|
|
8932
|
+
maxTokens;
|
|
11515
8933
|
model = null;
|
|
11516
8934
|
constructor(config) {
|
|
11517
|
-
|
|
8935
|
+
super(config, "callTool" in config.server ? config.server : void 0);
|
|
8936
|
+
this.server = config.server;
|
|
8937
|
+
this.tools = config.tools;
|
|
8938
|
+
this.providerOptions = config.providerOptions;
|
|
8939
|
+
this.maxTokens = config.maxTokens;
|
|
11518
8940
|
}
|
|
11519
|
-
|
|
11520
|
-
* Create a language model instance for a specific ACP agent
|
|
11521
|
-
*
|
|
11522
|
-
* @returns A LanguageModelV2 instance
|
|
11523
|
-
*/
|
|
11524
|
-
languageModel(modelId, modeId) {
|
|
8941
|
+
initProvider() {
|
|
11525
8942
|
if (!this.model) {
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
if (modeId) {
|
|
11532
|
-
this.model.modeId = modeId;
|
|
8943
|
+
const provider = new MCPSamplingProvider({
|
|
8944
|
+
server: this.server,
|
|
8945
|
+
maxTokens: this.maxTokens
|
|
8946
|
+
});
|
|
8947
|
+
this.model = provider.languageModel(this.providerOptions);
|
|
11533
8948
|
}
|
|
11534
8949
|
return this.model;
|
|
11535
8950
|
}
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
call() {
|
|
11540
|
-
return this.languageModel();
|
|
11541
|
-
}
|
|
11542
|
-
/**
|
|
11543
|
-
* Provider tools - includes the agent dynamic tool
|
|
11544
|
-
*/
|
|
11545
|
-
get tools() {
|
|
11546
|
-
return this.model?.tools;
|
|
11547
|
-
}
|
|
11548
|
-
/**
|
|
11549
|
-
* Returns the current session ID if one is active.
|
|
11550
|
-
* Useful when `persistSession` is enabled and you need to reference the session later.
|
|
11551
|
-
*/
|
|
11552
|
-
getSessionId() {
|
|
11553
|
-
return this.model?.getSessionId() ?? null;
|
|
8951
|
+
getModel() {
|
|
8952
|
+
if (!this.model) throw new Error("Model not initialized");
|
|
8953
|
+
return this.model;
|
|
11554
8954
|
}
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
* Call this before prompting to discover available options.
|
|
11558
|
-
*/
|
|
11559
|
-
initSession(tools) {
|
|
11560
|
-
if (!this.model) {
|
|
11561
|
-
this.languageModel();
|
|
11562
|
-
}
|
|
11563
|
-
return this.model.initSession(tools);
|
|
8955
|
+
getExecutorType() {
|
|
8956
|
+
return "mcp";
|
|
11564
8957
|
}
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
8958
|
+
buildTools() {
|
|
8959
|
+
const aiTools = {};
|
|
8960
|
+
for (const [name, detail] of this.tools) {
|
|
8961
|
+
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
8962
|
+
const result = await this.callTool(name, input);
|
|
8963
|
+
return this.formatResult(result);
|
|
8964
|
+
});
|
|
11572
8965
|
}
|
|
11573
|
-
return
|
|
8966
|
+
return aiTools;
|
|
11574
8967
|
}
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
setMode(modeId) {
|
|
11579
|
-
if (!this.model) {
|
|
11580
|
-
throw new Error("No model initialized. Call languageModel() first.");
|
|
8968
|
+
async callTool(name, input) {
|
|
8969
|
+
if ("callTool" in this.server) {
|
|
8970
|
+
return await this.server.callTool(name, input);
|
|
11581
8971
|
}
|
|
11582
|
-
|
|
8972
|
+
const detail = this.tools.find(([n]) => n === name)?.[1];
|
|
8973
|
+
if (detail?.execute) return await detail.execute(input);
|
|
8974
|
+
throw new Error(`Cannot call tool "${name}"`);
|
|
11583
8975
|
}
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
setModel(modelId) {
|
|
11588
|
-
if (!this.model) {
|
|
11589
|
-
throw new Error("No model initialized. Call languageModel() first.");
|
|
11590
|
-
}
|
|
11591
|
-
return this.model.setModel(modelId);
|
|
8976
|
+
formatResult(result) {
|
|
8977
|
+
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
8978
|
+
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
11592
8979
|
}
|
|
11593
|
-
|
|
11594
|
-
|
|
11595
|
-
|
|
11596
|
-
*/
|
|
11597
|
-
cleanup() {
|
|
11598
|
-
this.model?.forceCleanup();
|
|
8980
|
+
execute(args) {
|
|
8981
|
+
this.initProvider();
|
|
8982
|
+
return super.execute(args);
|
|
11599
8983
|
}
|
|
11600
8984
|
};
|
|
11601
|
-
|
|
11602
|
-
|
|
8985
|
+
|
|
8986
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-registrar.js
|
|
8987
|
+
function registerAISamplingTool(server, params) {
|
|
8988
|
+
const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false, maxTokens } = params;
|
|
8989
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
8990
|
+
const executor = new AISamplingExecutor({
|
|
8991
|
+
name,
|
|
8992
|
+
description,
|
|
8993
|
+
server,
|
|
8994
|
+
tools: toolNameToDetailList,
|
|
8995
|
+
providerOptions,
|
|
8996
|
+
maxSteps,
|
|
8997
|
+
tracingEnabled,
|
|
8998
|
+
maxTokens
|
|
8999
|
+
});
|
|
9000
|
+
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
9001
|
+
toolName: name,
|
|
9002
|
+
description,
|
|
9003
|
+
toolList: allToolNames.map((n) => `- ${n}`).join("\n")
|
|
9004
|
+
});
|
|
9005
|
+
const argsDef = createArgsDef.forSampling();
|
|
9006
|
+
const schema = allToolNames.length > 0 ? argsDef : {
|
|
9007
|
+
type: "object",
|
|
9008
|
+
properties: {}
|
|
9009
|
+
};
|
|
9010
|
+
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
9011
|
+
const validationResult = validateSchema(args, schema);
|
|
9012
|
+
if (!validationResult.valid) {
|
|
9013
|
+
return {
|
|
9014
|
+
content: [
|
|
9015
|
+
{
|
|
9016
|
+
type: "text",
|
|
9017
|
+
text: CompiledPrompts.errorResponse({
|
|
9018
|
+
errorMessage: validationResult.error || "Validation failed"
|
|
9019
|
+
})
|
|
9020
|
+
}
|
|
9021
|
+
],
|
|
9022
|
+
isError: true
|
|
9023
|
+
};
|
|
9024
|
+
}
|
|
9025
|
+
const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
|
|
9026
|
+
return executor.execute({
|
|
9027
|
+
prompt,
|
|
9028
|
+
context: args.context
|
|
9029
|
+
});
|
|
9030
|
+
});
|
|
11603
9031
|
}
|
|
11604
9032
|
|
|
9033
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-sampling-plugin.js
|
|
9034
|
+
var createAISamplingModePlugin = () => ({
|
|
9035
|
+
name: "mode-ai-sampling",
|
|
9036
|
+
version: "1.0.0",
|
|
9037
|
+
apply: "ai_sampling",
|
|
9038
|
+
registerAgentTool: (context2) => {
|
|
9039
|
+
const opts = context2.options;
|
|
9040
|
+
registerAISamplingTool(context2.server, {
|
|
9041
|
+
description: context2.description,
|
|
9042
|
+
name: context2.name,
|
|
9043
|
+
allToolNames: context2.allToolNames,
|
|
9044
|
+
depGroups: context2.depGroups,
|
|
9045
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
9046
|
+
providerOptions: opts.providerOptions,
|
|
9047
|
+
maxSteps: opts.maxSteps,
|
|
9048
|
+
tracingEnabled: opts.tracingEnabled,
|
|
9049
|
+
maxTokens: opts.maxTokens
|
|
9050
|
+
});
|
|
9051
|
+
}
|
|
9052
|
+
});
|
|
9053
|
+
var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
|
|
9054
|
+
|
|
11605
9055
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-executor.js
|
|
9056
|
+
var import_acp_ai_provider = require("@mcpc-tech/acp-ai-provider");
|
|
11606
9057
|
var AIACPExecutor = class extends BaseAIExecutor {
|
|
11607
9058
|
acpSettings;
|
|
11608
9059
|
tools;
|
|
@@ -11615,7 +9066,7 @@ var AIACPExecutor = class extends BaseAIExecutor {
|
|
|
11615
9066
|
}
|
|
11616
9067
|
initProvider() {
|
|
11617
9068
|
if (!this.model) {
|
|
11618
|
-
this.provider = createACPProvider(this.acpSettings);
|
|
9069
|
+
this.provider = (0, import_acp_ai_provider.createACPProvider)(this.acpSettings);
|
|
11619
9070
|
this.model = this.provider.languageModel();
|
|
11620
9071
|
}
|
|
11621
9072
|
return this.model;
|
|
@@ -11627,12 +9078,6 @@ var AIACPExecutor = class extends BaseAIExecutor {
|
|
|
11627
9078
|
getExecutorType() {
|
|
11628
9079
|
return "acp";
|
|
11629
9080
|
}
|
|
11630
|
-
getToolListDescription() {
|
|
11631
|
-
if (this.tools.length === 0) {
|
|
11632
|
-
return "Tools will be provided by ACP agent";
|
|
11633
|
-
}
|
|
11634
|
-
return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
11635
|
-
}
|
|
11636
9081
|
buildTools() {
|
|
11637
9082
|
const aiTools = {};
|
|
11638
9083
|
for (const [name, detail] of this.tools) {
|
|
@@ -11642,7 +9087,7 @@ var AIACPExecutor = class extends BaseAIExecutor {
|
|
|
11642
9087
|
return this.formatResult(result);
|
|
11643
9088
|
});
|
|
11644
9089
|
}
|
|
11645
|
-
return acpTools(aiTools);
|
|
9090
|
+
return (0, import_acp_ai_provider.acpTools)(aiTools);
|
|
11646
9091
|
}
|
|
11647
9092
|
formatResult(result) {
|
|
11648
9093
|
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
@@ -12027,13 +9472,13 @@ var PluginManager = class {
|
|
|
12027
9472
|
/**
|
|
12028
9473
|
* Apply transformTool hooks to a tool during composition
|
|
12029
9474
|
*/
|
|
12030
|
-
async applyTransformToolHooks(
|
|
9475
|
+
async applyTransformToolHooks(tool2, context2) {
|
|
12031
9476
|
const transformPlugins = this.plugins.filter((p2) => p2.transformTool && shouldApplyPlugin(p2, context2.mode));
|
|
12032
9477
|
if (transformPlugins.length === 0) {
|
|
12033
|
-
return
|
|
9478
|
+
return tool2;
|
|
12034
9479
|
}
|
|
12035
9480
|
const sortedPlugins = sortPluginsByOrder(transformPlugins);
|
|
12036
|
-
let currentTool =
|
|
9481
|
+
let currentTool = tool2;
|
|
12037
9482
|
for (const plugin of sortedPlugins) {
|
|
12038
9483
|
if (plugin.transformTool) {
|
|
12039
9484
|
try {
|
|
@@ -12145,7 +9590,7 @@ var ToolManager = class {
|
|
|
12145
9590
|
description,
|
|
12146
9591
|
schema
|
|
12147
9592
|
});
|
|
12148
|
-
if (options.
|
|
9593
|
+
if (options.hidden) {
|
|
12149
9594
|
this.toolConfigs.set(name, {
|
|
12150
9595
|
visibility: {
|
|
12151
9596
|
hidden: true
|
|
@@ -12165,6 +9610,11 @@ var ToolManager = class {
|
|
|
12165
9610
|
inputSchema: schema
|
|
12166
9611
|
});
|
|
12167
9612
|
}
|
|
9613
|
+
this.toolConfigs.set(name, {
|
|
9614
|
+
visibility: {
|
|
9615
|
+
public: true
|
|
9616
|
+
}
|
|
9617
|
+
});
|
|
12168
9618
|
}
|
|
12169
9619
|
/**
|
|
12170
9620
|
* Check if a tool is public (exposed to MCP clients)
|
|
@@ -12281,12 +9731,12 @@ var ToolManager = class {
|
|
|
12281
9731
|
* Get tool schema if it's hidden (for internal access)
|
|
12282
9732
|
*/
|
|
12283
9733
|
getHiddenToolSchema(name) {
|
|
12284
|
-
const
|
|
9734
|
+
const tool2 = this.toolRegistry.get(name);
|
|
12285
9735
|
const config = this.toolConfigs.get(name);
|
|
12286
|
-
if (
|
|
9736
|
+
if (tool2 && config?.visibility?.hidden && tool2.schema) {
|
|
12287
9737
|
return {
|
|
12288
|
-
description:
|
|
12289
|
-
schema:
|
|
9738
|
+
description: tool2.description,
|
|
9739
|
+
schema: tool2.schema
|
|
12290
9740
|
};
|
|
12291
9741
|
}
|
|
12292
9742
|
return void 0;
|
|
@@ -12315,18 +9765,18 @@ var ToolManager = class {
|
|
|
12315
9765
|
*/
|
|
12316
9766
|
getRegisteredToolsAsComposed() {
|
|
12317
9767
|
const composedTools = {};
|
|
12318
|
-
for (const [name,
|
|
9768
|
+
for (const [name, tool2] of this.toolRegistry.entries()) {
|
|
12319
9769
|
if (this.toolConfigs.get(name)?.visibility?.public === true) {
|
|
12320
9770
|
continue;
|
|
12321
9771
|
}
|
|
12322
9772
|
composedTools[name] = {
|
|
12323
9773
|
name,
|
|
12324
|
-
description:
|
|
12325
|
-
inputSchema: jsonSchema(
|
|
9774
|
+
description: tool2.description,
|
|
9775
|
+
inputSchema: jsonSchema(tool2.schema || {
|
|
12326
9776
|
type: "object",
|
|
12327
9777
|
properties: {}
|
|
12328
9778
|
}),
|
|
12329
|
-
execute:
|
|
9779
|
+
execute: tool2.callback
|
|
12330
9780
|
};
|
|
12331
9781
|
}
|
|
12332
9782
|
return composedTools;
|
|
@@ -12396,18 +9846,18 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
|
|
|
12396
9846
|
function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
|
|
12397
9847
|
const depGroups = {};
|
|
12398
9848
|
const toolManager = server.toolManager;
|
|
12399
|
-
toolNameToDetailList.forEach(([toolName,
|
|
9849
|
+
toolNameToDetailList.forEach(([toolName, tool2]) => {
|
|
12400
9850
|
const resolvedName = toolManager.resolveToolName(toolName);
|
|
12401
9851
|
if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
|
|
12402
9852
|
return;
|
|
12403
9853
|
}
|
|
12404
|
-
if (!
|
|
9854
|
+
if (!tool2) {
|
|
12405
9855
|
const allToolNames = [
|
|
12406
9856
|
...toolNameToDetailList.map(([n]) => n)
|
|
12407
9857
|
];
|
|
12408
9858
|
throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
|
|
12409
9859
|
}
|
|
12410
|
-
const baseSchema =
|
|
9860
|
+
const baseSchema = tool2.inputSchema.jsonSchema ?? tool2.inputSchema ?? {
|
|
12411
9861
|
type: "object",
|
|
12412
9862
|
properties: {},
|
|
12413
9863
|
required: []
|
|
@@ -12418,7 +9868,7 @@ function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicTool
|
|
|
12418
9868
|
const sanitizedKey = sanitizePropertyKey(toolName);
|
|
12419
9869
|
depGroups[sanitizedKey] = {
|
|
12420
9870
|
type: "object",
|
|
12421
|
-
description:
|
|
9871
|
+
description: tool2.description,
|
|
12422
9872
|
properties: updatedProperties,
|
|
12423
9873
|
required: [
|
|
12424
9874
|
...baseRequired
|
|
@@ -12694,9 +10144,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
12694
10144
|
const requestedToolNames = /* @__PURE__ */ new Set();
|
|
12695
10145
|
const availableToolNames = /* @__PURE__ */ new Set();
|
|
12696
10146
|
const allPlaceholderUsages = [];
|
|
12697
|
-
tagToResults.tool.forEach((
|
|
12698
|
-
if (
|
|
12699
|
-
const originalName =
|
|
10147
|
+
tagToResults.tool.forEach((tool2) => {
|
|
10148
|
+
if (tool2.attribs.name) {
|
|
10149
|
+
const originalName = tool2.attribs.name;
|
|
12700
10150
|
const toolName = sanitizePropertyKey(originalName);
|
|
12701
10151
|
if (toolName.endsWith(`_${ALL_TOOLS_PLACEHOLDER2}`) || toolName === ALL_TOOLS_PLACEHOLDER2) {
|
|
12702
10152
|
allPlaceholderUsages.push(originalName);
|
|
@@ -12714,24 +10164,24 @@ var ComposableMCPServer = class extends Server {
|
|
|
12714
10164
|
if (!this.toolNameMapping.has(internalName)) {
|
|
12715
10165
|
this.toolManager.setToolNameMapping(internalName, toolId);
|
|
12716
10166
|
}
|
|
12717
|
-
return tagToResults.tool.find((
|
|
12718
|
-
const selectAll =
|
|
10167
|
+
return tagToResults.tool.find((tool2) => {
|
|
10168
|
+
const selectAll = tool2.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool2.attribs.name === `${mcpName}`;
|
|
12719
10169
|
if (selectAll) {
|
|
12720
10170
|
return true;
|
|
12721
10171
|
}
|
|
12722
|
-
return
|
|
10172
|
+
return tool2.attribs.name === toolNameWithScope || tool2.attribs.name === toolId;
|
|
12723
10173
|
});
|
|
12724
10174
|
});
|
|
12725
|
-
Object.entries(tools).forEach(([toolId,
|
|
12726
|
-
this.toolManager.registerTool(toolId,
|
|
10175
|
+
Object.entries(tools).forEach(([toolId, tool2]) => {
|
|
10176
|
+
this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute);
|
|
12727
10177
|
});
|
|
12728
10178
|
const registeredTools = this.toolManager.getRegisteredToolsAsComposed();
|
|
12729
10179
|
const allTools = {
|
|
12730
10180
|
...tools
|
|
12731
10181
|
};
|
|
12732
|
-
Object.entries(registeredTools).forEach(([toolName,
|
|
10182
|
+
Object.entries(registeredTools).forEach(([toolName, tool2]) => {
|
|
12733
10183
|
if (!allTools[toolName]) {
|
|
12734
|
-
allTools[toolName] =
|
|
10184
|
+
allTools[toolName] = tool2;
|
|
12735
10185
|
}
|
|
12736
10186
|
availableToolNames.add(toolName);
|
|
12737
10187
|
});
|
|
@@ -12773,13 +10223,13 @@ var ComposableMCPServer = class extends Server {
|
|
|
12773
10223
|
const toolNameToDetailList = Object.entries(allTools);
|
|
12774
10224
|
const publicToolNames = this.getPublicToolNames();
|
|
12775
10225
|
const hiddenToolNames = this.getHiddenToolNames();
|
|
12776
|
-
const contextToolNames = toolNameToDetailList.map(([name2]) => name2).filter((n) => !hiddenToolNames.includes(n));
|
|
10226
|
+
const contextToolNames = toolNameToDetailList.map(([name2]) => name2).filter((n) => !hiddenToolNames.includes(n) && !publicToolNames.includes(n));
|
|
12777
10227
|
publicToolNames.forEach((toolId) => {
|
|
12778
|
-
const
|
|
12779
|
-
if (!
|
|
12780
|
-
|
|
10228
|
+
const tool2 = allTools[toolId];
|
|
10229
|
+
if (!tool2) {
|
|
10230
|
+
return;
|
|
12781
10231
|
}
|
|
12782
|
-
this.tool(toolId,
|
|
10232
|
+
this.tool(toolId, tool2.description || "", jsonSchema(tool2.inputSchema), tool2.execute, {
|
|
12783
10233
|
internal: false
|
|
12784
10234
|
});
|
|
12785
10235
|
});
|
|
@@ -12832,12 +10282,12 @@ var ComposableMCPServer = class extends Server {
|
|
|
12832
10282
|
};
|
|
12833
10283
|
|
|
12834
10284
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
|
|
12835
|
-
var
|
|
12836
|
-
var isSCF = () => Boolean(
|
|
10285
|
+
var import_node_process8 = __toESM(require("node:process"), 1);
|
|
10286
|
+
var isSCF = () => Boolean(import_node_process8.default.env.SCF_RUNTIME || import_node_process8.default.env.PROD_SCF);
|
|
12837
10287
|
if (isSCF()) {
|
|
12838
10288
|
console.log({
|
|
12839
10289
|
isSCF: isSCF(),
|
|
12840
|
-
SCF_RUNTIME:
|
|
10290
|
+
SCF_RUNTIME: import_node_process8.default.env.SCF_RUNTIME
|
|
12841
10291
|
});
|
|
12842
10292
|
}
|
|
12843
10293
|
|
|
@@ -12886,15 +10336,13 @@ function createSearchPlugin(options = {}) {
|
|
|
12886
10336
|
const timeoutMs = options.timeoutMs || 3e4;
|
|
12887
10337
|
const global2 = options.global ?? true;
|
|
12888
10338
|
const agentName = options.agentName;
|
|
12889
|
-
const toolName = agentName ? `${agentName}
|
|
10339
|
+
const toolName = agentName ? `${agentName}__grep` : "mcpc__grep";
|
|
12890
10340
|
const activeTimeouts = /* @__PURE__ */ new Set();
|
|
12891
10341
|
return {
|
|
12892
10342
|
name: "plugin-search",
|
|
12893
10343
|
version: "1.0.0",
|
|
12894
10344
|
configureServer: (server) => {
|
|
12895
|
-
const defaultDescription = agentName ? `
|
|
12896
|
-
Only search within the allowed directory: ${allowedSearchDir}` : `Search for text patterns in files and directories. Use this to find specific content, code, or information within files. Provide a simple literal string or a regular expression. If your pattern is a regex, ensure it's valid; otherwise use quotes or escape special characters to treat it as a literal string.
|
|
12897
|
-
Only search within the allowed directory: ${allowedSearchDir}`;
|
|
10345
|
+
const defaultDescription = agentName ? `Grep/search for text patterns within large tool result files for the "${agentName}" agent. **IMPORTANT**: You MUST execute the actual tool first and get a "Result too large, saved to file" response before using this grep tool. This tool searches within previously saved large results only. Provide a simple literal string or a regular expression. Only search within the allowed directory: ${allowedSearchDir}` : `Grep/search for text patterns within large tool result files. **IMPORTANT**: You MUST execute the actual tool first and get a "Result too large, saved to file" response before using this grep tool. This tool searches within previously saved large results only. Provide a simple literal string or a regular expression. If your pattern is a regex, ensure it's valid. Only search within the allowed directory: ${allowedSearchDir}`;
|
|
12898
10346
|
const toolDescription = options.toolDescription || defaultDescription;
|
|
12899
10347
|
server.tool(toolName, toolDescription, jsonSchema({
|
|
12900
10348
|
type: "object",
|
|
@@ -13113,7 +10561,7 @@ function createLargeResultPlugin(options = {}) {
|
|
|
13113
10561
|
let tempDir = options.tempDir || null;
|
|
13114
10562
|
let serverRef = null;
|
|
13115
10563
|
let agentName = null;
|
|
13116
|
-
const defaultSearchDescription = `
|
|
10564
|
+
const defaultSearchDescription = `Grep/search within large tool result files that were saved due to size limits. **IMPORTANT**: You MUST execute the actual tool first and get a "Result too large, saved to file" response before using this grep tool. This tool is ONLY for searching within previously saved large results, not for general file search. Provide specific keywords or regex patterns related to the content you're looking for.`;
|
|
13117
10565
|
return {
|
|
13118
10566
|
name: "plugin-large-result-handler",
|
|
13119
10567
|
version: "1.0.0",
|
|
@@ -13128,17 +10576,17 @@ function createLargeResultPlugin(options = {}) {
|
|
|
13128
10576
|
maxResults: options.search?.maxResults || 15,
|
|
13129
10577
|
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
13130
10578
|
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
13131
|
-
global:
|
|
10579
|
+
global: false,
|
|
13132
10580
|
agentName
|
|
13133
10581
|
};
|
|
13134
10582
|
const searchPlugin = createSearchPlugin(searchConfig);
|
|
13135
10583
|
await serverRef.addPlugin(searchPlugin);
|
|
13136
10584
|
}
|
|
13137
10585
|
},
|
|
13138
|
-
transformTool: (
|
|
13139
|
-
const originalExecute =
|
|
13140
|
-
const searchToolName = agentName ? `${agentName}
|
|
13141
|
-
|
|
10586
|
+
transformTool: (tool2, context2) => {
|
|
10587
|
+
const originalExecute = tool2.execute;
|
|
10588
|
+
const searchToolName = agentName ? `${agentName}__grep` : "mcpc__grep";
|
|
10589
|
+
tool2.execute = async (args) => {
|
|
13142
10590
|
try {
|
|
13143
10591
|
const result = await originalExecute(args);
|
|
13144
10592
|
const resultText = JSON.stringify(result);
|
|
@@ -13180,7 +10628,7 @@ ${preview}
|
|
|
13180
10628
|
throw error;
|
|
13181
10629
|
}
|
|
13182
10630
|
};
|
|
13183
|
-
return
|
|
10631
|
+
return tool2;
|
|
13184
10632
|
},
|
|
13185
10633
|
dispose: () => {
|
|
13186
10634
|
serverRef = null;
|