Skip to content

Commit 51c89ab

Browse files
committed
feat: update version to 0.1.8; enhance validation logic in AgenticExecutor and improve search tool plugin descriptions
1 parent 3fcab31 commit 51c89ab

File tree

6 files changed

+74
-115
lines changed

6 files changed

+74
-115
lines changed

packages/core/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mcpc/core",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"tasks": {
55
"server:compile": "echo \"no need to compile\"",
66
"test": "deno test --allow-env --allow-read tests/",

packages/core/src/executors/agentic/agentic-executor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,17 @@ export class AgenticExecutor {
143143
}
144144

145145
// Validate arguments using JSON schema
146-
validate(args: Record<string, unknown>, schema: Record<string, unknown>): {
146+
validate(
147+
args: Record<string, unknown>,
148+
schema: Record<string, unknown>,
149+
): {
147150
valid: boolean;
148151
error?: string;
149152
} {
153+
// Skip validation for complete decision
154+
if (args.decision === "complete") {
155+
return { valid: true };
156+
}
150157
const validate = ajv.compile(schema);
151158
if (!validate(args)) {
152159
const errors = new AggregateAjvError(validate.errors!);

packages/core/src/factories/args-def-factory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Workflow step definitions - provide ONLY on initial call.
108108
type: "string",
109109
enum: Object.values(DECISION_OPTIONS),
110110
description:
111-
`**Step control: \`${DECISION_OPTIONS.PROCEED}\` = next step, \`${DECISION_OPTIONS.RETRY}\` = retry current, \`${DECISION_OPTIONS.COMPLETE}\` = finish workflow**`,
111+
`**Step control: \`${DECISION_OPTIONS.PROCEED}\` = next step, \`${DECISION_OPTIONS.RETRY}\` = retry/repeat current, \`${DECISION_OPTIONS.COMPLETE}\` = finish workflow**`,
112112
}),
113113

114114
action: (): JSONSchema => ({
@@ -180,7 +180,7 @@ Workflow step definitions - provide ONLY on initial call.
180180
);
181181

182182
const actionDescription =
183-
"Specifies the action to be performed from the enum. Based on the value chosen for 'action', the corresponding sibling property (which shares the same name as the action value and contains its specific parameters) **MUST** also be provided in this object. For example, if 'action' is 'get_weather', then the 'get_weather' parameter object is mandatory.";
183+
`Specifies the action to be performed from the enum. **⚠️ When setting \`action: "example_action"\`, you MUST also provide \`"example_action": { ... }\`**`;
184184

185185
const baseProperties = {
186186
[ACTION_KEY]: {
@@ -192,7 +192,7 @@ Workflow step definitions - provide ONLY on initial call.
192192
type: "string",
193193
enum: allToolNames,
194194
description:
195-
"Specify the next action to execute only when the user's request requires additional steps. If no next action is needed, this property **MUST BE OMITTED** from the object.",
195+
"Optional: Specify the next action to execute. Only include this when you know additional actions are needed after the current one completes.",
196196
},
197197
decision: this.decision(),
198198
...depGroups,

packages/core/src/plugins/search-tool.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
4242
// Register the search tool once during plugin initialization
4343
server.tool(
4444
"search-tool-result",
45-
`Search files for text patterns. Allowed directory: ${allowedSearchDir}`,
45+
`Search for text patterns in files and directories. Use this to find specific content, code, or information within files.`,
4646
jsonSchema<{ pattern: string; path?: string; maxResults?: number }>({
4747
type: "object",
4848
properties: {
@@ -84,7 +84,8 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
8484
content: [
8585
{
8686
type: "text",
87-
text: `❌ Path "${args.path}" not allowed. Must be within: ${allowedSearchDir}`,
87+
text:
88+
`❌ Path "${args.path}" not allowed. Must be within: ${allowedSearchDir}`,
8889
},
8990
],
9091
};
@@ -125,20 +126,23 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
125126
content: [
126127
{
127128
type: "text",
128-
text: `No matches found for: "${args.pattern}"\n\nTry:\n- **Simpler/ pattern** or \`*\`\n- Check if files exist in: ${searchPath}\n- Use specific file path`,
129+
text:
130+
`No matches found for: "${args.pattern}"\n\nTry:\n- **Simpler pattern** or \`*\`\n- Check if files exist in: ${searchPath}\n- Use specific file path`,
129131
},
130132
],
131133
};
132134
}
133135

134136
// Build output and check size
135137
const matches = result.matches.slice(0, limit);
136-
let output = `Found ${result.matches.length} matches (showing up to ${matches.length}):\n\n`;
138+
let output =
139+
`Found ${result.matches.length} matches (showing up to ${matches.length}):\n\n`;
137140
let matchesIncluded = 0;
138141

139142
for (const match of matches) {
140143
const baseMatchText = `**${match.path}:${match.lineNumber}**\n`;
141-
const fullMatchText = `${baseMatchText}\`\`\`\n${match.line}\n\`\`\`\n\n`;
144+
const fullMatchText =
145+
`${baseMatchText}\`\`\`\n${match.line}\n\`\`\`\n\n`;
142146

143147
// Check if adding this match would exceed size limit
144148
if ((output + fullMatchText).length > maxOutputSize) {
@@ -148,7 +152,8 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
148152
if (remainingSpace > 50) {
149153
// Only truncate if we have reasonable space
150154
const truncatedLine = match.line.slice(0, remainingSpace);
151-
output += `${baseMatchText}\`\`\`\n${truncatedLine}...\n\`\`\`\n\n`;
155+
output +=
156+
`${baseMatchText}\`\`\`\n${truncatedLine}...\n\`\`\`\n\n`;
152157
output += `⚠️ Content truncated\n`;
153158
matchesIncluded++;
154159
} else {
@@ -164,10 +169,12 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
164169

165170
// Add size limit warning if needed
166171
if (matchesIncluded < matches.length) {
167-
output += `\n⚠️ Showing ${matchesIncluded}/${matches.length} matches (size limit)\n`;
172+
output +=
173+
`\n⚠️ Showing ${matchesIncluded}/${matches.length} matches (size limit)\n`;
168174
output += `\nFor more results:\n`;
169175
output += `- Use specific pattern: "${args.pattern} keyword"\n`;
170-
output += `- Search specific file: {"pattern": "${args.pattern}", "path": "/file.txt"}\n`;
176+
output +=
177+
`- Search specific file: {"pattern": "${args.pattern}", "path": "/file.txt"}\n`;
171178
output += `- Use fewer results: {"maxResults": 5}`;
172179
}
173180

@@ -180,8 +187,9 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
180187
],
181188
};
182189
} catch (error) {
183-
const errorMsg =
184-
error instanceof Error ? error.message : String(error);
190+
const errorMsg = error instanceof Error
191+
? error.message
192+
: String(error);
185193
const isTimeout = errorMsg.includes("timeout");
186194

187195
return {
@@ -198,7 +206,7 @@ export function createSearchPlugin(options: SearchOptions = {}): ToolPlugin {
198206
};
199207
}
200208
},
201-
{ internal: !global }
209+
{ internal: !global },
202210
);
203211
},
204212
};

packages/core/src/prompts/index.ts

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,30 @@ export const SystemPrompts = {
1212
* Base system prompt for autonomous MCP execution
1313
*/
1414
AUTONOMOUS_EXECUTION:
15-
`Agentic MCP tool \`{toolName}\` that processes instructions through iterative self-invocation and autonomous decision-making.
15+
`Autonomous AI Agent \`{toolName}\` that answers user questions through iterative self-invocation and collecting feedback.
1616
1717
<instructions>{description}</instructions>
1818
19-
## Autonomous Execution Protocol
20-
21-
**🎯 FIRST CALL (Analysis & Planning):**
22-
1. **Understand Request:** Analyze the user's instruction and identify the end goal
23-
2. **Plan Approach:** Determine the sequence of actions needed
24-
3. **Execute First Action:** Start with the most logical first step
25-
26-
**⚡ SUBSEQUENT CALLS (Iterative Execution):**
27-
1. **Evaluate Previous Action:** Analyze results from the last action
28-
2. **Assess Progress:** Determine completion status toward the final goal
29-
3. **Decision Making:**
30-
- **Continue:** Execute next logical action if more work is needed
31-
- **Complete:** Finish if the user request is fully satisfied
32-
33-
**🔄 Key Execution Rules:**
34-
- Each call should execute exactly ONE action
35-
- Always evaluate results before planning the next action
36-
- Maintain context and progress toward the original goal
37-
- Use clear reasoning for action selection
38-
- Stop when the user request is fully satisfied
39-
40-
**📋 Action Selection Criteria:**
41-
- Choose actions that directly advance toward the goal
42-
- Prioritize logical sequence and dependencies
43-
- Consider error handling and validation needs`,
19+
## Execution Rules
20+
1. **Follow instructions above** carefully
21+
2. **Answer user question** as primary goal
22+
3. **Execute** one action per call
23+
4. **Collect feedback** from each action result
24+
5. **Decide** next step:
25+
- **proceed**: More work needed
26+
- **complete**: Question answered
27+
- **retry**: Current action failed
28+
6. **Provide** parameter object matching action name
29+
7. **Continue** until complete
30+
31+
## Call Format
32+
\`\`\`json
33+
{
34+
"action": "tool_name",
35+
"decision": "proceed|retry|complete",
36+
"tool_name": { /* tool parameters */ }
37+
}
38+
\`\`\``,
4439

4540
/**
4641
* Workflow execution system prompt
@@ -66,40 +61,33 @@ export const SystemPrompts = {
6661
**⚠️ CRITICAL: When retrying failed steps, MUST use \`decision: "retry"\`**`,
6762

6863
/**
69-
* Sampling execution system prompt with JSON output constraints
64+
* JSON-only execution system prompt
7065
*/
7166
SAMPLING_EXECUTION:
72-
`You are an autonomous AI Agent named \`{toolName}\` that processes instructions through iterative sampling execution and autonomous decision-making.
67+
`Autonomous AI Agent \`{toolName}\` that answers user questions by iteratively collecting feedback and adapting your approach.
7368
7469
<instructions>{description}</instructions>
7570
76-
## Agentic Sampling Protocol
77-
78-
**🧠 AGENTIC REASONING:**
79-
1. **Autonomous Analysis:** Independently analyze the user's instruction and identify the end goal
80-
2. **Self-Directed Planning:** Autonomously determine the sequence of tools needed
81-
3. **Iterative Execution:** Use available tools step by step with self-guided decision making
82-
4. **Goal-Oriented Adaptation:** Continuously evaluate progress and adapt strategy autonomously
83-
84-
**⚡ AGENTIC EXECUTION RULES:**
85-
- Each response demonstrates autonomous reasoning and decision-making
86-
- Make self-directed choices about which tools to use and when
87-
- Adapt your approach based on previous results without external guidance
88-
- Use "decision: complete" when you autonomously determine the task is finished
89-
90-
**🔄 JSON Response Format (Agentic Decision Output):**
91-
You MUST respond with a JSON object that demonstrates your autonomous decision:
92-
- action: Your self-selected tool name
93-
- decision: "proceed" (continue execution), "retry" (retry current step), or "complete" (finish task)
94-
- [tool parameters]: Tool-specific parameters you autonomously determine
95-
96-
**📋 Available Tools:**
97-
{toolList}
98-
99-
**🎯 AGENTIC CONSTRAINTS:**
100-
- Response must be pure JSON demonstrating autonomous decision-making
101-
- Invalid JSON indicates failure in agentic reasoning
102-
- Tool parameters must reflect your independent analysis and planning`,
71+
## Execution Rules
72+
- Respond with valid JSON only
73+
- **Follow instructions above** carefully
74+
- **Answer user question** as primary goal
75+
- **Collect feedback** from each action result
76+
- **Adapt approach** based on gathered information
77+
- action = "X" → provide parameter "X"
78+
- Continue until question answered
79+
80+
## JSON Response Format
81+
\`\`\`json
82+
{
83+
"action": "tool_name",
84+
"decision": "proceed|retry|complete",
85+
"tool_name": { /* tool parameters */ }
86+
}
87+
\`\`\`
88+
89+
## Available Tools
90+
{toolList}`,
10391

10492
/**
10593
* Sampling workflow execution system prompt combining sampling with workflow capabilities

packages/core/src/utils/actions.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)