@thinknimble/tnm-cli
v1.0.1
Published
CLI and MCP server for querying OpenAPI/Swagger schemas - extract routes, entities, and schemas
Readme
TN Models CLI
tnm-cli is a command line interface for querying and extracting information from OpenAPI schema files. It allows you to inspect schemas, routes, and entities defined in your OpenAPI specifications.
Installation
First, install bun (required):
curl -fsSL https://bun.sh/install | bashThen install the CLI:
npm install -g @thinknimble/tnm-cli
# or
bun install -g @thinknimble/tnm-cliUsage
The CLI requires an OpenAPI schema to be provided via either a file path or a YAML/JSON string.
Basic Syntax
tn-models-cli [--file <path> | --yaml <string>] <command> [arguments]Options
--file, -f <path>- Path to the OpenAPI schema file (YAML or JSON)--yaml, -y <string>- OpenAPI schema as a YAML or JSON string
Available Commands
hello
Print a hello message.
tn-models-cli --file schema.yaml helloschema <name>
Get a specific schema by name from the components/schemas section.
tn-models-cli --file schema.yaml schema Userroute <path>
Get route information for a specific path.
tn-models-cli --file schema.yaml route /api/users/routes
Get all routes defined in the OpenAPI schema.
tn-models-cli --file schema.yaml routesentities
Get all entity schemas from the components/schemas section.
tn-models-cli --file schema.yaml entitiesExamples
Using a local file:
tn-models-cli --file openapi.yaml routes
tn-models-cli -f openapi.json schema PetUsing inline YAML:
tn-models-cli --yaml "$(cat schema.yaml)" entitiesDevelopment
To install dependencies:
bun installTo build:
bun run buildTo run locally:
bun run src/v1/cli.ts --file <path> <command>This project was created using bun init in bun v1.1.22. Bun is a fast all-in-one JavaScript runtime.
Running as MCP Server
This tool can run as an MCP (Model Context Protocol) server in two modes:
1. MCP stdio Server (Recommended for Claude Desktop)
The stdio server uses the standard MCP protocol over stdio for integration with Claude Desktop and other MCP clients.
# Using the built version
tn-models-mcp
# Or using the -m flag with the main CLI
tn-models-cli -m
./build/cli.js -m
# Or run directly with bunx
bunx ./src/v1/mcp-server.tsTesting with MCP Inspector:
npx @modelcontextprotocol/inspector build/cli.js -mMCP Tools Available:
get_schema- Get a specific schema by name (requiresschema_pathandschema_nameparameters)get_route- Get route information for a path (requiresschema_pathandroute_pathparameters)get_routes- Get all routes (requiresschema_pathparameter)get_entities- Get all entity schemas (requiresschema_pathparameter)
Note: In MCP mode, the schema file path is passed as a parameter to each tool call, not at startup.
Claude Desktop / Claude Code Configuration:
Add to your MCP config (~/.claude/settings.json for Claude Code, or claude_desktop_config.json for Claude Desktop):
Using npx (recommended for npm package):
{
"mcpServers": {
"tnm-openapi": {
"command": "npx",
"args": ["-y", "@thinknimble/tnm-cli", "-m"]
}
}
}Or using the dedicated MCP binary:
{
"mcpServers": {
"tnm-openapi": {
"command": "npx",
"args": ["-y", "-p", "@thinknimble/tnm-cli", "tn-models-mcp"]
}
}
}Using bunx (for local development):
{
"mcpServers": {
"tnm-openapi": {
"command": "bunx",
"args": ["/path/to/tnm-cli/src/v1/mcp-server.ts"]
}
}
}2. HTTP Server Mode
You can also run an HTTP server that exposes REST endpoints. The schema can be provided either at startup or per-request.
Start with a default schema:
# Using the serve subcommand
tn-models-cli --file ./sample.yaml serve --port 8080
# Or using the --mcp flag
tn-models-cli --mcp --file ./sample.yaml --port 8080Start without a default schema:
tn-models-cli serve --port 8080
# Provide schema_path as a query parameter in each requestHTTP Endpoints:
GET /health- Health checkGET /routes?schema_path=/path/to/schema.yaml- Get all routesGET /entities?schema_path=/path/to/schema.yaml- Get all entitiesGET /schema/:name?schema_path=/path/to/schema.yaml- Get specific schemaGET /route?path=/api/users&schema_path=/path/to/schema.yaml- Get specific route
If a default schema was provided at startup, the schema_path query parameter is optional.
