Skip to content

Commit c61c723

Browse files
authored
Add structure to relevant questions tool (#61)
* Add structure to relevant questions tool * review fix : * fix tests
1 parent 875e2c4 commit c61c723

File tree

4 files changed

+142
-135
lines changed

4 files changed

+142
-135
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
"@cloudflare/workers-oauth-provider": "^0.0.5",
4646
"@hono/zod-validator": "^0.7.2",
4747
"@microlabs/otel-cf-workers": "^1.0.0-rc.52",
48-
"@modelcontextprotocol/sdk": "^1.15.1",
48+
"@modelcontextprotocol/sdk": "^1.17.4",
4949
"@thoughtspot/rest-api-sdk": "^2.13.1",
50-
"agents": "^0.0.105",
50+
"agents": "^0.0.113",
5151
"hono": "^4.7.8",
5252
"rxjs": "^7.8.2",
5353
"yaml": "^2.7.1",

src/servers/mcp-server.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import { BaseMCPServer, type Context, type ToolResponse } from "./mcp-server-bas
1616

1717

1818
const ToolInputSchema = ToolSchema.shape.inputSchema;
19-
export type ToolInput = z.infer<typeof ToolInputSchema>;
19+
type ToolInput = z.infer<typeof ToolInputSchema>;
20+
21+
export const ToolOutputSchema = ToolSchema.shape.outputSchema;
22+
type ToolOutput = z.infer<typeof ToolOutputSchema>;
2023

2124
export const PingSchema = z.object({});
2225

@@ -29,6 +32,13 @@ export const GetRelevantQuestionsSchema = z.object({
2932
.describe("The datasources to get questions for, this is the ids of the datasources to get data from. Each id is a GUID string.")
3033
});
3134

35+
export const GetRelevantQuestionsOutputSchema = z.object({
36+
questions: z.array(z.object({
37+
question: z.string(),
38+
datasourceId: z.string(),
39+
})),
40+
});
41+
3242
export const GetAnswerSchema = z.object({
3343
question: z.string().describe("The question to get the answer for, these are generally the questions generated by the getRelevantQuestions tool."),
3444
datasourceId: z.string()
@@ -94,6 +104,7 @@ export const toolDefinitionsMCPServer = [
94104
name: ToolName.GetRelevantQuestions,
95105
description: "Get relevant data questions from ThoughtSpot database",
96106
inputSchema: zodToJsonSchema(GetRelevantQuestionsSchema) as ToolInput,
107+
outputSchema: zodToJsonSchema(GetRelevantQuestionsOutputSchema) as ToolOutput,
97108
annotations: {
98109
title: "Get Relevant Questions for a Query",
99110
readOnlyHint: true,
@@ -237,11 +248,7 @@ export class MCPServer extends BaseMCPServer {
237248
return this.createSuccessResponse("No relevant questions found");
238249
}
239250

240-
const questionTexts = relevantQuestions.questions.map(q =>
241-
`Question: ${q.question}\nDatasourceId: ${q.datasourceId}`
242-
);
243-
244-
return this.createArraySuccessResponse(questionTexts, "Relevant questions found");
251+
return this.createStructuredContentSuccessResponse({ questions: relevantQuestions.questions }, "Relevant questions found");
245252
}
246253

247254
@WithSpan('call-get-answer')
@@ -268,7 +275,7 @@ export class MCPServer extends BaseMCPServer {
268275
async callCreateLiveboard(request: z.infer<typeof CallToolRequestSchema>) {
269276
const { name, answers, noteTile } = CreateLiveboardSchema.parse(request.params.arguments);
270277
const liveboard = await this.getThoughtSpotService().fetchTMLAndCreateLiveboard(name, answers, noteTile);
271-
278+
272279
if (liveboard.error) {
273280
return this.createErrorResponse(liveboard.error.message, `Error creating liveboard ${liveboard.error.message}`);
274281
}

0 commit comments

Comments
 (0)