— MIT Licensed — 6 Protocol Adapters

OpenAPI 3.2 API Debugger & Request Runner

Debug and run API requests from OpenAPI collections. HTTP, SSE, WebSocket, GraphQL, gRPC, and MCP. Schema inference, response write-back, Postman script support. Subpath exports for each protocol.

$npm install @powerduck/openapi-request
HTTP + SSE + WSGraphQL + gRPC + MCPSchema InferenceResponse Write-BackPostman ScriptsSubpath Exports
Quick Start

Debug APIs in seconds

import { createClient } from "@powerduck/openapi-request";

// CreateClientOptions: { writeBack?, response? } — both optional
const client = createClient({
  writeBack: { strategy: "merge" },  // WriteBackOptions: strategy/keepExistingDescription/allowedStatusCodes
});

// Full SendOptions — all fields shown
const response = await client.send({
  spec: openApiDocument,                    // REQUIRED: OpenAPI 3.2 document
  target: { operationId: "getUserById" }, // REQUIRED: { operationId? } or { path?, method? }
  values: {                                  // RequestValues: path/query/header/cookie/querystring/body/contentType
    path: { id: "123" },
    query: { verbose: true },
    header: { "X-Request-Id": "abc-123" },
    body: { name: "John" },
    contentType: "application/json",
  },
  serverUrl: "https://api.example.com/v1",  // Override servers[0].url
  serverVariables: { host: "api", port: "443" },
  variables: { baseUrl: "https://api.example.com" }, // {{name}} env vars
  auth: { type: "bearer", token: "my-token" }, // AuthConfig: bearer/basic/apikey/none
  timeout: 30000,                           // Request timeout in ms
  maxResponseSize: 10 * 1024 * 1024,       // Max response body size (10 MB)
  writeBack: true,                        // Write response back into spec
  signal: abortController.signal,            // AbortSignal for cancellation
  onEvent: (event) => console.log(event.type), // Streaming event callback
});

console.log(result.response.status, result.response.body);
Features

Powerful API debugging toolkit

Built for API developers who need more than just HTTP requests.

02

Two Execution Modes

createClient() for UI-first interactive debugging. createDebugger() for scripted batch execution with send(), sendMany(), and toCollection(). Choose the mode that fits your workflow.

03

Schema Inference

inferSchema() and inferSchemaFromMany() automatically infer JSON Schemas from response bodies. mergeSchema() combines multiple samples. sampleFromSchema() generates example data.

04

Response Write-Back

writeBackResponse() writes response examples back into OpenAPI operation definitions. toResponseObject() normalizes responses for collection storage. Keep your spec in sync with reality.

05

Streaming Support

probeStreamingResponse() detects SSE and streaming content types. isStreamingOperation(), isSseContentType(), isStreamingContentType(). acceptHeaderFor() sets correct Accept headers.

06

Subpath Exports

Import only what you need: @powerduck/openapi-request/http, /ws, /grpc, /mcp, /graphql. Tree-shakeable, smaller bundles. Full API from root import.

Adapters

Six protocol adapters

Each adapter has its own subpath export and specialized APIs.

HTTP

HttpAdapter

Full HTTP client with method, headers, body, query, auth. Response capture and timing. Import from @powerduck/openapi-request/http.

SSE

SseParser

Parse Server-Sent Event streams. Event and data extraction. Reconnect handling. Import from root or /http.

WS

WebSocketAdapter

Connect, send, receive. Manual sessions via createWsManualSession(). Message sequence tracking. Import from /ws.

GQL

GraphQLAdapter

Queries, mutations, subscriptions. Schema introspection via introspectSchema(). Operation generation via generateOperation(). Import from /graphql.

gRPC

GrpcAdapter

Unary and streaming calls. Proto file loading via scanProtoFiles(). Reflection via fetchDescriptorSet(). Import from /grpc.

MCP

McpAdapter

Tool calls, resource listing, prompt resolution. SSE and stdio transports. Capability discovery via discoverMcpCapabilities(). Import from /mcp.

API Reference

Core API

Main exports from the package root.

functioncreateClient(options)Create an interactive API client for UI-first debugging
Parameter Type Description
options.writeBack WriteBackOptions Response write-back config: strategy, keepExistingDescription, allowedStatusCodes, protectComponentRefs, overwriteExamples
options.response ToResponseOptions Response normalization config: includeHeaders, includeBody
Client Methods
prepare(request), send(request), sendMany(spec, targets, shared?), connect(options), discover(options), writeback(spec, prepared, result), dispose()
functioncreateDebugger(options)Create a scripted debugger for batch request execution
Debugger Methods
send(request), sendMany(requests, options?), toCollection()
functioncreateManualSession()Create a unified long-lived session for WebSocket, MCP, or gRPC

Returns a session object with connect(), send(), receive(), close() methods. Protocol-agnostic interface.

functionlocateOperation(spec, operationId)Find an operation in an OpenAPI spec by operationId
Returns
{ method: string; path: string; operation: OperationObject } | null
functioninferSchema(value)Infer a JSON Schema from a sample value

Infers type, properties, items, required, enum, and format from sample data. Handles nested objects and arrays.

functioninferSchemaFromMany(values)Infer and merge a JSON Schema from multiple sample values

Convenience wrapper that infers schema from each value and merges them. Produces a schema that accommodates all samples.

functionmergeSchema(schemas)Merge multiple JSON Schemas into one

Merges types (oneOf for mixed), properties (union), items (merge), required (intersection). Handles conflicting schemas gracefully.

functionsampleFromSchema(schema)Generate a sample value from a JSON Schema

Generates realistic sample data respecting type, format, enum, default, example, min/max, and pattern constraints.

functionwriteBackResponse(spec, path, method, fragment, options?)Write a response fragment back into an OpenAPI operation

Adds or updates the response at the given status code in the operation identified by path + method. fragment is { statusCode, response } from toResponseObject().

functiontoResponseObject(result, options?)Normalize an ExecResult to an OpenAPI response fragment

Converts a SendResult/ExecResult to { statusCode, response } format suitable for writeBackResponse(). Options: includeHeaders, includeBody.

functionprobeStreamingResponse(response)Detect if a response is a streaming (SSE) response

Checks content-type and transfer-encoding headers. Returns { isStreaming, type: "sse" | "chunked" | null }.

functionisStreamingOperation(operation)Check if an OpenAPI operation is likely to stream

Checks for text/event-stream in response content types or x-streaming extension.

functionacceptHeaderFor(operation)Get the appropriate Accept header for an operation

Returns text/event-stream for SSE operations, application/json for JSON, or */* as fallback.

classAdapterRegistryRegistry for protocol adapters

register(adapter), unregister(protocol), get(protocol), list(). Manages HttpAdapter, WebSocketAdapter, GraphQLAdapter, GrpcAdapter, McpAdapter.

classProtoKitErrorCustom error class for protocol toolkit errors

Extends Error with code, protocol, operationId, and cause properties for structured error handling.

Subpath Exports

/http

@powerduck/openapi-request/http

HttpAdapter, SseParser, isSseContentType, isStreamingContentType, BUILTIN_CAPTURE_TEST

/ws

@powerduck/openapi-request/ws

WebSocketAdapter, createWsManualSession

/graphql

@powerduck/openapi-request/graphql

GraphQLAdapter, resolveGraphQLConfig, runGraphQL, introspectSchema, INTROSPECTION_QUERY, generateOperation, generateAllOperations, writeGraphQLOperations, discoverAndWriteGraphQLSchema

/grpc

@powerduck/openapi-request/grpc

GrpcAdapter, grpcCall, createGrpcManualSession, grpcDiscover, resolveMethod, buildMessageTemplate, buildCatalog, LOADER_OPTIONS, scanProtoFiles, fetchDescriptorSet, listServices, buildCredentials, loadGrpc, isGrpcAvailable

/mcp

@powerduck/openapi-request/mcp

McpAdapter, createMcpManualSession, createMcpStdioSession, resolveMcpConfig, initializeMcpSession, discoverMcpCapabilities, MCP_PROTOCOL_VERSION, generateMcpCall, generateAllMcpCalls, writeMcpOperations, discoverAndWriteMcpCapabilities, createHttpMcpTransport, createStdioMcpTransport

root

@powerduck/openapi-request

All of the above plus core utilities: createClient, createDebugger, createManualSession, locateOperation, inferSchema, mergeSchema, sampleFromSchema, writeBackResponse, toResponseObject, probeStreamingResponse, AdapterRegistry, ProtoKitError

6
Protocols
5
Subpath Exports
2
Execution Modes
MIT
License