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+
714export async function getDocsTools ( ) : Promise < MCPTool > {
8- const mcpServerPath = system . get < string > ( AppSystemProp . DOCS_MCP_SERVER_PATH ) ;
9- if ( ! mcpServerPath ) {
15+ const mcpServerUrl = system . get < string > ( AppSystemProp . DOCS_MCP_SERVER_PATH ) ;
16+ if ( ! mcpServerUrl ) {
1017 return {
1118 client : undefined ,
1219 toolSet : { } ,
1320 } ;
1421 }
1522
1623 logger . debug ( 'Creating MCP client for docs' , {
17- serverPath : mcpServerPath ,
24+ serverPath : mcpServerUrl ,
1825 } ) ;
1926
2027 const client = await createMCPClient ( {
21- transport : new StdioMCPTransport ( {
22- command : 'node ' ,
23- args : [ mcpServerPath ] ,
24- } ) ,
28+ transport : {
29+ type : 'http ' ,
30+ url : mcpServerUrl ,
31+ } as Parameters < typeof createMCPClient > [ 0 ] [ 'transport' ] ,
2532 } ) ;
2633
2734 const tools = await client . tools ( ) ;
28- const searchTool = tools [ 'search' ] ;
35+ const toolEntries =
36+ tools instanceof Map ? Array . from ( tools . entries ( ) ) : Object . entries ( tools ) ;
37+
38+ const searchTool = toolEntries . find ( ( [ name ] ) =>
39+ name . toLowerCase ( ) . includes ( 'search' ) ,
40+ ) ?. [ 1 ] as MCPSearchTool | undefined ;
41+
42+ if ( ! searchTool ?. execute ) {
43+ logger . error ( 'Docs MCP search tool not available' , {
44+ availableTools : toolEntries . map ( ( [ name ] ) => name ) ,
45+ } ) ;
46+ }
2947
3048 const toolSet = {
3149 OpenOps_Documentation : tool ( {
@@ -41,25 +59,21 @@ Use this tool to find accurate, verified information before answering OpenOps-sp
4159 query : z . string ( ) . describe ( 'The search query' ) ,
4260 } ) ,
4361 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- }
62+ if ( ! searchTool ?. execute ) {
63+ return { success : false , error : 'search tool not available' } ;
64+ }
5165
52- const result = await searchTool . execute (
66+ try {
67+ return await searchTool . execute (
5368 { query } ,
5469 { toolCallId : '' , messages : [ ] } ,
5570 ) ;
56- return result ;
5771 } catch ( error ) {
5872 logger . error ( 'OpenOps Documentation MCP client error:' , { error } ) ;
59- return Promise . resolve ( {
73+ return {
6074 success : false ,
6175 error : error instanceof Error ? error . message : String ( error ) ,
62- } ) ;
76+ } ;
6377 }
6478 } ,
6579 } ) ,
0 commit comments