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.
- package/dist/cli/commands/blame.d.ts +259 -0
- package/dist/cli/commands/blame.d.ts.map +1 -0
- package/dist/cli/commands/blame.js +609 -0
- package/dist/cli/commands/blame.js.map +1 -0
- package/dist/cli/commands/branch.d.ts +249 -0
- package/dist/cli/commands/branch.d.ts.map +1 -0
- package/dist/cli/commands/branch.js +693 -0
- package/dist/cli/commands/branch.js.map +1 -0
- package/dist/cli/commands/commit.d.ts +182 -0
- package/dist/cli/commands/commit.d.ts.map +1 -0
- package/dist/cli/commands/commit.js +437 -0
- package/dist/cli/commands/commit.js.map +1 -0
- package/dist/cli/commands/diff.d.ts +464 -0
- package/dist/cli/commands/diff.d.ts.map +1 -0
- package/dist/cli/commands/diff.js +958 -0
- package/dist/cli/commands/diff.js.map +1 -0
- package/dist/cli/commands/log.d.ts +239 -0
- package/dist/cli/commands/log.d.ts.map +1 -0
- package/dist/cli/commands/log.js +535 -0
- package/dist/cli/commands/log.js.map +1 -0
- package/dist/cli/commands/review.d.ts +457 -0
- package/dist/cli/commands/review.d.ts.map +1 -0
- package/dist/cli/commands/review.js +533 -0
- package/dist/cli/commands/review.js.map +1 -0
- package/dist/cli/commands/status.d.ts +269 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +493 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/web.d.ts +199 -0
- package/dist/cli/commands/web.d.ts.map +1 -0
- package/dist/cli/commands/web.js +696 -0
- package/dist/cli/commands/web.js.map +1 -0
- package/dist/cli/fs-adapter.d.ts +656 -0
- package/dist/cli/fs-adapter.d.ts.map +1 -0
- package/dist/cli/fs-adapter.js +1179 -0
- package/dist/cli/fs-adapter.js.map +1 -0
- package/dist/cli/index.d.ts +387 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +523 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ui/components/DiffView.d.ts +7 -0
- package/dist/cli/ui/components/DiffView.d.ts.map +1 -0
- package/dist/cli/ui/components/DiffView.js +11 -0
- package/dist/cli/ui/components/DiffView.js.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -0
- package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -0
- package/dist/cli/ui/components/ErrorDisplay.js +11 -0
- package/dist/cli/ui/components/ErrorDisplay.js.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts +9 -0
- package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -0
- package/dist/cli/ui/components/FuzzySearch.js +12 -0
- package/dist/cli/ui/components/FuzzySearch.js.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -0
- package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -0
- package/dist/cli/ui/components/LoadingSpinner.js +10 -0
- package/dist/cli/ui/components/LoadingSpinner.js.map +1 -0
- package/dist/cli/ui/components/NavigationList.d.ts +9 -0
- package/dist/cli/ui/components/NavigationList.d.ts.map +1 -0
- package/dist/cli/ui/components/NavigationList.js +11 -0
- package/dist/cli/ui/components/NavigationList.js.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts +8 -0
- package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -0
- package/dist/cli/ui/components/ScrollableContent.js +11 -0
- package/dist/cli/ui/components/ScrollableContent.js.map +1 -0
- package/dist/cli/ui/components/index.d.ts +7 -0
- package/dist/cli/ui/components/index.d.ts.map +1 -0
- package/dist/cli/ui/components/index.js +9 -0
- package/dist/cli/ui/components/index.js.map +1 -0
- package/dist/cli/ui/terminal-ui.d.ts +52 -0
- package/dist/cli/ui/terminal-ui.d.ts.map +1 -0
- package/dist/cli/ui/terminal-ui.js +121 -0
- package/dist/cli/ui/terminal-ui.js.map +1 -0
- package/dist/durable-object/object-store.d.ts +401 -23
- package/dist/durable-object/object-store.d.ts.map +1 -1
- package/dist/durable-object/object-store.js +414 -25
- package/dist/durable-object/object-store.js.map +1 -1
- package/dist/durable-object/schema.d.ts +188 -0
- package/dist/durable-object/schema.d.ts.map +1 -1
- package/dist/durable-object/schema.js +160 -0
- package/dist/durable-object/schema.js.map +1 -1
- package/dist/durable-object/wal.d.ts +336 -31
- package/dist/durable-object/wal.d.ts.map +1 -1
- package/dist/durable-object/wal.js +272 -27
- package/dist/durable-object/wal.js.map +1 -1
- package/dist/index.d.ts +379 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +379 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp/adapter.d.ts +579 -38
- package/dist/mcp/adapter.d.ts.map +1 -1
- package/dist/mcp/adapter.js +426 -33
- package/dist/mcp/adapter.js.map +1 -1
- package/dist/mcp/sandbox.d.ts +532 -29
- package/dist/mcp/sandbox.d.ts.map +1 -1
- package/dist/mcp/sandbox.js +389 -22
- package/dist/mcp/sandbox.js.map +1 -1
- package/dist/mcp/sdk-adapter.d.ts +478 -56
- package/dist/mcp/sdk-adapter.d.ts.map +1 -1
- package/dist/mcp/sdk-adapter.js +346 -44
- package/dist/mcp/sdk-adapter.js.map +1 -1
- package/dist/mcp/tools.d.ts +445 -30
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +363 -33
- package/dist/mcp/tools.js.map +1 -1
- package/dist/ops/blame.d.ts +424 -21
- package/dist/ops/blame.d.ts.map +1 -1
- package/dist/ops/blame.js +303 -20
- package/dist/ops/blame.js.map +1 -1
- package/dist/ops/branch.d.ts +583 -32
- package/dist/ops/branch.d.ts.map +1 -1
- package/dist/ops/branch.js +365 -23
- package/dist/ops/branch.js.map +1 -1
- package/dist/ops/commit-traversal.d.ts +164 -24
- package/dist/ops/commit-traversal.d.ts.map +1 -1
- package/dist/ops/commit-traversal.js +68 -2
- package/dist/ops/commit-traversal.js.map +1 -1
- package/dist/ops/commit.d.ts +387 -53
- package/dist/ops/commit.d.ts.map +1 -1
- package/dist/ops/commit.js +249 -29
- package/dist/ops/commit.js.map +1 -1
- package/dist/ops/merge-base.d.ts +195 -21
- package/dist/ops/merge-base.d.ts.map +1 -1
- package/dist/ops/merge-base.js +122 -12
- package/dist/ops/merge-base.js.map +1 -1
- package/dist/ops/merge.d.ts +600 -130
- package/dist/ops/merge.d.ts.map +1 -1
- package/dist/ops/merge.js +408 -60
- package/dist/ops/merge.js.map +1 -1
- package/dist/ops/tag.d.ts +67 -2
- package/dist/ops/tag.d.ts.map +1 -1
- package/dist/ops/tag.js +42 -1
- package/dist/ops/tag.js.map +1 -1
- package/dist/ops/tree-builder.d.ts +102 -6
- package/dist/ops/tree-builder.d.ts.map +1 -1
- package/dist/ops/tree-builder.js +30 -5
- package/dist/ops/tree-builder.js.map +1 -1
- package/dist/ops/tree-diff.d.ts +50 -2
- package/dist/ops/tree-diff.d.ts.map +1 -1
- package/dist/ops/tree-diff.js +50 -2
- package/dist/ops/tree-diff.js.map +1 -1
- package/dist/pack/delta.d.ts +211 -39
- package/dist/pack/delta.d.ts.map +1 -1
- package/dist/pack/delta.js +232 -46
- package/dist/pack/delta.js.map +1 -1
- package/dist/pack/format.d.ts +390 -28
- package/dist/pack/format.d.ts.map +1 -1
- package/dist/pack/format.js +344 -33
- package/dist/pack/format.js.map +1 -1
- package/dist/pack/full-generation.d.ts +313 -28
- package/dist/pack/full-generation.d.ts.map +1 -1
- package/dist/pack/full-generation.js +238 -19
- package/dist/pack/full-generation.js.map +1 -1
- package/dist/pack/generation.d.ts +346 -23
- package/dist/pack/generation.d.ts.map +1 -1
- package/dist/pack/generation.js +269 -21
- package/dist/pack/generation.js.map +1 -1
- package/dist/pack/index.d.ts +407 -86
- package/dist/pack/index.d.ts.map +1 -1
- package/dist/pack/index.js +351 -70
- package/dist/pack/index.js.map +1 -1
- package/dist/refs/branch.d.ts +517 -71
- package/dist/refs/branch.d.ts.map +1 -1
- package/dist/refs/branch.js +410 -26
- package/dist/refs/branch.js.map +1 -1
- package/dist/refs/storage.d.ts +610 -57
- package/dist/refs/storage.d.ts.map +1 -1
- package/dist/refs/storage.js +481 -29
- package/dist/refs/storage.js.map +1 -1
- package/dist/refs/tag.d.ts +677 -67
- package/dist/refs/tag.d.ts.map +1 -1
- package/dist/refs/tag.js +497 -30
- package/dist/refs/tag.js.map +1 -1
- package/dist/storage/lru-cache.d.ts +556 -53
- package/dist/storage/lru-cache.d.ts.map +1 -1
- package/dist/storage/lru-cache.js +439 -36
- package/dist/storage/lru-cache.js.map +1 -1
- package/dist/storage/object-index.d.ts +483 -38
- package/dist/storage/object-index.d.ts.map +1 -1
- package/dist/storage/object-index.js +388 -22
- package/dist/storage/object-index.js.map +1 -1
- package/dist/storage/r2-pack.d.ts +957 -94
- package/dist/storage/r2-pack.d.ts.map +1 -1
- package/dist/storage/r2-pack.js +756 -48
- package/dist/storage/r2-pack.js.map +1 -1
- package/dist/tiered/cdc-pipeline.d.ts +1610 -38
- package/dist/tiered/cdc-pipeline.d.ts.map +1 -1
- package/dist/tiered/cdc-pipeline.js +1131 -22
- package/dist/tiered/cdc-pipeline.js.map +1 -1
- package/dist/tiered/migration.d.ts +903 -41
- package/dist/tiered/migration.d.ts.map +1 -1
- package/dist/tiered/migration.js +646 -24
- package/dist/tiered/migration.js.map +1 -1
- package/dist/tiered/parquet-writer.d.ts +944 -47
- package/dist/tiered/parquet-writer.d.ts.map +1 -1
- package/dist/tiered/parquet-writer.js +667 -39
- package/dist/tiered/parquet-writer.js.map +1 -1
- package/dist/tiered/read-path.d.ts +728 -34
- package/dist/tiered/read-path.d.ts.map +1 -1
- package/dist/tiered/read-path.js +310 -27
- package/dist/tiered/read-path.js.map +1 -1
- package/dist/types/objects.d.ts +457 -0
- package/dist/types/objects.d.ts.map +1 -1
- package/dist/types/objects.js +305 -4
- package/dist/types/objects.js.map +1 -1
- package/dist/types/storage.d.ts +407 -35
- package/dist/types/storage.d.ts.map +1 -1
- package/dist/types/storage.js +27 -3
- package/dist/types/storage.js.map +1 -1
- package/dist/utils/hash.d.ts +133 -12
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +133 -12
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/sha1.d.ts +102 -9
- package/dist/utils/sha1.d.ts.map +1 -1
- package/dist/utils/sha1.js +114 -11
- package/dist/utils/sha1.js.map +1 -1
- package/dist/wire/capabilities.d.ts +896 -88
- package/dist/wire/capabilities.d.ts.map +1 -1
- package/dist/wire/capabilities.js +566 -62
- package/dist/wire/capabilities.js.map +1 -1
- package/dist/wire/pkt-line.d.ts +293 -15
- package/dist/wire/pkt-line.d.ts.map +1 -1
- package/dist/wire/pkt-line.js +251 -15
- package/dist/wire/pkt-line.js.map +1 -1
- package/dist/wire/receive-pack.d.ts +814 -64
- package/dist/wire/receive-pack.d.ts.map +1 -1
- package/dist/wire/receive-pack.js +542 -41
- package/dist/wire/receive-pack.js.map +1 -1
- package/dist/wire/smart-http.d.ts +575 -97
- package/dist/wire/smart-http.d.ts.map +1 -1
- package/dist/wire/smart-http.js +337 -46
- package/dist/wire/smart-http.js.map +1 -1
- package/dist/wire/upload-pack.d.ts +492 -98
- package/dist/wire/upload-pack.d.ts.map +1 -1
- package/dist/wire/upload-pack.js +347 -59
- package/dist/wire/upload-pack.js.map +1 -1
- package/package.json +10 -2
package/dist/mcp/sdk-adapter.js
CHANGED
|
@@ -1,40 +1,120 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP SDK Adapter
|
|
2
|
+
* @fileoverview MCP SDK Adapter
|
|
3
3
|
*
|
|
4
4
|
* This module provides a full-featured adapter for the MCP SDK,
|
|
5
5
|
* including SDK initialization, tool registration, request/response
|
|
6
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
|
|
7
48
|
*/
|
|
8
49
|
import { gitTools } from './tools';
|
|
9
50
|
/**
|
|
10
|
-
* MCP SDK Error codes - JSON-RPC 2.0 standard codes and MCP-specific codes
|
|
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}
|
|
11
59
|
*/
|
|
12
60
|
export var MCPSDKErrorCode;
|
|
13
61
|
(function (MCPSDKErrorCode) {
|
|
14
|
-
|
|
62
|
+
/** Parse error - Invalid JSON (-32700) */
|
|
15
63
|
MCPSDKErrorCode[MCPSDKErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
64
|
+
/** Invalid Request - Not a valid Request object (-32600) */
|
|
16
65
|
MCPSDKErrorCode[MCPSDKErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
|
|
66
|
+
/** Method not found - Method does not exist (-32601) */
|
|
17
67
|
MCPSDKErrorCode[MCPSDKErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
|
|
68
|
+
/** Invalid params - Invalid method parameters (-32602) */
|
|
18
69
|
MCPSDKErrorCode[MCPSDKErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
|
|
70
|
+
/** Internal error - Internal JSON-RPC error (-32603) */
|
|
19
71
|
MCPSDKErrorCode[MCPSDKErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
|
|
20
|
-
|
|
72
|
+
/** Tool not found - Requested tool does not exist (-32001) */
|
|
21
73
|
MCPSDKErrorCode[MCPSDKErrorCode["TOOL_NOT_FOUND"] = -32001] = "TOOL_NOT_FOUND";
|
|
74
|
+
/** Resource not found - Requested resource does not exist (-32002) */
|
|
22
75
|
MCPSDKErrorCode[MCPSDKErrorCode["RESOURCE_NOT_FOUND"] = -32002] = "RESOURCE_NOT_FOUND";
|
|
76
|
+
/** Prompt not found - Requested prompt does not exist (-32003) */
|
|
23
77
|
MCPSDKErrorCode[MCPSDKErrorCode["PROMPT_NOT_FOUND"] = -32003] = "PROMPT_NOT_FOUND";
|
|
78
|
+
/** Capability not supported - Capability is not enabled (-32004) */
|
|
24
79
|
MCPSDKErrorCode[MCPSDKErrorCode["CAPABILITY_NOT_SUPPORTED"] = -32004] = "CAPABILITY_NOT_SUPPORTED";
|
|
25
80
|
})(MCPSDKErrorCode || (MCPSDKErrorCode = {}));
|
|
26
81
|
/**
|
|
27
|
-
* MCP SDK Error class
|
|
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
|
+
* )
|
|
28
96
|
*/
|
|
29
97
|
export class MCPSDKError extends Error {
|
|
98
|
+
/** The error code */
|
|
30
99
|
code;
|
|
100
|
+
/** Optional additional error data */
|
|
31
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
|
+
*/
|
|
32
108
|
constructor(code, message, data) {
|
|
33
109
|
super(message);
|
|
34
110
|
this.code = code;
|
|
35
111
|
this.data = data;
|
|
36
112
|
this.name = 'MCPSDKError';
|
|
37
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Convert to JSON-RPC error format.
|
|
116
|
+
* @returns Object suitable for JSON-RPC error responses
|
|
117
|
+
*/
|
|
38
118
|
toJSONRPC() {
|
|
39
119
|
const result = {
|
|
40
120
|
code: this.code,
|
|
@@ -47,28 +127,85 @@ export class MCPSDKError extends Error {
|
|
|
47
127
|
}
|
|
48
128
|
}
|
|
49
129
|
/**
|
|
50
|
-
* MCP SDK Adapter class
|
|
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()
|
|
51
155
|
*/
|
|
52
156
|
export class MCPSDKAdapter {
|
|
157
|
+
/** @internal */
|
|
53
158
|
config;
|
|
159
|
+
/** @internal */
|
|
54
160
|
connectionState = 'disconnected';
|
|
161
|
+
/** @internal */
|
|
55
162
|
tools = new Map();
|
|
163
|
+
/** @internal */
|
|
56
164
|
toolIdCounter = 0;
|
|
165
|
+
/** @internal */
|
|
57
166
|
session = null;
|
|
167
|
+
/** @internal */
|
|
58
168
|
stateChangeListeners = [];
|
|
169
|
+
/** @internal */
|
|
59
170
|
connectedListeners = [];
|
|
171
|
+
/** @internal */
|
|
60
172
|
disconnectedListeners = [];
|
|
173
|
+
/** @internal */
|
|
61
174
|
notificationListeners = new Map();
|
|
175
|
+
/** @internal */
|
|
62
176
|
progressListeners = [];
|
|
177
|
+
/** @internal */
|
|
63
178
|
errorListeners = [];
|
|
179
|
+
/** @internal */
|
|
64
180
|
pongListeners = [];
|
|
181
|
+
/** @internal */
|
|
65
182
|
connectionTimeoutListeners = [];
|
|
183
|
+
/** @internal */
|
|
66
184
|
pendingRequests = new Map();
|
|
185
|
+
/** @internal */
|
|
67
186
|
currentRequestId = 0;
|
|
187
|
+
/** Current transport connection */
|
|
68
188
|
transport = null;
|
|
189
|
+
/** @internal */
|
|
69
190
|
clientResponsive = true;
|
|
191
|
+
/** @internal */
|
|
70
192
|
pingTimeoutId = null;
|
|
193
|
+
/** Whether to cleanup tools on shutdown */
|
|
71
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
|
+
*/
|
|
72
209
|
constructor(config) {
|
|
73
210
|
// Validate configuration
|
|
74
211
|
if (config?.name !== undefined && config.name === '') {
|
|
@@ -88,43 +225,50 @@ export class MCPSDKAdapter {
|
|
|
88
225
|
};
|
|
89
226
|
}
|
|
90
227
|
/**
|
|
91
|
-
* Get the adapter configuration
|
|
228
|
+
* Get the adapter configuration.
|
|
229
|
+
* @returns Copy of the current configuration
|
|
92
230
|
*/
|
|
93
231
|
getConfig() {
|
|
94
232
|
return { ...this.config };
|
|
95
233
|
}
|
|
96
234
|
/**
|
|
97
|
-
* Get supported transports
|
|
235
|
+
* Get supported transports.
|
|
236
|
+
* @returns Array of supported transport types
|
|
98
237
|
*/
|
|
99
238
|
getSupportedTransports() {
|
|
100
239
|
return [...(this.config.transports || ['stdio'])];
|
|
101
240
|
}
|
|
102
241
|
/**
|
|
103
|
-
* Get protocol version
|
|
242
|
+
* Get protocol version.
|
|
243
|
+
* @returns The MCP protocol version string
|
|
104
244
|
*/
|
|
105
245
|
getProtocolVersion() {
|
|
106
246
|
return this.config.protocolVersion || '2024-11-05';
|
|
107
247
|
}
|
|
108
248
|
/**
|
|
109
|
-
* Get SDK version
|
|
249
|
+
* Get SDK version.
|
|
250
|
+
* @returns The SDK version string
|
|
110
251
|
*/
|
|
111
252
|
getSDKVersion() {
|
|
112
253
|
return '1.0.0';
|
|
113
254
|
}
|
|
114
255
|
/**
|
|
115
|
-
* Get capabilities
|
|
256
|
+
* Get capabilities.
|
|
257
|
+
* @returns Copy of the server capabilities configuration
|
|
116
258
|
*/
|
|
117
259
|
getCapabilities() {
|
|
118
260
|
return { ...this.config.capabilities };
|
|
119
261
|
}
|
|
120
262
|
/**
|
|
121
|
-
* Get connection state
|
|
263
|
+
* Get connection state.
|
|
264
|
+
* @returns Current connection state
|
|
122
265
|
*/
|
|
123
266
|
getConnectionState() {
|
|
124
267
|
return this.connectionState;
|
|
125
268
|
}
|
|
126
269
|
/**
|
|
127
|
-
* Set connection state and notify listeners
|
|
270
|
+
* Set connection state and notify listeners.
|
|
271
|
+
* @internal
|
|
128
272
|
*/
|
|
129
273
|
setConnectionState(state) {
|
|
130
274
|
this.connectionState = state;
|
|
@@ -143,25 +287,34 @@ export class MCPSDKAdapter {
|
|
|
143
287
|
}
|
|
144
288
|
}
|
|
145
289
|
/**
|
|
146
|
-
* Register a state change listener
|
|
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
|
+
* })
|
|
147
296
|
*/
|
|
148
297
|
onStateChange(listener) {
|
|
149
298
|
this.stateChangeListeners.push(listener);
|
|
150
299
|
}
|
|
151
300
|
/**
|
|
152
|
-
* Register a connected listener
|
|
301
|
+
* Register a connected listener.
|
|
302
|
+
* @param listener - Callback invoked when connection is established
|
|
153
303
|
*/
|
|
154
304
|
onConnected(listener) {
|
|
155
305
|
this.connectedListeners.push(listener);
|
|
156
306
|
}
|
|
157
307
|
/**
|
|
158
|
-
* Register a disconnected listener
|
|
308
|
+
* Register a disconnected listener.
|
|
309
|
+
* @param listener - Callback invoked when connection is lost
|
|
159
310
|
*/
|
|
160
311
|
onDisconnected(listener) {
|
|
161
312
|
this.disconnectedListeners.push(listener);
|
|
162
313
|
}
|
|
163
314
|
/**
|
|
164
|
-
* Register a notification listener
|
|
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
|
|
165
318
|
*/
|
|
166
319
|
onNotification(type, listener) {
|
|
167
320
|
const listeners = this.notificationListeners.get(type) || [];
|
|
@@ -169,7 +322,8 @@ export class MCPSDKAdapter {
|
|
|
169
322
|
this.notificationListeners.set(type, listeners);
|
|
170
323
|
}
|
|
171
324
|
/**
|
|
172
|
-
* Emit a notification
|
|
325
|
+
* Emit a notification.
|
|
326
|
+
* @internal
|
|
173
327
|
*/
|
|
174
328
|
emitNotification(type) {
|
|
175
329
|
const listeners = this.notificationListeners.get(type) || [];
|
|
@@ -178,31 +332,45 @@ export class MCPSDKAdapter {
|
|
|
178
332
|
}
|
|
179
333
|
}
|
|
180
334
|
/**
|
|
181
|
-
* Register a progress listener
|
|
335
|
+
* Register a progress listener.
|
|
336
|
+
* @param listener - Callback invoked when tool reports progress
|
|
182
337
|
*/
|
|
183
338
|
onProgress(listener) {
|
|
184
339
|
this.progressListeners.push(listener);
|
|
185
340
|
}
|
|
186
341
|
/**
|
|
187
|
-
* Register an error listener
|
|
342
|
+
* Register an error listener.
|
|
343
|
+
* @param listener - Callback invoked when an error occurs
|
|
188
344
|
*/
|
|
189
345
|
onError(listener) {
|
|
190
346
|
this.errorListeners.push(listener);
|
|
191
347
|
}
|
|
192
348
|
/**
|
|
193
|
-
* Register a pong listener
|
|
349
|
+
* Register a pong listener.
|
|
350
|
+
* @param listener - Callback invoked when pong response is received
|
|
194
351
|
*/
|
|
195
352
|
onPong(listener) {
|
|
196
353
|
this.pongListeners.push(listener);
|
|
197
354
|
}
|
|
198
355
|
/**
|
|
199
|
-
* Register a connection timeout listener
|
|
356
|
+
* Register a connection timeout listener.
|
|
357
|
+
* @param listener - Callback invoked when connection times out
|
|
200
358
|
*/
|
|
201
359
|
onConnectionTimeout(listener) {
|
|
202
360
|
this.connectionTimeoutListeners.push(listener);
|
|
203
361
|
}
|
|
204
362
|
/**
|
|
205
|
-
* Start the adapter
|
|
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()
|
|
206
374
|
*/
|
|
207
375
|
async start() {
|
|
208
376
|
if (this.connectionState !== 'disconnected') {
|
|
@@ -214,7 +382,13 @@ export class MCPSDKAdapter {
|
|
|
214
382
|
this.setConnectionState('connected');
|
|
215
383
|
}
|
|
216
384
|
/**
|
|
217
|
-
* Connect with a transport
|
|
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
|
|
218
392
|
*/
|
|
219
393
|
async connect(transport) {
|
|
220
394
|
this.transport = transport;
|
|
@@ -223,7 +397,20 @@ export class MCPSDKAdapter {
|
|
|
223
397
|
}
|
|
224
398
|
}
|
|
225
399
|
/**
|
|
226
|
-
* Shutdown the adapter
|
|
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 })
|
|
227
414
|
*/
|
|
228
415
|
async shutdown(options) {
|
|
229
416
|
const cleanup = options?.cleanup ?? false;
|
|
@@ -245,7 +432,8 @@ export class MCPSDKAdapter {
|
|
|
245
432
|
this.setConnectionState('disconnected');
|
|
246
433
|
}
|
|
247
434
|
/**
|
|
248
|
-
* Wait for all pending requests to complete
|
|
435
|
+
* Wait for all pending requests to complete.
|
|
436
|
+
* @internal
|
|
249
437
|
*/
|
|
250
438
|
async waitForPendingRequests() {
|
|
251
439
|
while (this.pendingRequests.size > 0) {
|
|
@@ -253,7 +441,15 @@ export class MCPSDKAdapter {
|
|
|
253
441
|
}
|
|
254
442
|
}
|
|
255
443
|
/**
|
|
256
|
-
* Handle client initialization
|
|
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
|
|
257
453
|
*/
|
|
258
454
|
async handleClientInitialize(request) {
|
|
259
455
|
// Validate protocol version
|
|
@@ -276,13 +472,31 @@ export class MCPSDKAdapter {
|
|
|
276
472
|
};
|
|
277
473
|
}
|
|
278
474
|
/**
|
|
279
|
-
* Get current session
|
|
475
|
+
* Get current session.
|
|
476
|
+
* @returns Current session or null if not initialized
|
|
280
477
|
*/
|
|
281
478
|
getSession() {
|
|
282
479
|
return this.session;
|
|
283
480
|
}
|
|
284
481
|
/**
|
|
285
|
-
* Register a tool
|
|
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
|
+
* })
|
|
286
500
|
*/
|
|
287
501
|
registerTool(registration) {
|
|
288
502
|
// Validate schema type
|
|
@@ -304,7 +518,15 @@ export class MCPSDKAdapter {
|
|
|
304
518
|
this.emitNotification('tools/list_changed');
|
|
305
519
|
}
|
|
306
520
|
/**
|
|
307
|
-
* Register multiple tools
|
|
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
|
|
308
530
|
*/
|
|
309
531
|
registerTools(registrations) {
|
|
310
532
|
for (const registration of registrations) {
|
|
@@ -328,14 +550,17 @@ export class MCPSDKAdapter {
|
|
|
328
550
|
this.emitNotification('tools/list_changed');
|
|
329
551
|
}
|
|
330
552
|
/**
|
|
331
|
-
* Unregister a tool
|
|
553
|
+
* Unregister a tool.
|
|
554
|
+
* @param name - Name of the tool to unregister
|
|
332
555
|
*/
|
|
333
556
|
unregisterTool(name) {
|
|
334
557
|
this.tools.delete(name);
|
|
335
558
|
this.emitNotification('tools/list_changed');
|
|
336
559
|
}
|
|
337
560
|
/**
|
|
338
|
-
* Get a tool by name
|
|
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
|
|
339
564
|
*/
|
|
340
565
|
getTool(name) {
|
|
341
566
|
const tool = this.tools.get(name);
|
|
@@ -349,7 +574,8 @@ export class MCPSDKAdapter {
|
|
|
349
574
|
};
|
|
350
575
|
}
|
|
351
576
|
/**
|
|
352
|
-
* List all tools
|
|
577
|
+
* List all tools.
|
|
578
|
+
* @returns Array of tool metadata (without handlers)
|
|
353
579
|
*/
|
|
354
580
|
listTools() {
|
|
355
581
|
const result = [];
|
|
@@ -364,7 +590,11 @@ export class MCPSDKAdapter {
|
|
|
364
590
|
return result;
|
|
365
591
|
}
|
|
366
592
|
/**
|
|
367
|
-
* Register gitdo tools
|
|
593
|
+
* Register gitdo tools.
|
|
594
|
+
*
|
|
595
|
+
* @description
|
|
596
|
+
* Convenience method that registers all built-in git tools.
|
|
597
|
+
* Skips tools that are already registered.
|
|
368
598
|
*/
|
|
369
599
|
registerGitdoTools() {
|
|
370
600
|
for (const tool of gitTools) {
|
|
@@ -379,7 +609,14 @@ export class MCPSDKAdapter {
|
|
|
379
609
|
}
|
|
380
610
|
}
|
|
381
611
|
/**
|
|
382
|
-
* Handle tools/list request
|
|
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
|
|
383
620
|
*/
|
|
384
621
|
async handleToolsList(options) {
|
|
385
622
|
const allTools = this.listTools();
|
|
@@ -404,7 +641,23 @@ export class MCPSDKAdapter {
|
|
|
404
641
|
return result;
|
|
405
642
|
}
|
|
406
643
|
/**
|
|
407
|
-
* Handle tools/call request
|
|
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
|
|
408
661
|
*/
|
|
409
662
|
handleToolsCall(request) {
|
|
410
663
|
// Generate requestId upfront for consistent tracking
|
|
@@ -473,7 +726,13 @@ export class MCPSDKAdapter {
|
|
|
473
726
|
return promise;
|
|
474
727
|
}
|
|
475
728
|
/**
|
|
476
|
-
* Cancel a request
|
|
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
|
|
477
736
|
*/
|
|
478
737
|
cancelRequest(requestId) {
|
|
479
738
|
if (requestId) {
|
|
@@ -484,7 +743,14 @@ export class MCPSDKAdapter {
|
|
|
484
743
|
}
|
|
485
744
|
}
|
|
486
745
|
/**
|
|
487
|
-
* Handle raw JSON-RPC message
|
|
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
|
|
488
754
|
*/
|
|
489
755
|
async handleMessage(message) {
|
|
490
756
|
let parsed;
|
|
@@ -565,7 +831,8 @@ export class MCPSDKAdapter {
|
|
|
565
831
|
}
|
|
566
832
|
}
|
|
567
833
|
/**
|
|
568
|
-
* Simulate a pending request (for testing)
|
|
834
|
+
* Simulate a pending request (for testing).
|
|
835
|
+
* @internal
|
|
569
836
|
*/
|
|
570
837
|
simulatePendingRequest() {
|
|
571
838
|
const requestId = `sim-req-${++this.currentRequestId}`;
|
|
@@ -577,7 +844,8 @@ export class MCPSDKAdapter {
|
|
|
577
844
|
};
|
|
578
845
|
}
|
|
579
846
|
/**
|
|
580
|
-
* Simulate an internal error (for testing)
|
|
847
|
+
* Simulate an internal error (for testing).
|
|
848
|
+
* @internal
|
|
581
849
|
*/
|
|
582
850
|
simulateInternalError(error) {
|
|
583
851
|
const mcpError = new MCPSDKError(MCPSDKErrorCode.INTERNAL_ERROR, error.message);
|
|
@@ -586,7 +854,7 @@ export class MCPSDKAdapter {
|
|
|
586
854
|
}
|
|
587
855
|
}
|
|
588
856
|
/**
|
|
589
|
-
* Send ping
|
|
857
|
+
* Send ping to check client responsiveness.
|
|
590
858
|
*/
|
|
591
859
|
sendPing() {
|
|
592
860
|
// Simulate ping/pong
|
|
@@ -609,7 +877,8 @@ export class MCPSDKAdapter {
|
|
|
609
877
|
}
|
|
610
878
|
}
|
|
611
879
|
/**
|
|
612
|
-
* Simulate client becoming unresponsive (for testing)
|
|
880
|
+
* Simulate client becoming unresponsive (for testing).
|
|
881
|
+
* @internal
|
|
613
882
|
*/
|
|
614
883
|
simulateClientUnresponsive() {
|
|
615
884
|
this.clientResponsive = false;
|
|
@@ -618,7 +887,21 @@ export class MCPSDKAdapter {
|
|
|
618
887
|
}
|
|
619
888
|
}
|
|
620
889
|
/**
|
|
621
|
-
* Transport factory
|
|
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' })
|
|
622
905
|
*/
|
|
623
906
|
export const MCPSDKTransport = {
|
|
624
907
|
createStdio(_options) {
|
|
@@ -664,7 +947,26 @@ export const MCPSDKTransport = {
|
|
|
664
947
|
},
|
|
665
948
|
};
|
|
666
949
|
/**
|
|
667
|
-
* Factory function to create an MCP SDK adapter
|
|
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()
|
|
668
970
|
*/
|
|
669
971
|
export function createMCPSDKAdapter(config) {
|
|
670
972
|
return new MCPSDKAdapter(config);
|