@@ -8,12 +8,15 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
88import type { CoreWorkload } from '@api/types.gen'
99import log from '../logger'
1010
11- export type McpToolDefinition = Tool
11+ export interface McpToolDefinition {
12+ description ?: string
13+ inputSchema : Tool [ 'inputSchema' ]
14+ }
1215
13- export function isMcpToolDefinition ( obj : unknown ) : obj is Tool {
16+ export function isMcpToolDefinition ( obj : unknown ) : obj is McpToolDefinition {
1417 if ( ! obj || typeof obj !== 'object' || obj === null ) return false
1518
16- const tool = obj as Record < string , unknown >
19+ const tool = obj
1720
1821 // Description should be string if present
1922 if (
@@ -105,12 +108,16 @@ export async function getWorkloadAvailableTools(
105108 const rawTools = await mcpClient . tools < 'automatic' > ( )
106109
107110 // Filter and validate tools using type guard
108- const serverMcpTools : Record < string , McpToolDefinition > = { }
109- for ( const [ name , def ] of Object . entries ( rawTools ) ) {
110- if ( name && def && isMcpToolDefinition ( def ) ) {
111- serverMcpTools [ name ] = def
112- }
113- }
111+ const serverMcpTools = Object . entries ( rawTools )
112+ . filter ( ( [ , defTool ] ) => isMcpToolDefinition ( defTool ) )
113+ . reduce < Record < string , McpToolDefinition > > ( ( prev , [ name , def ] ) => {
114+ if ( ! def || ! name ) return prev
115+ prev [ name ] = {
116+ description : def . description ,
117+ inputSchema : def . inputSchema ,
118+ }
119+ return prev
120+ } , { } )
114121 await mcpClient . close ( )
115122 return serverMcpTools
116123 }
0 commit comments