@leeguoo/yapi-mcp 0.3.21 → 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,108 +5,86 @@ description: Query and sync YApi interface documentation. Use when user mentions
5
5
 
6
6
  # YApi interface docs
7
7
 
8
- ## URL Detection
8
+ ## Command policy
9
9
 
10
- When user provides a URL, check if it matches the configured YApi instance:
10
+ Prefer `yapi` command. If missing, fallback to one-shot npx without forcing global install:
11
11
 
12
- 1. Read config to get base_url:
13
12
  ```bash
14
- cat ~/.yapi/config.toml | grep base_url
13
+ yapi -h
14
+ # fallback:
15
+ npx -y @leeguoo/yapi-mcp -h
15
16
  ```
16
17
 
17
- 2. If the URL's origin matches `base_url`, use yapi CLI to operate:
18
- - Extract `project_id` from URL path (e.g., `/project/123/...` → project_id=123)
19
- - Extract `api_id` from URL path (e.g., `.../api/456` → api_id=456)
20
- - Use `yapi --path /api/interface/get --query id=<api_id>` to fetch details
21
-
22
- 3. Example URL patterns:
23
- - `https://yapi.example.com/project/123/interface/api/456` → project=123, api=456
24
- - `https://yapi.example.com/project/123/interface/api/cat_789` → project=123, category=789
18
+ In command examples below, `yapi` can be replaced by `npx -y @leeguoo/yapi-mcp`.
25
19
 
26
- ## Prerequisites
20
+ ## Quick workflow
21
+ 1. If user gives a YApi URL, verify it belongs to configured `base_url`.
22
+ 2. Confirm auth (`yapi whoami`), then run `yapi login --browser` when needed (open base URL, finish login in browser, then press Enter to sync cookie).
23
+ 3. Resolve target by `api_id` / keyword / category.
24
+ 4. Fetch raw JSON first, then summarize: method, path, headers, params, body, response schema/examples.
25
+ 5. For docs sync tasks, do `--dry-run` first, then real sync.
27
26
 
28
- ### Check if yapi CLI is installed
29
- ```bash
30
- yapi --version
31
- ```
27
+ ## URL detection
32
28
 
33
- ### If not installed, ask user to install globally
29
+ 1. Read configured `base_url` from `~/.yapi/config.toml`.
34
30
  ```bash
35
- npm install -g @leeguoo/yapi-mcp
36
- # or
37
- pnpm add -g @leeguoo/yapi-mcp
31
+ rg -n "^base_url\\s*=" ~/.yapi/config.toml
38
32
  ```
39
-
40
- ### Check login status
33
+ 2. If URL origin matches `base_url`, extract IDs from path:
34
+ - `/project/123/...` -> `project_id=123`
35
+ - `.../api/456` -> `api_id=456`
36
+ - `.../api/cat_789` -> `catid=789`
37
+ 3. Prefer direct lookup when `api_id` exists:
41
38
  ```bash
42
- yapi whoami
39
+ yapi --path /api/interface/get --query id=<api_id>
43
40
  ```
44
41
 
45
- ### If not logged in, login interactively
46
- ```bash
47
- yapi login
48
- ```
49
- This will prompt for:
50
- - YApi base URL (e.g., https://yapi.example.com)
51
- - Email
52
- - Password
53
-
54
- Config is saved to `~/.yapi/config.toml`.
55
-
56
- ## Workflow
57
- 1. If user provides a YApi URL, check if it matches configured `base_url` in `~/.yapi/config.toml`.
58
- 2. Ensure yapi CLI is installed (prompt user to install globally if missing).
59
- 3. Check login status with `yapi whoami`; if not logged in, run `yapi login`.
60
- 4. Load config from `~/.yapi/config.toml` (base_url, auth_mode, email/password or token, optional project_id).
61
- 5. Identify the target interface by id, URL, or keyword; ask for project/category ids if needed.
62
- 6. Call YApi endpoints with the CLI (see examples below) to fetch raw JSON.
63
- 7. Summarize method, path, headers, query/body schema, response schema, and examples.
64
-
65
- ## CLI Usage
66
- - Config location: `~/.yapi/config.toml`
67
- - Auth cache: `~/.yapi-mcp/auth-*.json`
42
+ ## Common commands
68
43
 
69
- ### Common commands
70
44
  ```bash
71
- # Check version
45
+ # version/help
72
46
  yapi --version
73
-
74
- # Show help
75
47
  yapi -h
76
48
 
77
- # Check current user
49
+ # auth
78
50
  yapi whoami
51
+ yapi login --browser
52
+ yapi login --login-url https://your-yapi-domain.com/
53
+ yapi logout
79
54
 
80
- # Login (interactive)
81
- yapi login
82
-
83
- # Search interfaces
84
- yapi search --q keyword
85
-
86
- # Get interface by ID
55
+ # search / fetch
56
+ yapi search --q keyword --project-id 310
87
57
  yapi --path /api/interface/get --query id=123
88
-
89
- # List interfaces in category
90
58
  yapi --path /api/interface/list_cat --query catid=123
91
59
  ```
92
60
 
61
+ Config cache locations:
62
+ - Config: `~/.yapi/config.toml`
63
+ - Auth cache: `~/.yapi-mcp/auth-*.json`
64
+
65
+ Browser login dependency:
66
+ ```bash
67
+ agent-browser-stealth -V
68
+ # install once if missing browser runtime
69
+ agent-browser-stealth install
70
+ ```
71
+
93
72
  ## Docs sync
94
- - Bind local docs to YApi category with `yapi docs-sync bind add --name <binding> --dir <path> --project-id <id> --catid <id>` (stored in `.yapi/docs-sync.json`).
95
- - Sync with `yapi docs-sync --binding <binding>` or run all bindings with `yapi docs-sync`.
96
- - Title defaults to the first Markdown H1 (`# Title` / Setext `===`); falls back to filename stem when missing.
97
- - Path uses the filename stem: `/${stem}`.
98
- - Default syncs only changed files; use `--force` to sync everything.
99
- - Mermaid rendering depends on `mmdc` (hand-drawn look by default; auto-installed if possible; failures do not block sync).
100
- - PlantUML rendering depends on `plantuml` (requires Java).
101
- - Graphviz rendering depends on `dot` (graphviz).
102
- - D2 rendering depends on `d2`.
103
- - macOS: `brew install plantuml graphviz d2`
104
- - For full Markdown render, install `pandoc` (manual install required).
105
- - Extra mappings (generated after docs-sync run in binding mode):
106
- - `.yapi/docs-sync.links.json`: local docs to YApi doc URLs.
107
- - `.yapi/docs-sync.projects.json`: cached project metadata/envs.
108
- - `.yapi/docs-sync.deployments.json`: local docs to deployed URLs.
109
-
110
- ## Interface creation tips
111
- - When adding interfaces, always set `req_body_type` (use `json` if unsure) and provide `res_body` (prefer JSON Schema). Empty values can make `/api/interface/add` fail.
112
- - Keep request/response structures in `req_*` / `res_body` instead of stuffing them into `desc` or `markdown`.
73
+
74
+ Binding mode (recommended):
75
+ ```bash
76
+ yapi docs-sync bind add --name projectA --dir docs/release-notes --project-id 267 --catid 3667
77
+ yapi docs-sync --binding projectA --dry-run
78
+ yapi docs-sync --binding projectA
79
+ ```
80
+
81
+ Notes:
82
+ - Binding file: `.yapi/docs-sync.json`
83
+ - Mapping outputs: `.yapi/docs-sync.links.json`, `.yapi/docs-sync.projects.json`, `.yapi/docs-sync.deployments.json`
84
+ - Default behavior syncs changed files only; use `--force` for full sync.
85
+ - Compatible with directory `.yapi.json` config as fallback (without binding).
86
+ - Mermaid/PlantUML/Graphviz/D2 rendering depends on local tool availability; missing tools do not block basic sync.
87
+
88
+ ## Interface creation guardrails
89
+ - Always set `req_body_type` (use `json` if unsure) and provide `res_body` (prefer JSON Schema) when creating/updating interfaces.
90
+ - Put structured request/response fields in `req_*` / `res_body`, not only in free-text `desc`/`markdown`.