mcp-orbit 0.1.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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +247 -0
  3. package/dist/__tests__/helpers/test-server.d.ts +2 -0
  4. package/dist/__tests__/helpers/test-server.d.ts.map +1 -0
  5. package/dist/__tests__/helpers/test-server.js +27 -0
  6. package/dist/__tests__/helpers/test-server.js.map +1 -0
  7. package/dist/cli.d.ts +23 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +56 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/clients/mcp-http.d.ts +36 -0
  12. package/dist/clients/mcp-http.d.ts.map +1 -0
  13. package/dist/clients/mcp-http.js +148 -0
  14. package/dist/clients/mcp-http.js.map +1 -0
  15. package/dist/clients/mcp-stdio.d.ts +38 -0
  16. package/dist/clients/mcp-stdio.d.ts.map +1 -0
  17. package/dist/clients/mcp-stdio.js +164 -0
  18. package/dist/clients/mcp-stdio.js.map +1 -0
  19. package/dist/clients/types.d.ts +104 -0
  20. package/dist/clients/types.d.ts.map +1 -0
  21. package/dist/clients/types.js +8 -0
  22. package/dist/clients/types.js.map +1 -0
  23. package/dist/core/prompt-registry.d.ts +56 -0
  24. package/dist/core/prompt-registry.d.ts.map +1 -0
  25. package/dist/core/prompt-registry.js +100 -0
  26. package/dist/core/prompt-registry.js.map +1 -0
  27. package/dist/core/resource-registry.d.ts +79 -0
  28. package/dist/core/resource-registry.d.ts.map +1 -0
  29. package/dist/core/resource-registry.js +135 -0
  30. package/dist/core/resource-registry.js.map +1 -0
  31. package/dist/core/resource-uri-templates.d.ts +64 -0
  32. package/dist/core/resource-uri-templates.d.ts.map +1 -0
  33. package/dist/core/resource-uri-templates.js +168 -0
  34. package/dist/core/resource-uri-templates.js.map +1 -0
  35. package/dist/core/server-http.d.ts +15 -0
  36. package/dist/core/server-http.d.ts.map +1 -0
  37. package/dist/core/server-http.js +302 -0
  38. package/dist/core/server-http.js.map +1 -0
  39. package/dist/core/server-stdio.d.ts +8 -0
  40. package/dist/core/server-stdio.d.ts.map +1 -0
  41. package/dist/core/server-stdio.js +15 -0
  42. package/dist/core/server-stdio.js.map +1 -0
  43. package/dist/core/server.d.ts +29 -0
  44. package/dist/core/server.d.ts.map +1 -0
  45. package/dist/core/server.js +265 -0
  46. package/dist/core/server.js.map +1 -0
  47. package/dist/core/types.d.ts +265 -0
  48. package/dist/core/types.d.ts.map +1 -0
  49. package/dist/core/types.js +9 -0
  50. package/dist/core/types.js.map +1 -0
  51. package/dist/index.d.ts +28 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +26 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/utils/dynamic-resource-manager.d.ts +115 -0
  56. package/dist/utils/dynamic-resource-manager.d.ts.map +1 -0
  57. package/dist/utils/dynamic-resource-manager.js +460 -0
  58. package/dist/utils/dynamic-resource-manager.js.map +1 -0
  59. package/dist/utils/http-client.d.ts +29 -0
  60. package/dist/utils/http-client.d.ts.map +1 -0
  61. package/dist/utils/http-client.js +59 -0
  62. package/dist/utils/http-client.js.map +1 -0
  63. package/dist/utils/logger.d.ts +25 -0
  64. package/dist/utils/logger.d.ts.map +1 -0
  65. package/dist/utils/logger.js +105 -0
  66. package/dist/utils/logger.js.map +1 -0
  67. package/dist/utils/zod-to-mcp-schema.d.ts +42 -0
  68. package/dist/utils/zod-to-mcp-schema.d.ts.map +1 -0
  69. package/dist/utils/zod-to-mcp-schema.js +87 -0
  70. package/dist/utils/zod-to-mcp-schema.js.map +1 -0
  71. package/package.json +57 -0
  72. package/src/__tests__/helpers/test-server.ts +31 -0
  73. package/src/__tests__/plugin-system.basic.test.ts +137 -0
  74. package/src/__tests__/server.basic.test.ts +37 -0
  75. package/src/__tests__/stdio-roundtrip.basic.test.ts +67 -0
  76. package/src/__tests__/tool-registry.basic.test.ts +114 -0
  77. package/src/__tests__/zod-schema.basic.test.ts +105 -0
  78. package/src/cli.ts +58 -0
  79. package/src/clients/mcp-http.ts +192 -0
  80. package/src/clients/mcp-stdio.ts +209 -0
  81. package/src/clients/types.ts +136 -0
  82. package/src/core/prompt-registry.ts +114 -0
  83. package/src/core/resource-registry.ts +166 -0
  84. package/src/core/resource-uri-templates.ts +216 -0
  85. package/src/core/server-http.ts +407 -0
  86. package/src/core/server-stdio.ts +20 -0
  87. package/src/core/server.ts +320 -0
  88. package/src/core/types.ts +312 -0
  89. package/src/index.ts +92 -0
  90. package/src/utils/dynamic-resource-manager.ts +581 -0
  91. package/src/utils/http-client.ts +86 -0
  92. package/src/utils/logger.ts +138 -0
  93. package/src/utils/zod-to-mcp-schema.ts +127 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 okahari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # mcp-orbit
2
+
3
+ A lightweight framework for building and connecting [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) servers and clients in Node.js.
4
+
5
+ Build MCP-compliant tool servers with stdio or HTTP transport, define tools with Zod schemas, and connect to any MCP server from your application.
6
+
7
+ ## Features
8
+
9
+ - **Server Framework** — Register tools, resources, and prompts with a simple API
10
+ - **Dual Transport** — Stdio (for local/CLI use) and HTTP (for remote servers)
11
+ - **Client Libraries** — Connect to any MCP server (stdio or HTTP) from your app
12
+ - **Zod Integration** — Define tool input schemas with Zod, auto-converted to JSON Schema
13
+ - **Resource System** — RFC 6570 URI templates for dynamic resources
14
+ - **Prompt Registry** — Templated prompts with argument validation
15
+ - **CLI Helpers** — `--stdio` / `--http` argument parsing out of the box
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install mcp-orbit
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ### Build a Tool Server
26
+
27
+ ```typescript
28
+ import { registerTool, startServer, parseArgs, applyPreInit } from "mcp-orbit";
29
+ import { z } from "zod";
30
+
31
+ // Define a tool with Zod schema
32
+ registerTool({
33
+ name: "greet",
34
+ description: "Greet someone by name",
35
+ inputSchema: z.object({
36
+ name: z.string().describe("Name of the person to greet"),
37
+ }),
38
+ execute: async ({ name }) => ({
39
+ content: [{ type: "text", text: `Hello, ${name}!` }],
40
+ }),
41
+ });
42
+
43
+ // Start the server (auto-detects --stdio or --http from CLI args)
44
+ const config = parseArgs();
45
+ applyPreInit(config);
46
+ const server = startServer(config);
47
+ ```
48
+
49
+ Run it:
50
+
51
+ ```bash
52
+ # Stdio mode (for Claude Desktop, local integrations)
53
+ node dist/index.js --stdio
54
+
55
+ # HTTP mode (for remote access)
56
+ node dist/index.js --http --http-port=8080
57
+ ```
58
+
59
+ ### Connect to an MCP Server
60
+
61
+ ```typescript
62
+ import { StdioMCPClient, HttpMCPClient } from "mcp-orbit";
63
+
64
+ // Connect to a local stdio server
65
+ const local = new StdioMCPClient({
66
+ name: "my-plugin",
67
+ command: "node",
68
+ args: ["./plugins/my-plugin/dist/index.js", "--stdio"],
69
+ });
70
+ const tools = await local.listTools();
71
+ const result = await local.callTool("greet", { name: "World" });
72
+
73
+ // Connect to a remote HTTP server
74
+ const remote = new HttpMCPClient({
75
+ name: "remote-api",
76
+ url: "https://api.example.com/mcp/",
77
+ headers: { Authorization: "Bearer sk-..." },
78
+ });
79
+ const remoteTools = await remote.listTools();
80
+ ```
81
+
82
+ ## API Reference
83
+
84
+ ### Server
85
+
86
+ | Export | Description |
87
+ |--------|-------------|
88
+ | `registerTool(tool)` | Register a tool with name, schema, and execute function |
89
+ | `startServer(config)` | Start the MCP server with the given transport config |
90
+ | `createMCPServer()` | Create the underlying MCP SDK Server instance |
91
+ | `executeTool(name, args)` | Execute a registered tool by name |
92
+ | `getTool(name)` | Get a registered tool definition |
93
+ | `getToolCount()` | Number of registered tools |
94
+ | `getToolDefinitions()` | All tool schemas for MCP ListTools |
95
+ | `startHttpServer(port, host, server)` | Start HTTP transport directly |
96
+ | `startStdioServer(server)` | Start stdio transport directly |
97
+
98
+ ### Clients
99
+
100
+ Both `StdioMCPClient` and `HttpMCPClient` implement the `IMcpClient` interface:
101
+
102
+ ```typescript
103
+ interface IMcpClient {
104
+ listTools(timeoutMs?: number): Promise<{ tools: MCPToolSchema[] }>;
105
+ callTool(name: string, args: Record<string, any>, timeoutMs?: number): Promise<MCPToolResponse>;
106
+ listResources(timeoutMs?: number): Promise<MCPResourceList>;
107
+ readResource(uri: string, timeoutMs?: number): Promise<MCPResourceContent>;
108
+ listPrompts(timeoutMs?: number): Promise<MCPPromptList>;
109
+ getPrompt(name: string, args?: Record<string, any>, timeoutMs?: number): Promise<MCPPromptResponse>;
110
+ close(): Promise<void>;
111
+ }
112
+ ```
113
+
114
+ #### StdioMCPClient
115
+
116
+ Spawns a local child process and communicates via stdin/stdout.
117
+
118
+ ```typescript
119
+ const client = new StdioMCPClient({
120
+ name: "my-server",
121
+ command: "node",
122
+ args: ["./server.js", "--stdio"],
123
+ env: {
124
+ API_KEY: "${MY_API_KEY}", // Resolved from process.env
125
+ },
126
+ cwd: "./plugins",
127
+ });
128
+ ```
129
+
130
+ Environment variables with `${VAR_NAME}` syntax are automatically resolved from `process.env`.
131
+
132
+ #### HttpMCPClient
133
+
134
+ Connects to a remote MCP server over HTTP (Streamable HTTP transport, Protocol 2025-03-26).
135
+
136
+ ```typescript
137
+ const client = new HttpMCPClient({
138
+ name: "remote",
139
+ url: "https://api.example.com/mcp/",
140
+ headers: { Authorization: "Bearer sk-..." },
141
+ timeout_ms: 15000,
142
+ });
143
+ ```
144
+
145
+ ### Resources
146
+
147
+ Register resources with static URIs or RFC 6570 templates:
148
+
149
+ ```typescript
150
+ import { createAndRegisterResource } from "mcp-orbit";
151
+
152
+ createAndRegisterResource({
153
+ uri: "config://app/settings",
154
+ name: "App Settings",
155
+ description: "Current application configuration",
156
+ mimeType: "application/json",
157
+ read: async () => JSON.stringify({ theme: "dark" }),
158
+ });
159
+ ```
160
+
161
+ ### Prompts
162
+
163
+ Register prompt templates with optional argument validation:
164
+
165
+ ```typescript
166
+ import { createAndRegisterPrompt } from "mcp-orbit";
167
+ import { z } from "zod";
168
+
169
+ createAndRegisterPrompt({
170
+ name: "analyze-data",
171
+ description: "Analyze a dataset",
172
+ arguments: [
173
+ { name: "dataset", description: "Dataset name", required: true },
174
+ { name: "format", description: "Output format", required: false },
175
+ ],
176
+ inputSchema: z.object({
177
+ dataset: z.string(),
178
+ format: z.enum(["json", "csv"]).default("json"),
179
+ }),
180
+ render: async ({ dataset, format }) => ({
181
+ messages: [
182
+ { role: "user", content: { type: "text", text: `Analyze ${dataset} as ${format}` } },
183
+ ],
184
+ }),
185
+ });
186
+ ```
187
+
188
+ ### Utilities
189
+
190
+ | Export | Description |
191
+ |--------|-------------|
192
+ | `createLogger(scope)` | Scoped, colored console logger |
193
+ | `zodToMcpJsonSchema(schema)` | Convert Zod schema to MCP JSON Schema |
194
+ | `HTTPClient` | Lightweight HTTP client for tool implementations |
195
+ | `parseArgs()` | Parse `--stdio` / `--http` CLI arguments |
196
+ | `applyPreInit(config)` | Configure stderr logging for stdio mode |
197
+
198
+ ## Building Plugins
199
+
200
+ Create an MCP plugin as a standalone npm package:
201
+
202
+ ```typescript
203
+ // my-plugin/src/index.ts
204
+ import { registerTool, startServer, parseArgs, applyPreInit } from "mcp-orbit";
205
+ import { z } from "zod";
206
+
207
+ // Register your tools
208
+ registerTool({
209
+ name: "my_tool",
210
+ description: "Does something useful",
211
+ inputSchema: z.object({
212
+ input: z.string(),
213
+ }),
214
+ execute: async ({ input }) => ({
215
+ content: [{ type: "text", text: `Processed: ${input}` }],
216
+ }),
217
+ });
218
+
219
+ // Start server
220
+ const config = parseArgs();
221
+ applyPreInit(config);
222
+ startServer(config);
223
+ ```
224
+
225
+ Then use it as a stdio plugin from any MCP client:
226
+
227
+ ```bash
228
+ node ./node_modules/my-plugin/dist/index.js --stdio
229
+ ```
230
+
231
+ ## Transport Modes
232
+
233
+ | Mode | Flag | Use Case |
234
+ |------|------|----------|
235
+ | Stdio | `--stdio` | Local integrations, Claude Desktop, CLI tools |
236
+ | HTTP | `--http` | Remote servers, multi-client access |
237
+
238
+ HTTP mode supports session management, bearer token auth, health checks (`/health`), and graceful shutdown.
239
+
240
+ ## Requirements
241
+
242
+ - Node.js >= 20.0.0
243
+ - TypeScript (recommended)
244
+
245
+ ## License
246
+
247
+ MIT
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-server.d.ts","sourceRoot":"","sources":["../../../src/__tests__/helpers/test-server.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Minimal test server for stdio roundtrip tests.
3
+ * Registers one echo tool and starts in stdio mode.
4
+ */
5
+ import { z } from "zod";
6
+ import { registerTool, startServer } from "../../core/server.js";
7
+ import { zodToMcpJsonSchema } from "../../utils/zod-to-mcp-schema.js";
8
+ const inputSchema = z.object({
9
+ message: z.string().describe("Message to echo back"),
10
+ });
11
+ const tool = {
12
+ definition: {
13
+ name: "roundtrip_echo",
14
+ description: "Echo for roundtrip test",
15
+ inputSchema: zodToMcpJsonSchema(inputSchema),
16
+ },
17
+ runtimeInputSchema: inputSchema,
18
+ async execute(args) {
19
+ const { message } = inputSchema.parse(args);
20
+ return {
21
+ content: [{ type: "text", text: `echo: ${message}` }],
22
+ };
23
+ },
24
+ };
25
+ registerTool(tool);
26
+ startServer({ mode: "stdio", serverName: "test-roundtrip-server", serverVersion: "0.0.1" });
27
+ //# sourceMappingURL=test-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-server.js","sourceRoot":"","sources":["../../../src/__tests__/helpers/test-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,YAAY,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AAGpE,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;CACrD,CAAC,CAAC;AAEH,MAAM,IAAI,GAAS;IACjB,UAAU,EAAE;QACV,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,yBAAyB;QACtC,WAAW,EAAE,kBAAkB,CAAC,WAAW,CAAe;KAC3D;IACD,kBAAkB,EAAE,WAAW;IAC/B,KAAK,CAAC,OAAO,CAAC,IAAa;QACzB,MAAM,EAAC,OAAO,EAAC,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO;YACL,OAAO,EAAE,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,EAAC,CAAC;SACpD,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,YAAY,CAAC,IAAI,CAAC,CAAC;AAEnB,WAAW,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,aAAa,EAAE,OAAO,EAAC,CAAC,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * CLI Helpers — shared by all mcp-orbit packages
3
+ *
4
+ * parseArgs(): Reads --stdio / --http / --http-port / --http-host from argv
5
+ * and PORT / MCP_HTTP_HOST from env.
6
+ */
7
+ import type { ServerConfig } from "./core/server.js";
8
+ /**
9
+ * Parse command line arguments into a ServerConfig.
10
+ *
11
+ * Examples:
12
+ * node index.js → stdio (default, unless PORT is set)
13
+ * node index.js --stdio → stdio (explicit)
14
+ * node index.js --http → HTTP on 0.0.0.0:3333 (or PORT)
15
+ * node index.js --http --http-port=8080 → HTTP on 0.0.0.0:8080
16
+ * node index.js --http --http-host=127.0.0.1 → HTTP on 127.0.0.1:3333
17
+ *
18
+ * Environment variables:
19
+ * PORT → auto-enables HTTP mode (Render/Cloud standard)
20
+ * MCP_HTTP_HOST → override host binding (default 0.0.0.0)
21
+ */
22
+ export declare function parseArgs(): ServerConfig;
23
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,YAAY,EAAgB,MAAM,kBAAkB,CAAC;AAElE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,IAAI,YAAY,CAiCxC"}
package/dist/cli.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * CLI Helpers — shared by all mcp-orbit packages
3
+ *
4
+ * parseArgs(): Reads --stdio / --http / --http-port / --http-host from argv
5
+ * and PORT / MCP_HTTP_HOST from env.
6
+ */
7
+ /**
8
+ * Parse command line arguments into a ServerConfig.
9
+ *
10
+ * Examples:
11
+ * node index.js → stdio (default, unless PORT is set)
12
+ * node index.js --stdio → stdio (explicit)
13
+ * node index.js --http → HTTP on 0.0.0.0:3333 (or PORT)
14
+ * node index.js --http --http-port=8080 → HTTP on 0.0.0.0:8080
15
+ * node index.js --http --http-host=127.0.0.1 → HTTP on 127.0.0.1:3333
16
+ *
17
+ * Environment variables:
18
+ * PORT → auto-enables HTTP mode (Render/Cloud standard)
19
+ * MCP_HTTP_HOST → override host binding (default 0.0.0.0)
20
+ */
21
+ export function parseArgs() {
22
+ const args = process.argv.slice(2);
23
+ let mode = process.env.PORT ? "http" : "stdio";
24
+ let httpPort = process.env.PORT ? parseInt(process.env.PORT, 10) : undefined;
25
+ let httpHost = process.env.MCP_HTTP_HOST || "0.0.0.0";
26
+ for (let i = 0; i < args.length; i++) {
27
+ const arg = args[i];
28
+ if (arg === "--http") {
29
+ mode = "http";
30
+ }
31
+ else if (arg === "--stdio") {
32
+ mode = "stdio";
33
+ }
34
+ else if (arg.startsWith("--http-port=")) {
35
+ httpPort = parseInt(arg.split("=")[1] || "", 10);
36
+ mode = "http";
37
+ }
38
+ else if (arg === "--http-port") {
39
+ httpPort = parseInt(args[++i] || "", 10);
40
+ mode = "http";
41
+ }
42
+ else if (arg.startsWith("--http-host=")) {
43
+ httpHost = arg.split("=")[1];
44
+ mode = "http";
45
+ }
46
+ else if (arg === "--http-host") {
47
+ httpHost = args[++i];
48
+ mode = "http";
49
+ }
50
+ }
51
+ if (mode === "http" && (!httpPort || isNaN(httpPort))) {
52
+ httpPort = 3333;
53
+ }
54
+ return { mode, httpPort, httpHost };
55
+ }
56
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEnC,IAAI,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AAG,MAAM,CAAC;QAChB,CAAC;aAAM,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;YACjC,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YACrB,IAAI,GAAG,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACtD,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * HTTP MCP Client (Protocol 2025-03-26)
3
+ *
4
+ * Modern MCP client using StreamableHTTPClientTransport
5
+ * Features:
6
+ * - Session management with automatic reconnection
7
+ * - Bearer token authentication via custom headers
8
+ * - Type-safe tool execution
9
+ * - Resource & Prompt management
10
+ * - Connection pooling & caching
11
+ *
12
+ * Based on MCP SDK:
13
+ * @see @modelcontextprotocol/sdk/client/streamableHttp
14
+ */
15
+ import type { McpHttpServerConfig, MCPToolSchema, MCPToolResponse, MCPResourceList, MCPResourceContent, MCPPromptList, MCPPromptResponse, IMcpClient } from "./types.js";
16
+ export declare class HttpMCPClient implements IMcpClient {
17
+ private clientCache;
18
+ private connectionPromises;
19
+ private readonly serverConfig;
20
+ onerror?: (error: Error) => void;
21
+ onclose?: () => void;
22
+ constructor(serverConfig: McpHttpServerConfig);
23
+ listTools(timeoutMs?: number): Promise<{
24
+ tools: MCPToolSchema[];
25
+ }>;
26
+ callTool(toolName: string, args: Record<string, any>, timeoutMs?: number): Promise<MCPToolResponse>;
27
+ listResources(timeoutMs?: number): Promise<MCPResourceList>;
28
+ readResource(uri: string, timeoutMs?: number): Promise<MCPResourceContent>;
29
+ listPrompts(timeoutMs?: number): Promise<MCPPromptList>;
30
+ getPrompt(name: string, args?: Record<string, any>, timeoutMs?: number): Promise<MCPPromptResponse>;
31
+ private createClient;
32
+ private getOrCreateClient;
33
+ private getServerKey;
34
+ close(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=mcp-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-http.d.ts","sourceRoot":"","sources":["../../src/clients/mcp-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,qBAAa,aAAc,YAAW,UAAU;IAC9C,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,kBAAkB,CAAsC;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IAG5C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;gBAEhB,YAAY,EAAE,mBAAmB;IAQvC,SAAS,CAAC,SAAS,SAAQ,GAAG,OAAO,CAAC;QAAC,KAAK,EAAE,aAAa,EAAE,CAAA;KAAC,CAAC;IAgB/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAwBlG,aAAa,CAAC,SAAS,SAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ1D,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAYzE,WAAW,CAAC,SAAS,SAAQ,GAAG,OAAO,CAAC,aAAa,CAAC;IAQtD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAY1F,YAAY;YA4BZ,iBAAiB;IA4B/B,OAAO,CAAC,YAAY;IAId,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * HTTP MCP Client (Protocol 2025-03-26)
3
+ *
4
+ * Modern MCP client using StreamableHTTPClientTransport
5
+ * Features:
6
+ * - Session management with automatic reconnection
7
+ * - Bearer token authentication via custom headers
8
+ * - Type-safe tool execution
9
+ * - Resource & Prompt management
10
+ * - Connection pooling & caching
11
+ *
12
+ * Based on MCP SDK:
13
+ * @see @modelcontextprotocol/sdk/client/streamableHttp
14
+ */
15
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
16
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
17
+ export class HttpMCPClient {
18
+ clientCache = new Map();
19
+ connectionPromises = new Map();
20
+ serverConfig;
21
+ // Event handlers (exposed from underlying MCP SDK Client)
22
+ onerror;
23
+ onclose;
24
+ constructor(serverConfig) {
25
+ this.serverConfig = serverConfig;
26
+ }
27
+ // ============================================================================
28
+ // TOOLS
29
+ // ============================================================================
30
+ async listTools(timeoutMs = 15000) {
31
+ const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
32
+ const resp = (await client.listTools({}, { timeout: timeoutMs }));
33
+ const tools = Array.isArray(resp?.tools)
34
+ ? resp.tools.map((tool) => ({
35
+ name: tool.name,
36
+ description: tool.description,
37
+ input_schema: tool.input_schema ?? tool.inputSchema ?? { type: "object", properties: {} },
38
+ tags: tool.tags ?? tool._meta?.tags,
39
+ }))
40
+ : [];
41
+ return { tools };
42
+ }
43
+ async callTool(toolName, args, timeoutMs = 15000) {
44
+ const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
45
+ const response = (await client.callTool({
46
+ name: toolName,
47
+ arguments: args,
48
+ }, undefined, { timeout: timeoutMs }));
49
+ return {
50
+ content: Array.isArray(response?.content) ? response.content : [],
51
+ isError: response?.isError ?? false,
52
+ structuredContent: response?.structuredContent,
53
+ _meta: response?._meta,
54
+ };
55
+ }
56
+ // ============================================================================
57
+ // RESOURCES
58
+ // ============================================================================
59
+ async listResources(timeoutMs = 15000) {
60
+ const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
61
+ const response = (await client.listResources({}, { timeout: timeoutMs }));
62
+ return {
63
+ resources: response.resources || [],
64
+ };
65
+ }
66
+ async readResource(uri, timeoutMs = 15000) {
67
+ const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
68
+ const response = (await client.readResource({ uri }, { timeout: timeoutMs }));
69
+ return {
70
+ contents: response.contents || [],
71
+ };
72
+ }
73
+ // ============================================================================
74
+ // PROMPTS
75
+ // ============================================================================
76
+ async listPrompts(timeoutMs = 15000) {
77
+ const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
78
+ const response = (await client.listPrompts({}, { timeout: timeoutMs }));
79
+ return {
80
+ prompts: response.prompts || [],
81
+ };
82
+ }
83
+ async getPrompt(name, args, timeoutMs = 15000) {
84
+ const client = await this.getOrCreateClient(this.serverConfig, timeoutMs);
85
+ const response = (await client.getPrompt({ name, arguments: args }, { timeout: timeoutMs }));
86
+ return {
87
+ messages: response.messages || [],
88
+ };
89
+ }
90
+ // ============================================================================
91
+ // PRIVATE HELPERS
92
+ // ============================================================================
93
+ async createClient(server, timeoutMs) {
94
+ const client = new Client({ name: "mcp-orbit-client", version: "1.0.0" });
95
+ // Wire up event handlers from SDK Client to our wrapper
96
+ client.onerror = (error) => {
97
+ this.onerror?.(error);
98
+ };
99
+ client.onclose = () => {
100
+ this.onclose?.();
101
+ };
102
+ const baseUrl = new URL(server.url);
103
+ // Create Streamable HTTP transport with optional authentication
104
+ const transport = new StreamableHTTPClientTransport(baseUrl, {
105
+ // Add custom headers (e.g., Authorization) to all requests
106
+ requestInit: server.headers
107
+ ? {
108
+ headers: server.headers,
109
+ }
110
+ : undefined,
111
+ });
112
+ await client.connect(transport, { timeout: timeoutMs });
113
+ return client;
114
+ }
115
+ async getOrCreateClient(server, timeoutMs) {
116
+ const key = this.getServerKey(server);
117
+ const existing = this.clientCache.get(key);
118
+ if (existing) {
119
+ return existing;
120
+ }
121
+ const pending = this.connectionPromises.get(key);
122
+ if (pending !== undefined) {
123
+ return pending;
124
+ }
125
+ const connectPromise = this.createClient(server, timeoutMs)
126
+ .then((client) => {
127
+ this.connectionPromises.delete(key);
128
+ this.clientCache.set(key, client);
129
+ return client;
130
+ })
131
+ .catch((error) => {
132
+ this.connectionPromises.delete(key);
133
+ throw error;
134
+ });
135
+ this.connectionPromises.set(key, connectPromise);
136
+ return connectPromise;
137
+ }
138
+ getServerKey(config) {
139
+ return `streamable-http:${config.url}`;
140
+ }
141
+ async close() {
142
+ const closePromises = Array.from(this.clientCache.values()).map((client) => client.close().catch(() => undefined));
143
+ this.clientCache.clear();
144
+ this.connectionPromises.clear();
145
+ await Promise.all(closePromises);
146
+ }
147
+ }
148
+ //# sourceMappingURL=mcp-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-http.js","sourceRoot":"","sources":["../../src/clients/mcp-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAC,MAAM,EAAC,MAAM,2CAA2C,CAAC;AACjE,OAAO,EAAC,6BAA6B,EAAC,MAAM,oDAAoD,CAAC;AAYjG,MAAM,OAAO,aAAa;IAChB,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,kBAAkB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC/C,YAAY,CAAsB;IAEnD,0DAA0D;IACnD,OAAO,CAA0B;IACjC,OAAO,CAAc;IAE5B,YAAY,YAAiC;QAC3C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,+EAA+E;IAC/E,QAAQ;IACR,+EAA+E;IAE/E,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,KAAK;QAC/B,MAAM,MAA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AC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QACnH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Stdio MCP Client
3
+ *
4
+ * Client for connecting to MCP servers via stdio (local child process)
5
+ * Features:
6
+ * - Client caching & connection pooling
7
+ * - Type-safe tool execution
8
+ * - Resource & Prompt management
9
+ */
10
+ import type { McpStdioServerConfig, MCPToolSchema, MCPToolResponse, MCPResourceList, MCPResourceContent, MCPPromptList, MCPPromptResponse, IMcpClient } from "./types.js";
11
+ export declare class StdioMCPClient implements IMcpClient {
12
+ private clientCache;
13
+ private connectionPromises;
14
+ private readonly serverConfig;
15
+ onerror?: (error: Error) => void;
16
+ onclose?: () => void;
17
+ constructor(serverConfig: McpStdioServerConfig);
18
+ listTools(timeoutMs?: number): Promise<{
19
+ tools: MCPToolSchema[];
20
+ }>;
21
+ callTool(toolName: string, args: Record<string, any>, timeoutMs?: number): Promise<MCPToolResponse>;
22
+ listResources(timeoutMs?: number): Promise<MCPResourceList>;
23
+ readResource(uri: string, timeoutMs?: number): Promise<MCPResourceContent>;
24
+ listPrompts(timeoutMs?: number): Promise<MCPPromptList>;
25
+ getPrompt(name: string, args?: Record<string, any>, timeoutMs?: number): Promise<MCPPromptResponse>;
26
+ /**
27
+ * Resolve environment variable placeholders like ${VAR_NAME}
28
+ * @param value - String that may contain placeholders
29
+ * @param env - Current environment variables to resolve from
30
+ * @returns Resolved string with placeholders replaced
31
+ */
32
+ private resolveEnvPlaceholders;
33
+ private createClient;
34
+ private getOrCreateClient;
35
+ private getServerKey;
36
+ close(): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=mcp-stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-stdio.d.ts","sourceRoot":"","sources":["../../src/clients/mcp-stdio.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,kBAAkB,CAAsC;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;IAG7C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;gBAEhB,YAAY,EAAE,oBAAoB;IAQxC,SAAS,CAAC,SAAS,SAAQ,GAAG,OAAO,CAAC;QAAC,KAAK,EAAE,aAAa,EAAE,CAAA;KAAC,CAAC;IAgB/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAwBlG,aAAa,CAAC,SAAS,SAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ1D,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAYzE,WAAW,CAAC,SAAS,SAAQ,GAAG,OAAO,CAAC,aAAa,CAAC;IAQtD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,C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