Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions netlify/edge-functions/mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const API_BASE = "https://api.kapa.ai";
const KAPA_API_KEY = Netlify.env.get('KAPA_API_KEY');
const KAPA_PROJECT_ID = Netlify.env.get('KAPA_PROJECT_ID');
const KAPA_INTEGRATION_ID = Netlify.env.get('KAPA_INTEGRATION_ID');
const MCPCAT_PROJECT = Netlify.env.get('MCPCAT_PROJECT');

// Initialize MCP Server and register tools
const server = new McpServer({
Expand Down Expand Up @@ -93,6 +94,27 @@ server.registerTool(
}
);

// Initialize MCPcat tracking (if MCPCAT_PROJECT is set)
// MCPcat is an open-source analytics platform for MCP usage tracking.
// See https://www.mcpcat.com/ for details.
if (MCPCAT_PROJECT) {
const prevProcess = globalThis['process']
try {
// Steer module resolution away from Node branches some bundlers pick up.
globalThis['process'] = undefined;

const mcpcat = await import(
"https://esm.sh/[email protected]?target=deno&conditions=browser&bundle"
);
mcpcat.track(server, MCPCAT_PROJECT);
} catch (e) {
// Don't crash the MCP server if analytics fail to load.
console.warn("[mcpcat] disabled due to import error:", e);
} finally {
globalThis['process'] = prevProcess;
}
}

// Wrap the server with the Netlify Edge handler
// ---------------------------------------------
// The `handle` function from `@modelfetch/netlify` does several things:
Expand Down
223 changes: 172 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.