npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@emcy/sdk

v0.2.0

Published

Emcy telemetry SDK for MCP servers - track tool invocations, errors, and performance

Readme

@emcy/sdk

Telemetry SDK for MCP (Model Context Protocol) servers. Track tool invocations, errors, and performance.

npm version License: MIT

What is this?

This SDK adds observability to your MCP servers. When AI agents call your tools, Emcy tracks:

  • Tool invocations - Which tools are called and how often
  • Errors - Failures with full context for debugging
  • Performance - Latency metrics and success rates
  • Metadata - Custom attributes for filtering and analysis

View your data in the Emcy Dashboard.

Installation

npm install @emcy/sdk

Quick Start

import { EmcyTelemetry } from '@emcy/sdk';

// Initialize with your API key
const emcy = new EmcyTelemetry({
  apiKey: process.env.EMCY_API_KEY!,
  endpoint: 'https://api.emcy.ai/v1/telemetry',
  mcpServerId: process.env.EMCY_MCP_SERVER_ID,
});

// Set server info for metadata
emcy.setServerInfo('my-mcp-server', '1.0.0');

// Wrap your tool handlers with trace()
const result = await emcy.trace('get_user', async () => {
  return await api.getUser(userId);
});

API

EmcyTelemetry

The main class for telemetry.

const emcy = new EmcyTelemetry({
  apiKey: string;           // Required: Your Emcy API key
  endpoint?: string;        // Optional: Telemetry endpoint (default: https://api.emcy.ai/v1/telemetry)
  mcpServerId?: string;     // Optional: MCP server ID for grouping
  debug?: boolean;          // Optional: Enable debug logging
  flushInterval?: number;   // Optional: Batch flush interval in ms (default: 5000)
  maxBatchSize?: number;    // Optional: Max events per batch (default: 100)
});

setServerInfo(name, version)

Set server metadata included with all events.

emcy.setServerInfo('my-server', '1.2.3');

trace<T>(toolName, fn)

Wrap an async function to track its execution.

const result = await emcy.trace('search_products', async () => {
  return await api.searchProducts(query);
});

The trace automatically captures:

  • Start time
  • End time / duration
  • Success or failure
  • Error details if thrown

trackInvocation(invocation)

Manually track a tool invocation.

emcy.trackInvocation({
  toolName: 'get_user',
  startTime: Date.now(),
  endTime: Date.now() + 150,
  success: true,
  metadata: { userId: '123' },
});

flush()

Force send all pending events. Called automatically on interval.

await emcy.flush();

shutdown()

Flush and stop the telemetry client.

await emcy.shutdown();

Configuration

Environment Variables

The SDK reads these environment variables:

| Variable | Description | |----------|-------------| | EMCY_API_KEY | Your Emcy API key (required) | | EMCY_TELEMETRY_URL | Telemetry endpoint URL | | EMCY_MCP_SERVER_ID | MCP server ID for grouping | | EMCY_DEBUG | Set to true for debug logs |

With @emcy/openapi-to-mcp

If you generated your MCP server with @emcy/openapi-to-mcp and the --emcy flag, the SDK is already integrated. Just set your environment variables:

EMCY_API_KEY=your-api-key
EMCY_TELEMETRY_URL=https://api.emcy.ai/v1/telemetry
EMCY_MCP_SERVER_ID=mcp_xxxxxxxxxxxx

Example: Manual Integration

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { EmcyTelemetry } from '@emcy/sdk';

const emcy = new EmcyTelemetry({
  apiKey: process.env.EMCY_API_KEY!,
});

emcy.setServerInfo('my-server', '1.0.0');

const server = new Server(
  { name: 'my-server', version: '1.0.0' },
  { capabilities: { tools: {} } }
);

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name: toolName, arguments: args } = request.params;
  
  // Wrap the tool execution with telemetry
  return emcy.trace(toolName, async () => {
    switch (toolName) {
      case 'get_data':
        return await getData(args);
      default:
        throw new Error(`Unknown tool: ${toolName}`);
    }
  });
});

// Graceful shutdown
process.on('SIGINT', async () => {
  await emcy.shutdown();
  process.exit(0);
});

Data Format

Events are batched and sent as:

interface TelemetryBatch {
  apiKey: string;
  mcpServerId?: string;
  serverName?: string;
  serverVersion?: string;
  invocations: ToolInvocation[];
}

interface ToolInvocation {
  toolName: string;
  startTime: number;
  endTime: number;
  success: boolean;
  errorMessage?: string;
  errorStack?: string;
  metadata?: Record<string, unknown>;
}

Self-Hosting

Point the SDK at your own telemetry endpoint:

const emcy = new EmcyTelemetry({
  apiKey: 'your-key',
  endpoint: 'https://your-server.com/api/v1/telemetry',
});

The endpoint should accept POST requests with the TelemetryBatch JSON body.

License

MIT © Emcy