gitx.do 0.0.1 → 0.0.3

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 (237) hide show
  1. package/dist/cli/commands/blame.d.ts +259 -0
  2. package/dist/cli/commands/blame.d.ts.map +1 -0
  3. package/dist/cli/commands/blame.js +609 -0
  4. package/dist/cli/commands/blame.js.map +1 -0
  5. package/dist/cli/commands/branch.d.ts +249 -0
  6. package/dist/cli/commands/branch.d.ts.map +1 -0
  7. package/dist/cli/commands/branch.js +693 -0
  8. package/dist/cli/commands/branch.js.map +1 -0
  9. package/dist/cli/commands/commit.d.ts +182 -0
  10. package/dist/cli/commands/commit.d.ts.map +1 -0
  11. package/dist/cli/commands/commit.js +437 -0
  12. package/dist/cli/commands/commit.js.map +1 -0
  13. package/dist/cli/commands/diff.d.ts +464 -0
  14. package/dist/cli/commands/diff.d.ts.map +1 -0
  15. package/dist/cli/commands/diff.js +958 -0
  16. package/dist/cli/commands/diff.js.map +1 -0
  17. package/dist/cli/commands/log.d.ts +239 -0
  18. package/dist/cli/commands/log.d.ts.map +1 -0
  19. package/dist/cli/commands/log.js +535 -0
  20. package/dist/cli/commands/log.js.map +1 -0
  21. package/dist/cli/commands/review.d.ts +457 -0
  22. package/dist/cli/commands/review.d.ts.map +1 -0
  23. package/dist/cli/commands/review.js +533 -0
  24. package/dist/cli/commands/review.js.map +1 -0
  25. package/dist/cli/commands/status.d.ts +269 -0
  26. package/dist/cli/commands/status.d.ts.map +1 -0
  27. package/dist/cli/commands/status.js +493 -0
  28. package/dist/cli/commands/status.js.map +1 -0
  29. package/dist/cli/commands/web.d.ts +199 -0
  30. package/dist/cli/commands/web.d.ts.map +1 -0
  31. package/dist/cli/commands/web.js +696 -0
  32. package/dist/cli/commands/web.js.map +1 -0
  33. package/dist/cli/fs-adapter.d.ts +656 -0
  34. package/dist/cli/fs-adapter.d.ts.map +1 -0
  35. package/dist/cli/fs-adapter.js +1179 -0
  36. package/dist/cli/fs-adapter.js.map +1 -0
  37. package/dist/cli/index.d.ts +387 -0
  38. package/dist/cli/index.d.ts.map +1 -0
  39. package/dist/cli/index.js +523 -0
  40. package/dist/cli/index.js.map +1 -0
  41. package/dist/cli/ui/components/DiffView.d.ts +7 -0
  42. package/dist/cli/ui/components/DiffView.d.ts.map +1 -0
  43. package/dist/cli/ui/components/DiffView.js +11 -0
  44. package/dist/cli/ui/components/DiffView.js.map +1 -0
  45. package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -0
  46. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -0
  47. package/dist/cli/ui/components/ErrorDisplay.js +11 -0
  48. package/dist/cli/ui/components/ErrorDisplay.js.map +1 -0
  49. package/dist/cli/ui/components/FuzzySearch.d.ts +9 -0
  50. package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -0
  51. package/dist/cli/ui/components/FuzzySearch.js +12 -0
  52. package/dist/cli/ui/components/FuzzySearch.js.map +1 -0
  53. package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -0
  54. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -0
  55. package/dist/cli/ui/components/LoadingSpinner.js +10 -0
  56. package/dist/cli/ui/components/LoadingSpinner.js.map +1 -0
  57. package/dist/cli/ui/components/NavigationList.d.ts +9 -0
  58. package/dist/cli/ui/components/NavigationList.d.ts.map +1 -0
  59. package/dist/cli/ui/components/NavigationList.js +11 -0
  60. package/dist/cli/ui/components/NavigationList.js.map +1 -0
  61. package/dist/cli/ui/components/ScrollableContent.d.ts +8 -0
  62. package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -0
  63. package/dist/cli/ui/components/ScrollableContent.js +11 -0
  64. package/dist/cli/ui/components/ScrollableContent.js.map +1 -0
  65. package/dist/cli/ui/components/index.d.ts +7 -0
  66. package/dist/cli/ui/components/index.d.ts.map +1 -0
  67. package/dist/cli/ui/components/index.js +9 -0
  68. package/dist/cli/ui/components/index.js.map +1 -0
  69. package/dist/cli/ui/terminal-ui.d.ts +52 -0
  70. package/dist/cli/ui/terminal-ui.d.ts.map +1 -0
  71. package/dist/cli/ui/terminal-ui.js +121 -0
  72. package/dist/cli/ui/terminal-ui.js.map +1 -0
  73. package/dist/durable-object/object-store.d.ts +401 -23
  74. package/dist/durable-object/object-store.d.ts.map +1 -1
  75. package/dist/durable-object/object-store.js +414 -25
  76. package/dist/durable-object/object-store.js.map +1 -1
  77. package/dist/durable-object/schema.d.ts +188 -0
  78. package/dist/durable-object/schema.d.ts.map +1 -1
  79. package/dist/durable-object/schema.js +160 -0
  80. package/dist/durable-object/schema.js.map +1 -1
  81. package/dist/durable-object/wal.d.ts +336 -31
  82. package/dist/durable-object/wal.d.ts.map +1 -1
  83. package/dist/durable-object/wal.js +272 -27
  84. package/dist/durable-object/wal.js.map +1 -1
  85. package/dist/index.d.ts +379 -3
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +379 -7
  88. package/dist/index.js.map +1 -1
  89. package/dist/mcp/adapter.d.ts +579 -38
  90. package/dist/mcp/adapter.d.ts.map +1 -1
  91. package/dist/mcp/adapter.js +426 -33
  92. package/dist/mcp/adapter.js.map +1 -1
  93. package/dist/mcp/sandbox.d.ts +532 -29
  94. package/dist/mcp/sandbox.d.ts.map +1 -1
  95. package/dist/mcp/sandbox.js +389 -22
  96. package/dist/mcp/sandbox.js.map +1 -1
  97. package/dist/mcp/sdk-adapter.d.ts +478 -56
  98. package/dist/mcp/sdk-adapter.d.ts.map +1 -1
  99. package/dist/mcp/sdk-adapter.js +346 -44
  100. package/dist/mcp/sdk-adapter.js.map +1 -1
  101. package/dist/mcp/tools.d.ts +445 -30
  102. package/dist/mcp/tools.d.ts.map +1 -1
  103. package/dist/mcp/tools.js +363 -33
  104. package/dist/mcp/tools.js.map +1 -1
  105. package/dist/ops/blame.d.ts +424 -21
  106. package/dist/ops/blame.d.ts.map +1 -1
  107. package/dist/ops/blame.js +303 -20
  108. package/dist/ops/blame.js.map +1 -1
  109. package/dist/ops/branch.d.ts +583 -32
  110. package/dist/ops/branch.d.ts.map +1 -1
  111. package/dist/ops/branch.js +365 -23
  112. package/dist/ops/branch.js.map +1 -1
  113. package/dist/ops/commit-traversal.d.ts +164 -24
  114. package/dist/ops/commit-traversal.d.ts.map +1 -1
  115. package/dist/ops/commit-traversal.js +68 -2
  116. package/dist/ops/commit-traversal.js.map +1 -1
  117. package/dist/ops/commit.d.ts +387 -53
  118. package/dist/ops/commit.d.ts.map +1 -1
  119. package/dist/ops/commit.js +249 -29
  120. package/dist/ops/commit.js.map +1 -1
  121. package/dist/ops/merge-base.d.ts +195 -21
  122. package/dist/ops/merge-base.d.ts.map +1 -1
  123. package/dist/ops/merge-base.js +122 -12
  124. package/dist/ops/merge-base.js.map +1 -1
  125. package/dist/ops/merge.d.ts +600 -130
  126. package/dist/ops/merge.d.ts.map +1 -1
  127. package/dist/ops/merge.js +408 -60
  128. package/dist/ops/merge.js.map +1 -1
  129. package/dist/ops/tag.d.ts +67 -2
  130. package/dist/ops/tag.d.ts.map +1 -1
  131. package/dist/ops/tag.js +42 -1
  132. package/dist/ops/tag.js.map +1 -1
  133. package/dist/ops/tree-builder.d.ts +102 -6
  134. package/dist/ops/tree-builder.d.ts.map +1 -1
  135. package/dist/ops/tree-builder.js +30 -5
  136. package/dist/ops/tree-builder.js.map +1 -1
  137. package/dist/ops/tree-diff.d.ts +50 -2
  138. package/dist/ops/tree-diff.d.ts.map +1 -1
  139. package/dist/ops/tree-diff.js +50 -2
  140. package/dist/ops/tree-diff.js.map +1 -1
  141. package/dist/pack/delta.d.ts +211 -39
  142. package/dist/pack/delta.d.ts.map +1 -1
  143. package/dist/pack/delta.js +232 -46
  144. package/dist/pack/delta.js.map +1 -1
  145. package/dist/pack/format.d.ts +390 -28
  146. package/dist/pack/format.d.ts.map +1 -1
  147. package/dist/pack/format.js +344 -33
  148. package/dist/pack/format.js.map +1 -1
  149. package/dist/pack/full-generation.d.ts +313 -28
  150. package/dist/pack/full-generation.d.ts.map +1 -1
  151. package/dist/pack/full-generation.js +238 -19
  152. package/dist/pack/full-generation.js.map +1 -1
  153. package/dist/pack/generation.d.ts +346 -23
  154. package/dist/pack/generation.d.ts.map +1 -1
  155. package/dist/pack/generation.js +269 -21
  156. package/dist/pack/generation.js.map +1 -1
  157. package/dist/pack/index.d.ts +407 -86
  158. package/dist/pack/index.d.ts.map +1 -1
  159. package/dist/pack/index.js +351 -70
  160. package/dist/pack/index.js.map +1 -1
  161. package/dist/refs/branch.d.ts +517 -71
  162. package/dist/refs/branch.d.ts.map +1 -1
  163. package/dist/refs/branch.js +410 -26
  164. package/dist/refs/branch.js.map +1 -1
  165. package/dist/refs/storage.d.ts +610 -57
  166. package/dist/refs/storage.d.ts.map +1 -1
  167. package/dist/refs/storage.js +481 -29
  168. package/dist/refs/storage.js.map +1 -1
  169. package/dist/refs/tag.d.ts +677 -67
  170. package/dist/refs/tag.d.ts.map +1 -1
  171. package/dist/refs/tag.js +497 -30
  172. package/dist/refs/tag.js.map +1 -1
  173. package/dist/storage/lru-cache.d.ts +556 -53
  174. package/dist/storage/lru-cache.d.ts.map +1 -1
  175. package/dist/storage/lru-cache.js +439 -36
  176. package/dist/storage/lru-cache.js.map +1 -1
  177. package/dist/storage/object-index.d.ts +483 -38
  178. package/dist/storage/object-index.d.ts.map +1 -1
  179. package/dist/storage/object-index.js +388 -22
  180. package/dist/storage/object-index.js.map +1 -1
  181. package/dist/storage/r2-pack.d.ts +957 -94
  182. package/dist/storage/r2-pack.d.ts.map +1 -1
  183. package/dist/storage/r2-pack.js +756 -48
  184. package/dist/storage/r2-pack.js.map +1 -1
  185. package/dist/tiered/cdc-pipeline.d.ts +1610 -38
  186. package/dist/tiered/cdc-pipeline.d.ts.map +1 -1
  187. package/dist/tiered/cdc-pipeline.js +1131 -22
  188. package/dist/tiered/cdc-pipeline.js.map +1 -1
  189. package/dist/tiered/migration.d.ts +903 -41
  190. package/dist/tiered/migration.d.ts.map +1 -1
  191. package/dist/tiered/migration.js +646 -24
  192. package/dist/tiered/migration.js.map +1 -1
  193. package/dist/tiered/parquet-writer.d.ts +944 -47
  194. package/dist/tiered/parquet-writer.d.ts.map +1 -1
  195. package/dist/tiered/parquet-writer.js +667 -39
  196. package/dist/tiered/parquet-writer.js.map +1 -1
  197. package/dist/tiered/read-path.d.ts +728 -34
  198. package/dist/tiered/read-path.d.ts.map +1 -1
  199. package/dist/tiered/read-path.js +310 -27
  200. package/dist/tiered/read-path.js.map +1 -1
  201. package/dist/types/objects.d.ts +457 -0
  202. package/dist/types/objects.d.ts.map +1 -1
  203. package/dist/types/objects.js +305 -4
  204. package/dist/types/objects.js.map +1 -1
  205. package/dist/types/storage.d.ts +407 -35
  206. package/dist/types/storage.d.ts.map +1 -1
  207. package/dist/types/storage.js +27 -3
  208. package/dist/types/storage.js.map +1 -1
  209. package/dist/utils/hash.d.ts +133 -12
  210. package/dist/utils/hash.d.ts.map +1 -1
  211. package/dist/utils/hash.js +133 -12
  212. package/dist/utils/hash.js.map +1 -1
  213. package/dist/utils/sha1.d.ts +102 -9
  214. package/dist/utils/sha1.d.ts.map +1 -1
  215. package/dist/utils/sha1.js +114 -11
  216. package/dist/utils/sha1.js.map +1 -1
  217. package/dist/wire/capabilities.d.ts +896 -88
  218. package/dist/wire/capabilities.d.ts.map +1 -1
  219. package/dist/wire/capabilities.js +566 -62
  220. package/dist/wire/capabilities.js.map +1 -1
  221. package/dist/wire/pkt-line.d.ts +293 -15
  222. package/dist/wire/pkt-line.d.ts.map +1 -1
  223. package/dist/wire/pkt-line.js +251 -15
  224. package/dist/wire/pkt-line.js.map +1 -1
  225. package/dist/wire/receive-pack.d.ts +814 -64
  226. package/dist/wire/receive-pack.d.ts.map +1 -1
  227. package/dist/wire/receive-pack.js +542 -41
  228. package/dist/wire/receive-pack.js.map +1 -1
  229. package/dist/wire/smart-http.d.ts +575 -97
  230. package/dist/wire/smart-http.d.ts.map +1 -1
  231. package/dist/wire/smart-http.js +337 -46
  232. package/dist/wire/smart-http.js.map +1 -1
  233. package/dist/wire/upload-pack.d.ts +492 -98
  234. package/dist/wire/upload-pack.d.ts.map +1 -1
  235. package/dist/wire/upload-pack.js +347 -59
  236. package/dist/wire/upload-pack.js.map +1 -1
  237. package/package.json +10 -2
@@ -1,32 +1,136 @@
1
1
  /**
2
- * MCP (Model Context Protocol) SDK Adapter
2
+ * @fileoverview MCP (Model Context Protocol) SDK Adapter
3
3
  *
4
4
  * This module provides an adapter that bridges the MCP protocol to git operations,
5
5
  * handling request/response, tool registration/invocation, resource listing,
6
- * and error handling.
6
+ * and error handling. It implements the JSON-RPC 2.0 specification for MCP
7
+ * communication.
8
+ *
9
+ * The adapter supports:
10
+ * - Tool registration and invocation with schema validation
11
+ * - Resource registration and reading
12
+ * - Prompt registration and retrieval
13
+ * - Standard and custom MCP error codes
14
+ * - Batch request processing
15
+ * - Capability negotiation
16
+ *
17
+ * @module mcp/adapter
18
+ *
19
+ * @example
20
+ * // Create and configure an MCP adapter
21
+ * import { createMCPAdapter, MCPAdapter } from './adapter'
22
+ *
23
+ * const adapter = createMCPAdapter({
24
+ * name: 'my-git-server',
25
+ * version: '1.0.0',
26
+ * capabilities: ['tools', 'resources']
27
+ * })
28
+ *
29
+ * // Register git tools and start
30
+ * adapter.registerGitTools()
31
+ * await adapter.start()
32
+ *
33
+ * // Handle incoming requests
34
+ * const response = await adapter.handleRequest({
35
+ * jsonrpc: '2.0',
36
+ * id: 1,
37
+ * method: 'tools/list',
38
+ * params: {}
39
+ * })
40
+ *
41
+ * @example
42
+ * // Handle raw JSON requests
43
+ * const rawResponse = await adapter.handleRawRequest(
44
+ * '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}'
45
+ * )
7
46
  */
8
47
  import { type MCPToolResult } from './tools';
9
48
  /**
10
- * JSON-RPC 2.0 error codes and MCP-specific error codes
49
+ * JSON-RPC 2.0 error codes and MCP-specific error codes.
50
+ *
51
+ * @description
52
+ * Enumeration of error codes used in MCP responses. Includes standard
53
+ * JSON-RPC 2.0 error codes (negative 32xxx range) and MCP-specific
54
+ * error codes for resource, tool, and prompt operations.
55
+ *
56
+ * @enum {number}
57
+ *
58
+ * @example
59
+ * // Using error codes in responses
60
+ * if (!tool) {
61
+ * return {
62
+ * jsonrpc: '2.0',
63
+ * id: requestId,
64
+ * error: {
65
+ * code: MCPErrorCode.TOOL_NOT_FOUND,
66
+ * message: 'Tool not found'
67
+ * }
68
+ * }
69
+ * }
11
70
  */
12
71
  export declare enum MCPErrorCode {
72
+ /** Parse error - Invalid JSON was received (-32700) */
13
73
  PARSE_ERROR = -32700,
74
+ /** Invalid Request - The JSON sent is not a valid Request object (-32600) */
14
75
  INVALID_REQUEST = -32600,
76
+ /** Method not found - The method does not exist or is not available (-32601) */
15
77
  METHOD_NOT_FOUND = -32601,
78
+ /** Invalid params - Invalid method parameter(s) (-32602) */
16
79
  INVALID_PARAMS = -32602,
80
+ /** Internal error - Internal JSON-RPC error (-32603) */
17
81
  INTERNAL_ERROR = -32603,
82
+ /** Resource not found - The requested resource does not exist (-32001) */
18
83
  RESOURCE_NOT_FOUND = -32001,
84
+ /** Tool not found - Maps to METHOD_NOT_FOUND as tools are methods (-32601) */
19
85
  TOOL_NOT_FOUND = -32601,
86
+ /** Prompt not found - The requested prompt does not exist (-32003) */
20
87
  PROMPT_NOT_FOUND = -32003,
88
+ /** Capability not supported - The requested capability is not enabled (-32004) */
21
89
  CAPABILITY_NOT_SUPPORTED = -32004
22
90
  }
23
91
  /**
24
- * Custom error class for MCP errors
92
+ * Custom error class for MCP errors.
93
+ *
94
+ * @description
95
+ * Error class that encapsulates MCP error information including a numeric
96
+ * error code, human-readable message, and optional additional data. Can be
97
+ * serialized to JSON-RPC error format using the toJSON() method.
98
+ *
99
+ * @class MCPError
100
+ * @extends Error
101
+ *
102
+ * @example
103
+ * // Throw an MCP error
104
+ * throw new MCPError(
105
+ * MCPErrorCode.TOOL_NOT_FOUND,
106
+ * 'Tool "unknown_tool" not found',
107
+ * { toolName: 'unknown_tool' }
108
+ * )
109
+ *
110
+ * @example
111
+ * // Convert to JSON-RPC error format
112
+ * const error = new MCPError(MCPErrorCode.INVALID_PARAMS, 'Missing required field')
113
+ * const jsonError = error.toJSON()
114
+ * // { code: -32602, message: 'Missing required field' }
25
115
  */
26
116
  export declare class MCPError extends Error {
117
+ /** The MCP error code */
27
118
  code: MCPErrorCode;
119
+ /** Optional additional error data */
28
120
  data?: unknown;
121
+ /**
122
+ * Create a new MCP error.
123
+ *
124
+ * @param code - The MCP error code
125
+ * @param message - Human-readable error message
126
+ * @param data - Optional additional error data
127
+ */
29
128
  constructor(code: MCPErrorCode, message: string, data?: unknown);
129
+ /**
130
+ * Convert the error to JSON-RPC error format.
131
+ *
132
+ * @returns Object suitable for JSON-RPC error responses
133
+ */
30
134
  toJSON(): {
31
135
  code: MCPErrorCode;
32
136
  message: string;
@@ -34,79 +138,224 @@ export declare class MCPError extends Error {
34
138
  };
35
139
  }
36
140
  /**
37
- * MCP capability types
141
+ * MCP capability types.
142
+ *
143
+ * @description
144
+ * Type representing the different capabilities an MCP server can support.
145
+ * Capabilities are negotiated during initialization.
146
+ *
147
+ * @typedef {'tools' | 'resources' | 'prompts'} MCPCapability
38
148
  */
39
149
  export type MCPCapability = 'tools' | 'resources' | 'prompts';
40
150
  /**
41
- * Server configuration for MCP adapter
151
+ * Server configuration for MCP adapter.
152
+ *
153
+ * @description
154
+ * Configuration options for initializing an MCP adapter instance.
155
+ * All fields are optional with sensible defaults.
156
+ *
157
+ * @interface MCPServerConfig
158
+ *
159
+ * @example
160
+ * const config: MCPServerConfig = {
161
+ * name: 'my-git-server',
162
+ * version: '1.0.0',
163
+ * capabilities: ['tools', 'resources']
164
+ * }
42
165
  */
43
166
  export interface MCPServerConfig {
167
+ /** Server name (default: 'gitx.do') */
44
168
  name?: string;
169
+ /** Server version (default: '1.0.0') */
45
170
  version?: string;
171
+ /** Enabled capabilities (default: ['tools']) */
46
172
  capabilities?: MCPCapability[];
47
173
  }
48
174
  /**
49
- * MCP request structure (JSON-RPC 2.0)
175
+ * MCP request structure (JSON-RPC 2.0).
176
+ *
177
+ * @description
178
+ * Represents an incoming MCP request following the JSON-RPC 2.0 specification.
179
+ * Requests without an id are treated as notifications.
180
+ *
181
+ * @interface MCPRequest
182
+ *
183
+ * @example
184
+ * const request: MCPRequest = {
185
+ * jsonrpc: '2.0',
186
+ * id: 1,
187
+ * method: 'tools/call',
188
+ * params: { name: 'git_status', arguments: {} }
189
+ * }
50
190
  */
51
191
  export interface MCPRequest {
192
+ /** JSON-RPC version (must be '2.0') */
52
193
  jsonrpc: '2.0';
194
+ /** Request identifier (omit for notifications) */
53
195
  id?: string | number;
196
+ /** The method to invoke */
54
197
  method: string;
198
+ /** Method parameters */
55
199
  params?: Record<string, unknown>;
56
200
  }
57
201
  /**
58
- * MCP response structure (JSON-RPC 2.0)
202
+ * MCP response structure (JSON-RPC 2.0).
203
+ *
204
+ * @description
205
+ * Represents an outgoing MCP response. Contains either a result or an error,
206
+ * never both. Responses include the id from the corresponding request.
207
+ *
208
+ * @interface MCPResponse
209
+ *
210
+ * @example
211
+ * // Success response
212
+ * const success: MCPResponse = {
213
+ * jsonrpc: '2.0',
214
+ * id: 1,
215
+ * result: { tools: [...] }
216
+ * }
217
+ *
218
+ * // Error response
219
+ * const error: MCPResponse = {
220
+ * jsonrpc: '2.0',
221
+ * id: 1,
222
+ * error: { code: -32601, message: 'Method not found' }
223
+ * }
59
224
  */
60
225
  export interface MCPResponse {
226
+ /** JSON-RPC version (always '2.0') */
61
227
  jsonrpc: '2.0';
228
+ /** Request identifier from the corresponding request */
62
229
  id?: string | number;
230
+ /** Result data (mutually exclusive with error) */
63
231
  result?: unknown;
232
+ /** Error information (mutually exclusive with result) */
64
233
  error?: {
234
+ /** Numeric error code */
65
235
  code: number;
236
+ /** Human-readable error message */
66
237
  message: string;
238
+ /** Additional error data */
67
239
  data?: unknown;
68
240
  };
69
241
  }
70
242
  /**
71
- * Tool information for registration
243
+ * Tool information for registration.
244
+ *
245
+ * @description
246
+ * Complete tool definition including metadata, input schema, and handler
247
+ * function. Used when registering tools with the adapter.
248
+ *
249
+ * @interface MCPToolInfo
250
+ *
251
+ * @example
252
+ * const toolInfo: MCPToolInfo = {
253
+ * name: 'my_tool',
254
+ * description: 'Does something useful',
255
+ * inputSchema: {
256
+ * type: 'object',
257
+ * properties: { input: { type: 'string' } },
258
+ * required: ['input']
259
+ * },
260
+ * handler: async (params) => ({
261
+ * content: [{ type: 'text', text: 'Result' }]
262
+ * })
263
+ * }
72
264
  */
73
265
  export interface MCPToolInfo {
266
+ /** Unique tool name */
74
267
  name: string;
268
+ /** Human-readable description */
75
269
  description: string;
270
+ /** JSON Schema for input parameters */
76
271
  inputSchema: {
77
272
  type: string;
78
273
  properties?: Record<string, unknown>;
79
274
  required?: string[];
80
275
  };
276
+ /** Async function that executes the tool */
81
277
  handler: (params: Record<string, unknown>) => Promise<MCPToolResult>;
82
278
  }
83
279
  /**
84
- * Resource information for registration
280
+ * Resource information for registration.
281
+ *
282
+ * @description
283
+ * Defines a resource that can be read via the resources/read method.
284
+ * Resources have a URI, name, and optional handler for dynamic content.
285
+ *
286
+ * @interface MCPResourceInfo
287
+ *
288
+ * @example
289
+ * const resource: MCPResourceInfo = {
290
+ * uri: 'git://repo/HEAD',
291
+ * name: 'Current HEAD',
292
+ * mimeType: 'text/plain',
293
+ * description: 'The current HEAD commit',
294
+ * handler: async () => ({ content: 'abc123...' })
295
+ * }
85
296
  */
86
297
  export interface MCPResourceInfo {
298
+ /** Unique resource URI */
87
299
  uri: string;
300
+ /** Human-readable name */
88
301
  name: string;
302
+ /** MIME type of the resource content */
89
303
  mimeType?: string;
304
+ /** Human-readable description */
90
305
  description?: string;
306
+ /** Async function to retrieve resource content */
91
307
  handler?: () => Promise<{
92
308
  content: string;
93
309
  }>;
94
310
  }
95
311
  /**
96
- * Prompt argument definition
312
+ * Prompt argument definition.
313
+ *
314
+ * @description
315
+ * Defines an argument that can be passed to a prompt template.
316
+ *
317
+ * @interface MCPPromptArgument
97
318
  */
98
319
  export interface MCPPromptArgument {
320
+ /** Argument name */
99
321
  name: string;
322
+ /** Human-readable description */
100
323
  description?: string;
324
+ /** Whether this argument is required */
101
325
  required?: boolean;
102
326
  }
103
327
  /**
104
- * Prompt information for registration
328
+ * Prompt information for registration.
329
+ *
330
+ * @description
331
+ * Defines a prompt template that can be retrieved via prompts/get.
332
+ * Prompts can have arguments and a handler to generate messages.
333
+ *
334
+ * @interface MCPPromptInfo
335
+ *
336
+ * @example
337
+ * const prompt: MCPPromptInfo = {
338
+ * name: 'commit-message',
339
+ * description: 'Generate a commit message',
340
+ * arguments: [
341
+ * { name: 'changes', description: 'Description of changes', required: true }
342
+ * ],
343
+ * handler: async (args) => ({
344
+ * messages: [{
345
+ * role: 'user',
346
+ * content: { type: 'text', text: `Write commit message for: ${args.changes}` }
347
+ * }]
348
+ * })
349
+ * }
105
350
  */
106
351
  export interface MCPPromptInfo {
352
+ /** Unique prompt name */
107
353
  name: string;
354
+ /** Human-readable description */
108
355
  description?: string;
356
+ /** Prompt arguments */
109
357
  arguments?: MCPPromptArgument[];
358
+ /** Async function to generate prompt messages */
110
359
  handler?: (args: Record<string, unknown>) => Promise<{
111
360
  messages: Array<{
112
361
  role: string;
@@ -118,114 +367,406 @@ export interface MCPPromptInfo {
118
367
  }>;
119
368
  }
120
369
  /**
121
- * MCP Adapter class that bridges MCP protocol to git operations
370
+ * MCP Adapter class that bridges MCP protocol to git operations.
371
+ *
372
+ * @description
373
+ * The main adapter class that handles MCP protocol communication. It manages
374
+ * tool, resource, and prompt registrations, processes JSON-RPC requests,
375
+ * and returns properly formatted responses.
376
+ *
377
+ * The adapter supports the following MCP methods:
378
+ * - initialize: Server initialization and capability negotiation
379
+ * - tools/list: List all registered tools
380
+ * - tools/call: Invoke a registered tool
381
+ * - resources/list: List all registered resources
382
+ * - resources/read: Read a resource's content
383
+ * - prompts/list: List all registered prompts
384
+ * - prompts/get: Get a prompt's generated messages
385
+ *
386
+ * @class MCPAdapter
387
+ *
388
+ * @example
389
+ * // Create and use an adapter
390
+ * const adapter = new MCPAdapter({
391
+ * name: 'my-server',
392
+ * version: '1.0.0',
393
+ * capabilities: ['tools']
394
+ * })
395
+ *
396
+ * adapter.registerGitTools()
397
+ * await adapter.start()
398
+ *
399
+ * const response = await adapter.handleRequest({
400
+ * jsonrpc: '2.0',
401
+ * id: 1,
402
+ * method: 'tools/list'
403
+ * })
122
404
  */
123
405
  export declare class MCPAdapter {
406
+ /** @internal */
124
407
  private config;
408
+ /** @internal */
125
409
  private initialized;
410
+ /** @internal */
126
411
  private tools;
412
+ /** @internal */
127
413
  private resources;
414
+ /** @internal */
128
415
  private prompts;
416
+ /**
417
+ * Create a new MCP adapter instance.
418
+ *
419
+ * @param config - Optional configuration options
420
+ *
421
+ * @example
422
+ * const adapter = new MCPAdapter({
423
+ * name: 'git-mcp-server',
424
+ * version: '2.0.0',
425
+ * capabilities: ['tools', 'resources', 'prompts']
426
+ * })
427
+ */
129
428
  constructor(config?: MCPServerConfig);
130
429
  /**
131
- * Get the server configuration
430
+ * Get the server configuration.
431
+ *
432
+ * @description
433
+ * Returns a copy of the current server configuration including name,
434
+ * version, and enabled capabilities.
435
+ *
436
+ * @returns A copy of the server configuration
437
+ *
438
+ * @example
439
+ * const config = adapter.getConfig()
440
+ * console.log(`Server: ${config.name} v${config.version}`)
132
441
  */
133
442
  getConfig(): MCPServerConfig;
134
443
  /**
135
- * Check if adapter has a specific capability
444
+ * Check if adapter has a specific capability.
445
+ *
446
+ * @description
447
+ * Tests whether a specific capability is enabled for this adapter.
448
+ * Used internally to determine which methods are available.
449
+ *
450
+ * @param capability - The capability to check ('tools', 'resources', or 'prompts')
451
+ * @returns True if the capability is enabled
452
+ *
453
+ * @example
454
+ * if (adapter.hasCapability('resources')) {
455
+ * adapter.registerResource(myResource)
456
+ * }
136
457
  */
137
458
  hasCapability(capability: MCPCapability): boolean;
138
459
  /**
139
- * Check if the adapter is initialized
460
+ * Check if the adapter is initialized.
461
+ *
462
+ * @description
463
+ * Returns whether the adapter has been started and is ready to handle requests.
464
+ *
465
+ * @returns True if the adapter is initialized and running
140
466
  */
141
467
  isInitialized(): boolean;
142
468
  /**
143
- * Start the MCP adapter
469
+ * Start the MCP adapter.
470
+ *
471
+ * @description
472
+ * Initializes the adapter and prepares it to handle requests.
473
+ * Must be called before processing any MCP requests.
474
+ *
475
+ * @returns Promise that resolves when the adapter is started
476
+ * @throws {Error} If the adapter is already started
477
+ *
478
+ * @example
479
+ * const adapter = new MCPAdapter()
480
+ * await adapter.start()
481
+ * // Adapter is now ready to handle requests
144
482
  */
145
483
  start(): Promise<void>;
146
484
  /**
147
- * Stop the MCP adapter
485
+ * Stop the MCP adapter.
486
+ *
487
+ * @description
488
+ * Shuts down the adapter and clears all registered tools, resources,
489
+ * and prompts. After stopping, the adapter must be restarted before
490
+ * handling new requests.
491
+ *
492
+ * @returns Promise that resolves when the adapter is stopped
493
+ * @throws {Error} If the adapter is not currently running
494
+ *
495
+ * @example
496
+ * await adapter.stop()
497
+ * // All registrations are cleared
148
498
  */
149
499
  stop(): Promise<void>;
150
500
  /**
151
- * Register a tool
501
+ * Register a tool.
502
+ *
503
+ * @description
504
+ * Adds a tool to the adapter's registry. The tool will be available
505
+ * for listing via tools/list and invocation via tools/call.
506
+ *
507
+ * @param toolInfo - The tool definition to register
508
+ * @returns void
509
+ * @throws {Error} If a tool with the same name is already registered
510
+ *
511
+ * @example
512
+ * adapter.registerTool({
513
+ * name: 'my_tool',
514
+ * description: 'Does something',
515
+ * inputSchema: { type: 'object', properties: {} },
516
+ * handler: async (params) => ({
517
+ * content: [{ type: 'text', text: 'Done' }]
518
+ * })
519
+ * })
152
520
  */
153
521
  registerTool(toolInfo: MCPToolInfo): void;
154
522
  /**
155
- * Unregister a tool by name
523
+ * Unregister a tool by name.
524
+ *
525
+ * @description
526
+ * Removes a tool from the adapter's registry. The tool will no longer
527
+ * be available for listing or invocation.
528
+ *
529
+ * @param name - The name of the tool to unregister
530
+ * @returns void
531
+ * @throws {Error} If no tool with the given name exists
532
+ *
533
+ * @example
534
+ * adapter.unregisterTool('my_tool')
156
535
  */
157
536
  unregisterTool(name: string): void;
158
537
  /**
159
- * List all registered tools (without handlers)
538
+ * List all registered tools (without handlers).
539
+ *
540
+ * @description
541
+ * Returns an array of all registered tools with their metadata.
542
+ * Handler functions are omitted for serialization safety.
543
+ *
544
+ * @returns Array of tool definitions without handlers
545
+ *
546
+ * @example
547
+ * const tools = adapter.listTools()
548
+ * for (const tool of tools) {
549
+ * console.log(`${tool.name}: ${tool.description}`)
550
+ * }
160
551
  */
161
552
  listTools(): Array<Omit<MCPToolInfo, 'handler'>>;
162
553
  /**
163
- * Get a tool by name (without handler)
554
+ * Get a tool by name (without handler).
555
+ *
556
+ * @description
557
+ * Retrieves a single tool's metadata by name. Returns undefined if
558
+ * the tool is not found.
559
+ *
560
+ * @param name - The name of the tool to retrieve
561
+ * @returns The tool definition without handler, or undefined if not found
562
+ *
563
+ * @example
564
+ * const tool = adapter.getTool('git_status')
565
+ * if (tool) {
566
+ * console.log(tool.description)
567
+ * }
164
568
  */
165
569
  getTool(name: string): Omit<MCPToolInfo, 'handler'> | undefined;
166
570
  /**
167
- * Register all git tools
571
+ * Register all git tools.
572
+ *
573
+ * @description
574
+ * Convenience method that registers all built-in git tools from the
575
+ * tools module. Skips any tools that are already registered.
576
+ *
577
+ * @returns void
578
+ *
579
+ * @example
580
+ * const adapter = new MCPAdapter()
581
+ * adapter.registerGitTools()
582
+ * // All 18 git tools are now registered
168
583
  */
169
584
  registerGitTools(): void;
170
585
  /**
171
- * Register a resource
586
+ * Register a resource.
587
+ *
588
+ * @description
589
+ * Adds a resource to the adapter's registry. The resource will be
590
+ * available for listing and reading via the resources/* methods.
591
+ *
592
+ * @param resourceInfo - The resource definition to register
593
+ * @returns void
594
+ *
595
+ * @example
596
+ * adapter.registerResource({
597
+ * uri: 'git://repo/config',
598
+ * name: 'Repository Config',
599
+ * mimeType: 'application/json',
600
+ * handler: async () => ({ content: JSON.stringify(config) })
601
+ * })
172
602
  */
173
603
  registerResource(resourceInfo: MCPResourceInfo): void;
174
604
  /**
175
- * Register a prompt
605
+ * Register a prompt.
606
+ *
607
+ * @description
608
+ * Adds a prompt template to the adapter's registry. The prompt will
609
+ * be available for listing and retrieval via the prompts/* methods.
610
+ *
611
+ * @param promptInfo - The prompt definition to register
612
+ * @returns void
613
+ *
614
+ * @example
615
+ * adapter.registerPrompt({
616
+ * name: 'review-code',
617
+ * description: 'Review code changes',
618
+ * handler: async () => ({
619
+ * messages: [{ role: 'user', content: { type: 'text', text: '...' } }]
620
+ * })
621
+ * })
176
622
  */
177
623
  registerPrompt(promptInfo: MCPPromptInfo): void;
178
624
  /**
179
- * Handle a raw JSON string request
625
+ * Handle a raw JSON string request.
626
+ *
627
+ * @description
628
+ * Parses a raw JSON string as an MCP request and processes it.
629
+ * Returns a parse error response if the JSON is invalid.
630
+ *
631
+ * @param rawRequest - Raw JSON string containing the request
632
+ * @returns Promise resolving to the MCP response
633
+ *
634
+ * @example
635
+ * const response = await adapter.handleRawRequest(
636
+ * '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
637
+ * )
180
638
  */
181
639
  handleRawRequest(rawRequest: string): Promise<MCPResponse>;
182
640
  /**
183
- * Handle a batch of requests
641
+ * Handle a batch of requests.
642
+ *
643
+ * @description
644
+ * Processes multiple MCP requests sequentially. Notifications (requests
645
+ * without an id) are processed but do not produce responses.
646
+ *
647
+ * @param requests - Array of MCP requests to process
648
+ * @returns Promise resolving to array of responses (excluding notifications)
649
+ *
650
+ * @example
651
+ * const responses = await adapter.handleBatchRequest([
652
+ * { jsonrpc: '2.0', id: 1, method: 'tools/list' },
653
+ * { jsonrpc: '2.0', id: 2, method: 'initialize', params: {} }
654
+ * ])
184
655
  */
185
656
  handleBatchRequest(requests: MCPRequest[]): Promise<MCPResponse[]>;
186
657
  /**
187
- * Handle a single MCP request
658
+ * Handle a single MCP request.
659
+ *
660
+ * @description
661
+ * Main request handler that routes MCP requests to the appropriate
662
+ * method handler. Supports initialize, tools/*, resources/*, and prompts/*
663
+ * methods. Returns undefined for notifications (requests without id).
664
+ *
665
+ * @param request - The MCP request to handle
666
+ * @returns Promise resolving to response, or undefined for notifications
667
+ *
668
+ * @example
669
+ * const response = await adapter.handleRequest({
670
+ * jsonrpc: '2.0',
671
+ * id: 1,
672
+ * method: 'tools/call',
673
+ * params: { name: 'git_status', arguments: {} }
674
+ * })
188
675
  */
189
676
  handleRequest(request: MCPRequest): Promise<MCPResponse | undefined>;
190
677
  /**
191
- * Handle initialize request
678
+ * Handle initialize request.
679
+ *
680
+ * @description
681
+ * Processes the MCP initialize request and returns server information
682
+ * and capabilities. This is the first request a client should send.
683
+ *
684
+ * @param request - The initialize request
685
+ * @returns Response with server info and capabilities
686
+ * @internal
192
687
  */
193
688
  private handleInitialize;
194
689
  /**
195
- * Handle tools/list request
690
+ * Handle tools/list request.
691
+ * @param request - The tools/list request
692
+ * @returns Response with list of registered tools
693
+ * @internal
196
694
  */
197
695
  private handleToolsList;
198
696
  /**
199
- * Handle tools/call request
697
+ * Handle tools/call request.
698
+ * @param request - The tools/call request with tool name and arguments
699
+ * @returns Response with tool execution result
700
+ * @internal
200
701
  */
201
702
  private handleToolsCall;
202
703
  /**
203
- * Validate tool parameters against schema
704
+ * Validate tool parameters against schema.
705
+ * @param tool - The tool to validate parameters for
706
+ * @param params - The parameters to validate
707
+ * @returns Validation result with errors array
708
+ * @internal
204
709
  */
205
710
  private validateToolParams;
206
711
  /**
207
- * Handle resources/list request
712
+ * Handle resources/list request.
713
+ * @param request - The resources/list request
714
+ * @returns Response with list of registered resources
715
+ * @internal
208
716
  */
209
717
  private handleResourcesList;
210
718
  /**
211
- * Handle resources/read request
719
+ * Handle resources/read request.
720
+ * @param request - The resources/read request with URI
721
+ * @returns Response with resource content
722
+ * @internal
212
723
  */
213
724
  private handleResourcesRead;
214
725
  /**
215
- * Handle prompts/list request
726
+ * Handle prompts/list request.
727
+ * @param request - The prompts/list request
728
+ * @returns Response with list of registered prompts
729
+ * @internal
216
730
  */
217
731
  private handlePromptsList;
218
732
  /**
219
- * Handle prompts/get request
733
+ * Handle prompts/get request.
734
+ * @param request - The prompts/get request with name and arguments
735
+ * @returns Response with generated prompt messages
736
+ * @internal
220
737
  */
221
738
  private handlePromptsGet;
222
739
  /**
223
- * Create an error response
740
+ * Create an error response.
741
+ * @param id - Request ID
742
+ * @param code - Error code
743
+ * @param message - Error message
744
+ * @param data - Optional additional error data
745
+ * @returns Formatted error response
746
+ * @internal
224
747
  */
225
748
  private errorResponse;
226
749
  }
227
750
  /**
228
- * Factory function to create an MCP adapter
751
+ * Factory function to create an MCP adapter.
752
+ *
753
+ * @description
754
+ * Convenience function for creating a new MCP adapter instance.
755
+ * Equivalent to using `new MCPAdapter(config)`.
756
+ *
757
+ * @param config - Optional server configuration
758
+ * @returns A new MCPAdapter instance
759
+ *
760
+ * @example
761
+ * import { createMCPAdapter } from './adapter'
762
+ *
763
+ * const adapter = createMCPAdapter({
764
+ * name: 'my-git-server',
765
+ * capabilities: ['tools', 'resources']
766
+ * })
767
+ *
768
+ * adapter.registerGitTools()
769
+ * await adapter.start()
229
770
  */
230
771
  export declare function createMCPAdapter(config?: MCPServerConfig): MCPAdapter;
231
772
  //# sourceMappingURL=adapter.d.ts.map