@haddowg/json-api-mcp

中文文档
1.26.0发布于 2026/11/17MITTypeScriptESM + CJS构建来源已验证近 30 天下载 6724

MCP tool definitions and a call handler for a JSON:API server, served from a model generated at build time from its OpenAPI document.

原始使用文档
文档目录3 节
  1. Install
  2. Generate the model
  3. Serve it

@haddowg/json-api-mcp

Part of the jsonapi.rest suite — a complete, spec-compliant JSON:API 1.1 stack: a framework-agnostic PHP core, a Symfony bundle, a Laravel package, and the typed TypeScript client, bound together by one conformance-tested OpenAPI 3.1 contract. Full documentation: haddowg.github.io/json-api-ts.

MCP tool definitions and a call handler for a haddowg/json-api server. A build-time generator turns the server's OpenAPI document into one JSON model, which you commit; the runtime serves one tool per collection, resource, related and custom action operation from it, with input schemas valid under OpenAI's and Anthropic's strict modes. Calls run through @haddowg/json-api-client. The package doesn't own an MCP server: the host lists the tools and passes calls to the handler.

Install

npm install @haddowg/json-api-mcp @haddowg/json-api-client
npm install --save-dev @haddowg/json-api-codegen

Generate the model

npx @haddowg/json-api-mcp --input openapi/v5.json --output src/mcp/v5.mcp.json
npx @haddowg/json-api-mcp --input openapi/v5.json --output src/mcp/v5.mcp.json --check # in CI

The model is generated, and its leading $comment says so. Regenerate it rather than editing it by hand.

Tools include one relationship deep by default, so each tool's schema carries only the types its direct relations reach. Pass --include-depth <n>, or all for every path the document declares, to change that.

An operation can drop or reshape its tool with the x-mcp vendor extension. false leaves its tool out of the model, and an object of name, title and description replaces those parts of the tool.

A deprecated operation's tool description starts with Deprecated., an x-mcp description included, and so does the description of each deprecated attribute, relationship, filter and sort key in a tool's input.

Serve it

The runtime loads from ESM or CommonJS and needs only the client.

const { createJsonApiMcp } = require('@haddowg/json-api-mcp')

const mcp = createJsonApiMcp({ model: require('./mcp/v5.mcp.json') })
const session = await mcp.forRequest({ grantedScopes: token.scopes, context: { token } })
session.tools // answer tools/list with these
await session.callTool('albums_list', { sort: ['-releasedAt'], pageSize: 5 })

Every result's structuredContent is a JSON:API-like envelope. A single resource comes back as { data }, a collection as { data, links, meta } with only the pagination links, a delete as { data: null } and a meta-only action as { meta }. A flattened resource keeps the links its type names, such as a presigned upload URL, under links.

Coming from 1.2: a get returns { data } where it returned { item }, a create or update is wrapped in { data } instead of coming back bare, and a collection lists its resources under data instead of items. A delete returns { data: null } instead of a line of text, a meta-only action { meta } instead of the bare meta object, and a URL action { data: { url, type, expiresAt? } } instead of the bare object. Regenerate the model to get the new shapes. A model generated by 1.2 still loads and keeps the 1.2 shapes its output schemas describe. The migration notes cover the rest.

Scope filtering counts only the security requirements a caller can meet with its credential schemes, the document's oauth2 schemes unless you pass credentialSchemes. Scopes, feature gates, headers and error hints come from optional hooks: scopeMatcher, capabilities, includeOperation, decorateTool, requestInit and mapError. See the MCP tools guide.

版本与发布记录

@haddowg/json-api-mcp 共发布 38 个版本,首次发布于 2026/10/28;过去 12 个月发布了 38 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.26.0latest2026/11/17今天
1.25.12026/11/17今天
1.25.02026/11/16今天
1.24.02026/11/133 天前
1.23.02026/11/133 天前
1.22.02026/11/133 天前

关于 @haddowg/json-api-mcp 的常见问题

@haddowg/json-api-mcp 是什么?

MCP tool definitions and a call handler for a JSON:API server, served from a model generated at build time from its OpenAPI document.

如何安装 @haddowg/json-api-mcp?

在项目目录运行 npm install @haddowg/json-api-mcp,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 json-api-mcp,可以用 npx json-api-mcp 直接运行。

@haddowg/json-api-mcp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@haddowg/json-api-mcp 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@haddowg/json-api-mcp 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@haddowg/json-api-mcp 可以商用吗?

@haddowg/json-api-mcp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@haddowg/json-api-mcp 的下载量有多少?

根据 npm 官方下载统计,@haddowg/json-api-mcp 在 2026/10/17 – 2026/11/15 这 30 天内被下载 6,724 次,日均约 224 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@haddowg/json-api-mcp 还在维护吗?

最新版本 1.26.0 发布于 2026/11/17(今天);至今共发布 38 个版本,其中过去 12 个月发布了 38 个;首次发布于 2026/10/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。