Skip to content

Commit 08026d2

Browse files
committed
Use Spotter3 apis for beta api version
1 parent 5357ec8 commit 08026d2

14 files changed

Lines changed: 776 additions & 544 deletions

README.md

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,66 @@ Make sure to add the following entries in your ThoughtSpot instance:
321321
npm run dev
322322
```
323323

324+
### Adding New Tools
325+
326+
When adding new MCP tools to the server:
327+
328+
1. **Define schemas and tools** in `src/servers/tool-definitions.ts`
329+
2. **Implement handlers** in `src/servers/mcp-server.ts`
330+
3. **Update version registry** in `src/servers/version-registry.ts`:
331+
- Add new tools to appropriate version(s) in `VERSION_REGISTRY`
332+
- For new stable features, update `DEFAULT_VERSION`
333+
- For beta features, add to the `beta` version entry
334+
4. **Add tests** for new tools and version configurations
335+
5. **Update documentation** in README.md
336+
337+
**Important:** The version registry controls which tools are available in each API version. Make sure to add new tools to the correct version configuration to ensure they're accessible to users.
338+
324339
### Endpoints
325340

326341
**OAuth-based endpoints:**
327-
- `/mcp`: MCP HTTP Streaming endpoint (supports `?api-version=beta`)
328-
- `/sse`: Server-sent events for MCP (supports `?api-version=beta`)
342+
- `/mcp`: MCP HTTP Streaming endpoint (supports `?api-version`)
343+
- `/sse`: Server-sent events for MCP (supports `?api-version`)
329344
- `/api`: MCP tools exposed as HTTP endpoints
330345
- `/authorize`, `/token`, `/register`: OAuth endpoints
331346

332347
**Token-based endpoints (Recommended for APIs):**
333-
- `/token/mcp`: MCP HTTP Streaming with bearer auth (supports `?api-version=beta`)
334-
- `/token/sse`: Server-sent events with bearer auth (supports `?api-version=beta`)
348+
- `/token/mcp`: MCP HTTP Streaming with bearer auth (supports `?api-version`)
349+
- `/token/sse`: Server-sent events with bearer auth (supports `?api-version`)
335350

336351
**Deprecated endpoints:**
337352
- `/bearer/mcp`, `/bearer/sse`: Legacy MCP endpoints with bearer auth (**deprecated**, no `api-version` support). Use `/token/*` endpoints instead.
338353

339-
**Beta Tools Access:**
354+
**API Versioning:**
355+
356+
The ThoughtSpot MCP Server supports API versioning to access different tool sets. You can specify the version using the `api-version` query parameter on OAuth and `/token/*` endpoints (not supported on deprecated `/bearer/*` endpoints).
357+
358+
**Version Formats:**
359+
- **Beta version**: `?api-version=beta` - Access the latest beta features
360+
- **Date-based version**: `?api-version=YYYY-MM-DD` - Access tools from a specific release date or the latest version on or before that date
361+
- **Default** (no parameter): Returns the stable default tool set
362+
363+
**Examples:**
364+
```bash
365+
# Beta version (latest experimental features)
366+
https://agent.thoughtspot.app/token/mcp?api-version=beta
367+
368+
# Specific date version (Spotter3 agent tools)
369+
https://agent.thoughtspot.app/token/mcp?api-version=2025-03-01
370+
371+
# Date range resolution (returns latest version ≤ specified date)
372+
https://agent.thoughtspot.app/token/mcp?api-version=2025-03-15
373+
374+
# Default version (stable tools)
375+
https://agent.thoughtspot.app/token/mcp
376+
```
377+
378+
**Available Versions:**
379+
- `beta`: Latest beta features with Spotter3 agent conversation tools
380+
- `2025-03-01`: Spotter3 agent conversation tools (`createConversation`, `sendConversationMessage`, `getConversationUpdates`)
381+
- `2024-12-01`: Base MCP tools (`getRelevantQuestions`, `getAnswer`, `getDataSourceSuggestions`)
382+
- `default`: Stable base tools (same as `2024-12-01`)
340383

341-
To access beta tools, append `?api-version=beta` to any MCP endpoint (except deprecated `/bearer/*` endpoints):
342-
- Example: `https://agent.thoughtspot.app/token/mcp?api-version=beta`
343-
- Beta tools include experimental features
384+
**Note:** The `/bearer/*` endpoints always return the default stable tool set and ignore the `api-version` parameter for backward compatibility.
344385

345386
MCP Server, © ThoughtSpot, Inc. 2025

package-lock.json

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@modelcontextprotocol/sdk": "^1.20.1",
5555
"@thoughtspot/rest-api-sdk": "^2.22.0",
5656
"agents": "^0.2.14",
57-
"ai": "^6.0.138",
5857
"hono": "^4.10.3",
5958
"rxjs": "^7.8.2",
6059
"yaml": "^2.7.1",

src/api-schemas/open-api-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hono } from "hono";
2-
import { toolDefinitionsMCPServer } from "../servers/mcp-server";
2+
import { toolDefinitionsMCPServer } from "../servers/tool-definitions";
33
import { capitalize } from "../utils";
44

55
export const openApiSpecHandler = new Hono();

src/bearer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,32 @@ function handleTokenAuth(
4141
const clientName =
4242
req.headers.get("x-ts-client-name") || "Bearer Token client";
4343

44+
const url = new URL(req.url);
45+
4446
// Build props object
4547
const props: any = {
4648
accessToken: accessToken,
4749
instanceUrl: validateAndSanitizeUrl(tsHost),
4850
clientName,
4951
};
5052

51-
// Add api-version support only for /token endpoints
53+
// Add api-version support only for /token endpoints (supports "beta" or "YYYY-MM-DD" format)
5254
if (supportApiVersion) {
53-
const url = new URL(req.url);
5455
const apiVersion = url.searchParams.get("api-version");
55-
if (apiVersion === "beta") {
56-
props.apiVersion = "beta" as const;
56+
if (apiVersion) {
57+
props.apiVersion = apiVersion;
5758
}
5859
}
5960

6061
(ctx as any).props = props;
6162

6263
// Route to appropriate handler
63-
if (req.url.endsWith("/mcp") || req.url.includes("/mcp?")) {
64+
const pathname = url.pathname;
65+
if (pathname.endsWith("/mcp")) {
6466
return MCPServer.serve("/mcp").fetch(req, env, ctx);
6567
}
6668

67-
if (req.url.endsWith("/sse") || req.url.includes("/sse?")) {
69+
if (pathname.endsWith("/sse")) {
6870
return MCPServer.serveSSE("/sse").fetch(req, env, ctx);
6971
}
7072

src/index.ts

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const ThoughtSpotOpenAIDeepResearchMCP = instrumentedMCPServer(
3838
function createMCPRouter(
3939
path: string,
4040
serverClass: typeof ThoughtSpotMCP,
41+
serveMethod: "serve" | "serveSSE",
4142
options?: { binding?: string },
4243
) {
4344
return {
@@ -49,64 +50,33 @@ function createMCPRouter(
4950
const url = new URL(request.url);
5051
const apiVersion = url.searchParams.get("api-version");
5152

52-
// Inject apiVersion into props if it's "beta"
53-
if (apiVersion === "beta") {
53+
// Inject apiVersion into props if provided (supports "beta" or "YYYY-MM-DD" format)
54+
if (apiVersion) {
5455
const originalProps = (ctx as any).props || {};
5556
(ctx as any).props = {
5657
...originalProps,
57-
apiVersion: "beta" as const,
58+
apiVersion,
5859
};
5960
}
6061

6162
// Route to the appropriate serve method
62-
return serverClass.serve(path, options).fetch(request, env, ctx);
63-
},
64-
};
65-
}
66-
67-
// Router function for SSE endpoints
68-
function createMCPRouterSSE(
69-
path: string,
70-
serverClass: typeof ThoughtSpotMCP,
71-
options?: { binding?: string },
72-
) {
73-
return {
74-
async fetch(
75-
request: Request,
76-
env: Env,
77-
ctx: ExecutionContext,
78-
): Promise<Response> {
79-
const url = new URL(request.url);
80-
const apiVersion = url.searchParams.get("api-version");
81-
82-
// Inject apiVersion into props if it's "beta"
83-
if (apiVersion === "beta") {
84-
const originalProps = (ctx as any).props || {};
85-
(ctx as any).props = {
86-
...originalProps,
87-
apiVersion: "beta" as const,
88-
};
89-
}
90-
91-
// Route to the appropriate serveSSE method
92-
return serverClass.serveSSE(path, options).fetch(request, env, ctx);
63+
return serverClass[serveMethod](path, options).fetch(request, env, ctx);
9364
},
9465
};
9566
}
9667

9768
// Create the OAuth provider instance
9869
const oauthProvider = new OAuthProvider({
9970
apiHandlers: {
100-
"/mcp": createMCPRouter("/mcp", ThoughtSpotMCP) as any,
101-
"/sse": createMCPRouterSSE("/sse", ThoughtSpotMCP) as any,
71+
"/mcp": createMCPRouter("/mcp", ThoughtSpotMCP, "serve") as any,
72+
"/sse": createMCPRouter("/sse", ThoughtSpotMCP, "serveSSE") as any,
10273
"/openai/mcp": ThoughtSpotOpenAIDeepResearchMCP.serve("/openai/mcp", {
10374
binding: "OPENAI_DEEP_RESEARCH_MCP_OBJECT",
10475
}) as any, // TODO: Remove 'any'
10576
"/openai/sse": ThoughtSpotOpenAIDeepResearchMCP.serveSSE("/openai/sse", {
10677
binding: "OPENAI_DEEP_RESEARCH_MCP_OBJECT",
10778
}) as any, // TODO: Remove 'any'
10879
"/api": apiServer as any, // TODO: Remove 'any'
109-
"/bearer/mcp": withBearerHandler(handler, ThoughtSpotMCP) as any,
11080
},
11181
defaultHandler: withBearerHandler(handler, ThoughtSpotMCP) as any, // TODO: Remove 'any'
11282
authorizeEndpoint: "/authorize",

src/servers/api-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
CreateLiveboardSchema,
99
GetAnswerSchema,
1010
GetRelevantQuestionsSchema,
11-
} from "./mcp-server";
11+
} from "./tool-definitions";
1212

1313
const apiServer = new Hono<{ Bindings: Env & { props: Props } }>();
1414

0 commit comments

Comments
 (0)