Class: ClaudeMemory::Commands::ServeMcpCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/claude_memory/commands/serve_mcp_command.rb

Overview

Starts MCP server

Instance Attribute Summary

Attributes inherited from BaseCommand

#stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from ClaudeMemory::Commands::BaseCommand

Instance Method Details

#call(_args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/claude_memory/commands/serve_mcp_command.rb', line 7

def call(_args)
  # Capture real stdout for MCP JSON-RPC transport, then redirect
  # $stdout to $stderr so accidental puts/print calls from gems or
  # debug output don't corrupt the stdio protocol stream.
  original_stdout = $stdout
  mcp_output = $stdout.dup
  $stdout = $stderr

  manager = ClaudeMemory::Store::StoreManager.new
  server = ClaudeMemory::MCP::Server.new(manager, output: mcp_output)
  server.run
  manager.close
  0
ensure
  $stdout = original_stdout if original_stdout
end