publishMock
Publish a mock server to update its access control to public, enabling external access.
Instructions
Publishes a mock server. Publishing a mock server sets its Access Control configuration setting to public.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mockId | Yes | The mock's ID. |
Implementation Reference
- src/tools/publishMock.ts:18-44 (handler)The handler function that executes the publishMock tool logic. It sends a POST request to /mocks/{mockId}/publish to set the mock server's Access Control to public.
export async function handler( args: z.infer<typeof parameters>, extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise<CallToolResult> { try { const endpoint = `/mocks/${args.mockId}/publish`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const options: any = { headers: extra.headers, }; const result = await extra.client.post(url, options); return { content: [ { type: 'text', text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`, }, ], }; } catch (e: unknown) { if (e instanceof McpError) { throw e; } throw asMcpError(e); } } - src/tools/publishMock.ts:1-16 (schema)The schema definition for publishMock: exports method='publishMock', description, Zod parameters (mockId string), and annotations.
import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'publishMock'; export const description = 'Publishes a mock server. Publishing a mock server sets its **Access Control** configuration setting to public.'; export const parameters = z.object({ mockId: z.string().describe("The mock's ID.") }); export const annotations = { title: 'Publishes a mock server. Publishing a mock server sets its **Access Control** configuration setting to public.', readOnlyHint: false, destructiveHint: false, idempotentHint: false, }; - src/index.ts:97-148 (registration)The loadAllTools() function dynamically loads all tool modules (including publishMock) from the tools directory. Tools are imported and registered iteratively in the main run() function.
async function loadAllTools(): Promise<ToolModule[]> { const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const generatedToolsDir = join(__dirname, './tools'); const tools: ToolModule[] = []; // Load generated tools from ./tools/*.js try { log('info', 'Loading tools from directory', { toolsDir: generatedToolsDir }); const files = await readdir(generatedToolsDir); const toolFiles = files.filter((file) => file.endsWith('.js')); log('debug', 'Discovered tool files', { count: toolFiles.length }); const importResults = await Promise.allSettled( toolFiles.map(async (file) => { const toolPath = join(generatedToolsDir, file); const toolModule = await import(pathToFileURL(toolPath).href); return { toolModule, file }; }) ); for (const result of importResults) { if (result.status === 'rejected') { log('error', 'Failed to load tool module', { error: String(result.reason?.message || result.reason), }); continue; } const { toolModule, file } = result.value; if ( toolModule.method && toolModule.description && toolModule.parameters && toolModule.handler ) { tools.push(toolModule as ToolModule); log('info', 'Loaded tool', { method: toolModule.method, file }); } else { log('warn', 'Tool module missing required exports; skipping', { file }); } } } catch (error: any) { log('error', 'Failed to read tools directory', { toolsDir: generatedToolsDir, error: String(error?.message || error), }); } log('info', 'Tool loading completed', { totalLoaded: tools.length }); return tools; } - src/enabledResources.ts:79-261 (registration)publishMock is listed in the 'full' (line 85) and 'minimal' (line 189) enabled resources arrays, controlling which tool sets include it.
// Mocks 'createMock', 'deleteMock', 'getMock', 'getMocks', 'updateMock', 'publishMock', 'unpublishMock', // Monitors 'createMonitor', 'deleteMonitor', 'getMonitor', 'getMonitors', 'updateMonitor', 'runMonitor', // Specs 'createSpec', 'deleteSpec', 'getSpec', 'getAllSpecs', 'getSpecDefinition', 'updateSpecProperties', 'createSpecFile', 'getSpecFile', 'getSpecFiles', 'updateSpecFile', // Workspaces 'createWorkspace', 'deleteWorkspace', 'getWorkspace', 'getWorkspaces', 'updateWorkspace', 'getWorkspaceGlobalVariables', 'updateWorkspaceGlobalVariables', 'getWorkspaceTags', 'updateWorkspaceTags', // PAN (Private API Network) 'listPrivateNetworkWorkspaces', 'listPrivateNetworkAddRequests', 'removeWorkspaceFromPrivateNetwork', 'addWorkspaceToPrivateNetwork', 'respondPrivateNetworkAddRequest', // // Documentation 'publishDocumentation', 'unpublishDocumentation', // Tasks and Status 'getAsyncSpecTaskStatus', 'getStatusOfAnAsyncApiTask', // User and Tags 'getAuthenticatedUser', 'getTaggedEntities', // Code Generation 'getCodeGenerationInstructions', // Transfer 'transferCollectionFolders', 'transferCollectionResponses', 'transferCollectionResponses', // 'asyncMergePullCollectionFork' skipped // 'asyncMergePullCollectionTaskStatus' skipped // Duplicate Collection 'duplicateCollection', 'getDuplicateCollectionTaskStatus', 'deleteApiCollectionComment', 'deleteSpecFile', 'getEnabledTools', 'searchPostmanElementsInPublicNetwork', 'searchPostmanElementsInPrivateNetwork', // Analytics 'getAnalyticsData', 'getAnalyticsMetadata', ] as const; const minimal = [ 'createCollection', 'createEnvironment', 'createMock', 'createSpec', 'createSpecFile', 'createWorkspace', 'generateCollection', 'generateSpecFromCollection', 'getAllSpecs', 'getAuthenticatedUser', 'getCollection', 'getCollections', 'getEnvironment', 'getEnvironments', 'getGeneratedCollectionSpecs', 'getMock', 'getMocks', 'getSpec', 'getSpecCollections', 'getSpecDefinition', 'getSpecFile', 'getSpecFiles', 'getTaggedEntities', 'getWorkspace', 'getWorkspaces', 'publishMock', 'putCollection', 'putEnvironment', 'syncCollectionWithSpec', 'syncSpecWithCollection', 'updateMock', 'updateSpecFile', 'updateSpecProperties', 'updateWorkspace', 'createCollectionRequest', 'createCollectionResponse', 'duplicateCollection', 'getDuplicateCollectionTaskStatus', 'runCollection', 'getEnabledTools', 'updateCollectionRequest', ] as const; const code = [ 'getCodeGenerationInstructions', 'getWorkspace', 'getWorkspaces', 'searchPostmanElementsInPublicNetwork', 'getCollectionRequest', 'getCollectionResponse', 'getCollectionFolder', 'getAuthenticatedUser', 'getCollection', 'getEnvironment', 'getEnvironments', 'searchPostmanElementsInPrivateNetwork', ] as const; const excludedFromGeneration = [ 'runCollection', 'getEnabledTools', 'getCodeGenerationInstructions', 'getCollectionMap', 'getCollection', 'searchPostmanElementsInPublicNetwork', 'searchPostmanElementsInPrivateNetwork', ] as const; /** * Subtools are tools that are grouped under a parent tool orchestrator. * Each subtool is defined with: * - orchestrator: The main tool that will be exposed (the index.ts file) * - subtools: Array of tools that will be placed in the orchestrator's folder * * Example structure for 'getCollection': * tools/ * getCollection/ * index.ts <- orchestrator (handles routing logic) * getCollection.ts <- subtool (the actual API call) * getCollectionMap.ts <- subtool (the map variant) */ const subtools = { getCollection: { orchestrator: 'getCollection', subtools: ['getCollection', 'getCollectionMap'], }, } as const; const templated = ['getCollections', 'getWorkspaces'] as const; export const enabledResources = { full, minimal, code, excludedFromGeneration, subtools, templated, };