1+ import { experimental_createMCPClient as createMCPClient } from '@ai-sdk/mcp' ;
12import { AppSystemProp , logger , system } from '@openops/server-shared' ;
2- import { experimental_createMCPClient as createMCPClient , tool } from 'ai' ;
3- import { Experimental_StdioMCPTransport as StdioMCPTransport } from 'ai/mcp-stdio' ;
3+ import { tool } from 'ai' ;
44import { z } from 'zod' ;
55import { MCPTool } from './types' ;
66
7+ type MCPSearchTool = {
8+ execute : (
9+ args : { query : string } ,
10+ options : { toolCallId : string ; messages : unknown [ ] } ,
11+ ) => Promise < unknown > ;
12+ } ;
13+
14+ type MCPHttpTransport = {
15+ type : 'http' ;
16+ url : string ;
17+ } ;
18+
719export async function getDocsTools ( ) : Promise < MCPTool > {
8- const mcpServerPath = system . get < string > ( AppSystemProp . DOCS_MCP_SERVER_PATH ) ;
9- if ( ! mcpServerPath ) {
20+ const mcpServerUrl = system . get < string > ( AppSystemProp . DOCS_MCP_SERVER_PATH ) ;
21+ if ( ! mcpServerUrl ) {
1022 return {
1123 client : undefined ,
1224 toolSet : { } ,
1325 } ;
1426 }
1527
1628 logger . debug ( 'Creating MCP client for docs' , {
17- serverPath : mcpServerPath ,
29+ serverPath : mcpServerUrl ,
1830 } ) ;
1931
2032 const client = await createMCPClient ( {
21- transport : new StdioMCPTransport ( {
22- command : 'node ' ,
23- args : [ mcpServerPath ] ,
24- } ) ,
33+ transport : {
34+ type : 'http ' ,
35+ url : mcpServerUrl ,
36+ } as MCPHttpTransport ,
2537 } ) ;
2638
2739 const tools = await client . tools ( ) ;
28- const searchTool = tools [ 'search' ] ;
40+ const toolsObject = tools instanceof Map ? Object . fromEntries ( tools ) : tools ;
41+
42+ const searchToolName = Object . keys ( toolsObject ) . find ( ( name ) =>
43+ name . toLowerCase ( ) . includes ( 'search' ) ,
44+ ) ;
45+ const searchTool = searchToolName
46+ ? ( toolsObject [ searchToolName ] as MCPSearchTool )
47+ : undefined ;
48+
49+ if ( ! searchTool ?. execute ) {
50+ logger . error ( 'Docs MCP search tool not available' , {
51+ availableTools : Object . keys ( toolsObject ) ,
52+ } ) ;
53+ }
2954
3055 const toolSet = {
3156 OpenOps_Documentation : tool ( {
@@ -41,25 +66,21 @@ Use this tool to find accurate, verified information before answering OpenOps-sp
4166 query : z . string ( ) . describe ( 'The search query' ) ,
4267 } ) ,
4368 execute : async ( { query } ) => {
44- try {
45- if ( ! searchTool || typeof searchTool . execute !== 'function' ) {
46- return await Promise . resolve ( {
47- success : false ,
48- error : 'search tool not available' ,
49- } ) ;
50- }
69+ if ( ! searchTool ?. execute ) {
70+ return { success : false , error : 'search tool not available' } ;
71+ }
5172
52- const result = await searchTool . execute (
73+ try {
74+ return await searchTool . execute (
5375 { query } ,
5476 { toolCallId : '' , messages : [ ] } ,
5577 ) ;
56- return result ;
5778 } catch ( error ) {
5879 logger . error ( 'OpenOps Documentation MCP client error:' , { error } ) ;
59- return Promise . resolve ( {
80+ return {
6081 success : false ,
6182 error : error instanceof Error ? error . message : String ( error ) ,
62- } ) ;
83+ } ;
6384 }
6485 } ,
6586 } ) ,
0 commit comments