paparam-mcp

paparam-mcp

Exposes any paparam CLI as an MCP server, automatically deriving tool definitions, resources, and prompts from the command's own schema, with validation before execution and support for both MCP protocol eras.

Category
访问服务器

README

paparam-mcp

Expose any paparam CLI as an MCP server.

A CLI built with paparam already describes its whole surface precisely: every flag's type, every choice, every default, every required argument. That is exactly what an MCP tool definition needs — so the tool list is derived, not hand-written, and a model calls

{ "name": "launch", "arguments": { "vehicle": "MRDN-7", "mode": "orbit" } }

against a real schema instead of guessing at an argv string.

Every call is validated by your own command (parse with run: false) before anything executes, so a bad call comes back as an error the model can read and correct — not a half-run command.

Built on paparam-reflect, which is its only dependency. Runs on Bare and on Node.

Install

npm install paparam-mcp

Use

const { command, flag, arg } = require('paparam')
const { isMcpMode, runMcp } = require('paparam-mcp')

const cmd = command(
  'orbital',
  command(
    'launch',
    arg('<vehicle>', 'hull id'),
    flag('--mode|-m [mode]', 'flight profile').choices(['orbit', 'suborbital']),
    flag('--crewed', 'fly with crew aboard').default(true),
    (c) => {
      /* your real runner */
    }
  )
)

if (isMcpMode(Bare.argv)) await runMcp(cmd, { name: 'orbital', version: '1.0.0' })
else cmd.parse(Bare.argv.slice(2))

That's the whole integration. --mcp is one more branch on the same ladder bare-tui-paparam already establishes:

if (isMcpMode(Bare.argv))
  await runMcp(cmd, opts) // an agent host drives it
else if (isMenuMode(Bare.argv))
  await runMenu(cmd) // a human picks from a menu
else cmd.parse(Bare.argv.slice(2)) // the normal CLI

Register it with a host

claude mcp add orbital -- bare ./cli.js --mcp

Or in a config file:

{ "mcpServers": { "orbital": { "command": "bare", "args": ["./cli.js", "--mcp"] } } }

Try it with the Inspector

Pass the server through a config file — the Inspector's own argument parser will otherwise swallow your --mcp:

npx @modelcontextprotocol/inspector --cli --config ./mcp.json --server orbital --method tools/list

What gets generated

From the definition above:

{
  "name": "launch",
  "title": "launch",
  "description": "launch a vehicle\n\nRuns: launch <vehicle>",
  "inputSchema": {
    "type": "object",
    "properties": {
      "vehicle": { "type": "string", "description": "hull id" },
      "mode": {
        "type": "string",
        "description": "flight profile",
        "enum": ["orbit", "suborbital"]
      },
      "crewed": { "type": "boolean", "description": "fly with crew aboard", "default": true }
    },
    "required": ["vehicle"],
    "additionalProperties": false
  },
  "annotations": {}
}

Choices become enum. .default() becomes default. Required positionals become required. Hidden flags never appear. .hide() on a command keeps it out entirely — it is the zero-config way to keep something away from the model.

Resources are served too: paparam://help (the full reference), paparam://help/<command> (one command's help) and paparam://catalog.json. A host can read the manual without spending a tool call.

A prompt, use_<name>, seeds a conversation with the whole command reference plus your supplement.

How many tools?

A host has to fit every tool from every connected server into the model's context, so a 60-subcommand CLI that insists on 60 tools is a bad neighbour. Two shapes, picked automatically:

commands mode tools
≤ 25 tools one typed tool per command
> 25 meta list_commands, describe_command, run_command

Per-command is much better for the model — real enums, real defaults, no discovery round-trips — so it is the default wherever it fits. Meta mode costs two extra calls but keeps the tool list at three. Execution goes through the identical path either way.

Override with mode: 'tools' | 'meta' | 'auto' and threshold.

Options

runMcp(cmd, {
  name: 'orbital', // server identity reported to the host
  version: '1.0.0',
  instructions: '…', // guidance for the model, in the discovery response
  supplement: '…', // extra grounding folded into the prompt

  mode: 'auto', // 'tools' | 'meta' | 'auto'
  threshold: 25, // where 'auto' switches
  prefix: 'orbital', // prepended to every tool name

  include: ['launch'], // strict allowlist, by command label
  exclude: ['scuttle'], // or a denylist
  expose: (item) => true, // or a predicate

  annotations: {
    // per-command behaviour hints, by label
    scuttle: { destructiveHint: true }
  },

  validateSubmission, // (result, { argv, command }) => error|null
  onCall, // (result, { argv, item }) => any — runs INSTEAD of parse
  dryRun: false // validate and report argv, never run
})

Annotations

readOnlyHint / idempotentHint are set automatically for commands whose leaf verb is list, show, status, get, … and destructiveHint for delete, reset, purge, scuttle-like verbs. Anything unrecognised is left unannotated on purpose: MCP already treats a tool with no readOnlyHint as potentially destructive, which is the safe reading. Your annotations map always wins.

validateSubmission

Runs after paparam accepts the argv and before anything executes. Return a string to reject; the model sees it and can retry.

result is what parse() returns — the deepest matched Command — so read result.name, result.args and result.flags directly:

validateSubmission: (result) => {
  if (result.name === 'launch' && result.flags.crewed !== false && !result.args.window) {
    return 'a crewed launch needs an explicit window'
  }
  return null
}

onCall

By default the server runs command.parse(argv) and returns whatever the runner printed. Supply onCall to take over — return a string for text, or an object to become structuredContent. This is the right hook when a command should return structured data rather than terminal output.

Writing runners that behave as MCP tools

On stdio, stdout is the JSON-RPC wire. Anything a runner prints to it would corrupt the protocol stream. So:

  • console.log / .info / .warn / .error are captured for the duration of a call and returned as the tool's result — which is where a model can actually see them. warn and error are also mirrored to real stderr.
  • A runner that writes directly to Bare.stdio.out or process.stdout bypasses that and will corrupt the stream. Use onCall for those.
  • Bare.exit() inside a runner takes the server down with it.
  • Calls are handled one at a time, because console capture swaps a global.

Two protocol eras

MCP changed shape in revision 2026-07-28: protocol version and client identity moved into per-request _meta, server/discover became mandatory, and results carry a resultType. Revisions up to 2025-11-25 instead open with an initialize handshake.

This server answers both, which is what the spec's dual-era guidance prescribes — a request carrying modern _meta is served statelessly under the new rules, an initialize request selects legacy semantics. You don't have to care which your host speaks.

Testing your own server

createMcpServer is transport-free — handle(message) takes a parsed JSON-RPC object and resolves to the response. No pipes, no subprocesses:

const { createMcpServer } = require('paparam-mcp')
const server = createMcpServer(cmd, { name: 'orbital' })

const res = await server.handle({
  jsonrpc: '2.0',
  id: 1,
  method: 'tools/call',
  params: { name: 'launch', arguments: { vehicle: 'MRDN-7' } }
})

When you don't want a server at all

Not every agent speaks MCP, and MCP tool definitions sit in the model's context on every request. A paparam CLI is already installed and already self-describing, so an agent can just run it — it only needs to know what exists. paparam-reflect generates that reference from the same command definition:

const { isDocsMode, printAgentDocs } = require('paparam-reflect')

if (isDocsMode(Bare.argv)) printAgentDocs(cmd, { invocation: 'orbital' })
else if (isMcpMode(Bare.argv)) await runMcp(cmd, opts)
else cmd.parse(Bare.argv.slice(2))

On the example below that is 318 tokens against 565 for the equivalent tools/list, or 106 at --agent-docs=index (where the agent drills into any one command with the CLI's own --help). Same source of truth, different delivery — pick per host, or ship both.

Example

examples/orbital-mcp.js — a mission-control CLI wiring all of the above.

bare examples/orbital-mcp.js status --verbose   # the normal CLI
bare examples/orbital-mcp.js --agent-docs       # the markdown reference
bare examples/orbital-mcp.js --mcp              # the MCP server

Tests

npm test          # both runtimes

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选