Skip to content

Add debug logging for MCP skill startup time #49

@FL4TLiN3

Description

@FL4TLiN3

Background

initializeRuntime to skillConnected takes approximately 7 seconds, and we need to identify the bottleneck. Currently, StdioClientTransport is created with stderr: "ignore", so base skill startup logs are not captured.

Target File

packages/runtime/src/skill-manager/mcp.ts - McpSkillManager._initStdio() method

Proposed Changes

1. Add timing logs to measure each step

async _initStdio(skill: McpStdioSkill) {
  // ... env setup ...
  
  const startTime = Date.now()
  console.log(`[MCP] Starting skill ${skill.name}...`)
  
  const { command, args } = this._getCommandArgs(skill)
  const transport = new StdioClientTransport({ command, args, env, stderr: "pipe" })
  
  const transportStartTime = Date.now()
  await this._mcpClient.connect(transport)
  const connectTime = Date.now()
  
  console.log(`[MCP] Skill ${skill.name} connected in ${connectTime - transportStartTime}ms (total: ${connectTime - startTime}ms)`)
  
  // ... rest of the method ...
}

2. Change stderr from "ignore" to "pipe" and capture stderr output

const transport = new StdioClientTransport({ 
  command, 
  args, 
  env, 
  stderr: "pipe"  // Changed from "ignore"
})

// Capture stderr output
if (transport.stderr) {
  transport.stderr.on("data", (chunk: Buffer) => {
    console.log(`[MCP:${skill.name}:stderr] ${chunk.toString().trim()}`)
  })
}

Technical Considerations

  • MCP SDK version: ^1.23.0
  • Verify: Whether transport.stderr is a public API of StdioClientTransport
  • Alternative: If transport.stderr is not accessible, consider other approaches to capture child process output

Expected Output

[MCP] Starting skill @perstack/base...
[MCP:@perstack/base:stderr] Running @repo/base-v1_0 version 1.0.0
[MCP] Skill @perstack/base connected in 150ms (total: 200ms)

Purpose

This change will help identify:

  • Time from process spawn to log output (binary startup time)
  • connect() duration (MCP handshake time)
  • Total elapsed time

Notes

  • This is for debugging purposes
  • Consider adding a debug flag to enable/disable verbose logging in production

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions