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