mcp-lsp-driver 0.2.0 → 1.0.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.
package/README.md CHANGED
@@ -6,8 +6,7 @@ A TypeScript SDK that bridges Language Server Protocol (LSP) capabilities with t
6
6
 
7
7
  - **Fuzzy-to-Exact Resolution**: LLMs interact via semantic anchors (`symbolName`, `lineHint`), and the SDK resolves them to precise coordinates
8
8
  - **Disk-Based Truth**: All read operations reflect the state of files on disk, ignoring unsaved IDE buffers
9
- - **Human-in-the-Loop Edits**: Write operations require explicit user approval before applying changes
10
- - **Type Safety**: Strict TypeScript with no `any` types
9
+ - **High Abstraction**: Beyond LSP, it also provides functionality related to something like dual chains (graph capability) and metadata (frontmatter capability).
11
10
 
12
11
  ## Installation
13
12
 
@@ -42,11 +41,17 @@ const fileAccess = {
42
41
  readDirectory: (uri: string) => yourIDE.workspace.readDirectory(uri)
43
42
  }
44
43
 
45
- // 3. Implement User Interaction (required for edits)
46
- const userInteraction = {
44
+ // 3. Implement Edit Provider (required for edits)
45
+ const edit = {
46
+ // Option 1: Preview and apply with user approval
47
47
  previewAndApplyEdits: async (operation) => {
48
48
  // Show diff in your IDE and get user approval
49
49
  return await showDiffDialog(operation)
50
+ },
51
+ // Option 2: Apply directly without preview (use one or both)
52
+ applyEdits: async (operation) => {
53
+ // Apply edits directly
54
+ return await yourIDE.applyEdits(operation)
50
55
  }
51
56
  }
52
57
 
@@ -79,7 +84,7 @@ const outline = {
79
84
  // 5. Register LSP tools and resources on the server
80
85
  const capabilities: IdeCapabilities = {
81
86
  fileAccess,
82
- userInteraction,
87
+ edit,
83
88
  definition,
84
89
  diagnostics,
85
90
  outline,
@@ -115,16 +120,21 @@ interface FileAccessProvider {
115
120
  }
116
121
  ```
117
122
 
118
- #### `UserInteractionProvider` (Required for edits)
123
+ #### `EditProvider` (Required for edits)
119
124
 
120
- Handles user approval for edit operations:
125
+ Handles applying changes to files. At least one method must be implemented:
121
126
 
122
127
  ```typescript
123
- interface UserInteractionProvider {
124
- previewAndApplyEdits(operation: PendingEditOperation): Promise<boolean>
128
+ interface EditProvider {
129
+ // Apply edits directly without user interaction
130
+ applyEdits?(operation: PendingEditOperation): Promise<boolean>
131
+ // Preview edits and get user approval before applying
132
+ previewAndApplyEdits?(operation: PendingEditOperation): Promise<boolean>
125
133
  }
126
134
  ```
127
135
 
136
+ If both methods are provided, `previewAndApplyEdits` takes precedence.
137
+
128
138
  ### Capability Providers
129
139
 
130
140
  All capability providers receive `ExactPosition` coordinates (0-based). The SDK handles fuzzy-to-exact conversion before calling these.
@@ -195,6 +205,51 @@ Provides global find and replace functionality across the workspace. `GlobalFind
195
205
  - `matchText`: The matching text
196
206
  - `context`: Context around the match (e.g., the full line)
197
207
 
208
+ #### `GraphProvider`
209
+
210
+ ```typescript
211
+ interface GraphProvider {
212
+ getLinkStructure(): Promise<Link[]>
213
+ resolveOutlinks(path: UnifiedUri): Promise<Link[]>
214
+ resolveBacklinks(path: UnifiedUri): Promise<Link[]>
215
+ addLink(path: UnifiedUri, pattern: string, linkTo: UnifiedUri): Promise<boolean>
216
+ }
217
+ ```
218
+
219
+ Provides graph/link functionality for document relationships (e.g., wiki-style links, cross-references). `Link` includes:
220
+ - `sourceUri`: The source URI where the link originates
221
+ - `targetUri`: The target URI the link points to
222
+ - `subpath`: Optional subpath within the target (e.g., `#section` for Obsidian-style anchors)
223
+ - `displayText`: Optional display text of the link
224
+ - `resolved`: Whether the link target exists
225
+ - `line`: 1-based line number where the link appears
226
+ - `column`: 1-based column number where the link starts
227
+
228
+ #### `FrontmatterProvider`
229
+
230
+ ```typescript
231
+ interface FrontmatterProvider {
232
+ getFrontmatterStructure(property: string, path?: UnifiedUri): Promise<FrontmatterMatch[]>
233
+ getFrontmatter(path: UnifiedUri): Promise<Frontmatter>
234
+ setFrontmatter(path: UnifiedUri, property: string, value: FrontmatterValue): Promise<boolean>
235
+ }
236
+ ```
237
+
238
+ Provides frontmatter metadata functionality for documents (e.g., YAML frontmatter in Markdown files). Types:
239
+
240
+ ```typescript
241
+ type FrontmatterValue = string | string[] | number | number[] | boolean | boolean[] | Date | undefined
242
+ type Frontmatter = { [key: string]: FrontmatterValue }
243
+ interface FrontmatterMatch {
244
+ path: UnifiedUri
245
+ value: FrontmatterValue
246
+ }
247
+ ```
248
+
249
+ - `getFrontmatterStructure`: Searches for a specific property across documents. If `path` is provided, searches only that document.
250
+ - `getFrontmatter`: Gets all frontmatter for a specific document.
251
+ - `setFrontmatter`: Sets a frontmatter property. Use `undefined` to remove the property.
252
+
198
253
  ### IdeCapabilities
199
254
 
200
255
  Combine all providers into a single configuration:
@@ -202,13 +257,15 @@ Combine all providers into a single configuration:
202
257
  ```typescript
203
258
  interface IdeCapabilities {
204
259
  fileAccess: FileAccessProvider // Required
205
- userInteraction?: UserInteractionProvider // Required for apply_edit tool
260
+ edit?: EditProvider // Required for apply_edit tool
206
261
  definition?: DefinitionProvider // Enables goto_definition tool
207
262
  references?: ReferencesProvider // Enables find_references tool
208
263
  hierarchy?: HierarchyProvider // Enables call_hierarchy tool
209
264
  diagnostics?: DiagnosticsProvider // Enables diagnostics resources
210
265
  outline?: OutlineProvider // Enables outline resource
211
266
  globalFind?: GlobalFindProvider // Enables global_find and global_replace tools
267
+ graph?: GraphProvider // Enables graph tools and resources
268
+ frontmatter?: FrontmatterProvider // Enables frontmatter tools and resource
212
269
  onDiagnosticsChanged?: (callback: OnDiagnosticsChangedCallback) => void
213
270
  }
214
271
  ```
@@ -280,27 +337,71 @@ Replace all occurrences of text across the entire workspace.
280
337
  - Number of replacements made
281
338
  - Success status and message
282
339
 
340
+ ### `get_link_structure`
341
+
342
+ Get all links in the workspace, showing relationships between documents.
343
+
344
+ **Inputs:** None
345
+
346
+ **Returns:**
347
+ - Array of links with source URI, target URI, subpath, display text, resolved status, line, and column
348
+
349
+ ### `add_link`
350
+
351
+ Add a link to a document by finding a text pattern and replacing it with a link.
352
+
353
+ **Inputs:**
354
+ - `path`: The path to the document to modify
355
+ - `pattern`: The text pattern to find and replace with a link
356
+ - `link_to`: The target URI the link should point to
357
+
358
+ **Returns:**
359
+ - Success status and message
360
+
361
+ ### `get_frontmatter_structure`
362
+
363
+ Get frontmatter property values across documents.
364
+
365
+ **Inputs:**
366
+ - `property`: The frontmatter property name to search for (required)
367
+ - `path`: Optional path to limit the search to a specific document
368
+
369
+ **Returns:**
370
+ - Array of matches with path and value
371
+
372
+ ### `set_frontmatter`
373
+
374
+ Set a frontmatter property on a document.
375
+
376
+ **Inputs:**
377
+ - `path`: The path to the document to modify (required)
378
+ - `property`: The frontmatter property name to set (required)
379
+ - `value`: The value to set. Can be a string, number, boolean, array of these types, or null to remove the property.
380
+
381
+ **Returns:**
382
+ - Success status and message
383
+
283
384
  ## MCP Resources
284
385
 
285
386
  The SDK automatically registers resources based on which capabilities you provide:
286
387
 
287
- ### `lsp://diagnostics/{path}`
388
+ ### `diagnostics://{path}`
288
389
 
289
390
  Get diagnostics (errors, warnings) for a specific file.
290
391
 
291
- **Resource URI Pattern:** `lsp://diagnostics/{+path}`
392
+ **Resource URI Pattern:** `diagnostics://{+path}`
292
393
 
293
- **Example:** `lsp://diagnostics/src/main.ts`
394
+ **Example:** `diagnostics://src/main.ts`
294
395
 
295
396
  Returns diagnostics formatted as markdown with location, severity, and message information.
296
397
 
297
398
  **Subscription Support:** If your IDE implements `onDiagnosticsChanged` capability, these resources become subscribable. When diagnostics change, the driver sends resource update notifications.
298
399
 
299
- ### `lsp://diagnostics/workspace`
400
+ ### `diagnostics://workspace`
300
401
 
301
402
  Get diagnostics across the entire workspace.
302
403
 
303
- **Resource URI:** `lsp://diagnostics/workspace`
404
+ **Resource URI:** `diagnostics://workspace`
304
405
 
305
406
  Only available if your `DiagnosticsProvider` implements the optional `getWorkspaceDiagnostics()` method.
306
407
 
@@ -308,13 +409,13 @@ Returns workspace diagnostics grouped by file, formatted as markdown.
308
409
 
309
410
  **Subscription Support:** If your IDE implements `onDiagnosticsChanged` capability, this resource becomes subscribable.
310
411
 
311
- ### `lsp://outline/{path}`
412
+ ### `outline://{path}`
312
413
 
313
414
  Get the document outline (symbol tree) for a file.
314
415
 
315
- **Resource URI Pattern:** `lsp://outline/{+path}`
416
+ **Resource URI Pattern:** `outline://{+path}`
316
417
 
317
- **Example:** `lsp://outline/src/components/Button.tsx`
418
+ **Example:** `outline://src/components/Button.tsx`
318
419
 
319
420
  Returns document symbols formatted as a hierarchical markdown outline, including:
320
421
  - Symbol names and kinds (class, function, method, etc.)
@@ -323,25 +424,61 @@ Returns document symbols formatted as a hierarchical markdown outline, including
323
424
 
324
425
  No subscription support for this resource (read-only).
325
426
 
326
- ### `lsp://filetree/{path}`
427
+ ### `filetree://{path}`
327
428
 
328
429
  Get the complete file tree for a directory, excluding git-ignored files.
329
430
 
330
- **Resource URI Pattern:** `lsp://filetree/{+path}`
431
+ **Resource URI Pattern:** `filetree://{+path}`
331
432
 
332
- **Example:** `lsp://filetree/src`, `lsp://filetree/.`
433
+ **Example:** `filetree://src`, `filetree://.`
333
434
 
334
435
  Returns a JSON array of all file paths in the directory tree (recursive). Use "." for the root directory.
335
436
 
336
437
  No subscription support for this resource (read-only).
337
438
 
338
- ### `lsp://files/{path}`
439
+ ### `files://{path}`
339
440
 
340
441
  For directories: returns directory children (git-ignored files excluded, similar to `ls`). For files: gets file content with optional line range.
341
442
 
342
- **Resource URI Pattern:** `lsp://files/{+path}`
443
+ **Resource URI Pattern:** `files://{+path}`
444
+
445
+ **Example:** `files://src`, `files://src/index.ts`, `files://src/index.ts#L1-L2`
446
+
447
+ No subscription support for this resource (read-only).
448
+
449
+ ### `outlinks://{path}`
450
+
451
+ Get outgoing links from a specific file.
452
+
453
+ **Resource URI Pattern:** `outlinks://{+path}`
454
+
455
+ **Example:** `outlinks://notes/index.md`
343
456
 
344
- **Example:** `lsp://files/src`, `lsp://files/src/index.ts`, `lsp://files/src/index.ts#L1-L2`
457
+ Returns a JSON array of links originating from the specified document.
458
+
459
+ No subscription support for this resource (read-only).
460
+
461
+ ### `backlinks://{path}`
462
+
463
+ Get incoming links (backlinks) to a specific file.
464
+
465
+ **Resource URI Pattern:** `backlinks://{+path}`
466
+
467
+ **Example:** `backlinks://notes/topic-a.md`
468
+
469
+ Returns a JSON array of links pointing to the specified document.
470
+
471
+ No subscription support for this resource (read-only).
472
+
473
+ ### `frontmatter://{path}`
474
+
475
+ Get frontmatter metadata for a specific file.
476
+
477
+ **Resource URI Pattern:** `frontmatter://{+path}`
478
+
479
+ **Example:** `frontmatter://notes/index.md`
480
+
481
+ Returns a JSON object containing all frontmatter properties and values for the document.
345
482
 
346
483
  No subscription support for this resource (read-only).
347
484
 
@@ -430,6 +567,16 @@ interface Diagnostic {
430
567
  code?: string | number
431
568
  }
432
569
 
570
+ interface Link {
571
+ sourceUri: UnifiedUri
572
+ targetUri: UnifiedUri
573
+ subpath?: string
574
+ displayText?: string
575
+ resolved: boolean
576
+ line: number
577
+ column: number
578
+ }
579
+
433
580
  type EditResult =
434
581
  | { success: true; message: string }
435
582
  | { success: false; message: string; reason: 'UserRejected' | 'IOError' | 'ValidationFailed' }