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.
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.
Install LSquare
Install
lsquarewith your project's package manager and update its dependency files. For npm:npm install lsquare- After installing, read
node_modules/lsquare/README.mdand follow its linked reference for your host. LSquare runs on Node 18+, Cloudflare Workers, and Bun.
- After installing, read
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 })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)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
waitUntilfrom@vercel/functionsand 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 onSIGTERM. - Keep a shared client alive across requests and invocations; shut it down only when the process is stopping.
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())Verify in dry run
Set
LSQUARE_DRY_RUN=1in 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, setLSQUARE_KEYin the server's environment, and restart it.
- When ready to send events, remove
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/mcpComplete the browser sign-in flow. If sign-in hasn't started, run
codex mcp login lsquaremcp. Check the configuration withcodex mcp list.Claude Code
claude mcp add --transport http lsquaremcp https://mcp.lsquare.io/mcpOpen Claude Code, run
/mcp, selectlsquaremcp, and complete the sign-in flow. Confirm the connection and available tools in/mcp.- MCP uses its own sign-in flow.
LSQUARE_KEYis the SDK's API key; keep it in your server's environment.
- MCP uses its own sign-in flow.