import { z } from 'zod';
import { PostmanAPIClient } from '../clients/postman.js';
import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
import { enabledResources } from '../enabledResources.js';
import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js';
export const method = 'getEnabledTools';
export const description =
'IMPORTANT: Run this tool first when a requested tool is unavailable. Returns information about which tools are enabled in the full and minimal tool sets, helping you identify available alternatives.';
export const parameters = z.object({});
export const annotations = {
title: 'Get Enabled Tools',
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
};
export async function handler(
_args: z.infer<typeof parameters>,
extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext }
): Promise<CallToolResult> {
try {
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
serverInfo: extra.serverContext
? {
serverType: extra.serverContext.serverType,
currentServerTools: extra.serverContext.availableTools,
currentServerToolCount: extra.serverContext.availableTools.length,
}
: {
serverType: 'unknown',
note: 'Server context not available',
},
enabledTools: {
full: Array.from(enabledResources.full),
minimal: Array.from(enabledResources.minimal),
excludedFromGeneration: Array.from(enabledResources.excludedFromGeneration),
},
stats: {
totalFull: enabledResources.full.length,
totalMinimal: enabledResources.minimal.length,
totalExcludedFromGeneration: enabledResources.excludedFromGeneration.length,
},
},
null,
2
),
},
],
};
} catch (e: unknown) {
if (e instanceof McpError) {
throw e;
}
throw asMcpError(e);
}
}