mcp-docs-service 0.1.1 → 0.2.1

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/LICENSE +1 -1
  3. package/README.md +28 -15
  4. package/dist/handlers/docs.d.ts +17 -0
  5. package/dist/handlers/docs.js +280 -0
  6. package/dist/handlers/docs.js.map +1 -0
  7. package/dist/handlers/file.d.ts +32 -0
  8. package/dist/handlers/file.js +222 -0
  9. package/dist/handlers/file.js.map +1 -0
  10. package/dist/handlers/index.d.ts +1 -0
  11. package/dist/handlers/index.js +3 -0
  12. package/dist/handlers/index.js.map +1 -0
  13. package/dist/index.d.ts +2 -24
  14. package/dist/index.js +431 -49
  15. package/dist/index.js.map +1 -1
  16. package/dist/schemas/index.d.ts +1 -0
  17. package/dist/schemas/index.js +3 -0
  18. package/dist/schemas/index.js.map +1 -0
  19. package/dist/schemas/tools.d.ts +141 -0
  20. package/dist/schemas/tools.js +46 -0
  21. package/dist/schemas/tools.js.map +1 -0
  22. package/dist/types/docs.d.ts +49 -0
  23. package/dist/types/docs.js +2 -0
  24. package/dist/types/docs.js.map +1 -0
  25. package/dist/types/file.d.ts +21 -0
  26. package/dist/types/file.js +2 -0
  27. package/dist/types/file.js.map +1 -0
  28. package/dist/types/index.d.ts +34 -43
  29. package/dist/types/index.js +3 -5
  30. package/dist/types/index.js.map +1 -1
  31. package/dist/types/tools.d.ts +11 -0
  32. package/dist/types/tools.js +2 -0
  33. package/dist/types/tools.js.map +1 -0
  34. package/dist/utils/file.d.ts +24 -0
  35. package/dist/utils/file.js +94 -0
  36. package/dist/utils/file.js.map +1 -0
  37. package/dist/utils/index.d.ts +1 -60
  38. package/dist/utils/index.js +2 -151
  39. package/dist/utils/index.js.map +1 -1
  40. package/dist/utils/path.d.ts +16 -0
  41. package/dist/utils/path.js +39 -0
  42. package/dist/utils/path.js.map +1 -0
  43. package/package.json +20 -6
  44. package/dist/cli/bin.d.ts +0 -6
  45. package/dist/cli/bin.js +0 -49
  46. package/dist/cli/bin.js.map +0 -1
  47. package/dist/cli/index.d.ts +0 -16
  48. package/dist/cli/index.js +0 -96
  49. package/dist/cli/index.js.map +0 -1
  50. package/dist/core/docAnalyzer.d.ts +0 -25
  51. package/dist/core/docAnalyzer.js +0 -118
  52. package/dist/core/docAnalyzer.js.map +0 -1
  53. package/dist/core/docManager.d.ts +0 -48
  54. package/dist/core/docManager.js +0 -257
  55. package/dist/core/docManager.js.map +0 -1
  56. package/dist/core/docProcessor.d.ts +0 -20
  57. package/dist/core/docProcessor.js +0 -127
  58. package/dist/core/docProcessor.js.map +0 -1
  59. package/dist/core/mcpDocsServer.d.ts +0 -61
  60. package/dist/core/mcpDocsServer.js +0 -395
  61. package/dist/core/mcpDocsServer.js.map +0 -1
@@ -0,0 +1,141 @@
1
+ import { z } from "zod";
2
+ export declare const ToolInputSchema: z.ZodObject<{
3
+ path: z.ZodOptional<z.ZodString>;
4
+ }, "strip", z.ZodTypeAny, {
5
+ path?: string | undefined;
6
+ }, {
7
+ path?: string | undefined;
8
+ }>;
9
+ export declare const ReadDocumentSchema: z.ZodObject<z.objectUtil.extendShape<{
10
+ path: z.ZodOptional<z.ZodString>;
11
+ }, {
12
+ path: z.ZodString;
13
+ }>, "strip", z.ZodTypeAny, {
14
+ path: string;
15
+ }, {
16
+ path: string;
17
+ }>;
18
+ export declare const ListDocumentsSchema: z.ZodObject<z.objectUtil.extendShape<{
19
+ path: z.ZodOptional<z.ZodString>;
20
+ }, {
21
+ basePath: z.ZodOptional<z.ZodString>;
22
+ }>, "strip", z.ZodTypeAny, {
23
+ path?: string | undefined;
24
+ basePath?: string | undefined;
25
+ }, {
26
+ path?: string | undefined;
27
+ basePath?: string | undefined;
28
+ }>;
29
+ export declare const GetStructureSchema: z.ZodObject<z.objectUtil.extendShape<{
30
+ path: z.ZodOptional<z.ZodString>;
31
+ }, {
32
+ basePath: z.ZodOptional<z.ZodString>;
33
+ }>, "strip", z.ZodTypeAny, {
34
+ path?: string | undefined;
35
+ basePath?: string | undefined;
36
+ }, {
37
+ path?: string | undefined;
38
+ basePath?: string | undefined;
39
+ }>;
40
+ export declare const GetNavigationSchema: z.ZodObject<z.objectUtil.extendShape<{
41
+ path: z.ZodOptional<z.ZodString>;
42
+ }, {
43
+ basePath: z.ZodOptional<z.ZodString>;
44
+ }>, "strip", z.ZodTypeAny, {
45
+ path?: string | undefined;
46
+ basePath?: string | undefined;
47
+ }, {
48
+ path?: string | undefined;
49
+ basePath?: string | undefined;
50
+ }>;
51
+ export declare const GetDocsKnowledgeBaseSchema: z.ZodObject<z.objectUtil.extendShape<{
52
+ path: z.ZodOptional<z.ZodString>;
53
+ }, {
54
+ basePath: z.ZodOptional<z.ZodString>;
55
+ includeSummaries: z.ZodOptional<z.ZodBoolean>;
56
+ maxSummaryLength: z.ZodOptional<z.ZodNumber>;
57
+ }>, "strip", z.ZodTypeAny, {
58
+ path?: string | undefined;
59
+ basePath?: string | undefined;
60
+ includeSummaries?: boolean | undefined;
61
+ maxSummaryLength?: number | undefined;
62
+ }, {
63
+ path?: string | undefined;
64
+ basePath?: string | undefined;
65
+ includeSummaries?: boolean | undefined;
66
+ maxSummaryLength?: number | undefined;
67
+ }>;
68
+ export declare const WriteDocumentSchema: z.ZodObject<z.objectUtil.extendShape<{
69
+ path: z.ZodOptional<z.ZodString>;
70
+ }, {
71
+ path: z.ZodString;
72
+ content: z.ZodString;
73
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
74
+ }>, "strip", z.ZodTypeAny, {
75
+ content: string;
76
+ path: string;
77
+ metadata?: Record<string, any> | undefined;
78
+ }, {
79
+ content: string;
80
+ path: string;
81
+ metadata?: Record<string, any> | undefined;
82
+ }>;
83
+ export declare const EditDocumentSchema: z.ZodObject<z.objectUtil.extendShape<{
84
+ path: z.ZodOptional<z.ZodString>;
85
+ }, {
86
+ path: z.ZodString;
87
+ edits: z.ZodArray<z.ZodObject<{
88
+ oldText: z.ZodString;
89
+ newText: z.ZodString;
90
+ }, "strip", z.ZodTypeAny, {
91
+ oldText: string;
92
+ newText: string;
93
+ }, {
94
+ oldText: string;
95
+ newText: string;
96
+ }>, "many">;
97
+ }>, "strip", z.ZodTypeAny, {
98
+ path: string;
99
+ edits: {
100
+ oldText: string;
101
+ newText: string;
102
+ }[];
103
+ }, {
104
+ path: string;
105
+ edits: {
106
+ oldText: string;
107
+ newText: string;
108
+ }[];
109
+ }>;
110
+ export declare const DeleteDocumentSchema: z.ZodObject<z.objectUtil.extendShape<{
111
+ path: z.ZodOptional<z.ZodString>;
112
+ }, {
113
+ path: z.ZodString;
114
+ }>, "strip", z.ZodTypeAny, {
115
+ path: string;
116
+ }, {
117
+ path: string;
118
+ }>;
119
+ export declare const SearchDocumentsSchema: z.ZodObject<z.objectUtil.extendShape<{
120
+ path: z.ZodOptional<z.ZodString>;
121
+ }, {
122
+ basePath: z.ZodOptional<z.ZodString>;
123
+ query: z.ZodOptional<z.ZodString>;
124
+ excludePatterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
125
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
126
+ status: z.ZodOptional<z.ZodString>;
127
+ }>, "strip", z.ZodTypeAny, {
128
+ tags?: string[] | undefined;
129
+ status?: string | undefined;
130
+ path?: string | undefined;
131
+ basePath?: string | undefined;
132
+ query?: string | undefined;
133
+ excludePatterns?: string[] | undefined;
134
+ }, {
135
+ tags?: string[] | undefined;
136
+ status?: string | undefined;
137
+ path?: string | undefined;
138
+ basePath?: string | undefined;
139
+ query?: string | undefined;
140
+ excludePatterns?: string[] | undefined;
141
+ }>;
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ // Base schema for tool inputs
3
+ export const ToolInputSchema = z.object({
4
+ path: z.string().optional(),
5
+ });
6
+ // Documentation schemas
7
+ export const ReadDocumentSchema = ToolInputSchema.extend({
8
+ path: z.string(),
9
+ });
10
+ export const ListDocumentsSchema = ToolInputSchema.extend({
11
+ basePath: z.string().optional(),
12
+ });
13
+ export const GetStructureSchema = ToolInputSchema.extend({
14
+ basePath: z.string().optional(),
15
+ });
16
+ export const GetNavigationSchema = ToolInputSchema.extend({
17
+ basePath: z.string().optional(),
18
+ });
19
+ export const GetDocsKnowledgeBaseSchema = ToolInputSchema.extend({
20
+ basePath: z.string().optional(),
21
+ includeSummaries: z.boolean().optional(),
22
+ maxSummaryLength: z.number().optional(),
23
+ });
24
+ export const WriteDocumentSchema = ToolInputSchema.extend({
25
+ path: z.string(),
26
+ content: z.string(),
27
+ metadata: z.record(z.any()).optional(),
28
+ });
29
+ export const EditDocumentSchema = ToolInputSchema.extend({
30
+ path: z.string(),
31
+ edits: z.array(z.object({
32
+ oldText: z.string(),
33
+ newText: z.string(),
34
+ })),
35
+ });
36
+ export const DeleteDocumentSchema = ToolInputSchema.extend({
37
+ path: z.string(),
38
+ });
39
+ export const SearchDocumentsSchema = ToolInputSchema.extend({
40
+ basePath: z.string().optional(),
41
+ query: z.string().optional(),
42
+ excludePatterns: z.array(z.string()).optional(),
43
+ tags: z.array(z.string()).optional(),
44
+ status: z.string().optional(),
45
+ });
46
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/schemas/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8BAA8B;AAC9B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC,CAAC;AAEH,wBAAwB;AACxB,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC,MAAM,CAAC;IACvD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CA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,GAAG,eAAe,CAAC,MAAM,CAAC;IACzD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC,MAAM,CAAC;IAC1D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,eAAe,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC/C,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Metadata for documentation files
3
+ */
4
+ export interface DocumentMetadata {
5
+ title?: string;
6
+ order?: number;
7
+ description?: string;
8
+ author?: string;
9
+ date?: Date;
10
+ tags?: string[];
11
+ status?: string;
12
+ [key: string]: any;
13
+ }
14
+ /**
15
+ * Entry for a documentation file
16
+ */
17
+ export interface DocumentEntry {
18
+ path: string;
19
+ name: string;
20
+ metadata: DocumentMetadata;
21
+ }
22
+ /**
23
+ * Tree entry for documentation structure
24
+ */
25
+ export interface TreeEntry {
26
+ name: string;
27
+ path: string;
28
+ type: string;
29
+ metadata?: DocumentMetadata;
30
+ children: TreeEntry[];
31
+ error?: string;
32
+ }
33
+ /**
34
+ * Navigation item for documentation
35
+ */
36
+ export interface NavigationItem {
37
+ title: string;
38
+ path: string | null;
39
+ order: number;
40
+ }
41
+ /**
42
+ * Navigation section for documentation
43
+ */
44
+ export interface NavigationSection {
45
+ title: string;
46
+ path: string | null;
47
+ items: NavigationItem[];
48
+ order: number;
49
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../src/types/docs.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * File information structure
3
+ */
4
+ export interface FileInfo {
5
+ size: number;
6
+ created: Date;
7
+ modified: Date;
8
+ accessed: Date;
9
+ isDirectory: boolean;
10
+ isFile: boolean;
11
+ permissions: string;
12
+ }
13
+ /**
14
+ * Tree entry for directory structure
15
+ */
16
+ export interface FileTreeEntry {
17
+ name: string;
18
+ path: string;
19
+ type: "file" | "directory";
20
+ children?: FileTreeEntry[];
21
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/types/file.ts"],"names":[],"mappings":""}
@@ -1,53 +1,44 @@
1
- /**
2
- * Types for the MCP Documentation Management Service
3
- */
4
- export interface DocMetadata {
5
- title: string;
1
+ export interface DocumentMetadata {
2
+ title?: string;
3
+ order?: number;
6
4
  description?: string;
5
+ author?: string;
6
+ date?: Date;
7
7
  tags?: string[];
8
- lastUpdated?: string;
9
- status?: "draft" | "review" | "published";
10
- globs?: string[];
11
- alwaysApply?: boolean;
12
- }
13
- export interface DocContent {
14
- metadata: DocMetadata;
15
- content: string;
16
- path: string;
17
- }
18
- export interface SearchOptions {
19
- query: string;
20
- tags?: string[];
21
- status?: "draft" | "review" | "published";
22
- directory?: string;
8
+ status?: string;
9
+ [key: string]: any;
23
10
  }
24
- export interface DocUpdateParams {
11
+ export interface DocumentEntry {
25
12
  path: string;
26
- content?: string;
27
- metadata?: Partial<DocMetadata>;
13
+ name: string;
14
+ metadata: DocumentMetadata;
28
15
  }
29
- export interface DocCreateParams {
16
+ export interface TreeEntry {
17
+ name: string;
30
18
  path: string;
31
- content: string;
32
- metadata: DocMetadata;
33
- }
34
- export interface MCPQueryResult {
35
- success: boolean;
36
- data?: any;
19
+ type: string;
20
+ metadata?: DocumentMetadata;
21
+ children: TreeEntry[];
37
22
  error?: string;
38
23
  }
39
- export interface DocSummary {
24
+ export interface NavigationItem {
40
25
  title: string;
41
- description?: string;
42
- path: string;
43
- lastUpdated?: string;
44
- tags?: string[];
45
- status?: "draft" | "review" | "published";
46
- }
47
- export interface DocAnalysisResult {
48
- documentCount: number;
49
- byStatus?: Record<string, number>;
50
- byDirectory?: Record<string, number>;
51
- recentlyUpdated?: DocSummary[];
52
- missingDescriptions?: DocSummary[];
26
+ path: string | null;
27
+ order: number;
53
28
  }
29
+ export interface NavigationSection {
30
+ title: string;
31
+ path: string | null;
32
+ items: NavigationItem[];
33
+ order: number;
34
+ }
35
+ export type ToolResponse = {
36
+ content: Array<{
37
+ type: string;
38
+ text: string;
39
+ }>;
40
+ metadata?: Record<string, any>;
41
+ isError?: boolean;
42
+ };
43
+ export * from "./docs.js";
44
+ export * from "./tools.js";
@@ -1,6 +1,4 @@
1
- "use strict";
2
- /**
3
- * Types for the MCP Documentation Management Service
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ // Re-export all types from specialized modules
2
+ export * from "./docs.js";
3
+ export * from "./tools.js";
6
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;GAEG"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAiDA,+CAA+C;AAC/C,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Standard response format for tools
3
+ */
4
+ export type ToolResponse = {
5
+ content: Array<{
6
+ type: string;
7
+ text: string;
8
+ }>;
9
+ metadata?: Record<string, any>;
10
+ isError?: boolean;
11
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/types/tools.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { FileInfo } from "../types/file.js";
2
+ /**
3
+ * Gets file statistics and information
4
+ */
5
+ export declare function getFileStats(filePath: string): Promise<FileInfo>;
6
+ /**
7
+ * Searches for files matching a pattern
8
+ */
9
+ export declare function searchFiles(rootPath: string, pattern: string, excludePatterns?: string[]): Promise<string[]>;
10
+ /**
11
+ * Normalizes line endings to LF
12
+ */
13
+ export declare function normalizeLineEndings(text: string): string;
14
+ /**
15
+ * Creates a unified diff between two text contents
16
+ */
17
+ export declare function createUnifiedDiff(originalContent: string, newContent: string, filepath?: string): string;
18
+ /**
19
+ * Applies edits to a file
20
+ */
21
+ export declare function applyFileEdits(filePath: string, edits: Array<{
22
+ oldText: string;
23
+ newText: string;
24
+ }>, dryRun?: boolean): Promise<string>;
@@ -0,0 +1,94 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import { createTwoFilesPatch } from "diff";
4
+ import { minimatch } from "minimatch";
5
+ /**
6
+ * Gets file statistics and information
7
+ */
8
+ export async function getFileStats(filePath) {
9
+ const stats = await fs.stat(filePath);
10
+ // Convert file mode to permission string (e.g., "rwxr-xr-x")
11
+ const mode = stats.mode;
12
+ const permissions = [
13
+ stats.mode & 0o400 ? "r" : "-",
14
+ stats.mode & 0o200 ? "w" : "-",
15
+ stats.mode & 0o100 ? "x" : "-",
16
+ stats.mode & 0o040 ? "r" : "-",
17
+ stats.mode & 0o020 ? "w" : "-",
18
+ stats.mode & 0o010 ? "x" : "-",
19
+ stats.mode & 0o004 ? "r" : "-",
20
+ stats.mode & 0o002 ? "w" : "-",
21
+ stats.mode & 0o001 ? "x" : "-",
22
+ ].join("");
23
+ return {
24
+ size: stats.size,
25
+ created: stats.birthtime,
26
+ modified: stats.mtime,
27
+ accessed: stats.atime,
28
+ isDirectory: stats.isDirectory(),
29
+ isFile: stats.isFile(),
30
+ permissions,
31
+ };
32
+ }
33
+ /**
34
+ * Searches for files matching a pattern
35
+ */
36
+ export async function searchFiles(rootPath, pattern, excludePatterns = []) {
37
+ const results = [];
38
+ async function search(currentPath) {
39
+ const entries = await fs.readdir(currentPath, { withFileTypes: true });
40
+ for (const entry of entries) {
41
+ const entryPath = path.join(currentPath, entry.name);
42
+ const relativePath = path.relative(rootPath, entryPath);
43
+ // Check if path should be excluded
44
+ if (excludePatterns.some((excludePattern) => minimatch(relativePath, excludePattern))) {
45
+ continue;
46
+ }
47
+ if (entry.isDirectory()) {
48
+ await search(entryPath);
49
+ }
50
+ else if (minimatch(relativePath, pattern)) {
51
+ results.push(entryPath);
52
+ }
53
+ }
54
+ }
55
+ await search(rootPath);
56
+ return results;
57
+ }
58
+ /**
59
+ * Normalizes line endings to LF
60
+ */
61
+ export function normalizeLineEndings(text) {
62
+ return text.replace(/\r\n/g, "\n");
63
+ }
64
+ /**
65
+ * Creates a unified diff between two text contents
66
+ */
67
+ export function createUnifiedDiff(originalContent, newContent, filepath = "file") {
68
+ return createTwoFilesPatch(filepath, filepath, normalizeLineEndings(originalContent), normalizeLineEndings(newContent), "", "", { context: 3 });
69
+ }
70
+ /**
71
+ * Applies edits to a file
72
+ */
73
+ export async function applyFileEdits(filePath, edits, dryRun = false) {
74
+ let content = await fs.readFile(filePath, "utf-8");
75
+ content = normalizeLineEndings(content);
76
+ // Apply all edits
77
+ for (const edit of edits) {
78
+ const { oldText, newText } = edit;
79
+ const normalizedOldText = normalizeLineEndings(oldText);
80
+ if (!content.includes(normalizedOldText)) {
81
+ throw new Error(`Edit failed: Could not find text to replace in ${filePath}`);
82
+ }
83
+ content = content.replace(normalizedOldText, normalizeLineEndings(newText));
84
+ }
85
+ // Create a diff to show changes
86
+ const originalContent = await fs.readFile(filePath, "utf-8");
87
+ const diff = createUnifiedDiff(originalContent, content, filePath);
88
+ // Write the changes if not a dry run
89
+ if (!dryRun) {
90
+ await fs.writeFile(filePath, content);
91
+ }
92
+ return diff;
93
+ }
94
+ //# sourceMappingURL=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AAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,iBAAiB,CAAC,eAAe,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEnE,qCAAqC;IACrC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,60 +1 @@
1
- /**
2
- * Utility functions for the MCP Documentation Service
3
- */
4
- /**
5
- * Check if a path is valid
6
- * @param path - Path to check
7
- * @returns True if the path is valid, false otherwise
8
- */
9
- export declare function isValidPath(path: string): boolean;
10
- /**
11
- * Normalize a path
12
- * @param path - Path to normalize
13
- * @returns Normalized path
14
- */
15
- export declare function normalizePath(path: string): string;
16
- /**
17
- * Get file extension
18
- * @param path - Path to get extension from
19
- * @returns File extension
20
- */
21
- export declare function getFileExtension(path: string): string;
22
- /**
23
- * Get file name
24
- * @param path - Path to get name from
25
- * @returns File name
26
- */
27
- export declare function getFileName(path: string): string;
28
- /**
29
- * Get directory name
30
- * @param path - Path to get directory name from
31
- * @returns Directory name
32
- */
33
- export declare function getDirectoryName(path: string): string;
34
- /**
35
- * Join paths
36
- * @param paths - Paths to join
37
- * @returns Joined path
38
- */
39
- export declare function joinPaths(...paths: string[]): string;
40
- /**
41
- * Escape regex special characters
42
- * @param str - String to escape
43
- * @returns Escaped string
44
- */
45
- export declare function escapeRegex(str: string): string;
46
- /**
47
- * Calculate relevance score
48
- * @param text - Text to search in
49
- * @param query - Query to search for
50
- * @returns Relevance score (0-1)
51
- */
52
- export declare function calculateRelevance(text: string, query: string): number;
53
- /**
54
- * Generate excerpt
55
- * @param text - Text to generate excerpt from
56
- * @param query - Query to highlight
57
- * @param length - Excerpt length
58
- * @returns Excerpt
59
- */
60
- export declare function generateExcerpt(text: string, query: string, length?: number): string;
1
+ export * from "./path.js";