McpClient.ts

lumiere · integration

McpClient — lightweight MCP client compatible with React Native. Communicates with MCP servers over Streamable HTTP (POST for requests, SSE for streaming). Does not depend on Node.js-specific APIs. /

/**
 * McpClient — lightweight MCP client compatible with React Native.
 *
 * Communicates with MCP servers over Streamable HTTP (POST for requests,
 * SSE for streaming). Does not depend on Node.js-specific APIs.
 */

import { logger } from '../../utils/logger'
import type {
  JsonRpcRequest,
  JsonRpcResponse,
  McpInitializeResult,
  McpServerConfig,
  McpTool,
  McpToolInputSchema,
  McpToolResult,
  McpToolResultContent,
} from './types'

const mcpLogger = logger.create('MCP')

const MCP_PROTOCOL_VERSION = '2025-03-26'

export class McpClient {
  private config: McpServerConfig
  private requestId = 0
  private sessionId: string | null = null
  private serverCapabilities: McpInitializeResult | null = null

  constructor(config: McpServerConfig) {
    this.config = config
  }

  /** Th

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key