Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-agents-mcp",
"version": "0.12.0",
"version": "0.12.1",
"mcpName": "io.github.shinpr/sub-agents-mcp",
"description": "MCP server for delegating tasks to specialized AI assistants in Cursor, Claude Code, Codex, Gemini, GLM, Kimi, Grok, and OpenCode",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"url": "https://github.com/shinpr/sub-agents-mcp",
"source": "github"
},
"version": "0.12.0",
"version": "0.12.1",
"packages": [
{
"registryType": "npm",
"registryBaseUrl": "https://registry.npmjs.org",
"identifier": "sub-agents-mcp",
"version": "0.12.0",
"version": "0.12.1",
"transport": {
"type": "stdio"
},
Expand Down
8 changes: 5 additions & 3 deletions src/__tests__/e2e/critical-user-journeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ describe('Critical User Journeys - E2E Tests', () => {
if (event === 'data') {
// Synchronous for test stability
if (isTestAgent) {
callback(Buffer.from('{"type": "result", "data": "E2E test successful"}\n'))
callback(Buffer.from('{"type": "result", "result": "E2E test successful"}\n'))
} else if (isPerformanceAgent) {
callback(Buffer.from('{"type": "result", "data": "Performance test complete"}\n'))
callback(Buffer.from('{"type": "result", "result": "Performance test complete"}\n'))
} else {
callback(Buffer.from('{"type": "result", "data": "Agent executed successfully"}\n'))
callback(
Buffer.from('{"type": "result", "result": "Agent executed successfully"}\n')
)
}
}
}),
Expand Down
31 changes: 31 additions & 0 deletions src/__tests__/integration/RunAgentTool.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,37 @@ describe('RunAgentTool', () => {
expect(parsedContent.result).not.toContain('{"type":"error"}')
})

it('should not report an agent error as a successful structured result', async () => {
const params = {
agent: 'failing-agent',
prompt: 'Test prompt',
cwd: process.cwd(),
}

vi.spyOn(mockAgentExecutor, 'executeAgent').mockResolvedValue({
stdout: '{"type":"result","is_error":true}',
stderr: '',
exitCode: 143,
executionTime: 50,
hasResult: true,
resultJson: {
type: 'result',
subtype: 'error_during_execution',
is_error: true,
status: 'error',
error: 'Authentication required',
},
})

const result = await runAgentTool.execute(params)

expect(result.isError).toBe(true)
expect(result.structuredContent).toMatchObject({
result: 'Authentication required',
status: 'error',
})
})

it('should include execution metadata in response', async () => {
const params = {
agent: 'test-agent',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/integration/execution.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('AgentExecutor Integration', () => {
Buffer.from(
`${JSON.stringify({
type: 'result',
data: 'Integration test execution success',
result: 'Integration test execution success',
})}\n`
)
)
Expand All @@ -53,7 +53,7 @@ describe('AgentExecutor Integration', () => {
Buffer.from(
`${JSON.stringify({
type: 'result',
data: 'Default integration execution',
result: 'Default integration execution',
})}\n`
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/security/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Security Validation Tests', () => {
Buffer.from(
`${JSON.stringify({
type: 'result',
data: 'Security test execution',
result: 'Security test execution',
})}\n`
)
)
Expand Down
49 changes: 31 additions & 18 deletions src/execution/AgentExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ export class AgentExecutor {
return
}

const streamProcessor = new StreamProcessor()
let stdout = ''
let stderr = ''
let stdoutBuffer = ''
const streamProcessor = new StreamProcessor(this.config.agentType)
const stdoutParts: string[] = []
const stderrParts: string[] = []
let stdoutLineParts: string[] = []
const stdoutDecoder = new StringDecoder('utf8')
const stderrDecoder = new StringDecoder('utf8')
let stdoutTruncated = false
Expand Down Expand Up @@ -843,17 +843,21 @@ export class AgentExecutor {

if (!stdoutTruncated) {
const tail = stdoutDecoder.end()
stdout += tail
stdoutBuffer += tail
stdoutParts.push(tail)
stdoutLineParts.push(tail)
}
if (!stderrTruncated) {
stderr += stderrDecoder.end()
stderrParts.push(stderrDecoder.end())
}

if (stdoutBuffer.trim()) {
streamProcessor.processLine(stdoutBuffer)
stdoutBuffer = ''
const trailingLine = stdoutLineParts.join('')
if (trailingLine.trim()) {
streamProcessor.processLine(trailingLine)
}
stdoutLineParts = []

const stdout = stdoutParts.join('')
const stderr = stderrParts.join('')

let result = streamProcessor.getResult()
if (result === null) {
Expand Down Expand Up @@ -925,13 +929,20 @@ export class AgentExecutor {
const chunk = captureChunk(data, stdoutDecoder, () => {
stdoutTruncated = true
})
stdout += chunk
stdoutBuffer += chunk
stdoutParts.push(chunk)

const lines = stdoutBuffer.split('\n')
stdoutBuffer = lines.pop() || ''
let chunkOffset = 0
while (chunkOffset < chunk.length) {
const newlineIndex = chunk.indexOf('\n', chunkOffset)
if (newlineIndex < 0) {
stdoutLineParts.push(chunk.slice(chunkOffset))
break
}

for (const line of lines) {
stdoutLineParts.push(chunk.slice(chunkOffset, newlineIndex))
const line = stdoutLineParts.join('')
stdoutLineParts = []
chunkOffset = newlineIndex + 1
if (streamProcessor.processLine(line)) {
requestTermination()
break
Expand All @@ -940,9 +951,11 @@ export class AgentExecutor {
})

childProcess.stderr?.on('data', (data: Buffer) => {
stderr += captureChunk(data, stderrDecoder, () => {
stderrTruncated = true
})
stderrParts.push(
captureChunk(data, stderrDecoder, () => {
stderrTruncated = true
})
)
})

childProcess.on('close', (code: number | null, signal?: NodeJS.Signals | null) => {
Expand Down
Loading
Loading