Skip to main content
Glama

createSpec

Create API specifications in Postman Spec Hub with support for OpenAPI, AsyncAPI, Protobuf, and GraphQL. Define single or multi-file specs with nested folders.

Instructions

Creates an API specification in Postman's Spec Hub. Specifications can be single or multi-file.

Note:

  • Postman supports OpenAPI 2.0, OpenAPI 3.0, OpenAPI 3.1, AsyncAPI 2.0, protobuf 2 and 3, and GraphQL specifications.

  • If the file path contains a `/` (forward slash) character, then a folder is created. For example, if the path is the `components/schemas.json` value, then a `components` folder is created with the `schemas.json` file inside.

  • Multi-file specifications can only have one root file.

  • Files cannot exceed a maximum of 10 MB in size.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspaceIdYesThe workspace's ID.
nameYesThe specification's name.
typeYesThe specification's type.
filesYesA list of the specification's files and their contents.

Implementation Reference

  • The handler function that executes the createSpec tool logic. It POSTs to the /specs endpoint with workspaceId, name, type, and files to create an API specification in Postman's Spec Hub.
    export async function handler(
      args: z.infer<typeof parameters>,
      extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext }
    ): Promise<CallToolResult> {
      try {
        const endpoint = `/specs`;
        const query = new URLSearchParams();
        if (args.workspaceId !== undefined) query.set('workspaceId', String(args.workspaceId));
        const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint;
        const bodyPayload: any = {};
        if (args.name !== undefined) bodyPayload.name = args.name;
        if (args.type !== undefined) bodyPayload.type = args.type;
        if (args.files !== undefined) bodyPayload.files = args.files;
        const options: any = {
          body: JSON.stringify(bodyPayload),
          contentType: ContentType.Json,
          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);
      }
    }
  • Input schema for createSpec defined using Zod. Requires workspaceId (string), name (string), type (enum of OpenAPI/AsyncAPI/Protobuf/GraphQL versions), and files (array of file objects with path, content, optional type).
    export const parameters = z.object({
      workspaceId: z.string().describe("The workspace's ID."),
      name: z.string().describe("The specification's name."),
      type: z
        .preprocess(
          (v) => (typeof v === 'string' ? v.toUpperCase() : v),
          z.enum([
            'OPENAPI:2.0',
            'OPENAPI:3.0',
            'OPENAPI:3.1',
            'ASYNCAPI:2.0',
            'PROTOBUF:2',
            'PROTOBUF:3',
            'GRAPHQL',
          ])
        )
        .describe("The specification's type."),
      files: z
        .array(
          z.union([
            z.object({
              path: z
                .string()
                .describe("The file's path. Accepts .json, .yaml, .proto and .graphql file types."),
              content: z.string().describe("The file's stringified contents."),
              type: z
                .preprocess(
                  (v) => (typeof v === 'string' ? v.toUpperCase() : v),
                  z.enum(['DEFAULT', 'ROOT'])
                )
                .describe(
                  'The type of file. This property is required when creating multi-file specifications:\n- `ROOT` — The file containing the full OpenAPI structure. This serves as the entry point for the API spec and references other (`DEFAULT`) spec files. Multi-file specs can only have one root file.\n- `DEFAULT` — A file referenced by the `ROOT` file.\n'
                ),
            }),
            z.object({
              path: z
                .string()
                .describe("The file's path. Accepts .json, .yaml, .proto and .graphql file types."),
              content: z.string().describe("The file's stringified contents."),
            }),
          ])
        )
        .describe("A list of the specification's files and their contents."),
    });
  • Registration of 'createSpec' in the 'full' tools list in enabledResources.
    'createSpec',
  • Registration of 'createSpec' in the 'minimal' tools list in enabledResources.
    'createSpec',
  • Helper utilities used by createSpec handler: asMcpError for error wrapping and ServerContext type definition.
    import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
    
    export { McpError };
    
    export interface ServerContext {
      serverType: 'full' | 'minimal' | 'code';
      availableTools: string[];
    }
    
    export function asMcpError(error: unknown): McpError {
      const cause = (error as any)?.cause ?? String(error);
      return new McpError(ErrorCode.InternalError, cause);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond annotations (non-readonly, non-destructive), the description adds key behaviors: supported spec types, file path folder creation, single root file requirement, and 10 MB file size limit. No contradictions with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is two paragraphs with bullet notes, well-structured and front-loaded. Each note adds value. Could be slightly more concise but not verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description adequately covers creation behavior, constraints, and supported formats. Missing return value details, but sufficient for most use cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baselines are 3. The description adds meaning by explaining folder creation via '/' in path, multi-file root file requirement, and enum values for type. This enhances understanding beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it creates an API specification in Postman's Spec Hub, explicitly listing supported formats and noting single or multi-file capability. This distinguishes it from sibling tools like createCollection or createSpecFile.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implicit usage through constraints and notes (e.g., root file, size limit) but does not explicitly guide when to use this tool over alternatives like createCollection or createEnvironment. No exclusions or when-not-to-use guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/postmanlabs/postman-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server