-
Notifications
You must be signed in to change notification settings - Fork 711
script: add docs API, MCP #22690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hfxsd
wants to merge
13
commits into
pingcap:master
Choose a base branch
from
hfxsd:docs-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
script: add docs API, MCP #22690
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
be9fb8b
delete unnecessary changes
hfxsd 9666f08
Add DOCS_API_SOURCE_DIR and template vars
hfxsd 809ab74
Add doc content endpoint and full-text search
hfxsd 07595db
Add experimental Docs MCP server
hfxsd bc1d600
Support HTTP transport and multi-source docs MCP
hfxsd 42da92f
Update docs-mcp-server.md
hfxsd 1b0ced1
Add TiDB Docs MCP Server docs, update TOC/API
hfxsd 2c5f8aa
Delete docs-mcp-server.md
hfxsd 23252a7
Update TOC-ai.md
hfxsd 8f29341
Update tidb-docs-mcp-server.md
hfxsd fcb3802
add SSH code and doc
hfxsd 3d2ef91
Update tidb-docs-over-ssh.md
hfxsd b360532
refine ssh code as per chatgpt
hfxsd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| title: Docs JSON API (Experimental) | ||
| summary: Provide a structured JSON API for TiDB docs with topic and feature filters. | ||
| --- | ||
|
|
||
| # Docs JSON API (Experimental) | ||
|
|
||
| This API layer exposes structured metadata for markdown docs. | ||
|
|
||
| ## Why | ||
|
|
||
| - Query docs by feature token (for example, `tidb_max_dist_task_nodes`) | ||
| - Query docs by topic/category | ||
| - Return structured schema instead of raw markdown only | ||
|
|
||
| ## Data schema | ||
|
|
||
| Each doc record includes: | ||
|
|
||
| - `id` | ||
| - `path` | ||
| - `title` | ||
| - `summary` | ||
| - `product` | ||
| - `topics` | ||
| - `features` | ||
| - `headings` | ||
| - `frontMatter` | ||
| - `frontMatterRaw` | ||
| - `updatedAt` | ||
|
|
||
| ## Build index | ||
|
|
||
| ```bash | ||
| npm run docs-api:build | ||
| ``` | ||
|
|
||
| Default output file: `tmp/docs-api-index.json` | ||
|
|
||
| ## Run API server | ||
|
|
||
| ```bash | ||
| npm run docs-api:serve | ||
| ``` | ||
|
|
||
| Default host and port: `127.0.0.1:3000` | ||
|
|
||
| ## Endpoints | ||
|
|
||
| - `GET /healthz` | ||
| - `GET /schema` | ||
| - `GET /topics` | ||
| - `GET /features` | ||
| - `GET /features?prefix=tidb_` | ||
| - `GET /docs` | ||
| - `GET /docs?feature=tidb_max_dist_task_nodes` | ||
| - `GET /docs?topic=tidb-cloud` | ||
| - `GET /docs?q=resource control` | ||
| - `GET /docs?feature=tidb_max_dist_task_nodes&limit=10&offset=0` | ||
| - `GET /reload` (reload in-memory index) | ||
|
|
||
| ## Environment variables | ||
|
|
||
| - `DOCS_API_HOST` (default `127.0.0.1`) | ||
| - `DOCS_API_PORT` (default `3000`) | ||
| - `DOCS_API_ROOT` (default current working directory) | ||
| - `DOCS_API_INDEX_FILE` (optional prebuilt JSON index path) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as fs from "fs"; | ||
| import path from "path"; | ||
| import { buildDocsIndex } from "./docs-api-lib.js"; | ||
|
|
||
| const args = process.argv.slice(2); | ||
| const outputArg = args[0] || "tmp/docs-api-index.json"; | ||
| const rootArg = args[1] || process.cwd(); | ||
|
|
||
| const outputPath = path.resolve(outputArg); | ||
| const outputDir = path.dirname(outputPath); | ||
|
|
||
| if (!fs.existsSync(outputDir)) { | ||
| fs.mkdirSync(outputDir, { recursive: true }); | ||
| } | ||
|
|
||
| const index = buildDocsIndex(rootArg); | ||
| fs.writeFileSync(outputPath, JSON.stringify(index, null, 2), "utf8"); | ||
|
|
||
| console.log( | ||
| `Docs API index generated: ${outputPath} (${index.totalDocs} docs, ${index.features.length} features)` | ||
| ); | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query parameter
q=resource controlcontains an unencoded space. In a URL, spaces should be encoded as%20or+to be technically accurate.References