knife4j-mcp AGENTS.md

knife4j-mcp AGENTS.md is an instructions file for Codex, OpenCode from chaselen/knife4j-mcp. It costs 912 tokens per session, scanned A, original, MIT.

Project instructions for a Node.js and TypeScript service that reads Swagger or OpenAPI files and lets an agent search an API catalogue. Swagger and OpenAPI are formats that describe web endpoints and how to call them.

In plain words
What is it for?
Use it when changing the service, its API-document parsing, its search tools, authentication, caching, or smoke tests.
Why use it?
It gives contributors the project’s goals, structure, configuration rules, and expected tool outputs in one place.

Instructions file for CodexOpenCode

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/chaselen/knife4j-mcp/agents-md
Clone the repo
git clone --depth 1 https://github.com/chaselen/knife4j-mcp

Made for: Codex, OpenCode.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for knife4j-mcp AGENTS.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/chaselen/knife4j-mcp/agents-md.svg)](https://agentmods.dev/instructions/chaselen/knife4j-mcp/agents-md)
Your own site
<a href="https://agentmods.dev/instructions/chaselen/knife4j-mcp/agents-md"><img src="https://agentmods.dev/badge/instructions/chaselen/knife4j-mcp/agents-md.svg" alt="Measured on agentmods" height="20"></a>
Per session 912 This file is loaded in full into every session.
When invoked 912 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00912 $0.00912
Opus 5 $0.00456 $0.00456
Sonnet 5 $0.00182 $0.00182
Haiku 4.5 $0.00091 $0.00091

Measured 5d ago against content hash 55f5074282b4, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

knife4j-mcp AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

AGENTS.md · 108 lines

What it actually says

AGENTS.md

项目目标

本仓库用于实现一个基于 Node.js + TypeScript 的 MCP server,用来读取 Knife4j / Swagger 多模块接口文档,并为 Codex 或其他支持 MCP 的 Agent 提供接口查询能力。

这个服务的核心用途是:

  • 读取 /swagger-resources
  • 拉取每个模块对应的 Swagger/OpenAPI 文档
  • 在内存中建立统一搜索索引
  • 根据路径、关键词、tag、operation 信息查询接口

实现上优先保持轻量、清晰、可本地运行。

当前技术栈

  • Node.js
  • TypeScript
  • @modelcontextprotocol/sdk
  • zod
  • 少量 Node 标准库能力

没有明确必要时,不要引入重型框架。

关键文件

  • src/index.ts:stdio MCP server 启动入口
  • src/server.ts:MCP tools 注册
  • src/swagger-registry.ts:spec 拉取、缓存、索引、查询
  • src/swagger-parser.ts:Swagger 2 / OpenAPI 3 统一抽取与映射
  • src/http.ts:认证请求与 URL 解析
  • examples/mock-swagger-server.ts:本地多模块 Swagger mock 服务
  • scripts/smoke-test.ts:stdio MCP 联调 smoke test
  • README.md:使用说明与验证步骤

MCP Tools

当前已提供这些 tools:

  • list_specs
  • find_api
  • get_api_detail
  • refresh_specs

如果修改 tool 行为,请遵循:

  • 输出保持结构化,优先返回适合 Agent 消费的 JSON
  • 除非有明确目的,不要随意改掉现有核心字段
  • 优先做兼容性增强,不轻易做破坏性 schema 变更

环境变量

当前支持的运行配置:

  • SWAGGER_RESOURCES_URL(必填)
  • SWAGGER_BASE_URL
  • SWAGGER_BASIC_AUTH
  • SWAGGER_HEADERS
  • SWAGGER_MODULE_ALLOWLIST
  • CACHE_TTL_MS
  • LOG_LEVEL

不要在源码中硬编码账号、密码、token 或其他敏感信息。

协作和编码方式

  • 优先实现最小可运行版本,再逐步迭代。
  • 优先复用现有的 registry + parser + server 分层,不随意新增平行抽象。
  • 保持 Swagger 2.0 支持稳定;OpenAPI 3 在可控范围内尽量兼容。
  • 做好局部失败隔离:单个模块 spec 拉取失败,不应导致整个服务不可用。
  • 能用 Node 内置能力或现有结构解决的问题,不要额外加依赖。

验证方式

完成较重要代码改动后,优先执行:

npm run build

做端到端验证时,使用:

MOCK_SWAGGER_BASIC_AUTH=demo:demo npm run mock:swagger
SWAGGER_RESOURCES_URL=http://127.0.0.1:3301/swagger-resources SWAGGER_BASIC_AUTH=demo:demo npm run test:smoke

如果改动影响索引逻辑、查询逻辑或 tool 输出,至少验证:

  • list_specs
  • find_api
  • get_api_detail

实现注意事项

  • swagger-resources 返回的模块地址可能是相对路径,必须正确补全。
  • 先把 Swagger/OpenAPI 文档映射成统一内部模型,再做搜索和查询逻辑。
  • 搜索结果应尽量简洁;详情结果应尽量完整,方便 Agent 联调。
  • 日志保持简洁即可,本地 MCP 使用场景下输出到 stderr 是可以接受的。

变更边界

  • 不要做与当前目标无关的大范围重构。
  • 没有强理由时,不要重命名 MCP tools。
  • 不要提交真实凭证、敏感配置或环境私有数据。
  • 当启动方式、脚本、配置项或接入方式变化时,要同步更新 README.md
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 108 lines · 912 tokens per session scan A 55f5074282b4

Subscribe to this mod's changes

knife4j-mcp AGENTS.md is an instructions file published in the GitHub repository chaselen/knife4j-mcp (0 stars, last pushed 1mo ago), licensed MIT. It adds 912 tokens to every session, about $0.0046 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.