mcp-docs-service 0.1.0

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.
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for the MCP Documentation Service
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateExcerpt = exports.calculateRelevance = exports.escapeRegex = exports.joinPaths = exports.getDirectoryName = exports.getFileName = exports.getFileExtension = exports.normalizePath = exports.isValidPath = void 0;
7
+ /**
8
+ * Check if a path is valid
9
+ * @param path - Path to check
10
+ * @returns True if the path is valid, false otherwise
11
+ */
12
+ function isValidPath(path) {
13
+ // Ensure path doesn't contain invalid characters or sequences
14
+ return !path.includes("..") && !path.includes("//") && !path.startsWith("/");
15
+ }
16
+ exports.isValidPath = isValidPath;
17
+ /**
18
+ * Normalize a path
19
+ * @param path - Path to normalize
20
+ * @returns Normalized path
21
+ */
22
+ function normalizePath(path) {
23
+ // Replace backslashes with forward slashes
24
+ path = path.replace(/\\/g, "/");
25
+ // Remove leading and trailing slashes
26
+ path = path.replace(/^\/+|\/+$/g, "");
27
+ // Replace multiple slashes with a single slash
28
+ path = path.replace(/\/+/g, "/");
29
+ return path;
30
+ }
31
+ exports.normalizePath = normalizePath;
32
+ /**
33
+ * Get file extension
34
+ * @param path - Path to get extension from
35
+ * @returns File extension
36
+ */
37
+ function getFileExtension(path) {
38
+ const match = path.match(/\.([^.]+)$/);
39
+ return match ? `.${match[1].toLowerCase()}` : "";
40
+ }
41
+ exports.getFileExtension = getFileExtension;
42
+ /**
43
+ * Get file name
44
+ * @param path - Path to get name from
45
+ * @returns File name
46
+ */
47
+ function getFileName(path) {
48
+ const match = path.match(/([^/]+)$/);
49
+ return match ? match[1] : "";
50
+ }
51
+ exports.getFileName = getFileName;
52
+ /**
53
+ * Get directory name
54
+ * @param path - Path to get directory name from
55
+ * @returns Directory name
56
+ */
57
+ function getDirectoryName(path) {
58
+ const match = path.match(/([^/]+)\/[^/]+$/);
59
+ return match ? match[1] : "";
60
+ }
61
+ exports.getDirectoryName = getDirectoryName;
62
+ /**
63
+ * Join paths
64
+ * @param paths - Paths to join
65
+ * @returns Joined path
66
+ */
67
+ function joinPaths(...paths) {
68
+ return normalizePath(paths.join("/"));
69
+ }
70
+ exports.joinPaths = joinPaths;
71
+ /**
72
+ * Escape regex special characters
73
+ * @param str - String to escape
74
+ * @returns Escaped string
75
+ */
76
+ function escapeRegex(str) {
77
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
78
+ }
79
+ exports.escapeRegex = escapeRegex;
80
+ /**
81
+ * Calculate relevance score
82
+ * @param text - Text to search in
83
+ * @param query - Query to search for
84
+ * @returns Relevance score (0-1)
85
+ */
86
+ function calculateRelevance(text, query) {
87
+ if (!query || !text)
88
+ return 0;
89
+ // Convert to lowercase for case-insensitive matching
90
+ const lowerText = text.toLowerCase();
91
+ const lowerQuery = query.toLowerCase();
92
+ // Check if the query is in the text
93
+ if (!lowerText.includes(lowerQuery))
94
+ return 0;
95
+ // Calculate relevance based on frequency and position
96
+ const frequency = (lowerText.match(new RegExp(escapeRegex(lowerQuery), "g")) || []).length;
97
+ const position = lowerText.indexOf(lowerQuery);
98
+ const textLength = text.length;
99
+ // Higher relevance for:
100
+ // - More occurrences of the query
101
+ // - Earlier position of the query
102
+ // - Shorter text (query is more significant in shorter text)
103
+ const frequencyFactor = Math.min(frequency / 5, 1); // Cap at 1
104
+ const positionFactor = 1 - position / textLength;
105
+ const lengthFactor = 1 - Math.min(textLength / 1000, 0.9); // Cap at 0.9
106
+ return frequencyFactor * 0.4 + positionFactor * 0.4 + lengthFactor * 0.2;
107
+ }
108
+ exports.calculateRelevance = calculateRelevance;
109
+ /**
110
+ * Generate excerpt
111
+ * @param text - Text to generate excerpt from
112
+ * @param query - Query to highlight
113
+ * @param length - Excerpt length
114
+ * @returns Excerpt
115
+ */
116
+ function generateExcerpt(text, query, length = 150) {
117
+ if (!text)
118
+ return "";
119
+ if (!query)
120
+ return text.substring(0, length);
121
+ // Find the position of the query
122
+ const lowerText = text.toLowerCase();
123
+ const lowerQuery = query.toLowerCase();
124
+ const position = lowerText.indexOf(lowerQuery);
125
+ if (position === -1) {
126
+ // Query not found, return the beginning of the text
127
+ return text.substring(0, length) + (text.length > length ? "..." : "");
128
+ }
129
+ // Calculate start and end positions for the excerpt
130
+ const halfLength = Math.floor(length / 2);
131
+ let start = Math.max(0, position - halfLength);
132
+ let end = Math.min(text.length, position + query.length + halfLength);
133
+ // Adjust if the excerpt is shorter than the desired length
134
+ if (end - start < length) {
135
+ if (start === 0) {
136
+ end = Math.min(text.length, length);
137
+ }
138
+ else if (end === text.length) {
139
+ start = Math.max(0, text.length - length);
140
+ }
141
+ }
142
+ // Generate the excerpt
143
+ let excerpt = text.substring(start, end);
144
+ // Add ellipsis if needed
145
+ if (start > 0)
146
+ excerpt = "..." + excerpt;
147
+ if (end < text.length)
148
+ excerpt = excerpt + "...";
149
+ return excerpt;
150
+ }
151
+ exports.generateExcerpt = generateExcerpt;
152
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;;;GAIG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,8DAA8D;IAC9D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC/E,CAAC;AAHD,kCAGC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAY;IACxC,2CAA2C;IAC3C,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEhC,sCAAsC;IACtC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAA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AAG,KAAK,GAAG,OAAO,CAAC;IACzC,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM;QAAE,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;IAEjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAxCD,0CAwCC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "mcp-docs-service",
3
+ "version": "0.1.0",
4
+ "description": "MCP Documentation Management Service - A Model Context Protocol implementation for documentation management",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "mcp-docs-service": "dist/cli/bin.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build",
13
+ "test": "echo \"No tests yet\" && exit 0",
14
+ "start": "node dist/cli/bin.js"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "documentation",
19
+ "cursor",
20
+ "claude",
21
+ "markdown",
22
+ "model-context-protocol"
23
+ ],
24
+ "author": "Your Name",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "js-yaml": "^4.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/js-yaml": "^4.0.5",
31
+ "@types/node": "^18.0.0",
32
+ "typescript": "^4.9.0"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }