@mcp-web/client 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.
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { MCPWebClient } from './client.js';
4
+ import { MCPWebClientConfigSchema } from './schemas.js';
5
+
6
+ export type { Query } from '@mcp-web/types';
7
+ // Export for programmatic use
8
+ export { MCPWebClient } from './client.js';
9
+ export type * from './types.js';
10
+
11
+ // Only run as CLI if this is the main module in Node.js
12
+ // Guard against running in Deno or when bundled
13
+ // @ts-expect-error - Deno global exists in Deno runtime
14
+ const isDeno = typeof Deno !== 'undefined';
15
+ const isNodeCLI = !isDeno &&
16
+ typeof process !== 'undefined' &&
17
+ process.argv &&
18
+ import.meta.url === `file://${process.argv[1]}`;
19
+
20
+ if (isNodeCLI) {
21
+ // Handle graceful shutdown
22
+ process.on('SIGINT', () => {
23
+ console.error('Shutting down MCP Bridge Client...');
24
+ process.exit(0);
25
+ });
26
+
27
+ process.on('SIGTERM', () => {
28
+ console.error('Shutting down MCP Bridge Client...');
29
+ process.exit(0);
30
+ });
31
+
32
+ const config = MCPWebClientConfigSchema.parse({
33
+ serverUrl: process.env.MCP_SERVER_URL,
34
+ authToken: process.env.AUTH_TOKEN,
35
+ ...(process.env.TIMEOUT !== undefined ? { timeout: Number.parseInt(process.env.TIMEOUT, 10) } : {})
36
+ });
37
+
38
+ // Start the client
39
+ const client = new MCPWebClient(config);
40
+ client.run().catch((error) => {
41
+ console.error('Failed to start MCP Bridge Client:', error);
42
+ process.exit(1);
43
+ });
44
+ }
package/src/schemas.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+
3
+ export const JsonRpcResponseSchema = z.object({
4
+ jsonrpc: z.literal('2.0').default('2.0'),
5
+ id: z.union([z.string(), z.number()]),
6
+ result: z.any().optional(),
7
+ error: z.object({
8
+ code: z.number(),
9
+ message: z.string(),
10
+ data: z.any().optional()
11
+ }).optional()
12
+ });
13
+
14
+ export const JsonRpcRequestSchema = z.object({
15
+ jsonrpc: z.literal('2.0').default('2.0'),
16
+ id: z.union([z.string(), z.number()]),
17
+ method: z.string(),
18
+ params: z.record(z.string(), z.unknown()).optional()
19
+ });
20
+
21
+ export const MCPWebClientConfigSchema = z.object({
22
+ serverUrl: z.url(),
23
+ authToken: z.string().min(1).optional(),
24
+ timeout: z.number().optional().default(30000)
25
+ });
26
+
27
+ export const TextContentSchema = z.object({
28
+ type: z.literal('text').default('text'),
29
+ text: z.string(),
30
+ });
31
+
32
+ export const ImageContentSchema = z.object({
33
+ type: z.literal('image').default('image'),
34
+ data: z.string(),
35
+ mimeType: z.string(),
36
+ });
37
+
38
+ export const ContentSchema = z.union([TextContentSchema, ImageContentSchema]);
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { z } from "zod";
2
+ import type {
3
+ ContentSchema,
4
+ ImageContentSchema,
5
+ MCPWebClientConfigSchema,
6
+ TextContentSchema,
7
+ } from "./schemas.js";
8
+
9
+ export type MCPWebClientConfig = z.input<typeof MCPWebClientConfigSchema>;
10
+ export type MCPWebClientConfigOutput = z.infer<typeof MCPWebClientConfigSchema>;
11
+
12
+ export type TextContent = z.infer<typeof TextContentSchema>;
13
+ export type ImageContent = z.infer<typeof ImageContentSchema>;
14
+ export type Content = z.infer<typeof ContentSchema>;
package/src/utils.ts ADDED
@@ -0,0 +1,5 @@
1
+ export const camelToSnakeCase = (str: string) => str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
2
+
3
+ export const camelToSnakeCaseProps = (obj: Record<string, unknown>): Record<string, unknown> => {
4
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [camelToSnakeCase(key), value]))
5
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "node16",
5
+ "moduleResolution": "node16",
6
+ "lib": [
7
+ "ES2022"
8
+ ],
9
+ "outDir": "dist",
10
+ "rootDir": "src"
11
+ },
12
+ "include": [
13
+ "src/**/*"
14
+ ],
15
+ "exclude": [
16
+ "node_modules",
17
+ "dist",
18
+ "**/*.test.ts"
19
+ ]
20
+ }