MCPcopy Index your code
hub / github.com/infinitered/reactotron / createMcpServer

Function createMcpServer

lib/reactotron-mcp/src/mcp-server.ts:22–167  ·  view source on GitHub ↗
(
  reactotronServer: ReactotronServer,
  redactionConfig?: Partial<McpRedactionServerConfig>
)

Source from the content-addressed store, hash-verified

20}
21
22export function createMcpServer(
23 reactotronServer: ReactotronServer,
24 redactionConfig?: Partial<McpRedactionServerConfig>
25): ReactotronMcpServer {
26 let serverRedactionConfig: McpRedactionServerConfig = {
27 ...DEFAULT_SERVER_CONFIG,
28 ...redactionConfig,
29 defaults: { ...DEFAULT_SERVER_CONFIG.defaults, ...redactionConfig?.defaults },
30 }
31 let httpServer: HttpServer | null = null
32 let started = false
33 let listenPort: number | null = null
34
35 // Command buffer — collects recent commands for resource reads
36 const commandBuffer: Command[] = []
37 const BUFFER_SIZE = 500
38 let commandListener: ((command: Command) => void) | null = null
39
40 function startBuffering() {
41 commandListener = (command: Command) => {
42 commandBuffer.push(command)
43 if (commandBuffer.length > BUFFER_SIZE) {
44 commandBuffer.shift()
45 }
46 }
47 reactotronServer.on("command", commandListener as any)
48 }
49
50 function stopBuffering() {
51 if (commandListener) {
52 reactotronServer.off("command", commandListener as any)
53 commandListener = null
54 }
55 commandBuffer.length = 0
56 }
57
58 /** Create a fresh McpServer instance with all resources/tools registered */
59 function createMcp(): McpServer {
60 const mcp = new McpServer(
61 { name: "reactotron", version: "0.1.0" },
62 { capabilities: { resources: {}, tools: {} } }
63 )
64 registerResources(mcp, reactotronServer, commandBuffer, serverRedactionConfig)
65 registerTools(mcp, reactotronServer, commandBuffer, serverRedactionConfig)
66 return mcp
67 }
68
69 return {
70 get started() { return started },
71 get port() { return listenPort },
72 get redactionConfig() { return serverRedactionConfig },
73
74 updateRedactionConfig(config: Partial<McpRedactionServerConfig>) {
75 serverRedactionConfig = {
76 ...serverRedactionConfig,
77 ...config,
78 defaults: config.defaults
79 ? { ...serverRedactionConfig.defaults, ...config.defaults }

Callers 2

mcp-server.test.tsFile · 0.90
ProviderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected