kernl 0.2.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-check-types.log +4 -0
  3. package/CHANGELOG.md +138 -0
  4. package/LICENSE +1 -1
  5. package/dist/agent/__tests__/concurrency.test.d.ts +2 -0
  6. package/dist/agent/__tests__/concurrency.test.d.ts.map +1 -0
  7. package/dist/agent/__tests__/concurrency.test.js +152 -0
  8. package/dist/agent/__tests__/run.test.d.ts +2 -0
  9. package/dist/agent/__tests__/run.test.d.ts.map +1 -0
  10. package/dist/agent/__tests__/run.test.js +357 -0
  11. package/dist/agent/index.d.ts +1 -0
  12. package/dist/agent/index.d.ts.map +1 -0
  13. package/dist/agent.d.ts +32 -9
  14. package/dist/agent.d.ts.map +1 -1
  15. package/dist/agent.js +101 -14
  16. package/dist/api/__tests__/cursor-page.test.d.ts +2 -0
  17. package/dist/api/__tests__/cursor-page.test.d.ts.map +1 -0
  18. package/dist/api/__tests__/cursor-page.test.js +414 -0
  19. package/dist/api/__tests__/offset-page.test.d.ts +2 -0
  20. package/dist/api/__tests__/offset-page.test.d.ts.map +1 -0
  21. package/dist/api/__tests__/offset-page.test.js +510 -0
  22. package/dist/api/__tests__/threads.test.d.ts +2 -0
  23. package/dist/api/__tests__/threads.test.d.ts.map +1 -0
  24. package/dist/api/__tests__/threads.test.js +338 -0
  25. package/dist/api/models/index.d.ts +2 -0
  26. package/dist/api/models/index.d.ts.map +1 -0
  27. package/dist/api/models/thread.d.ts +120 -0
  28. package/dist/api/models/thread.d.ts.map +1 -0
  29. package/dist/api/pagination/base.d.ts +48 -0
  30. package/dist/api/pagination/base.d.ts.map +1 -0
  31. package/dist/api/pagination/base.js +45 -0
  32. package/dist/api/pagination/cursor.d.ts +44 -0
  33. package/dist/api/pagination/cursor.d.ts.map +1 -0
  34. package/dist/api/pagination/cursor.js +52 -0
  35. package/dist/api/pagination/offset.d.ts +42 -0
  36. package/dist/api/pagination/offset.d.ts.map +1 -0
  37. package/dist/api/pagination/offset.js +55 -0
  38. package/dist/api/resources/threads/events.d.ts +21 -0
  39. package/dist/api/resources/threads/events.d.ts.map +1 -0
  40. package/dist/api/resources/threads/events.js +24 -0
  41. package/dist/api/resources/threads/index.d.ts +4 -0
  42. package/dist/api/resources/threads/index.d.ts.map +1 -0
  43. package/dist/api/resources/threads/index.js +2 -0
  44. package/dist/api/resources/threads/threads.d.ts +57 -0
  45. package/dist/api/resources/threads/threads.d.ts.map +1 -0
  46. package/dist/api/resources/threads/threads.js +199 -0
  47. package/dist/api/resources/threads/types.d.ts +123 -0
  48. package/dist/api/resources/threads/types.d.ts.map +1 -0
  49. package/dist/api/resources/threads/utils.d.ts +18 -0
  50. package/dist/api/resources/threads/utils.d.ts.map +1 -0
  51. package/dist/api/resources/threads/utils.js +78 -0
  52. package/dist/context.d.ts +5 -1
  53. package/dist/context.d.ts.map +1 -1
  54. package/dist/context.js +6 -1
  55. package/dist/index.d.ts +9 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +7 -0
  58. package/dist/internal.d.ts +4 -0
  59. package/dist/internal.d.ts.map +1 -0
  60. package/dist/internal.js +2 -0
  61. package/dist/kernl/index.d.ts +3 -0
  62. package/dist/kernl/index.d.ts.map +1 -0
  63. package/dist/kernl/index.js +2 -0
  64. package/dist/kernl/kernl.d.ts +64 -0
  65. package/dist/kernl/kernl.d.ts.map +1 -0
  66. package/dist/kernl/kernl.js +116 -0
  67. package/dist/kernl/threads.d.ts +110 -0
  68. package/dist/kernl/threads.d.ts.map +1 -0
  69. package/dist/kernl/threads.js +126 -0
  70. package/dist/kernl.d.ts +22 -6
  71. package/dist/kernl.d.ts.map +1 -1
  72. package/dist/kernl.js +73 -10
  73. package/dist/lib/env.d.ts +3 -3
  74. package/dist/lib/env.js +1 -1
  75. package/dist/mcp/__tests__/integration.test.js +8 -8
  76. package/dist/mcp/__tests__/utils.test.js +6 -6
  77. package/dist/mcp/http.d.ts +1 -1
  78. package/dist/mcp/http.d.ts.map +1 -1
  79. package/dist/mcp/http.js +9 -9
  80. package/dist/mcp/sse.d.ts +1 -1
  81. package/dist/mcp/sse.d.ts.map +1 -1
  82. package/dist/mcp/sse.js +7 -7
  83. package/dist/mcp/utils.d.ts +1 -1
  84. package/dist/mcp/utils.d.ts.map +1 -1
  85. package/dist/mcp/utils.js +4 -5
  86. package/dist/storage/__tests__/in-memory.test.d.ts +2 -0
  87. package/dist/storage/__tests__/in-memory.test.d.ts.map +1 -0
  88. package/dist/storage/__tests__/in-memory.test.js +455 -0
  89. package/dist/storage/base.d.ts +64 -0
  90. package/dist/storage/base.d.ts.map +1 -0
  91. package/dist/storage/base.js +4 -0
  92. package/dist/storage/in-memory.d.ts +62 -0
  93. package/dist/storage/in-memory.d.ts.map +1 -0
  94. package/dist/storage/in-memory.js +283 -0
  95. package/dist/storage/index.d.ts +10 -0
  96. package/dist/storage/index.d.ts.map +1 -0
  97. package/dist/storage/index.js +7 -0
  98. package/dist/storage/thread.d.ts +123 -0
  99. package/dist/storage/thread.d.ts.map +1 -0
  100. package/dist/storage/thread.js +4 -0
  101. package/dist/task.d.ts +5 -3
  102. package/dist/task.d.ts.map +1 -1
  103. package/dist/task.js +10 -8
  104. package/dist/thread/__tests__/fixtures/mock-model.d.ts +1 -2
  105. package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -1
  106. package/dist/thread/__tests__/integration.test.js +6 -6
  107. package/dist/thread/__tests__/namespace.test.d.ts +2 -0
  108. package/dist/thread/__tests__/namespace.test.d.ts.map +1 -0
  109. package/dist/thread/__tests__/namespace.test.js +131 -0
  110. package/dist/thread/__tests__/thread-persistence.test.d.ts +2 -0
  111. package/dist/thread/__tests__/thread-persistence.test.d.ts.map +1 -0
  112. package/dist/thread/__tests__/thread-persistence.test.js +351 -0
  113. package/dist/thread/__tests__/thread.test.js +49 -51
  114. package/dist/thread/thread.d.ts +70 -18
  115. package/dist/thread/thread.d.ts.map +1 -1
  116. package/dist/thread/thread.js +211 -73
  117. package/dist/thread/utils.d.ts +36 -8
  118. package/dist/thread/utils.d.ts.map +1 -1
  119. package/dist/thread/utils.js +52 -8
  120. package/dist/tool/__tests__/fixtures.js +1 -1
  121. package/dist/tool/__tests__/toolkit.test.js +15 -12
  122. package/dist/tool/tool.js +3 -3
  123. package/dist/types/kernl.d.ts +42 -0
  124. package/dist/types/kernl.d.ts.map +1 -0
  125. package/dist/types/thread.d.ts +108 -22
  126. package/dist/types/thread.d.ts.map +1 -1
  127. package/dist/types/thread.js +12 -0
  128. package/package.json +11 -7
  129. package/src/agent/__tests__/concurrency.test.ts +194 -0
  130. package/src/agent/__tests__/run.test.ts +441 -0
  131. package/src/agent/index.ts +0 -0
  132. package/src/agent.ts +139 -24
  133. package/src/api/__tests__/cursor-page.test.ts +512 -0
  134. package/src/api/__tests__/offset-page.test.ts +624 -0
  135. package/src/api/__tests__/threads.test.ts +415 -0
  136. package/src/api/models/index.ts +6 -0
  137. package/src/api/models/thread.ts +138 -0
  138. package/src/api/pagination/base.ts +79 -0
  139. package/src/api/pagination/cursor.ts +86 -0
  140. package/src/api/pagination/offset.ts +89 -0
  141. package/src/api/resources/threads/events.ts +26 -0
  142. package/src/api/resources/threads/index.ts +9 -0
  143. package/src/api/resources/threads/threads.ts +256 -0
  144. package/src/api/resources/threads/types.ts +143 -0
  145. package/src/api/resources/threads/utils.ts +104 -0
  146. package/src/context.ts +10 -1
  147. package/src/index.ts +49 -1
  148. package/src/internal.ts +15 -0
  149. package/src/kernl.ts +86 -17
  150. package/src/mcp/__tests__/integration.test.ts +8 -9
  151. package/src/mcp/__tests__/utils.test.ts +6 -6
  152. package/src/mcp/http.ts +9 -9
  153. package/src/mcp/sse.ts +7 -7
  154. package/src/mcp/utils.ts +6 -5
  155. package/src/storage/__tests__/in-memory.test.ts +534 -0
  156. package/src/storage/base.ts +77 -0
  157. package/src/storage/in-memory.ts +372 -0
  158. package/src/storage/index.ts +21 -0
  159. package/src/storage/thread.ts +141 -0
  160. package/src/task.ts +12 -10
  161. package/src/thread/__tests__/fixtures/mock-model.ts +2 -4
  162. package/src/thread/__tests__/integration.test.ts +13 -12
  163. package/src/thread/__tests__/namespace.test.ts +158 -0
  164. package/src/thread/__tests__/thread-persistence.test.ts +367 -0
  165. package/src/thread/__tests__/thread.test.ts +52 -54
  166. package/src/thread/thread.ts +247 -96
  167. package/src/thread/utils.ts +76 -13
  168. package/src/tool/__tests__/fixtures.ts +1 -1
  169. package/src/tool/__tests__/toolkit.test.ts +15 -12
  170. package/src/tool/tool.ts +3 -3
  171. package/src/types/kernl.ts +51 -0
  172. package/src/types/thread.ts +139 -25
  173. package/vitest.config.ts +1 -0
  174. package/dist/env.d.ts +0 -45
  175. package/dist/env.d.ts.map +0 -1
  176. package/dist/env.js +0 -31
  177. package/dist/error.d.ts +0 -1
  178. package/dist/error.d.ts.map +0 -1
  179. package/dist/kernel.d.ts +0 -7
  180. package/dist/kernel.d.ts.map +0 -1
  181. package/dist/kernel.js +0 -7
  182. package/dist/lib/serde/__tests__/codec.test.d.ts +0 -2
  183. package/dist/lib/serde/__tests__/codec.test.d.ts.map +0 -1
  184. package/dist/lib/serde/__tests__/codec.test.js +0 -75
  185. package/dist/lib/serde/codec.d.ts +0 -12
  186. package/dist/lib/serde/codec.d.ts.map +0 -1
  187. package/dist/lib/serde/codec.js +0 -54
  188. package/dist/lib/serde/thread.d.ts +0 -1
  189. package/dist/lib/serde/thread.d.ts.map +0 -1
  190. package/dist/lib/serde/thread.js +0 -172
  191. package/dist/lib/serde/tool.d.ts +0 -36
  192. package/dist/lib/serde/tool.d.ts.map +0 -1
  193. package/dist/lib/utils.d.ts +0 -19
  194. package/dist/lib/utils.d.ts.map +0 -1
  195. package/dist/lib/utils.js +0 -41
  196. package/dist/logger.d.ts +0 -36
  197. package/dist/logger.d.ts.map +0 -1
  198. package/dist/logger.js +0 -43
  199. package/dist/mcp/__tests__/fixtures/echo-server.d.ts +0 -3
  200. package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +0 -1
  201. package/dist/mcp/__tests__/fixtures/echo-server.js +0 -92
  202. package/dist/mcp/__tests__/fixtures/math-server.d.ts +0 -3
  203. package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +0 -1
  204. package/dist/mcp/__tests__/fixtures/math-server.js +0 -98
  205. package/dist/mcp/__tests__/fixtures/test-server.d.ts +0 -3
  206. package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +0 -1
  207. package/dist/mcp/__tests__/fixtures/test-server.js +0 -163
  208. package/dist/mcp/__tests__/test-utils.d.ts +0 -17
  209. package/dist/mcp/__tests__/test-utils.d.ts.map +0 -1
  210. package/dist/mcp/__tests__/test-utils.js +0 -42
  211. package/dist/mcp/node.d.ts +0 -60
  212. package/dist/mcp/node.d.ts.map +0 -1
  213. package/dist/mcp/node.js +0 -297
  214. package/dist/model.d.ts +0 -175
  215. package/dist/model.d.ts.map +0 -1
  216. package/dist/providers/ai.d.ts +0 -1
  217. package/dist/providers/ai.d.ts.map +0 -1
  218. package/dist/providers/ai.js +0 -1
  219. package/dist/providers/default.d.ts +0 -16
  220. package/dist/providers/default.d.ts.map +0 -1
  221. package/dist/providers/default.js +0 -17
  222. package/dist/providers/registry.d.ts +0 -1
  223. package/dist/providers/registry.d.ts.map +0 -1
  224. package/dist/providers/registry.js +0 -1
  225. package/dist/sched/scheduler.d.ts +0 -20
  226. package/dist/sched/scheduler.d.ts.map +0 -1
  227. package/dist/sched/task.d.ts +0 -92
  228. package/dist/sched/task.d.ts.map +0 -1
  229. package/dist/sched/task.js +0 -102
  230. package/dist/serde/__tests__/codec.test.d.ts +0 -2
  231. package/dist/serde/__tests__/codec.test.d.ts.map +0 -1
  232. package/dist/serde/__tests__/codec.test.js +0 -75
  233. package/dist/serde/codec.d.ts +0 -12
  234. package/dist/serde/codec.d.ts.map +0 -1
  235. package/dist/serde/codec.js +0 -54
  236. package/dist/serde/json.d.ts +0 -8
  237. package/dist/serde/json.d.ts.map +0 -1
  238. package/dist/serde/json.js +0 -13
  239. package/dist/serde/thread.d.ts +0 -687
  240. package/dist/serde/thread.d.ts.map +0 -1
  241. package/dist/serde/thread.js +0 -158
  242. package/dist/serde/tool.d.ts +0 -36
  243. package/dist/serde/tool.d.ts.map +0 -1
  244. package/dist/session.d.ts +0 -1
  245. package/dist/session.d.ts.map +0 -1
  246. package/dist/session.js +0 -1
  247. package/dist/thread/__tests__/stream.test.d.ts +0 -2
  248. package/dist/thread/__tests__/stream.test.d.ts.map +0 -1
  249. package/dist/thread/__tests__/stream.test.js +0 -244
  250. package/dist/tool/mcp.d.ts +0 -75
  251. package/dist/tool/mcp.d.ts.map +0 -1
  252. package/dist/tool/mcp.js +0 -111
  253. package/dist/tools.d.ts +0 -362
  254. package/dist/tools.d.ts.map +0 -1
  255. package/dist/tools.js +0 -220
  256. package/dist/types/proto.d.ts +0 -1551
  257. package/dist/types/proto.d.ts.map +0 -1
  258. package/dist/types/proto.js +0 -531
  259. package/dist/usage.d.ts +0 -43
  260. package/dist/usage.d.ts.map +0 -1
  261. package/dist/usage.js +0 -61
  262. package/src/lib/serde/thread.ts +0 -188
  263. /package/dist/{error.js → agent/index.js} +0 -0
  264. /package/dist/{lib/serde/tool.js → api/models/index.js} +0 -0
  265. /package/dist/{model.js → api/models/thread.js} +0 -0
  266. /package/dist/{sched/scheduler.js → api/resources/threads/types.js} +0 -0
  267. /package/dist/{serde/tool.js → types/kernl.js} +0 -0
@@ -1,163 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Simple test server combining math and string operations for MCP testing.
4
- *
5
- * Provides deterministic operations for comprehensive test coverage.
6
- */
7
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
8
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
- import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
10
- const server = new Server({
11
- name: "test-server",
12
- version: "1.0.0",
13
- }, {
14
- capabilities: {
15
- tools: {},
16
- },
17
- });
18
- // List available tools
19
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
20
- tools: [
21
- // Math tools
22
- {
23
- name: "add",
24
- description: "Add two numbers",
25
- inputSchema: {
26
- type: "object",
27
- properties: {
28
- a: { type: "number", description: "First number" },
29
- b: { type: "number", description: "Second number" },
30
- },
31
- required: ["a", "b"],
32
- },
33
- },
34
- {
35
- name: "multiply",
36
- description: "Multiply two numbers",
37
- inputSchema: {
38
- type: "object",
39
- properties: {
40
- a: { type: "number", description: "First number" },
41
- b: { type: "number", description: "Second number" },
42
- },
43
- required: ["a", "b"],
44
- },
45
- },
46
- {
47
- name: "divide",
48
- description: "Divide two numbers",
49
- inputSchema: {
50
- type: "object",
51
- properties: {
52
- a: { type: "number", description: "Numerator" },
53
- b: { type: "number", description: "Denominator" },
54
- },
55
- required: ["a", "b"],
56
- },
57
- },
58
- // String tools
59
- {
60
- name: "echo",
61
- description: "Echo back the input text",
62
- inputSchema: {
63
- type: "object",
64
- properties: {
65
- text: { type: "string", description: "Text to echo" },
66
- },
67
- required: ["text"],
68
- },
69
- },
70
- {
71
- name: "uppercase",
72
- description: "Convert text to uppercase",
73
- inputSchema: {
74
- type: "object",
75
- properties: {
76
- text: { type: "string", description: "Text to convert" },
77
- },
78
- required: ["text"],
79
- },
80
- },
81
- {
82
- name: "reverse",
83
- description: "Reverse the text",
84
- inputSchema: {
85
- type: "object",
86
- properties: {
87
- text: { type: "string", description: "Text to reverse" },
88
- },
89
- required: ["text"],
90
- },
91
- },
92
- ],
93
- }));
94
- // Handle tool calls
95
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
96
- const { name, arguments: args } = request.params;
97
- switch (name) {
98
- // Math operations
99
- case "add":
100
- return {
101
- content: [
102
- {
103
- type: "text",
104
- text: String(args.a + args.b),
105
- },
106
- ],
107
- };
108
- case "multiply":
109
- return {
110
- content: [
111
- {
112
- type: "text",
113
- text: String(args.a * args.b),
114
- },
115
- ],
116
- };
117
- case "divide":
118
- if (args.b === 0) {
119
- throw new Error("Division by zero");
120
- }
121
- return {
122
- content: [
123
- {
124
- type: "text",
125
- text: String(args.a / args.b),
126
- },
127
- ],
128
- };
129
- // String operations
130
- case "echo":
131
- return {
132
- content: [
133
- {
134
- type: "text",
135
- text: args.text,
136
- },
137
- ],
138
- };
139
- case "uppercase":
140
- return {
141
- content: [
142
- {
143
- type: "text",
144
- text: args.text.toUpperCase(),
145
- },
146
- ],
147
- };
148
- case "reverse":
149
- return {
150
- content: [
151
- {
152
- type: "text",
153
- text: args.text.split("").reverse().join(""),
154
- },
155
- ],
156
- };
157
- default:
158
- throw new Error(`Unknown tool: ${name}`);
159
- }
160
- });
161
- // Start the server
162
- const transport = new StdioServerTransport();
163
- await server.connect(transport);
@@ -1,17 +0,0 @@
1
- import { MCPServerStdio } from "../stdio";
2
- /**
3
- * Helper to run a test with an MCP server, ensuring cleanup.
4
- */
5
- export declare function withMCPServer<T>(serverPath: string, fn: (server: MCPServerStdio) => Promise<T>): Promise<T>;
6
- /**
7
- * Helper to create a server without auto-connecting.
8
- */
9
- export declare function createMCPServer(serverPath: string, options?: {
10
- id?: string;
11
- cacheToolsList?: boolean;
12
- }): MCPServerStdio;
13
- /**
14
- * Wait for a condition to be true or timeout.
15
- */
16
- export declare function waitFor(condition: () => boolean | Promise<boolean>, timeout?: number, interval?: number): Promise<void>;
17
- //# sourceMappingURL=test-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C;;GAEG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GACzC,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,GACtD,cAAc,CAOhB;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAC3C,OAAO,SAAO,EACd,QAAQ,SAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAWf"}
@@ -1,42 +0,0 @@
1
- import { MCPServerStdio } from "../stdio";
2
- /**
3
- * Helper to run a test with an MCP server, ensuring cleanup.
4
- */
5
- export async function withMCPServer(serverPath, fn) {
6
- const server = new MCPServerStdio({
7
- id: "test-server",
8
- command: "npx",
9
- args: ["tsx", serverPath],
10
- });
11
- try {
12
- await server.connect();
13
- return await fn(server);
14
- }
15
- finally {
16
- await server.close();
17
- }
18
- }
19
- /**
20
- * Helper to create a server without auto-connecting.
21
- */
22
- export function createMCPServer(serverPath, options = {}) {
23
- return new MCPServerStdio({
24
- id: options.id ?? "test-server",
25
- command: "npx",
26
- args: ["tsx", serverPath],
27
- cacheToolsList: options.cacheToolsList,
28
- });
29
- }
30
- /**
31
- * Wait for a condition to be true or timeout.
32
- */
33
- export async function waitFor(condition, timeout = 5000, interval = 100) {
34
- const startTime = Date.now();
35
- while (Date.now() - startTime < timeout) {
36
- if (await condition()) {
37
- return;
38
- }
39
- await new Promise((resolve) => setTimeout(resolve, interval));
40
- }
41
- throw new Error(`Timeout waiting for condition after ${timeout}ms`);
42
- }
@@ -1,60 +0,0 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { MCPTool, CallToolResultContent, DefaultMCPServerStdioOptions, InitializeResult, MCPServerSSEOptions, MCPServerStreamableHttpOptions, MCPServerStdioOptions } from "./types";
3
- export interface SessionMessage {
4
- message: any;
5
- }
6
- export declare class NodeMCPServerStdio extends BaseMCPServerStdio {
7
- protected session: Client | null;
8
- protected _cacheDirty: boolean;
9
- protected _toolsList: any[];
10
- protected serverInitializeResult: InitializeResult | null;
11
- protected clientSessionTimeoutSeconds?: number;
12
- protected timeout: number;
13
- params: DefaultMCPServerStdioOptions;
14
- private _name;
15
- private transport;
16
- constructor(params: MCPServerStdioOptions);
17
- connect(): Promise<void>;
18
- invalidateToolsCache(): Promise<void>;
19
- listTools(): Promise<MCPTool[]>;
20
- callTool(toolName: string, args: Record<string, unknown> | null): Promise<CallToolResultContent>;
21
- get name(): string;
22
- close(): Promise<void>;
23
- }
24
- export declare class NodeMCPServerSSE extends BaseMCPServerSSE {
25
- protected session: Client | null;
26
- protected _cacheDirty: boolean;
27
- protected _toolsList: any[];
28
- protected serverInitializeResult: InitializeResult | null;
29
- protected clientSessionTimeoutSeconds?: number;
30
- protected timeout: number;
31
- params: MCPServerSSEOptions;
32
- private _name;
33
- private transport;
34
- constructor(params: MCPServerSSEOptions);
35
- connect(): Promise<void>;
36
- invalidateToolsCache(): Promise<void>;
37
- listTools(): Promise<MCPTool[]>;
38
- callTool(toolName: string, args: Record<string, unknown> | null): Promise<CallToolResultContent>;
39
- get name(): string;
40
- close(): Promise<void>;
41
- }
42
- export declare class NodeMCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
43
- protected session: Client | null;
44
- protected _cacheDirty: boolean;
45
- protected _toolsList: any[];
46
- protected serverInitializeResult: InitializeResult | null;
47
- protected clientSessionTimeoutSeconds?: number;
48
- protected timeout: number;
49
- params: MCPServerStreamableHttpOptions;
50
- private _name;
51
- private transport;
52
- constructor(params: MCPServerStreamableHttpOptions);
53
- connect(): Promise<void>;
54
- invalidateToolsCache(): Promise<void>;
55
- listTools(): Promise<MCPTool[]>;
56
- callTool(toolName: string, args: Record<string, unknown> | null): Promise<CallToolResultContent>;
57
- get name(): string;
58
- close(): Promise<void>;
59
- }
60
- //# sourceMappingURL=node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file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C,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAoB/B,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACnC,OAAO,CAAC,qBAAqB,CAAC;IA4BjC,IAAI,IAAI,WAEP;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
package/dist/mcp/node.js DELETED
@@ -1,297 +0,0 @@
1
- import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
2
- import logger from "../logger";
3
- import { invalidateServerToolsCache } from "./base";
4
- function failedToImport(error) {
5
- logger.error(`
6
- Failed to load the MCP SDK. Please install the @modelcontextprotocol/sdk package.
7
-
8
- npm install @modelcontextprotocol/sdk
9
- `.trim());
10
- throw error;
11
- }
12
- export class NodeMCPServerStdio extends BaseMCPServerStdio {
13
- session = null;
14
- _cacheDirty = true;
15
- _toolsList = [];
16
- serverInitializeResult = null;
17
- clientSessionTimeoutSeconds;
18
- timeout;
19
- params;
20
- _name;
21
- transport = null;
22
- constructor(params) {
23
- super(params);
24
- this.clientSessionTimeoutSeconds = params.clientSessionTimeoutSeconds ?? 5;
25
- this.timeout = params.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
26
- if ("fullCommand" in params) {
27
- const elements = params.fullCommand.split(" ");
28
- const command = elements.shift();
29
- if (!command) {
30
- throw new Error("Invalid fullCommand: " + params.fullCommand);
31
- }
32
- this.params = {
33
- ...params,
34
- command: command,
35
- args: elements,
36
- encoding: params.encoding || "utf-8",
37
- encodingErrorHandler: params.encodingErrorHandler || "strict",
38
- };
39
- }
40
- else {
41
- this.params = params;
42
- }
43
- this._name = params.name || `stdio: ${this.params.command}`;
44
- }
45
- async connect() {
46
- try {
47
- this.transport = new StdioClientTransport({
48
- command: this.params.command,
49
- args: this.params.args,
50
- env: this.params.env,
51
- cwd: this.params.cwd,
52
- });
53
- this.session = new Client({
54
- name: this._name,
55
- version: "1.0.0",
56
- });
57
- await this.session.connect(this.transport);
58
- this.serverInitializeResult = {
59
- serverInfo: { name: this._name, version: "1.0.0" },
60
- };
61
- }
62
- catch (e) {
63
- this.logger.error("Error initializing MCP server:", e);
64
- await this.close();
65
- throw e;
66
- }
67
- this.debugLog(() => `Connected to MCP server: ${this._name}`);
68
- }
69
- async invalidateToolsCache() {
70
- await invalidateServerToolsCache(this.name);
71
- this._cacheDirty = true;
72
- }
73
- async listTools() {
74
- if (!this.session) {
75
- throw new Error("Server not initialized. Make sure you call connect() first.");
76
- }
77
- if (this.cacheToolsList && !this._cacheDirty && this._toolsList) {
78
- return this._toolsList;
79
- }
80
- this._cacheDirty = false;
81
- const response = await this.session.listTools();
82
- this.debugLog(() => `Listed tools: ${JSON.stringify(response)}`);
83
- this._toolsList = ListToolsResultSchema.parse(response).tools;
84
- return this._toolsList;
85
- }
86
- async callTool(toolName, args) {
87
- const { CallToolResultSchema } = await import("@modelcontextprotocol/sdk/types.js").catch(failedToImport);
88
- if (!this.session) {
89
- throw new Error("Server not initialized. Make sure you call connect() first.");
90
- }
91
- const response = await this.session.callTool({
92
- name: toolName,
93
- arguments: args ?? {},
94
- }, undefined, {
95
- timeout: this.timeout,
96
- });
97
- const parsed = CallToolResultSchema.parse(response);
98
- const result = parsed.content;
99
- this.debugLog(() => `Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`);
100
- return result;
101
- }
102
- get name() {
103
- return this._name;
104
- }
105
- async close() {
106
- if (this.transport) {
107
- await this.transport.close();
108
- this.transport = null;
109
- }
110
- if (this.session) {
111
- await this.session.close();
112
- this.session = null;
113
- }
114
- }
115
- }
116
- export class NodeMCPServerSSE extends BaseMCPServerSSE {
117
- session = null;
118
- _cacheDirty = true;
119
- _toolsList = [];
120
- serverInitializeResult = null;
121
- clientSessionTimeoutSeconds;
122
- timeout;
123
- params;
124
- _name;
125
- transport = null;
126
- constructor(params) {
127
- super(params);
128
- this.clientSessionTimeoutSeconds = params.clientSessionTimeoutSeconds ?? 5;
129
- this.params = params;
130
- this._name = params.name || `sse: ${this.params.url}`;
131
- this.timeout = params.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
132
- }
133
- async connect() {
134
- try {
135
- const { SSEClientTransport } = await import("@modelcontextprotocol/sdk/client/sse.js").catch(failedToImport);
136
- const { Client } = await import("@modelcontextprotocol/sdk/client/index.js").catch(failedToImport);
137
- this.transport = new SSEClientTransport(new URL(this.params.url), {
138
- authProvider: this.params.authProvider,
139
- requestInit: this.params.requestInit,
140
- eventSourceInit: this.params.eventSourceInit,
141
- });
142
- this.session = new Client({
143
- name: this._name,
144
- version: "1.0.0", // You may want to make this configurable
145
- });
146
- await this.session.connect(this.transport);
147
- this.serverInitializeResult = {
148
- serverInfo: { name: this._name, version: "1.0.0" },
149
- };
150
- }
151
- catch (e) {
152
- this.logger.error("Error initializing MCP server:", e);
153
- await this.close();
154
- throw e;
155
- }
156
- this.debugLog(() => `Connected to MCP server: ${this._name}`);
157
- }
158
- async invalidateToolsCache() {
159
- await invalidateServerToolsCache(this.name);
160
- this._cacheDirty = true;
161
- }
162
- async listTools() {
163
- const { ListToolsResultSchema } = await import("@modelcontextprotocol/sdk/types.js").catch(failedToImport);
164
- if (!this.session) {
165
- throw new Error("Server not initialized. Make sure you call connect() first.");
166
- }
167
- if (this.cacheToolsList && !this._cacheDirty && this._toolsList) {
168
- return this._toolsList;
169
- }
170
- this._cacheDirty = false;
171
- const response = await this.session.listTools();
172
- this.debugLog(() => `Listed tools: ${JSON.stringify(response)}`);
173
- this._toolsList = ListToolsResultSchema.parse(response).tools;
174
- return this._toolsList;
175
- }
176
- async callTool(toolName, args) {
177
- const { CallToolResultSchema } = await import("@modelcontextprotocol/sdk/types.js").catch(failedToImport);
178
- if (!this.session) {
179
- throw new Error("Server not initialized. Make sure you call connect() first.");
180
- }
181
- const response = await this.session.callTool({
182
- name: toolName,
183
- arguments: args ?? {},
184
- }, undefined, {
185
- timeout: this.timeout,
186
- });
187
- const parsed = CallToolResultSchema.parse(response);
188
- const result = parsed.content;
189
- this.debugLog(() => `Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`);
190
- return result;
191
- }
192
- get name() {
193
- return this._name;
194
- }
195
- async close() {
196
- if (this.transport) {
197
- await this.transport.close();
198
- this.transport = null;
199
- }
200
- if (this.session) {
201
- await this.session.close();
202
- this.session = null;
203
- }
204
- }
205
- }
206
- export class NodeMCPServerStreamableHttp extends BaseMCPServerStreamableHttp {
207
- session = null;
208
- _cacheDirty = true;
209
- _toolsList = [];
210
- serverInitializeResult = null;
211
- clientSessionTimeoutSeconds;
212
- timeout;
213
- params;
214
- _name;
215
- transport = null;
216
- constructor(params) {
217
- super(params);
218
- this.clientSessionTimeoutSeconds = params.clientSessionTimeoutSeconds ?? 5;
219
- this.params = params;
220
- this._name = params.name || `streamable-http: ${this.params.url}`;
221
- this.timeout = params.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
222
- }
223
- async connect() {
224
- try {
225
- const { StreamableHTTPClientTransport } = await import("@modelcontextprotocol/sdk/client/streamableHttp.js").catch(failedToImport);
226
- const { Client } = await import("@modelcontextprotocol/sdk/client/index.js").catch(failedToImport);
227
- this.transport = new StreamableHTTPClientTransport(new URL(this.params.url), {
228
- authProvider: this.params.authProvider,
229
- requestInit: this.params.requestInit,
230
- fetch: this.params.fetch,
231
- reconnectionOptions: this.params.reconnectionOptions,
232
- sessionId: this.params.sessionId,
233
- });
234
- this.session = new Client({
235
- name: this._name,
236
- version: "1.0.0", // You may want to make this configurable
237
- });
238
- await this.session.connect(this.transport);
239
- this.serverInitializeResult = {
240
- serverInfo: { name: this._name, version: "1.0.0" },
241
- };
242
- }
243
- catch (e) {
244
- this.logger.error("Error initializing MCP server:", e);
245
- await this.close();
246
- throw e;
247
- }
248
- this.debugLog(() => `Connected to MCP server: ${this._name}`);
249
- }
250
- async invalidateToolsCache() {
251
- await invalidateServerToolsCache(this.name);
252
- this._cacheDirty = true;
253
- }
254
- async listTools() {
255
- const { ListToolsResultSchema } = await import("@modelcontextprotocol/sdk/types.js").catch(failedToImport);
256
- if (!this.session) {
257
- throw new Error("Server not initialized. Make sure you call connect() first.");
258
- }
259
- if (this.cacheToolsList && !this._cacheDirty && this._toolsList) {
260
- return this._toolsList;
261
- }
262
- this._cacheDirty = false;
263
- const response = await this.session.listTools();
264
- this.debugLog(() => `Listed tools: ${JSON.stringify(response)}`);
265
- this._toolsList = ListToolsResultSchema.parse(response).tools;
266
- return this._toolsList;
267
- }
268
- async callTool(toolName, args) {
269
- const { CallToolResultSchema } = await import("@modelcontextprotocol/sdk/types.js").catch(failedToImport);
270
- if (!this.session) {
271
- throw new Error("Server not initialized. Make sure you call connect() first.");
272
- }
273
- const response = await this.session.callTool({
274
- name: toolName,
275
- arguments: args ?? {},
276
- }, undefined, {
277
- timeout: this.timeout,
278
- });
279
- const parsed = CallToolResultSchema.parse(response);
280
- const result = parsed.content;
281
- this.debugLog(() => `Called tool ${toolName} (args: ${JSON.stringify(args)}, result: ${JSON.stringify(result)})`);
282
- return result;
283
- }
284
- get name() {
285
- return this._name;
286
- }
287
- async close() {
288
- if (this.transport) {
289
- await this.transport.close();
290
- this.transport = null;
291
- }
292
- if (this.session) {
293
- await this.session.close();
294
- this.session = null;
295
- }
296
- }
297
- }