Skip to main content

Installation

Install the Heimdall JavaScript SDK from npm:
Or with yarn:

Basic Usage

Initialize the Client

You can also configure the client using environment variables and initialize without arguments:

Trace MCP Tools

Use traceMCPTool to wrap your MCP tool functions:
Important: Unlike Python, JavaScript cannot introspect parameter names at runtime. Use the paramNames option to display inputs as named objects:
  • With paramNames: {"query": "machine learning", "limit": 5}
  • Without paramNames: ["machine learning", 5]

Flush Traces

Always flush traces before your application exits:

Configuration Options

The traceMCPTool function accepts the following options:

General Tracing with observe

For non-MCP functions or when you need more control:

Error Handling

Errors are automatically captured and the span is marked as failed:

Complete Example

Here’s a complete example of an MCP server instrumented with Heimdall:

TypeScript Support

The SDK is written in TypeScript and provides full type definitions. Your traced functions maintain their original type signatures:

Next Steps

Environment Variables

Configure Heimdall using environment variables.

SDK Options

Explore all available configuration options.