Installation guide

Add LSquare to your TypeScript server

LSquare is the npm package lsquare. It records each tool call your MCP server handles. Add it to your existing server with the steps below.

  1. Find your MCP servers

    Find each MCP server and how it runs: stdio, HTTP, a new server per request, or serverless. Keep its existing tools, transport, and MCP SDK version.

  2. Install LSquare

    Install lsquare with your project's package manager and update its dependency files. For npm:

    npm install lsquare
    • After installing, read node_modules/lsquare/README.md and follow its linked reference for your host. LSquare runs on Node 18+, Cloudflare Workers, and Bun.

    TypeScript SDK README

  3. Create one shared client

    Create the client once per process and share it across your servers. Read the key from the environment; never hardcode or commit it. Import this client wherever you instrument a server.

    import { LSquare } from 'lsquare'
    
    export const lsquare = new LSquare({ apiKey: process.env.LSQUARE_KEY })

    Request API key

  4. Instrument each server

    Call instrument() before the server connects or starts serving requests. Use your existing server instance and the shared client.

    import { instrument } from 'lsquare/mcp'
    
    instrument(server, lsquare)
  5. Add what your host needs

    Follow the reference's recipe for your host. Pass the relevant options in the same instrument() call:

    • New server per request: instrument inside the factory, sharing the client across requests.
    • Cloudflare Workers: pass { waitUntil: ctx.waitUntil.bind(ctx) } from the current request. A reused server must resolve the current request's context each time.
    • Vercel: import waitUntil from @vercel/functions and pass { waitUntil }.
    • AWS Lambda, or Cloud Run without always-on CPU: pass { flushBeforeReply: true } so sending is awaited before replying.
    • Long-running HTTP server: call await lsquare.shutdown() in your graceful shutdown handler on SIGTERM.
    • Keep a shared client alive across requests and invocations; shut it down only when the process is stopping.

    Host setup and shutdown recipes

  6. Example: an existing stdio server

    The LSquare additions are marked below. This example uses MCP SDK 1.x imports; keep the imports and tool registrations your project already uses.

    import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
    import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
    import { LSquare } from 'lsquare'        // ADD THIS
    import { instrument } from 'lsquare/mcp' // ADD THIS
    
    const lsquare = new LSquare({ apiKey: process.env.LSQUARE_KEY }) // ADD THIS
    
    const server = new McpServer({ name: 'shop', version: '1.0.0' })
    // Keep your existing tool registrations here.
    
    instrument(server, lsquare) // ADD THIS
    
    await server.connect(new StdioServerTransport())
  7. Verify in dry run

    Set LSQUARE_DRY_RUN=1 in the server's environment and start it with your project's usual command. Call one existing tool through your MCP client and confirm [lsquare dry-run] lines appear on stderr. Nothing is sent in dry run. Keep stdout free of logs on stdio servers, then run your project's tests and type checks.

    • When ready to send events, remove LSQUARE_DRY_RUN, set LSQUARE_KEY in the server's environment, and restart it.
  8. Connect your coding agent to LSquare MCP

    Run the command for your coding agent from your project directory. It adds the remote LSquare MCP as lsquaremcp. Use the existing connection if it already points to this URL.

    Codex

    codex mcp add lsquaremcp --url https://mcp.lsquare.io/mcp

    Complete the browser sign-in flow. If sign-in hasn't started, run codex mcp login lsquaremcp. Check the configuration with codex mcp list.

    Claude Code

    claude mcp add --transport http lsquaremcp https://mcp.lsquare.io/mcp

    Open Claude Code, run /mcp, select lsquaremcp, and complete the sign-in flow. Confirm the connection and available tools in /mcp.

    • MCP uses its own sign-in flow. LSQUARE_KEY is the SDK's API key; keep it in your server's environment.