gitx.do 0.1.0 → 0.1.2

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 (344) hide show
  1. package/README.md +40 -353
  2. package/dist/do/logger.d.ts +50 -0
  3. package/dist/do/logger.d.ts.map +1 -0
  4. package/dist/do/logger.js +122 -0
  5. package/dist/do/logger.js.map +1 -0
  6. package/dist/{durable-object → do}/schema.d.ts +3 -3
  7. package/dist/do/schema.d.ts.map +1 -0
  8. package/dist/{durable-object → do}/schema.js +4 -3
  9. package/dist/do/schema.js.map +1 -0
  10. package/dist/do/types.d.ts +267 -0
  11. package/dist/do/types.d.ts.map +1 -0
  12. package/dist/do/types.js +62 -0
  13. package/dist/do/types.js.map +1 -0
  14. package/dist/index.d.ts +15 -415
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +31 -483
  17. package/dist/index.js.map +1 -1
  18. package/package.json +13 -21
  19. package/dist/cli/commands/add.d.ts +0 -174
  20. package/dist/cli/commands/add.d.ts.map +0 -1
  21. package/dist/cli/commands/add.js +0 -131
  22. package/dist/cli/commands/add.js.map +0 -1
  23. package/dist/cli/commands/blame.d.ts +0 -259
  24. package/dist/cli/commands/blame.d.ts.map +0 -1
  25. package/dist/cli/commands/blame.js +0 -609
  26. package/dist/cli/commands/blame.js.map +0 -1
  27. package/dist/cli/commands/branch.d.ts +0 -249
  28. package/dist/cli/commands/branch.d.ts.map +0 -1
  29. package/dist/cli/commands/branch.js +0 -693
  30. package/dist/cli/commands/branch.js.map +0 -1
  31. package/dist/cli/commands/commit.d.ts +0 -182
  32. package/dist/cli/commands/commit.d.ts.map +0 -1
  33. package/dist/cli/commands/commit.js +0 -437
  34. package/dist/cli/commands/commit.js.map +0 -1
  35. package/dist/cli/commands/diff.d.ts +0 -464
  36. package/dist/cli/commands/diff.d.ts.map +0 -1
  37. package/dist/cli/commands/diff.js +0 -958
  38. package/dist/cli/commands/diff.js.map +0 -1
  39. package/dist/cli/commands/log.d.ts +0 -239
  40. package/dist/cli/commands/log.d.ts.map +0 -1
  41. package/dist/cli/commands/log.js +0 -535
  42. package/dist/cli/commands/log.js.map +0 -1
  43. package/dist/cli/commands/merge.d.ts +0 -106
  44. package/dist/cli/commands/merge.d.ts.map +0 -1
  45. package/dist/cli/commands/merge.js +0 -55
  46. package/dist/cli/commands/merge.js.map +0 -1
  47. package/dist/cli/commands/review.d.ts +0 -457
  48. package/dist/cli/commands/review.d.ts.map +0 -1
  49. package/dist/cli/commands/review.js +0 -533
  50. package/dist/cli/commands/review.js.map +0 -1
  51. package/dist/cli/commands/status.d.ts +0 -269
  52. package/dist/cli/commands/status.d.ts.map +0 -1
  53. package/dist/cli/commands/status.js +0 -493
  54. package/dist/cli/commands/status.js.map +0 -1
  55. package/dist/cli/commands/web.d.ts +0 -199
  56. package/dist/cli/commands/web.d.ts.map +0 -1
  57. package/dist/cli/commands/web.js +0 -696
  58. package/dist/cli/commands/web.js.map +0 -1
  59. package/dist/cli/fs-adapter.d.ts +0 -656
  60. package/dist/cli/fs-adapter.d.ts.map +0 -1
  61. package/dist/cli/fs-adapter.js +0 -1179
  62. package/dist/cli/fs-adapter.js.map +0 -1
  63. package/dist/cli/fsx-cli-adapter.d.ts +0 -359
  64. package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
  65. package/dist/cli/fsx-cli-adapter.js +0 -619
  66. package/dist/cli/fsx-cli-adapter.js.map +0 -1
  67. package/dist/cli/index.d.ts +0 -387
  68. package/dist/cli/index.d.ts.map +0 -1
  69. package/dist/cli/index.js +0 -523
  70. package/dist/cli/index.js.map +0 -1
  71. package/dist/cli/ui/components/DiffView.d.ts +0 -7
  72. package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
  73. package/dist/cli/ui/components/DiffView.js +0 -11
  74. package/dist/cli/ui/components/DiffView.js.map +0 -1
  75. package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -6
  76. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
  77. package/dist/cli/ui/components/ErrorDisplay.js +0 -11
  78. package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
  79. package/dist/cli/ui/components/FuzzySearch.d.ts +0 -9
  80. package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
  81. package/dist/cli/ui/components/FuzzySearch.js +0 -12
  82. package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
  83. package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -6
  84. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
  85. package/dist/cli/ui/components/LoadingSpinner.js +0 -10
  86. package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
  87. package/dist/cli/ui/components/NavigationList.d.ts +0 -9
  88. package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
  89. package/dist/cli/ui/components/NavigationList.js +0 -11
  90. package/dist/cli/ui/components/NavigationList.js.map +0 -1
  91. package/dist/cli/ui/components/ScrollableContent.d.ts +0 -8
  92. package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
  93. package/dist/cli/ui/components/ScrollableContent.js +0 -11
  94. package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
  95. package/dist/cli/ui/components/index.d.ts +0 -7
  96. package/dist/cli/ui/components/index.d.ts.map +0 -1
  97. package/dist/cli/ui/components/index.js +0 -9
  98. package/dist/cli/ui/components/index.js.map +0 -1
  99. package/dist/cli/ui/terminal-ui.d.ts +0 -52
  100. package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
  101. package/dist/cli/ui/terminal-ui.js +0 -121
  102. package/dist/cli/ui/terminal-ui.js.map +0 -1
  103. package/dist/do/BashModule.d.ts +0 -871
  104. package/dist/do/BashModule.d.ts.map +0 -1
  105. package/dist/do/BashModule.js +0 -1143
  106. package/dist/do/BashModule.js.map +0 -1
  107. package/dist/do/FsModule.d.ts +0 -601
  108. package/dist/do/FsModule.d.ts.map +0 -1
  109. package/dist/do/FsModule.js +0 -1120
  110. package/dist/do/FsModule.js.map +0 -1
  111. package/dist/do/GitModule.d.ts +0 -635
  112. package/dist/do/GitModule.d.ts.map +0 -1
  113. package/dist/do/GitModule.js +0 -781
  114. package/dist/do/GitModule.js.map +0 -1
  115. package/dist/do/GitRepoDO.d.ts +0 -281
  116. package/dist/do/GitRepoDO.d.ts.map +0 -1
  117. package/dist/do/GitRepoDO.js +0 -479
  118. package/dist/do/GitRepoDO.js.map +0 -1
  119. package/dist/do/bash-ast.d.ts +0 -246
  120. package/dist/do/bash-ast.d.ts.map +0 -1
  121. package/dist/do/bash-ast.js +0 -888
  122. package/dist/do/bash-ast.js.map +0 -1
  123. package/dist/do/container-executor.d.ts +0 -491
  124. package/dist/do/container-executor.d.ts.map +0 -1
  125. package/dist/do/container-executor.js +0 -730
  126. package/dist/do/container-executor.js.map +0 -1
  127. package/dist/do/index.d.ts +0 -53
  128. package/dist/do/index.d.ts.map +0 -1
  129. package/dist/do/index.js +0 -91
  130. package/dist/do/index.js.map +0 -1
  131. package/dist/do/tiered-storage.d.ts +0 -403
  132. package/dist/do/tiered-storage.d.ts.map +0 -1
  133. package/dist/do/tiered-storage.js +0 -689
  134. package/dist/do/tiered-storage.js.map +0 -1
  135. package/dist/do/withBash.d.ts +0 -231
  136. package/dist/do/withBash.d.ts.map +0 -1
  137. package/dist/do/withBash.js +0 -244
  138. package/dist/do/withBash.js.map +0 -1
  139. package/dist/do/withFs.d.ts +0 -237
  140. package/dist/do/withFs.d.ts.map +0 -1
  141. package/dist/do/withFs.js +0 -387
  142. package/dist/do/withFs.js.map +0 -1
  143. package/dist/do/withGit.d.ts +0 -180
  144. package/dist/do/withGit.d.ts.map +0 -1
  145. package/dist/do/withGit.js +0 -271
  146. package/dist/do/withGit.js.map +0 -1
  147. package/dist/durable-object/object-store.d.ts +0 -633
  148. package/dist/durable-object/object-store.d.ts.map +0 -1
  149. package/dist/durable-object/object-store.js +0 -1161
  150. package/dist/durable-object/object-store.js.map +0 -1
  151. package/dist/durable-object/schema.d.ts.map +0 -1
  152. package/dist/durable-object/schema.js.map +0 -1
  153. package/dist/durable-object/wal.d.ts +0 -416
  154. package/dist/durable-object/wal.d.ts.map +0 -1
  155. package/dist/durable-object/wal.js +0 -445
  156. package/dist/durable-object/wal.js.map +0 -1
  157. package/dist/mcp/adapter.d.ts +0 -772
  158. package/dist/mcp/adapter.d.ts.map +0 -1
  159. package/dist/mcp/adapter.js +0 -895
  160. package/dist/mcp/adapter.js.map +0 -1
  161. package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
  162. package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
  163. package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
  164. package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
  165. package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
  166. package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
  167. package/dist/mcp/sandbox/object-store-proxy.js +0 -30
  168. package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
  169. package/dist/mcp/sandbox/template.d.ts +0 -17
  170. package/dist/mcp/sandbox/template.d.ts.map +0 -1
  171. package/dist/mcp/sandbox/template.js +0 -71
  172. package/dist/mcp/sandbox/template.js.map +0 -1
  173. package/dist/mcp/sandbox.d.ts +0 -764
  174. package/dist/mcp/sandbox.d.ts.map +0 -1
  175. package/dist/mcp/sandbox.js +0 -1362
  176. package/dist/mcp/sandbox.js.map +0 -1
  177. package/dist/mcp/sdk-adapter.d.ts +0 -835
  178. package/dist/mcp/sdk-adapter.d.ts.map +0 -1
  179. package/dist/mcp/sdk-adapter.js +0 -974
  180. package/dist/mcp/sdk-adapter.js.map +0 -1
  181. package/dist/mcp/tools/do.d.ts +0 -32
  182. package/dist/mcp/tools/do.d.ts.map +0 -1
  183. package/dist/mcp/tools/do.js +0 -115
  184. package/dist/mcp/tools/do.js.map +0 -1
  185. package/dist/mcp/tools.d.ts +0 -548
  186. package/dist/mcp/tools.d.ts.map +0 -1
  187. package/dist/mcp/tools.js +0 -1934
  188. package/dist/mcp/tools.js.map +0 -1
  189. package/dist/ops/blame.d.ts +0 -551
  190. package/dist/ops/blame.d.ts.map +0 -1
  191. package/dist/ops/blame.js +0 -1037
  192. package/dist/ops/blame.js.map +0 -1
  193. package/dist/ops/branch.d.ts +0 -766
  194. package/dist/ops/branch.d.ts.map +0 -1
  195. package/dist/ops/branch.js +0 -950
  196. package/dist/ops/branch.js.map +0 -1
  197. package/dist/ops/commit-traversal.d.ts +0 -349
  198. package/dist/ops/commit-traversal.d.ts.map +0 -1
  199. package/dist/ops/commit-traversal.js +0 -821
  200. package/dist/ops/commit-traversal.js.map +0 -1
  201. package/dist/ops/commit.d.ts +0 -555
  202. package/dist/ops/commit.d.ts.map +0 -1
  203. package/dist/ops/commit.js +0 -826
  204. package/dist/ops/commit.js.map +0 -1
  205. package/dist/ops/merge-base.d.ts +0 -397
  206. package/dist/ops/merge-base.d.ts.map +0 -1
  207. package/dist/ops/merge-base.js +0 -691
  208. package/dist/ops/merge-base.js.map +0 -1
  209. package/dist/ops/merge.d.ts +0 -855
  210. package/dist/ops/merge.d.ts.map +0 -1
  211. package/dist/ops/merge.js +0 -1551
  212. package/dist/ops/merge.js.map +0 -1
  213. package/dist/ops/tag.d.ts +0 -247
  214. package/dist/ops/tag.d.ts.map +0 -1
  215. package/dist/ops/tag.js +0 -649
  216. package/dist/ops/tag.js.map +0 -1
  217. package/dist/ops/tree-builder.d.ts +0 -178
  218. package/dist/ops/tree-builder.d.ts.map +0 -1
  219. package/dist/ops/tree-builder.js +0 -271
  220. package/dist/ops/tree-builder.js.map +0 -1
  221. package/dist/ops/tree-diff.d.ts +0 -291
  222. package/dist/ops/tree-diff.d.ts.map +0 -1
  223. package/dist/ops/tree-diff.js +0 -705
  224. package/dist/ops/tree-diff.js.map +0 -1
  225. package/dist/pack/delta.d.ts +0 -248
  226. package/dist/pack/delta.d.ts.map +0 -1
  227. package/dist/pack/delta.js +0 -736
  228. package/dist/pack/delta.js.map +0 -1
  229. package/dist/pack/format.d.ts +0 -446
  230. package/dist/pack/format.d.ts.map +0 -1
  231. package/dist/pack/format.js +0 -572
  232. package/dist/pack/format.js.map +0 -1
  233. package/dist/pack/full-generation.d.ts +0 -612
  234. package/dist/pack/full-generation.d.ts.map +0 -1
  235. package/dist/pack/full-generation.js +0 -1378
  236. package/dist/pack/full-generation.js.map +0 -1
  237. package/dist/pack/generation.d.ts +0 -441
  238. package/dist/pack/generation.d.ts.map +0 -1
  239. package/dist/pack/generation.js +0 -707
  240. package/dist/pack/generation.js.map +0 -1
  241. package/dist/pack/index.d.ts +0 -502
  242. package/dist/pack/index.d.ts.map +0 -1
  243. package/dist/pack/index.js +0 -833
  244. package/dist/pack/index.js.map +0 -1
  245. package/dist/refs/branch.d.ts +0 -668
  246. package/dist/refs/branch.d.ts.map +0 -1
  247. package/dist/refs/branch.js +0 -897
  248. package/dist/refs/branch.js.map +0 -1
  249. package/dist/refs/storage.d.ts +0 -833
  250. package/dist/refs/storage.d.ts.map +0 -1
  251. package/dist/refs/storage.js +0 -1023
  252. package/dist/refs/storage.js.map +0 -1
  253. package/dist/refs/tag.d.ts +0 -860
  254. package/dist/refs/tag.d.ts.map +0 -1
  255. package/dist/refs/tag.js +0 -996
  256. package/dist/refs/tag.js.map +0 -1
  257. package/dist/storage/backend.d.ts +0 -425
  258. package/dist/storage/backend.d.ts.map +0 -1
  259. package/dist/storage/backend.js +0 -41
  260. package/dist/storage/backend.js.map +0 -1
  261. package/dist/storage/fsx-adapter.d.ts +0 -204
  262. package/dist/storage/fsx-adapter.d.ts.map +0 -1
  263. package/dist/storage/fsx-adapter.js +0 -470
  264. package/dist/storage/fsx-adapter.js.map +0 -1
  265. package/dist/storage/lru-cache.d.ts +0 -691
  266. package/dist/storage/lru-cache.d.ts.map +0 -1
  267. package/dist/storage/lru-cache.js +0 -813
  268. package/dist/storage/lru-cache.js.map +0 -1
  269. package/dist/storage/object-index.d.ts +0 -585
  270. package/dist/storage/object-index.d.ts.map +0 -1
  271. package/dist/storage/object-index.js +0 -532
  272. package/dist/storage/object-index.js.map +0 -1
  273. package/dist/storage/r2-pack.d.ts +0 -1257
  274. package/dist/storage/r2-pack.d.ts.map +0 -1
  275. package/dist/storage/r2-pack.js +0 -1770
  276. package/dist/storage/r2-pack.js.map +0 -1
  277. package/dist/tiered/cdc-pipeline.d.ts +0 -1888
  278. package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
  279. package/dist/tiered/cdc-pipeline.js +0 -1880
  280. package/dist/tiered/cdc-pipeline.js.map +0 -1
  281. package/dist/tiered/migration.d.ts +0 -1104
  282. package/dist/tiered/migration.d.ts.map +0 -1
  283. package/dist/tiered/migration.js +0 -1214
  284. package/dist/tiered/migration.js.map +0 -1
  285. package/dist/tiered/parquet-writer.d.ts +0 -1145
  286. package/dist/tiered/parquet-writer.d.ts.map +0 -1
  287. package/dist/tiered/parquet-writer.js +0 -1183
  288. package/dist/tiered/parquet-writer.js.map +0 -1
  289. package/dist/tiered/read-path.d.ts +0 -835
  290. package/dist/tiered/read-path.d.ts.map +0 -1
  291. package/dist/tiered/read-path.js +0 -487
  292. package/dist/tiered/read-path.js.map +0 -1
  293. package/dist/types/capability.d.ts +0 -1385
  294. package/dist/types/capability.d.ts.map +0 -1
  295. package/dist/types/capability.js +0 -36
  296. package/dist/types/capability.js.map +0 -1
  297. package/dist/types/index.d.ts +0 -13
  298. package/dist/types/index.d.ts.map +0 -1
  299. package/dist/types/index.js +0 -18
  300. package/dist/types/index.js.map +0 -1
  301. package/dist/types/objects.d.ts +0 -692
  302. package/dist/types/objects.d.ts.map +0 -1
  303. package/dist/types/objects.js +0 -837
  304. package/dist/types/objects.js.map +0 -1
  305. package/dist/types/storage.d.ts +0 -603
  306. package/dist/types/storage.d.ts.map +0 -1
  307. package/dist/types/storage.js +0 -191
  308. package/dist/types/storage.js.map +0 -1
  309. package/dist/types/worker-loader.d.ts +0 -60
  310. package/dist/types/worker-loader.d.ts.map +0 -1
  311. package/dist/types/worker-loader.js +0 -62
  312. package/dist/types/worker-loader.js.map +0 -1
  313. package/dist/utils/hash.d.ts +0 -197
  314. package/dist/utils/hash.d.ts.map +0 -1
  315. package/dist/utils/hash.js +0 -268
  316. package/dist/utils/hash.js.map +0 -1
  317. package/dist/utils/sha1.d.ts +0 -290
  318. package/dist/utils/sha1.d.ts.map +0 -1
  319. package/dist/utils/sha1.js +0 -582
  320. package/dist/utils/sha1.js.map +0 -1
  321. package/dist/wire/capabilities.d.ts +0 -1044
  322. package/dist/wire/capabilities.d.ts.map +0 -1
  323. package/dist/wire/capabilities.js +0 -941
  324. package/dist/wire/capabilities.js.map +0 -1
  325. package/dist/wire/path-security.d.ts +0 -157
  326. package/dist/wire/path-security.d.ts.map +0 -1
  327. package/dist/wire/path-security.js +0 -307
  328. package/dist/wire/path-security.js.map +0 -1
  329. package/dist/wire/pkt-line.d.ts +0 -345
  330. package/dist/wire/pkt-line.d.ts.map +0 -1
  331. package/dist/wire/pkt-line.js +0 -381
  332. package/dist/wire/pkt-line.js.map +0 -1
  333. package/dist/wire/receive-pack.d.ts +0 -1059
  334. package/dist/wire/receive-pack.d.ts.map +0 -1
  335. package/dist/wire/receive-pack.js +0 -1414
  336. package/dist/wire/receive-pack.js.map +0 -1
  337. package/dist/wire/smart-http.d.ts +0 -799
  338. package/dist/wire/smart-http.d.ts.map +0 -1
  339. package/dist/wire/smart-http.js +0 -945
  340. package/dist/wire/smart-http.js.map +0 -1
  341. package/dist/wire/upload-pack.d.ts +0 -727
  342. package/dist/wire/upload-pack.d.ts.map +0 -1
  343. package/dist/wire/upload-pack.js +0 -1138
  344. package/dist/wire/upload-pack.js.map +0 -1
@@ -1,974 +0,0 @@
1
- /**
2
- * @fileoverview MCP SDK Adapter
3
- *
4
- * This module provides a full-featured adapter for the MCP SDK,
5
- * including SDK initialization, tool registration, request/response
6
- * handling, error propagation, and connection lifecycle management.
7
- *
8
- * The SDK adapter extends the basic adapter with:
9
- * - Multiple transport support (stdio, SSE, HTTP)
10
- * - Connection state management and events
11
- * - Request cancellation and progress reporting
12
- * - Session management with client information
13
- * - Ping/pong health checking
14
- * - Graceful shutdown with pending request handling
15
- *
16
- * @module mcp/sdk-adapter
17
- *
18
- * @example
19
- * // Create and start an SDK adapter
20
- * import { createMCPSDKAdapter, MCPSDKTransport } from './sdk-adapter'
21
- *
22
- * const adapter = createMCPSDKAdapter({
23
- * name: 'git-mcp-server',
24
- * version: '1.0.0',
25
- * transports: ['stdio', 'http'],
26
- * capabilities: { tools: { listChanged: true } }
27
- * })
28
- *
29
- * adapter.registerGitdoTools()
30
- * await adapter.start()
31
- *
32
- * // Connect with a transport
33
- * const transport = MCPSDKTransport.createStdio()
34
- * await adapter.connect(transport)
35
- *
36
- * @example
37
- * // Handle tool calls with progress
38
- * const result = adapter.handleToolsCall({
39
- * name: 'git_log',
40
- * arguments: { maxCount: 100 }
41
- * })
42
- *
43
- * adapter.onProgress((event) => {
44
- * console.log(`Progress: ${event.progress}/${event.total}`)
45
- * })
46
- *
47
- * const output = await result
48
- */
49
- import { gitTools } from './tools';
50
- /**
51
- * MCP SDK Error codes - JSON-RPC 2.0 standard codes and MCP-specific codes.
52
- *
53
- * @description
54
- * Enumeration of error codes used in MCP SDK responses. Follows JSON-RPC 2.0
55
- * specification for standard errors and defines MCP-specific codes for
56
- * resource, tool, and prompt operations.
57
- *
58
- * @enum {number}
59
- */
60
- export var MCPSDKErrorCode;
61
- (function (MCPSDKErrorCode) {
62
- /** Parse error - Invalid JSON (-32700) */
63
- MCPSDKErrorCode[MCPSDKErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
64
- /** Invalid Request - Not a valid Request object (-32600) */
65
- MCPSDKErrorCode[MCPSDKErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
66
- /** Method not found - Method does not exist (-32601) */
67
- MCPSDKErrorCode[MCPSDKErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
68
- /** Invalid params - Invalid method parameters (-32602) */
69
- MCPSDKErrorCode[MCPSDKErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
70
- /** Internal error - Internal JSON-RPC error (-32603) */
71
- MCPSDKErrorCode[MCPSDKErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
72
- /** Tool not found - Requested tool does not exist (-32001) */
73
- MCPSDKErrorCode[MCPSDKErrorCode["TOOL_NOT_FOUND"] = -32001] = "TOOL_NOT_FOUND";
74
- /** Resource not found - Requested resource does not exist (-32002) */
75
- MCPSDKErrorCode[MCPSDKErrorCode["RESOURCE_NOT_FOUND"] = -32002] = "RESOURCE_NOT_FOUND";
76
- /** Prompt not found - Requested prompt does not exist (-32003) */
77
- MCPSDKErrorCode[MCPSDKErrorCode["PROMPT_NOT_FOUND"] = -32003] = "PROMPT_NOT_FOUND";
78
- /** Capability not supported - Capability is not enabled (-32004) */
79
- MCPSDKErrorCode[MCPSDKErrorCode["CAPABILITY_NOT_SUPPORTED"] = -32004] = "CAPABILITY_NOT_SUPPORTED";
80
- })(MCPSDKErrorCode || (MCPSDKErrorCode = {}));
81
- /**
82
- * MCP SDK Error class.
83
- *
84
- * @description
85
- * Error class for MCP SDK operations. Encapsulates error code, message,
86
- * and optional data. Can be converted to JSON-RPC format.
87
- *
88
- * @class MCPSDKError
89
- * @extends Error
90
- *
91
- * @example
92
- * throw new MCPSDKError(
93
- * MCPSDKErrorCode.TOOL_NOT_FOUND,
94
- * 'Tool "unknown" not found'
95
- * )
96
- */
97
- export class MCPSDKError extends Error {
98
- /** The error code */
99
- code;
100
- /** Optional additional error data */
101
- data;
102
- /**
103
- * Create a new MCP SDK error.
104
- * @param code - The error code
105
- * @param message - Human-readable error message
106
- * @param data - Optional additional data
107
- */
108
- constructor(code, message, data) {
109
- super(message);
110
- this.code = code;
111
- this.data = data;
112
- this.name = 'MCPSDKError';
113
- }
114
- /**
115
- * Convert to JSON-RPC error format.
116
- * @returns Object suitable for JSON-RPC error responses
117
- */
118
- toJSONRPC() {
119
- const result = {
120
- code: this.code,
121
- message: this.message,
122
- };
123
- if (this.data !== undefined) {
124
- result.data = this.data;
125
- }
126
- return result;
127
- }
128
- }
129
- /**
130
- * MCP SDK Adapter class.
131
- *
132
- * @description
133
- * Full-featured MCP adapter with advanced features including:
134
- * - Multiple transport support (stdio, SSE, HTTP)
135
- * - Connection lifecycle management with events
136
- * - Request tracking, cancellation, and progress reporting
137
- * - Session management with client capabilities
138
- * - Health checking via ping/pong
139
- * - Graceful shutdown with request draining
140
- *
141
- * @class MCPSDKAdapter
142
- *
143
- * @example
144
- * const adapter = new MCPSDKAdapter({
145
- * name: 'git-server',
146
- * version: '1.0.0',
147
- * capabilities: { tools: { listChanged: true } }
148
- * })
149
- *
150
- * adapter.onConnected(() => console.log('Connected!'))
151
- * adapter.onError((err) => console.error(err))
152
- *
153
- * adapter.registerGitdoTools()
154
- * await adapter.start()
155
- */
156
- export class MCPSDKAdapter {
157
- /** @internal */
158
- config;
159
- /** @internal */
160
- connectionState = 'disconnected';
161
- /** @internal */
162
- tools = new Map();
163
- /** @internal */
164
- toolIdCounter = 0;
165
- /** @internal */
166
- session = null;
167
- /** @internal */
168
- stateChangeListeners = [];
169
- /** @internal */
170
- connectedListeners = [];
171
- /** @internal */
172
- disconnectedListeners = [];
173
- /** @internal */
174
- notificationListeners = new Map();
175
- /** @internal */
176
- progressListeners = [];
177
- /** @internal */
178
- errorListeners = [];
179
- /** @internal */
180
- pongListeners = [];
181
- /** @internal */
182
- connectionTimeoutListeners = [];
183
- /** @internal */
184
- pendingRequests = new Map();
185
- /** @internal */
186
- currentRequestId = 0;
187
- /** Current transport connection */
188
- transport = null;
189
- /** @internal */
190
- clientResponsive = true;
191
- /** @internal */
192
- pingTimeoutId = null;
193
- /** Whether to cleanup tools on shutdown */
194
- cleanupOnShutdown = false;
195
- /**
196
- * Create a new MCP SDK adapter.
197
- *
198
- * @param config - Optional configuration options
199
- * @throws {Error} If name is explicitly set to empty string
200
- *
201
- * @example
202
- * const adapter = new MCPSDKAdapter({
203
- * name: 'my-server',
204
- * version: '1.0.0',
205
- * mode: 'production',
206
- * logger: console
207
- * })
208
- */
209
- constructor(config) {
210
- // Validate configuration
211
- if (config?.name !== undefined && config.name === '') {
212
- throw new Error('Configuration error: name is required and cannot be empty');
213
- }
214
- this.config = {
215
- name: config?.name || 'gitx.do',
216
- version: config?.version || '0.0.1',
217
- vendor: config?.vendor || 'gitx.do',
218
- transports: config?.transports || ['stdio'],
219
- protocolVersion: config?.protocolVersion || '2024-11-05',
220
- capabilities: config?.capabilities || {},
221
- logger: config?.logger,
222
- mode: config?.mode || 'development',
223
- pingInterval: config?.pingInterval,
224
- pingTimeout: config?.pingTimeout,
225
- };
226
- }
227
- /**
228
- * Get the adapter configuration.
229
- * @returns Copy of the current configuration
230
- */
231
- getConfig() {
232
- return { ...this.config };
233
- }
234
- /**
235
- * Get supported transports.
236
- * @returns Array of supported transport types
237
- */
238
- getSupportedTransports() {
239
- return [...(this.config.transports || ['stdio'])];
240
- }
241
- /**
242
- * Get protocol version.
243
- * @returns The MCP protocol version string
244
- */
245
- getProtocolVersion() {
246
- return this.config.protocolVersion || '2024-11-05';
247
- }
248
- /**
249
- * Get SDK version.
250
- * @returns The SDK version string
251
- */
252
- getSDKVersion() {
253
- return '1.0.0';
254
- }
255
- /**
256
- * Get capabilities.
257
- * @returns Copy of the server capabilities configuration
258
- */
259
- getCapabilities() {
260
- return { ...this.config.capabilities };
261
- }
262
- /**
263
- * Get connection state.
264
- * @returns Current connection state
265
- */
266
- getConnectionState() {
267
- return this.connectionState;
268
- }
269
- /**
270
- * Set connection state and notify listeners.
271
- * @internal
272
- */
273
- setConnectionState(state) {
274
- this.connectionState = state;
275
- for (const listener of this.stateChangeListeners) {
276
- listener(state);
277
- }
278
- if (state === 'connected') {
279
- for (const listener of this.connectedListeners) {
280
- listener();
281
- }
282
- }
283
- else if (state === 'disconnected') {
284
- for (const listener of this.disconnectedListeners) {
285
- listener();
286
- }
287
- }
288
- }
289
- /**
290
- * Register a state change listener.
291
- * @param listener - Callback invoked when connection state changes
292
- * @example
293
- * adapter.onStateChange((state) => {
294
- * console.log(`State changed to: ${state}`)
295
- * })
296
- */
297
- onStateChange(listener) {
298
- this.stateChangeListeners.push(listener);
299
- }
300
- /**
301
- * Register a connected listener.
302
- * @param listener - Callback invoked when connection is established
303
- */
304
- onConnected(listener) {
305
- this.connectedListeners.push(listener);
306
- }
307
- /**
308
- * Register a disconnected listener.
309
- * @param listener - Callback invoked when connection is lost
310
- */
311
- onDisconnected(listener) {
312
- this.disconnectedListeners.push(listener);
313
- }
314
- /**
315
- * Register a notification listener.
316
- * @param type - Notification type to listen for (e.g., 'tools/list_changed')
317
- * @param listener - Callback invoked when notification is emitted
318
- */
319
- onNotification(type, listener) {
320
- const listeners = this.notificationListeners.get(type) || [];
321
- listeners.push(listener);
322
- this.notificationListeners.set(type, listeners);
323
- }
324
- /**
325
- * Emit a notification.
326
- * @internal
327
- */
328
- emitNotification(type) {
329
- const listeners = this.notificationListeners.get(type) || [];
330
- for (const listener of listeners) {
331
- listener();
332
- }
333
- }
334
- /**
335
- * Register a progress listener.
336
- * @param listener - Callback invoked when tool reports progress
337
- */
338
- onProgress(listener) {
339
- this.progressListeners.push(listener);
340
- }
341
- /**
342
- * Register an error listener.
343
- * @param listener - Callback invoked when an error occurs
344
- */
345
- onError(listener) {
346
- this.errorListeners.push(listener);
347
- }
348
- /**
349
- * Register a pong listener.
350
- * @param listener - Callback invoked when pong response is received
351
- */
352
- onPong(listener) {
353
- this.pongListeners.push(listener);
354
- }
355
- /**
356
- * Register a connection timeout listener.
357
- * @param listener - Callback invoked when connection times out
358
- */
359
- onConnectionTimeout(listener) {
360
- this.connectionTimeoutListeners.push(listener);
361
- }
362
- /**
363
- * Start the adapter.
364
- *
365
- * @description
366
- * Initializes the adapter and transitions to connected state.
367
- * Must be called before handling any requests.
368
- *
369
- * @returns Promise that resolves when started
370
- * @throws {Error} If adapter is already started
371
- *
372
- * @example
373
- * await adapter.start()
374
- */
375
- async start() {
376
- if (this.connectionState !== 'disconnected') {
377
- throw new Error('Adapter is already started or running');
378
- }
379
- this.setConnectionState('initializing');
380
- // Simulate initialization
381
- await new Promise((resolve) => setTimeout(resolve, 10));
382
- this.setConnectionState('connected');
383
- }
384
- /**
385
- * Connect with a transport.
386
- *
387
- * @description
388
- * Attaches a transport and starts the adapter if not already running.
389
- *
390
- * @param transport - The transport to connect with
391
- * @returns Promise that resolves when connected
392
- */
393
- async connect(transport) {
394
- this.transport = transport;
395
- if (this.connectionState === 'disconnected') {
396
- await this.start();
397
- }
398
- }
399
- /**
400
- * Shutdown the adapter.
401
- *
402
- * @description
403
- * Gracefully shuts down the adapter, optionally waiting for pending
404
- * requests and cleaning up registered tools.
405
- *
406
- * @param options - Shutdown options
407
- * @param options.graceful - If true, wait for pending requests
408
- * @param options.timeout - Max time to wait for pending requests (ms)
409
- * @param options.cleanup - If true, clear all registered tools
410
- * @returns Promise that resolves when shutdown is complete
411
- *
412
- * @example
413
- * await adapter.shutdown({ graceful: true, timeout: 5000, cleanup: true })
414
- */
415
- async shutdown(options) {
416
- const cleanup = options?.cleanup ?? false;
417
- this.cleanupOnShutdown = cleanup;
418
- if (options?.graceful && options?.timeout) {
419
- // Wait for pending requests with timeout
420
- const timeoutPromise = new Promise((resolve) => setTimeout(resolve, options.timeout));
421
- await Promise.race([this.waitForPendingRequests(), timeoutPromise]);
422
- }
423
- if (this.pingTimeoutId) {
424
- clearTimeout(this.pingTimeoutId);
425
- this.pingTimeoutId = null;
426
- }
427
- if (cleanup) {
428
- this.tools.clear();
429
- }
430
- this.transport = null;
431
- this.session = null;
432
- this.setConnectionState('disconnected');
433
- }
434
- /**
435
- * Wait for all pending requests to complete.
436
- * @internal
437
- */
438
- async waitForPendingRequests() {
439
- while (this.pendingRequests.size > 0) {
440
- await new Promise((resolve) => setTimeout(resolve, 10));
441
- }
442
- }
443
- /**
444
- * Handle client initialization.
445
- *
446
- * @description
447
- * Processes the client's initialize request, validates protocol version,
448
- * and creates a session.
449
- *
450
- * @param request - Client initialization request
451
- * @returns Server info and capabilities
452
- * @throws {MCPSDKError} If protocol version is incompatible
453
- */
454
- async handleClientInitialize(request) {
455
- // Validate protocol version
456
- const supportedVersions = ['2024-11-05'];
457
- if (!supportedVersions.includes(request.protocolVersion)) {
458
- throw new MCPSDKError(MCPSDKErrorCode.INVALID_PARAMS, `Incompatible protocol version: ${request.protocolVersion}. Supported versions: ${supportedVersions.join(', ')}`);
459
- }
460
- // Create session
461
- this.session = {
462
- id: `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
463
- clientInfo: request.clientInfo,
464
- clientCapabilities: request.capabilities,
465
- };
466
- return {
467
- serverInfo: {
468
- name: this.config.name,
469
- version: this.config.version,
470
- },
471
- capabilities: this.config.capabilities || {},
472
- };
473
- }
474
- /**
475
- * Get current session.
476
- * @returns Current session or null if not initialized
477
- */
478
- getSession() {
479
- return this.session;
480
- }
481
- /**
482
- * Register a tool.
483
- *
484
- * @description
485
- * Adds a tool to the adapter's registry. Emits tools/list_changed notification.
486
- *
487
- * @param registration - Tool registration details
488
- * @throws {Error} If schema type is invalid
489
- * @throws {Error} If tool with same name already exists
490
- *
491
- * @example
492
- * adapter.registerTool({
493
- * name: 'my_tool',
494
- * description: 'Does something',
495
- * inputSchema: { type: 'object', properties: {} },
496
- * handler: async (params, ctx) => ({
497
- * content: [{ type: 'text', text: 'Done' }]
498
- * })
499
- * })
500
- */
501
- registerTool(registration) {
502
- // Validate schema type
503
- if (registration.inputSchema.type !== 'object' &&
504
- registration.inputSchema.type !== 'string' &&
505
- registration.inputSchema.type !== 'number' &&
506
- registration.inputSchema.type !== 'boolean' &&
507
- registration.inputSchema.type !== 'array') {
508
- throw new Error(`Invalid schema type: ${registration.inputSchema.type}. Expected valid JSON Schema type.`);
509
- }
510
- if (this.tools.has(registration.name)) {
511
- throw new Error(`Tool '${registration.name}' already exists (duplicate)`);
512
- }
513
- const internalTool = {
514
- ...registration,
515
- id: `tool-${++this.toolIdCounter}`,
516
- };
517
- this.tools.set(registration.name, internalTool);
518
- this.emitNotification('tools/list_changed');
519
- }
520
- /**
521
- * Register multiple tools.
522
- *
523
- * @description
524
- * Batch registers multiple tools. More efficient than registering
525
- * individually as it only emits one notification.
526
- *
527
- * @param registrations - Array of tool registrations
528
- * @throws {Error} If any schema type is invalid
529
- * @throws {Error} If any tool name already exists
530
- */
531
- registerTools(registrations) {
532
- for (const registration of registrations) {
533
- // Don't emit notification for each tool
534
- if (registration.inputSchema.type !== 'object' &&
535
- registration.inputSchema.type !== 'string' &&
536
- registration.inputSchema.type !== 'number' &&
537
- registration.inputSchema.type !== 'boolean' &&
538
- registration.inputSchema.type !== 'array') {
539
- throw new Error(`Invalid schema type: ${registration.inputSchema.type}. Expected valid JSON Schema type.`);
540
- }
541
- if (this.tools.has(registration.name)) {
542
- throw new Error(`Tool '${registration.name}' already exists (duplicate)`);
543
- }
544
- const internalTool = {
545
- ...registration,
546
- id: `tool-${++this.toolIdCounter}`,
547
- };
548
- this.tools.set(registration.name, internalTool);
549
- }
550
- this.emitNotification('tools/list_changed');
551
- }
552
- /**
553
- * Unregister a tool.
554
- * @param name - Name of the tool to unregister
555
- */
556
- unregisterTool(name) {
557
- this.tools.delete(name);
558
- this.emitNotification('tools/list_changed');
559
- }
560
- /**
561
- * Get a tool by name.
562
- * @param name - Name of the tool to retrieve
563
- * @returns Tool metadata (without handler) or undefined if not found
564
- */
565
- getTool(name) {
566
- const tool = this.tools.get(name);
567
- if (!tool)
568
- return undefined;
569
- return {
570
- id: tool.id,
571
- name: tool.name,
572
- description: tool.description,
573
- inputSchema: tool.inputSchema,
574
- };
575
- }
576
- /**
577
- * List all tools.
578
- * @returns Array of tool metadata (without handlers)
579
- */
580
- listTools() {
581
- const result = [];
582
- for (const tool of this.tools.values()) {
583
- result.push({
584
- id: tool.id,
585
- name: tool.name,
586
- description: tool.description,
587
- inputSchema: tool.inputSchema,
588
- });
589
- }
590
- return result;
591
- }
592
- /**
593
- * Register gitdo tools.
594
- *
595
- * @description
596
- * Convenience method that registers all built-in git tools.
597
- * Skips tools that are already registered.
598
- */
599
- registerGitdoTools() {
600
- for (const tool of gitTools) {
601
- if (!this.tools.has(tool.name)) {
602
- this.registerTool({
603
- name: tool.name,
604
- description: tool.description,
605
- inputSchema: tool.inputSchema,
606
- handler: async (params) => tool.handler(params),
607
- });
608
- }
609
- }
610
- }
611
- /**
612
- * Handle tools/list request.
613
- *
614
- * @description
615
- * Returns paginated list of registered tools. Supports cursor-based pagination.
616
- *
617
- * @param options - Pagination options
618
- * @param options.cursor - Pagination cursor from previous response
619
- * @returns Paginated tool list with optional next cursor
620
- */
621
- async handleToolsList(options) {
622
- const allTools = this.listTools();
623
- const pageSize = 10;
624
- // Parse cursor
625
- let startIndex = 0;
626
- if (options?.cursor) {
627
- startIndex = parseInt(options.cursor, 10);
628
- }
629
- const endIndex = startIndex + pageSize;
630
- const pageTools = allTools.slice(startIndex, endIndex);
631
- const result = {
632
- tools: pageTools.map((t) => ({
633
- name: t.name,
634
- description: t.description,
635
- inputSchema: t.inputSchema,
636
- })),
637
- };
638
- if (endIndex < allTools.length) {
639
- result.nextCursor = String(endIndex);
640
- }
641
- return result;
642
- }
643
- /**
644
- * Handle tools/call request.
645
- *
646
- * @description
647
- * Executes a tool and returns the result. Provides progress reporting
648
- * and cancellation support through the tool context.
649
- *
650
- * @param request - Tool call request with name and arguments
651
- * @returns Promise with result and requestId for tracking
652
- * @throws {MCPSDKError} If tool not found or parameters invalid
653
- *
654
- * @example
655
- * const call = adapter.handleToolsCall({
656
- * name: 'git_status',
657
- * arguments: { short: true }
658
- * })
659
- * console.log(`Request ID: ${call.requestId}`)
660
- * const result = await call
661
- */
662
- handleToolsCall(request) {
663
- // Generate requestId upfront for consistent tracking
664
- const requestId = `req-${++this.currentRequestId}`;
665
- // Helper to create a rejected promise with requestId attached
666
- const createRejectedPromise = (error) => {
667
- const promise = Promise.reject(error);
668
- promise.requestId = requestId;
669
- return promise;
670
- };
671
- const tool = this.tools.get(request.name);
672
- if (!tool) {
673
- return createRejectedPromise(new MCPSDKError(MCPSDKErrorCode.TOOL_NOT_FOUND, `Tool '${request.name}' not found (nonexistent)`));
674
- }
675
- // Validate required parameters
676
- const schema = tool.inputSchema;
677
- if (schema.required) {
678
- for (const requiredParam of schema.required) {
679
- if (!(requiredParam in request.arguments) ||
680
- request.arguments[requiredParam] === undefined) {
681
- return createRejectedPromise(new MCPSDKError(MCPSDKErrorCode.INVALID_PARAMS, `Missing required parameter: ${requiredParam}`));
682
- }
683
- }
684
- }
685
- // Create request tracking
686
- this.pendingRequests.set(requestId, { cancelled: false });
687
- // Create context
688
- const context = {
689
- reportProgress: async (progress, total) => {
690
- for (const listener of this.progressListeners) {
691
- listener({ progress, total });
692
- }
693
- },
694
- isCancelled: () => {
695
- const req = this.pendingRequests.get(requestId);
696
- return req?.cancelled ?? false;
697
- },
698
- };
699
- const executeHandler = async () => {
700
- try {
701
- const result = await tool.handler(request.arguments, context);
702
- this.pendingRequests.delete(requestId);
703
- return { ...result, requestId };
704
- }
705
- catch (error) {
706
- this.pendingRequests.delete(requestId);
707
- // Log error if logger configured
708
- if (this.config.logger?.error) {
709
- this.config.logger.error('Tool execution error:', error instanceof Error ? error.message : String(error));
710
- }
711
- // Format error message based on mode
712
- let errorText = error instanceof Error ? error.message : String(error);
713
- if (this.config.mode === 'development' && error instanceof Error && error.stack) {
714
- errorText = error.stack;
715
- }
716
- return {
717
- content: [{ type: 'text', text: errorText }],
718
- isError: true,
719
- requestId,
720
- };
721
- }
722
- };
723
- // Create the promise and attach the requestId property
724
- const promise = executeHandler();
725
- promise.requestId = requestId;
726
- return promise;
727
- }
728
- /**
729
- * Cancel a request.
730
- *
731
- * @description
732
- * Marks a pending request as cancelled. The tool handler can check
733
- * cancellation status via context.isCancelled().
734
- *
735
- * @param requestId - The request ID to cancel
736
- */
737
- cancelRequest(requestId) {
738
- if (requestId) {
739
- const req = this.pendingRequests.get(requestId);
740
- if (req) {
741
- req.cancelled = true;
742
- }
743
- }
744
- }
745
- /**
746
- * Handle raw JSON-RPC message.
747
- *
748
- * @description
749
- * Parses and processes a raw JSON-RPC message string. Routes to
750
- * appropriate handlers based on the method.
751
- *
752
- * @param message - Raw JSON-RPC message string
753
- * @returns JSON-RPC response string
754
- */
755
- async handleMessage(message) {
756
- let parsed;
757
- try {
758
- parsed = JSON.parse(message);
759
- }
760
- catch {
761
- return JSON.stringify({
762
- jsonrpc: '2.0',
763
- id: null,
764
- error: {
765
- code: MCPSDKErrorCode.PARSE_ERROR,
766
- message: 'Parse error: Invalid JSON',
767
- },
768
- });
769
- }
770
- // Handle batch requests
771
- if (Array.isArray(parsed)) {
772
- const responses = await Promise.all(parsed.map((req) => this.handleSingleMessage(req)));
773
- return JSON.stringify(responses);
774
- }
775
- const response = await this.handleSingleMessage(parsed);
776
- return JSON.stringify(response);
777
- }
778
- /**
779
- * Handle a single JSON-RPC message
780
- */
781
- async handleSingleMessage(request) {
782
- const req = request;
783
- const id = req.id ?? null;
784
- if (req.jsonrpc !== '2.0') {
785
- return {
786
- jsonrpc: '2.0',
787
- id,
788
- error: {
789
- code: MCPSDKErrorCode.INVALID_REQUEST,
790
- message: 'Invalid Request: missing or invalid jsonrpc version',
791
- },
792
- };
793
- }
794
- try {
795
- switch (req.method) {
796
- case 'tools/list': {
797
- const result = await this.handleToolsList(req.params);
798
- return { jsonrpc: '2.0', id, result };
799
- }
800
- case 'tools/call': {
801
- const result = await this.handleToolsCall(req.params);
802
- return { jsonrpc: '2.0', id, result };
803
- }
804
- default:
805
- return {
806
- jsonrpc: '2.0',
807
- id,
808
- error: {
809
- code: MCPSDKErrorCode.METHOD_NOT_FOUND,
810
- message: `Method not found: ${req.method}`,
811
- },
812
- };
813
- }
814
- }
815
- catch (error) {
816
- if (error instanceof MCPSDKError) {
817
- return {
818
- jsonrpc: '2.0',
819
- id,
820
- error: error.toJSONRPC(),
821
- };
822
- }
823
- return {
824
- jsonrpc: '2.0',
825
- id,
826
- error: {
827
- code: MCPSDKErrorCode.INTERNAL_ERROR,
828
- message: error instanceof Error ? error.message : 'Internal error',
829
- },
830
- };
831
- }
832
- }
833
- /**
834
- * Simulate a pending request (for testing).
835
- * @internal
836
- */
837
- simulatePendingRequest() {
838
- const requestId = `sim-req-${++this.currentRequestId}`;
839
- this.pendingRequests.set(requestId, { cancelled: false });
840
- return {
841
- complete: async () => {
842
- this.pendingRequests.delete(requestId);
843
- },
844
- };
845
- }
846
- /**
847
- * Simulate an internal error (for testing).
848
- * @internal
849
- */
850
- simulateInternalError(error) {
851
- const mcpError = new MCPSDKError(MCPSDKErrorCode.INTERNAL_ERROR, error.message);
852
- for (const listener of this.errorListeners) {
853
- listener(mcpError);
854
- }
855
- }
856
- /**
857
- * Send ping to check client responsiveness.
858
- */
859
- sendPing() {
860
- // Simulate ping/pong
861
- setTimeout(() => {
862
- if (this.clientResponsive) {
863
- for (const listener of this.pongListeners) {
864
- listener();
865
- }
866
- }
867
- }, 10);
868
- // Set timeout for pong response
869
- if (this.config.pingTimeout) {
870
- this.pingTimeoutId = setTimeout(() => {
871
- if (!this.clientResponsive) {
872
- for (const listener of this.connectionTimeoutListeners) {
873
- listener();
874
- }
875
- }
876
- }, this.config.pingTimeout);
877
- }
878
- }
879
- /**
880
- * Simulate client becoming unresponsive (for testing).
881
- * @internal
882
- */
883
- simulateClientUnresponsive() {
884
- this.clientResponsive = false;
885
- // Trigger a ping to start the timeout
886
- this.sendPing();
887
- }
888
- }
889
- /**
890
- * Transport factory.
891
- *
892
- * @description
893
- * Factory object for creating transport instances. Provides methods
894
- * for creating stdio, SSE, and HTTP transports.
895
- *
896
- * @example
897
- * // Create a stdio transport
898
- * const transport = MCPSDKTransport.createStdio()
899
- *
900
- * // Create an SSE transport
901
- * const sseTransport = MCPSDKTransport.createSSE({ endpoint: '/sse' })
902
- *
903
- * // Create an HTTP transport
904
- * const httpTransport = MCPSDKTransport.createHTTP({ endpoint: '/api' })
905
- */
906
- export const MCPSDKTransport = {
907
- createStdio(_options) {
908
- return {
909
- type: 'stdio',
910
- isConnected: () => true,
911
- send: () => { },
912
- receive: async () => '',
913
- close: () => { },
914
- };
915
- },
916
- createSSE(_options) {
917
- let connected = false;
918
- return {
919
- type: 'sse',
920
- isConnected: () => connected,
921
- send: () => { },
922
- receive: async () => '',
923
- close: () => {
924
- connected = false;
925
- },
926
- handleRequest: async (_request) => {
927
- connected = true;
928
- return { status: 200, headers: {} };
929
- },
930
- };
931
- },
932
- createHTTP(_options) {
933
- return {
934
- type: 'http',
935
- isConnected: () => true,
936
- send: () => { },
937
- receive: async () => '',
938
- close: () => { },
939
- handleRequest: async (_request) => {
940
- return {
941
- status: 200,
942
- headers: { 'Content-Type': 'application/json' },
943
- body: JSON.stringify({ jsonrpc: '2.0', result: {} }),
944
- };
945
- },
946
- };
947
- },
948
- };
949
- /**
950
- * Factory function to create an MCP SDK adapter.
951
- *
952
- * @description
953
- * Convenience function for creating a new MCP SDK adapter instance.
954
- * Equivalent to using `new MCPSDKAdapter(config)`.
955
- *
956
- * @param config - Optional adapter configuration
957
- * @returns A new MCPSDKAdapter instance
958
- *
959
- * @example
960
- * import { createMCPSDKAdapter } from './sdk-adapter'
961
- *
962
- * const adapter = createMCPSDKAdapter({
963
- * name: 'git-server',
964
- * version: '1.0.0',
965
- * capabilities: { tools: { listChanged: true } }
966
- * })
967
- *
968
- * adapter.registerGitdoTools()
969
- * await adapter.start()
970
- */
971
- export function createMCPSDKAdapter(config) {
972
- return new MCPSDKAdapter(config);
973
- }
974
- //# sourceMappingURL=sdk-adapter.js.map