Examples

Realistic end-to-end examples

Use these patterns to wire MCP server instrumentation, ChatGPT widget instrumentation, ingest requests, and metrics verification.

MCP server integration

Pattern used in test/openai-apps/html-app/server.ts

server.ts
import { withMcpServerAnalytics } from "@mcpeek/server-sdk";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";

const apiConfig = {
  endpoint: process.env.MCPEEK_INGEST_ENDPOINT!,
  apiKey: process.env.MCPEEK_INGEST_KEY!,
  organizationId: process.env.MCPEEK_ORG_ID!,
  environment: "development" as const,
};

const transport = withMcpServerAnalytics(
  new StreamableHTTPServerTransport(),
  apiConfig,
);

await server.connect(transport);
await transport.handleRequest(req, res);

ChatGPT widget integration

Pattern used in test/openai-apps/html-app/public/todo-widget.html

todo-widget.html
// Exposed in the widget bundle (see test/openai-apps/html-app/client-sdk-entry.ts)
window.McPeek.withOpenAiClientAnalytics({
  endpoint: process.env.MCPEEK_INGEST_ENDPOINT,
  apiKey: process.env.MCPEEK_INGEST_KEY,
  organizationId: process.env.MCPEEK_ORG_ID,
  environment: "development",
});

// The SDK wraps window.openai methods automatically
const result = await window.openai.callTool("add_todo", {
  title: "Ship analytics",
});

console.log(result?.structuredContent);

Verify in dashboard

  1. 1Create API key and copy organization ID from Dashboard Settings.
  2. 2Set MCPEEK_INGEST_ENDPOINT, MCPEEK_INGEST_KEY, MCPEEK_ORG_ID in runtime env.
  3. 3Wrap MCP transport with withMcpServerAnalytics(...).
  4. 4Initialize widget with window.McPeek.withOpenAiClientAnalytics(...).
  5. 5Trigger tool calls / widget actions and confirm 202 responses from ingest endpoint.
  6. 6Open dashboard pages (Overview, Tool Calls, Engagement, User Insights) and verify data appears.

Practical recommendation

Start with environment: "development" to see emit logs, then switch to production mode once the full ingest + metrics path is validated.

Related references

For endpoint-level details, see Analytics API.