1- import { Hono } from ' hono' ;
2- import { toolDefinitionsMCPServer } from ' ../servers/mcp-server' ;
3- import { capitalize } from ' ../utils' ;
1+ import { Hono } from " hono" ;
2+ import { toolDefinitionsMCPServer } from " ../servers/mcp-server" ;
3+ import { capitalize } from " ../utils" ;
44
55export const openApiSpecHandler = new Hono ( ) ;
66
77// Helper function to generate tool schema
8- const generateToolSchema = ( tool : typeof toolDefinitionsMCPServer [ 0 ] ) => {
9- const schemaName = `${ capitalize ( tool . name ) } Request` ;
10- const generatedSchema = { ...tool . inputSchema } as any ;
11- generatedSchema . $schema = undefined ;
12- return { schemaName, schema : generatedSchema } ;
8+ const generateToolSchema = ( tool : ( typeof toolDefinitionsMCPServer ) [ 0 ] ) => {
9+ const schemaName = `${ capitalize ( tool . name ) } Request` ;
10+ const generatedSchema = { ...tool . inputSchema } as any ;
11+ generatedSchema . $schema = undefined ;
12+ return { schemaName, schema : generatedSchema } ;
1313} ;
1414
1515// Helper function to generate response schema
1616const generateResponseSchema = ( ) => {
17- return {
18- type : ' object' ,
19- description : ' Response from the API endpoint'
20- } ;
17+ return {
18+ type : " object" ,
19+ description : " Response from the API endpoint" ,
20+ } ;
2121} ;
2222
2323// Create individual endpoints for each tool
2424for ( const tool of toolDefinitionsMCPServer ) {
25- const { schemaName, schema } = generateToolSchema ( tool ) ;
26- const responseSchema = generateResponseSchema ( ) ;
25+ const { schemaName, schema } = generateToolSchema ( tool ) ;
26+ const responseSchema = generateResponseSchema ( ) ;
2727
28- openApiSpecHandler . get ( `/tools/${ tool . name } ` , async ( c ) => {
29- const toolSpec = {
30- openapi : ' 3.0.0' ,
31- info : {
32- title : ' ThoughtSpot API' ,
33- version : ' 1.0.0' ,
34- description : ' API for interacting with ThoughtSpot services'
35- } ,
36- servers : [
37- {
38- url : ' <TS_AGENT_URL>' ,
39- description : ' ThoughtSpot agent url'
40- }
41- ] ,
42- paths : {
43- [ `/api/tools/${ tool . name } ` ] : {
44- post : {
45- summary : tool . description ,
46- description : tool . description ,
47- operationId : tool . name ,
48- tags : [ ' Tools' ] ,
49- requestBody : {
50- required : true ,
51- content : {
52- ' application/json' : {
53- schema : {
54- $ref : `#/components/schemas/${ schemaName } `
55- }
56- }
57- }
58- } ,
59- responses : {
60- ' 200' : {
61- description : ' Successful response' ,
62- content : {
63- ' application/json' : {
64- schema : {
65- $ref : `#/components/schemas/${ capitalize ( tool . name ) } Response`
66- }
67- }
68- }
69- } ,
70- ' 400' : {
71- description : ' Bad request - Invalid input parameters'
72- } ,
73- ' 401' : {
74- description : ' Unauthorized - Invalid or missing authentication'
75- } ,
76- ' 500' : {
77- description : ' Internal server error'
78- }
79- }
80- }
81- }
82- } ,
83- components : {
84- schemas : {
85- [ schemaName ] : schema ,
86- [ `${ capitalize ( tool . name ) } Response` ] : responseSchema
87- }
88- }
89- } ;
28+ openApiSpecHandler . get ( `/tools/${ tool . name } ` , async ( c ) => {
29+ const toolSpec = {
30+ openapi : " 3.0.0" ,
31+ info : {
32+ title : " ThoughtSpot API" ,
33+ version : " 1.0.0" ,
34+ description : " API for interacting with ThoughtSpot services" ,
35+ } ,
36+ servers : [
37+ {
38+ url : " <TS_AGENT_URL>" ,
39+ description : " ThoughtSpot agent url" ,
40+ } ,
41+ ] ,
42+ paths : {
43+ [ `/api/tools/${ tool . name } ` ] : {
44+ post : {
45+ summary : tool . description ,
46+ description : tool . description ,
47+ operationId : tool . name ,
48+ tags : [ " Tools" ] ,
49+ requestBody : {
50+ required : true ,
51+ content : {
52+ " application/json" : {
53+ schema : {
54+ $ref : `#/components/schemas/${ schemaName } ` ,
55+ } ,
56+ } ,
57+ } ,
58+ } ,
59+ responses : {
60+ " 200" : {
61+ description : " Successful response" ,
62+ content : {
63+ " application/json" : {
64+ schema : {
65+ $ref : `#/components/schemas/${ capitalize ( tool . name ) } Response` ,
66+ } ,
67+ } ,
68+ } ,
69+ } ,
70+ " 400" : {
71+ description : " Bad request - Invalid input parameters" ,
72+ } ,
73+ " 401" : {
74+ description : " Unauthorized - Invalid or missing authentication" ,
75+ } ,
76+ " 500" : {
77+ description : " Internal server error" ,
78+ } ,
79+ } ,
80+ } ,
81+ } ,
82+ } ,
83+ components : {
84+ schemas : {
85+ [ schemaName ] : schema ,
86+ [ `${ capitalize ( tool . name ) } Response` ] : responseSchema ,
87+ } ,
88+ } ,
89+ } ;
9090
91- return c . json ( toolSpec ) ;
92- } ) ;
91+ return c . json ( toolSpec ) ;
92+ } ) ;
9393}
9494
9595// Main OpenAPI spec endpoint that combines all tools
96- openApiSpecHandler . get ( '/' , async ( c ) => {
97- const paths : Record < string , any > = { } ;
98- const schemas : Record < string , any > = { } ;
96+ openApiSpecHandler . get ( "/" , async ( c ) => {
97+ const paths : Record < string , any > = { } ;
98+ const schemas : Record < string , any > = { } ;
9999
100- // any tool added to the toolDefinitionsMCPServer will be added to the openapi spec automatically
101- // the api server path should be /api/tools/<tool-name>
102- for ( const tool of toolDefinitionsMCPServer ) {
103- const { schemaName, schema } = generateToolSchema ( tool ) ;
104- const responseSchema = generateResponseSchema ( ) ;
100+ // any tool added to the toolDefinitionsMCPServer will be added to the openapi spec automatically
101+ // the api server path should be /api/tools/<tool-name>
102+ for ( const tool of toolDefinitionsMCPServer ) {
103+ const { schemaName, schema } = generateToolSchema ( tool ) ;
104+ const responseSchema = generateResponseSchema ( ) ;
105105
106- schemas [ schemaName ] = schema ;
107- schemas [ `${ capitalize ( tool . name ) } Response` ] = responseSchema ;
108-
109- paths [ `/api/tools/${ tool . name } ` ] = {
110- post : {
111- summary : tool . description ,
112- description : tool . description ,
113- operationId : tool . name ,
114- tags : [ 'Tools' ] ,
115- requestBody : {
116- required : true ,
117- content : {
118- 'application/json' : {
119- schema : {
120- $ref : `#/components/schemas/${ schemaName } `
121- }
122- }
123- }
124- } ,
125- responses : {
126- '200' : {
127- description : 'Successful response' ,
128- content : {
129- 'application/json' : {
130- schema : {
131- $ref : `#/components/schemas/${ capitalize ( tool . name ) } Response`
132- }
133- }
134- }
135- } ,
136- '400' : {
137- description : 'Bad request - Invalid input parameters'
138- } ,
139- '401' : {
140- description : 'Unauthorized - Invalid or missing authentication'
141- } ,
142- '500' : {
143- description : 'Internal server error'
144- }
145- }
146- }
147- } ;
148- }
106+ schemas [ schemaName ] = schema ;
107+ schemas [ `${ capitalize ( tool . name ) } Response` ] = responseSchema ;
149108
150- const openApiDocument = {
151- openapi : '3.0.0' ,
152- info : {
153- title : 'ThoughtSpot API' ,
154- version : '1.0.0' ,
155- description : 'API for interacting with ThoughtSpot services'
156- } ,
157- servers : [
158- {
159- url : '<TS_AGENT_URL>' ,
160- description : 'ThoughtSpot agent url'
161- }
162- ] ,
163- paths : paths ,
164- components : {
165- schemas : schemas
166- }
167- } ;
109+ paths [ `/api/tools/${ tool . name } ` ] = {
110+ post : {
111+ summary : tool . description ,
112+ description : tool . description ,
113+ operationId : tool . name ,
114+ tags : [ "Tools" ] ,
115+ requestBody : {
116+ required : true ,
117+ content : {
118+ "application/json" : {
119+ schema : {
120+ $ref : `#/components/schemas/${ schemaName } ` ,
121+ } ,
122+ } ,
123+ } ,
124+ } ,
125+ responses : {
126+ "200" : {
127+ description : "Successful response" ,
128+ content : {
129+ "application/json" : {
130+ schema : {
131+ $ref : `#/components/schemas/${ capitalize ( tool . name ) } Response` ,
132+ } ,
133+ } ,
134+ } ,
135+ } ,
136+ "400" : {
137+ description : "Bad request - Invalid input parameters" ,
138+ } ,
139+ "401" : {
140+ description : "Unauthorized - Invalid or missing authentication" ,
141+ } ,
142+ "500" : {
143+ description : "Internal server error" ,
144+ } ,
145+ } ,
146+ } ,
147+ } ;
148+ }
168149
169- return c . json ( openApiDocument ) ;
170- } ) ;
150+ const openApiDocument = {
151+ openapi : "3.0.0" ,
152+ info : {
153+ title : "ThoughtSpot API" ,
154+ version : "1.0.0" ,
155+ description : "API for interacting with ThoughtSpot services" ,
156+ } ,
157+ servers : [
158+ {
159+ url : "<TS_AGENT_URL>" ,
160+ description : "ThoughtSpot agent url" ,
161+ } ,
162+ ] ,
163+ paths : paths ,
164+ components : {
165+ schemas : schemas ,
166+ } ,
167+ } ;
168+
169+ return c . json ( openApiDocument ) ;
170+ } ) ;
0 commit comments