[
https://issues.apache.org/jira/browse/TINKERPOP-3303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18142653#comment-18142653
]
ASF GitHub Bot commented on TINKERPOP-3303:
-------------------------------------------
xiazcy commented on code in PR #3768:
URL: https://github.com/apache/tinkerpop/pull/3768#discussion_r4531900208
##########
gremlin-js/gremlin-mcp/src/docs/store.ts:
##########
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @fileoverview Loads the TinkerPop docs versions gremlin-mcp can serve.
+ *
+ * A docs version is a directory named for the TinkerPop version, holding the
selected
+ * Markdown pages at their docs-relative paths plus a `manifest.json` listing
them. Versions
+ * come from two roots: the docs bundled in the gremlin-mcp package, and those
added with
+ * `gremlin-mcp docs install` under `~/.gremlin-mcp/docs/`. The set is read
once at startup;
+ * a version installed later is served after a restart.
+ */
+
+import { mkdir, readFile, readdir, rename, rm, writeFile } from
'node:fs/promises';
+import { join } from 'node:path';
+import { parseSections, type DocSection } from './sections.js';
+import {
+ isRelativeTarget,
+ resolveRelative,
+ sourceOf,
+ stripFragment,
+ type DocSource,
+} from './selection.js';
+
+export const DOCS_SITE_URL = 'https://tinkerpop.apache.org/docs';
+export const MANIFEST_FILE = 'manifest.json';
+
+// A released or snapshot TinkerPop version, e.g. 3.8.2, 4.0.0-beta.3 or
4.0.0-SNAPSHOT.
+const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?$/;
+
+/** True if the string is a TinkerPop version usable as a docs directory name.
*/
+export const isDocsVersion = (version: string): boolean =>
+ VERSION_PATTERN.test(version) && !version.includes('..');
+
+export type DocsOrigin = 'bundled' | 'installed';
+
+/** The manifest written beside a version's pages. */
+export interface DocsManifest {
+ readonly version: string;
+ readonly source: string;
+ readonly created: string;
+ readonly pages: readonly string[];
+}
+
+/** One served docs page. */
+export interface DocPage {
+ /** Docs-relative path, e.g. `reference/the-traversal.md`; the id the tools
use. */
+ readonly id: string;
+ readonly title: string;
+ readonly summary: string;
+ readonly source: DocSource;
+ /** Page Markdown with links rewritten to page ids or absolute site URLs. */
+ readonly markdown: string;
+ /** The page's anchored sections, in page order; the first is usually the
whole page. */
+ readonly sections: readonly DocSection[];
+}
+
+/** The pages of one docs version. */
+export interface DocsVersion {
+ readonly version: string;
+ readonly origin: DocsOrigin;
+ readonly pages: ReadonlyMap<string, DocPage>;
+}
+
+/** Where docs versions are read from. */
+export interface DocsLocations {
+ /** Docs bundled in the gremlin-mcp package. */
+ readonly bundledRoot: string;
+ /** Docs added with `gremlin-mcp docs install`. */
+ readonly installRoot: string;
+}
+
+/** The docs versions available to the tools, and any that could not be
loaded. */
+export interface DocsStore {
+ readonly versions: ReadonlyMap<string, DocsVersion>;
+ readonly problems: readonly string[];
+}
+
+const HEADING = /^#{1,6}\s+(.+?)\s*#*\s*$/;
+// The ASF license header the docs build writes as an HTML comment at the top
of every page.
+const LICENSE_COMMENT = /<!--\s*Licensed to the Apache Software
Foundation[\s\S]*?-->\n*/;
+
+/**
+ * Removes the license header comment from a page. The header stays in the
files gremlin-mcp
+ * distributes, but it is not documentation, so the tools never hand it to an
agent.
+ */
+export const stripLicenseComment = (raw: string): string =>
raw.replace(LICENSE_COMMENT, '');
+const SUMMARY = /^<!
> Serve docs from gremlin-mcp
> ---------------------------
>
> Key: TINKERPOP-3303
> URL: https://issues.apache.org/jira/browse/TINKERPOP-3303
> Project: TinkerPop
> Issue Type: Improvement
> Components: mcp
> Affects Versions: 3.8.2
> Reporter: Stephen Mallette
> Assignee: Stephen Mallette
> Priority: Major
>
> Serve markdown forms of TinkerPop documentation from gremlin-mcp
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)