Skip to content
Merged
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
109 changes: 98 additions & 11 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@biomejs/biome": "^1.9.4",
"@cloudflare/vitest-pool-workers": "^0.8.24",
"@cloudflare/workers-types": "^4.20250430.0",
"@types/mixpanel-browser": "^2.60.0",
"@types/node": "^22.15.3",
"@types/node-fetch": "^2.6.0",
"@vitest/coverage-istanbul": "^3.1.2",
Expand All @@ -46,6 +47,7 @@
"@thoughtspot/rest-api-sdk": "^2.13.1",
"agents": "^0.0.75",
"hono": "^4.7.8",
"mixpanel-browser": "^2.65.0",
"yaml": "^2.7.1",
"zod": "^3.24.3",
"zod-to-json-schema": "^3.24.5"
Expand Down
36 changes: 20 additions & 16 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ app.get("/", async (c) => {
app.get("/authorize", async (c) => {
const oauthReqInfo = await c.env.OAUTH_PROVIDER.parseAuthRequest(c.req.raw);
const { clientId } = oauthReqInfo
if (!clientId) {
return c.text('Invalid request', 400)
}
if (!clientId) {
return c.text('Invalid request', 400)
}
return renderApprovalDialog(c.req.raw, {
client: await c.env.OAUTH_PROVIDER.lookupClient(clientId),
server: {
name: "ThoughtSpot MCP Server",
logo: "https://avatars.githubusercontent.com/u/8906680?s=200&v=4",
description: 'MCP Server for ThoughtSpot Agent', // optional
},
state: { oauthReqInfo }, // arbitrary data that flows through the form submission below
})
client: await c.env.OAUTH_PROVIDER.lookupClient(clientId),
server: {
name: "ThoughtSpot MCP Server",
logo: "https://avatars.githubusercontent.com/u/8906680?s=200&v=4",
description: 'MCP Server for ThoughtSpot Agent', // optional
},
state: { oauthReqInfo }, // arbitrary data that flows through the form submission below
})
})

app.post("/authorize", async (c) => {
// Validates form submission and extracts state
const { state, instanceUrl } = await parseRedirectApproval(c.req.raw)
if (!state.oauthReqInfo) {
return c.text('Invalid request', 400)
}
const { state, instanceUrl } = await parseRedirectApproval(c.req.raw)
if (!state.oauthReqInfo) {
return c.text('Invalid request', 400)
}

if (!instanceUrl) {
return new Response('Missing instance URL', { status: 400 });
}

// Construct the redirect URL to v1/saml
const redirectUrl = new URL('callosum/v1/saml/login', instanceUrl);


// TODO(shikhar.bhargava): remove this once we have a proper callback URL
// the proper callback URL is the one /callosum/v1/v2/auth/token/authroize endpoint
Expand Down Expand Up @@ -110,6 +110,9 @@ app.post("/store-token", async (c) => {
return c.text('Missing token or OAuth request info or instanceUrl', 400);
}

const { clientId } = oauthReqInfo;
const clientName = await c.env.OAUTH_PROVIDER.lookupClient(clientId);

// Complete the authorization with the provided information
const { redirectTo } = await c.env.OAUTH_PROVIDER.completeAuthorization({
request: oauthReqInfo,
Expand All @@ -121,6 +124,7 @@ app.post("/store-token", async (c) => {
props: {
accessToken: token.data.token,
instanceUrl: instanceUrl,
clientName: clientName,
} as Props,
});

Expand Down
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ export class ThoughtSpotMCP extends McpAgent<Env, any, Props> {
server = new MCPServer(this);

async init() {
await this.server.init((eventName, ...args) => {
this.env.ANALYTICS.writeDataPoint({
blobs: [eventName, this.props.instanceUrl, ...args],
doubles: [1],
indexes: [crypto.randomUUID()],
});
});
await this.server.init();
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export enum TrackEvent {
CallTool = "mcp-call-tool",
Init = "mcp-init",
}


export interface Tracker {
track(eventName: string, props: { [key: string]: any }): void;
}

export class Trackers extends Set<Tracker> {
track(eventName: TrackEvent, props: { [key: string]: any } = {}) {
for (const tracker of this) {
tracker.track(eventName, props);
}
}
}
28 changes: 28 additions & 0 deletions src/metrics/mixpanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ThoughtSpotRestApi } from "@thoughtspot/rest-api-sdk";
import mixpanel, { type Mixpanel } from "mixpanel-browser";
import type { SessionInfo } from "../thoughtspot/thoughtspot-service";
import type { Tracker } from "./index";


export class MixpanelTracker implements Tracker {
private mixpanel: Mixpanel;

constructor(sessionInfo: SessionInfo, clientName: string) {
this.mixpanel = mixpanel.init(sessionInfo.mixpanelToken, {
disable_cookie: true,
disable_persistence: true,
autocapture: false,
}, 'mcpServer');
this.mixpanel.identify(sessionInfo.userGUID);
this.mixpanel.register_once({
clusterId: sessionInfo.clusterId,
clusterName: sessionInfo.clusterName,
releaseVersion: sessionInfo.releaseVersion,
clientName: clientName,
});
}

track(eventName: string, props: { [key: string]: any }) {
this.mixpanel.track(eventName, props);
}
}
Loading