@docsyncdev/mcp-server 1.0.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.
package/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # @docsync/mcp-server
2
+
3
+ MCP (Model Context Protocol) server for DocSync - enables AI coding assistants like Claude Code and Cursor to search and interact with your documentation.
4
+
5
+ ## Features
6
+
7
+ - **Context-Aware Docs**: Get documentation for any source file with full hierarchy (unit → topic → module)
8
+ - **Semantic Search**: Search your documentation using natural language queries
9
+ - **Documentation Browser**: List and browse docs by level (module, topic, unit)
10
+ - **Full Document Retrieval**: Get complete document content by ID
11
+ - **Caching**: Built-in LRU cache reduces API calls and improves latency
12
+ - **Rate Limiting**: Server-side rate limiting prevents abuse
13
+
14
+ ## Quick Start
15
+
16
+ ### 1. Get Your API Key
17
+
18
+ 1. Go to your DocSync dashboard at [docsync.dev](https://docsync.dev)
19
+ 2. Navigate to **Settings > API Keys**
20
+ 3. Click **Create API Key** and copy the key
21
+
22
+ ### 2. Get Your Project ID
23
+
24
+ 1. In DocSync dashboard, go to **Settings > API Keys**
25
+ 2. Select your project from the dropdown
26
+ 3. Copy the project ID from the generated config
27
+
28
+ ### 3. Configure Your AI Assistant
29
+
30
+ #### Claude Code
31
+
32
+ Add to your `claude_desktop_config.json` or `.claude/settings.json`:
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "docsync": {
38
+ "command": "npx",
39
+ "args": ["@docsync/mcp-server"],
40
+ "env": {
41
+ "DOCSYNC_API_KEY": "ds_your_api_key_here",
42
+ "DOCSYNC_PROJECT_ID": "your-project-uuid"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ #### Cursor
50
+
51
+ Add to your Cursor MCP configuration:
52
+
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "docsync": {
57
+ "command": "npx",
58
+ "args": ["@docsync/mcp-server"],
59
+ "env": {
60
+ "DOCSYNC_API_KEY": "ds_your_api_key_here",
61
+ "DOCSYNC_PROJECT_ID": "your-project-uuid"
62
+ }
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## Available Tools
69
+
70
+ ### search_docs
71
+
72
+ Search documentation semantically. Returns relevant chunks matching your query.
73
+
74
+ **Parameters:**
75
+
76
+ - `query` (string, required): Natural language search query
77
+ - `limit` (number, optional): Maximum results (default 10, max 50)
78
+
79
+ **Example:**
80
+
81
+ ```
82
+ How does authentication work in this project?
83
+ ```
84
+
85
+ ### get_document
86
+
87
+ Retrieve full content of a specific document by ID.
88
+
89
+ **Parameters:**
90
+
91
+ - `document_id` (string, required): Document ID from search results
92
+
93
+ ### get_docs_for_file ⭐
94
+
95
+ **The killer feature.** Get documentation relevant to a source code file, with full hierarchy context.
96
+
97
+ When you're working on `src/auth/jwt.ts`, this returns:
98
+
99
+ - Related unit docs (JWT implementation details)
100
+ - Parent topic doc (Authentication overview)
101
+ - Grandparent module doc (Security architecture)
102
+
103
+ All in one call. Full context pyramid.
104
+
105
+ **Parameters:**
106
+
107
+ - `file_path` (string, required): Path to the source code file
108
+ - `include_content` (boolean, optional): Include full content (default: true)
109
+
110
+ **Example:**
111
+
112
+ ```
113
+ Get docs for src/services/payment-processor.ts
114
+ ```
115
+
116
+ Returns:
117
+
118
+ ```
119
+ # 🏗️ Module Context
120
+ ## Billing & Payments
121
+ Overview of the billing system architecture...
122
+
123
+ # 📚 Topic Context
124
+ ## Payment Processing
125
+ How payments flow through the system...
126
+
127
+ # 📄 Related Documentation
128
+ ## PaymentProcessor Class
129
+ Detailed API for the payment processor...
130
+ ```
131
+
132
+ ### list_docs
133
+
134
+ Browse all documentation, optionally filtered by level.
135
+
136
+ **Parameters:**
137
+
138
+ - `level` (string, optional): Filter by "module", "topic", "unit", or "all" (default)
139
+
140
+ **Example:**
141
+
142
+ ```
143
+ List all module-level docs
144
+ ```
145
+
146
+ ## Environment Variables
147
+
148
+ | Variable | Required | Description |
149
+ | -------------------- | -------- | -------------------------------- |
150
+ | `DOCSYNC_API_KEY` | Yes | Your DocSync API key |
151
+ | `DOCSYNC_PROJECT_ID` | Yes | Your DocSync project ID |
152
+ | `DOCSYNC_API_URL` | No | Custom API URL (for development) |
153
+
154
+ ## Rate Limits
155
+
156
+ - `search_docs`: 200 requests per hour
157
+ - `get_docs_for_file`: 200 requests per hour
158
+ - `list_docs`: 200 requests per hour
159
+ - `get_document`: 500 requests per hour
160
+
161
+ Rate limits are per API key. If you hit a rate limit, the tool will return an error message.
162
+
163
+ ## Caching
164
+
165
+ The MCP server includes an in-memory LRU cache:
166
+
167
+ - Cache size: 100 entries per cache type
168
+ - TTL: 5 minutes
169
+ - Repeated queries return cached results instantly
170
+
171
+ Cache clears when the MCP server process restarts.
172
+
173
+ ## Troubleshooting
174
+
175
+ ### "DOCSYNC_API_KEY environment variable is required"
176
+
177
+ Make sure you've added the `env` section to your MCP configuration with your API key.
178
+
179
+ ### "Rate limit exceeded"
180
+
181
+ Wait a few minutes before making more requests. Consider if your agent is making too many searches.
182
+
183
+ ### "Document not found"
184
+
185
+ The document ID may be stale if documentation was recently updated. Run a new search to get current document IDs.
186
+
187
+ ### Connection issues
188
+
189
+ 1. Check that your API key is valid in DocSync settings
190
+ 2. Verify your project ID is correct
191
+ 3. Ensure you have internet connectivity
192
+
193
+ ## Development
194
+
195
+ ```bash
196
+ # Install dependencies
197
+ npm install
198
+
199
+ # Build
200
+ npm run build
201
+
202
+ # Run locally
203
+ DOCSYNC_API_KEY=your_key DOCSYNC_PROJECT_ID=your_project node dist/index.js
204
+ ```
205
+
206
+ ## License
207
+
208
+ MIT
@@ -0,0 +1,229 @@
1
+ import { LRUCache } from 'lru-cache';
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { CallToolResult, Tool } from '@modelcontextprotocol/sdk/types.js';
4
+
5
+ /**
6
+ * LRU Cache for DocSync MCP Server
7
+ *
8
+ * Caches search results to reduce API calls and improve latency.
9
+ * AI agents often repeat similar queries, so caching provides significant benefits.
10
+ */
11
+
12
+ interface SearchResult {
13
+ id: string;
14
+ file_path: string;
15
+ repository: string;
16
+ similarity: number;
17
+ metadata: {
18
+ type?: string;
19
+ level?: string;
20
+ concept?: string;
21
+ headerPath?: string[];
22
+ };
23
+ }
24
+ interface SearchResponse {
25
+ results: SearchResult[];
26
+ query: string;
27
+ credits_used: number;
28
+ }
29
+ interface DocInfo {
30
+ id: string;
31
+ file_path: string;
32
+ title: string;
33
+ level: string;
34
+ summary: string | null;
35
+ content?: string;
36
+ parent_path?: string | null;
37
+ }
38
+ interface ListDocsResponse {
39
+ success: boolean;
40
+ project_id: string;
41
+ project_name: string;
42
+ level: string;
43
+ docs: Array<{
44
+ id: string;
45
+ file_path: string;
46
+ repository_id: string;
47
+ repository_name: string;
48
+ title: string;
49
+ level: string;
50
+ parent_path: string | null;
51
+ summary: string | null;
52
+ }>;
53
+ count: number;
54
+ }
55
+ interface FileDocsResponse {
56
+ success: boolean;
57
+ project_id: string;
58
+ project_name: string;
59
+ file_path: string;
60
+ doc_path: string;
61
+ unit_doc: DocInfo | null;
62
+ topic: DocInfo | null;
63
+ module: DocInfo | null;
64
+ }
65
+ /**
66
+ * Search results cache
67
+ */
68
+ declare const searchCache: LRUCache<string, SearchResponse, unknown>;
69
+ /**
70
+ * Clear all caches (useful for testing or manual invalidation)
71
+ */
72
+ declare function clearCaches(): void;
73
+
74
+ /**
75
+ * DocSync API Client
76
+ *
77
+ * Wraps calls to DocSync edge functions with error handling and caching.
78
+ */
79
+
80
+ interface ClientConfig {
81
+ apiKey: string;
82
+ projectId: string;
83
+ baseUrl?: string;
84
+ }
85
+ /**
86
+ * DocSync API client for MCP server
87
+ */
88
+ declare class DocSyncClient {
89
+ private apiKey;
90
+ private projectId;
91
+ private baseUrl;
92
+ constructor(config: ClientConfig);
93
+ /**
94
+ * Search documentation semantically
95
+ */
96
+ search(query: string, limit?: number): Promise<SearchResponse>;
97
+ /**
98
+ * List documentation by level
99
+ */
100
+ listDocs(level?: 'unit' | 'topic' | 'module' | 'all'): Promise<ListDocsResponse>;
101
+ /**
102
+ * Get documentation related to a source file with hierarchy context
103
+ */
104
+ getDocsForFile(filePath: string, includeContent?: boolean): Promise<FileDocsResponse>;
105
+ /**
106
+ * Make authenticated request to DocSync API
107
+ */
108
+ private request;
109
+ }
110
+ /**
111
+ * Create a client from environment variables
112
+ */
113
+ declare function createClientFromEnv(): DocSyncClient;
114
+
115
+ /**
116
+ * DocSync MCP Server Implementation
117
+ *
118
+ * Implements the Model Context Protocol for AI coding assistants.
119
+ *
120
+ * ## AI Agent Instructions
121
+ *
122
+ * DocSync provides documentation context for codebases. Use these tools to understand
123
+ * code before modifying it, explain functionality to users, and navigate large codebases.
124
+ *
125
+ * ### Recommended Workflow
126
+ *
127
+ * **When user asks about a SPECIFIC FILE:**
128
+ * 1. Use `get_docs_for_file` with the file path → Returns unit doc + topic + module context
129
+ * This is the PRIMARY tool for understanding specific code.
130
+ *
131
+ * **When user asks a CONCEPTUAL QUESTION:**
132
+ * 1. Use `search_docs` with natural language → Find relevant documentation
133
+ * 2. Use `get_docs_for_file` with file paths from search results for full context
134
+ *
135
+ * **When user wants an OVERVIEW:**
136
+ * 1. Use `list_docs` with level="module" → See high-level architecture
137
+ * 2. Drill down with level="topic" for feature areas
138
+ *
139
+ * ### Tool Selection Guide
140
+ *
141
+ * | User Intent | Tool to Use |
142
+ * |------------------------------------|----------------------|
143
+ * | "Explain src/auth/jwt.ts" | get_docs_for_file |
144
+ * | "How does authentication work?" | search_docs |
145
+ * | "What's in this codebase?" | list_docs |
146
+ * | "Show me the billing module" | list_docs → search |
147
+ * | "I need to modify the API client" | get_docs_for_file |
148
+ *
149
+ * ### Key Principle
150
+ * ALWAYS fetch documentation context BEFORE explaining code or suggesting changes.
151
+ * The documentation contains architectural context, common patterns, and gotchas
152
+ * that may not be obvious from reading the source code alone.
153
+ */
154
+
155
+ /**
156
+ * Create and configure the MCP server
157
+ */
158
+ declare function createServer(client: DocSyncClient): Server;
159
+ /**
160
+ * Start the MCP server with stdio transport
161
+ */
162
+ declare function startServer(): Promise<void>;
163
+
164
+ /**
165
+ * search_docs MCP Tool
166
+ *
167
+ * Enables AI agents to semantically search documentation in DocSync.
168
+ */
169
+
170
+ declare const SEARCH_TOOL_NAME = "search_docs";
171
+ /**
172
+ * Tool definition for MCP registration
173
+ */
174
+ declare const searchToolDefinition: Tool;
175
+ interface SearchToolInput {
176
+ query: string;
177
+ limit?: number;
178
+ }
179
+ /**
180
+ * Execute search_docs tool
181
+ */
182
+ declare function executeSearchTool(client: DocSyncClient, input: SearchToolInput): Promise<CallToolResult>;
183
+
184
+ /**
185
+ * list_docs MCP Tool
186
+ *
187
+ * Enables AI agents to browse documentation by level (module, topic, unit).
188
+ */
189
+
190
+ declare const LIST_DOCS_TOOL_NAME = "list_docs";
191
+ /**
192
+ * Tool definition for MCP registration
193
+ */
194
+ declare const listDocsToolDefinition: Tool;
195
+ interface ListDocsToolInput {
196
+ level?: 'module' | 'topic' | 'unit' | 'all';
197
+ }
198
+ /**
199
+ * Execute list_docs tool
200
+ */
201
+ declare function executeListDocsTool(client: DocSyncClient, input: ListDocsToolInput): Promise<CallToolResult>;
202
+
203
+ /**
204
+ * get_docs_for_file MCP Tool
205
+ *
206
+ * The killer feature: given a source code file, returns related documentation
207
+ * along with parent (topic) and grandparent (module) context.
208
+ *
209
+ * This gives agents full context about what they're working on:
210
+ * - Specific docs for the file/component
211
+ * - How it fits into the broader topic
212
+ * - The module-level architecture
213
+ */
214
+
215
+ declare const FILE_DOCS_TOOL_NAME = "get_docs_for_file";
216
+ /**
217
+ * Tool definition for MCP registration
218
+ */
219
+ declare const fileDocsToolDefinition: Tool;
220
+ interface FileDocsToolInput {
221
+ file_path: string;
222
+ include_content?: boolean;
223
+ }
224
+ /**
225
+ * Execute get_docs_for_file tool
226
+ */
227
+ declare function executeFileDocsTool(client: DocSyncClient, input: FileDocsToolInput): Promise<CallToolResult>;
228
+
229
+ export { type ClientConfig, DocSyncClient, FILE_DOCS_TOOL_NAME, type FileDocsToolInput, LIST_DOCS_TOOL_NAME, type ListDocsToolInput, SEARCH_TOOL_NAME, type SearchResponse, type SearchResult, type SearchToolInput, clearCaches, createClientFromEnv, createServer, executeFileDocsTool, executeListDocsTool, executeSearchTool, fileDocsToolDefinition, listDocsToolDefinition, searchCache, searchToolDefinition, startServer };