@lushly-dev/afd-server 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 (43) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +381 -0
  3. package/dist/bootstrap/afd-docs.d.ts +27 -0
  4. package/dist/bootstrap/afd-docs.d.ts.map +1 -0
  5. package/dist/bootstrap/afd-docs.js +93 -0
  6. package/dist/bootstrap/afd-docs.js.map +1 -0
  7. package/dist/bootstrap/afd-help.d.ts +39 -0
  8. package/dist/bootstrap/afd-help.d.ts.map +1 -0
  9. package/dist/bootstrap/afd-help.js +77 -0
  10. package/dist/bootstrap/afd-help.js.map +1 -0
  11. package/dist/bootstrap/afd-schema.d.ts +34 -0
  12. package/dist/bootstrap/afd-schema.d.ts.map +1 -0
  13. package/dist/bootstrap/afd-schema.js +78 -0
  14. package/dist/bootstrap/afd-schema.js.map +1 -0
  15. package/dist/bootstrap/index.d.ts +11 -0
  16. package/dist/bootstrap/index.d.ts.map +1 -0
  17. package/dist/bootstrap/index.js +11 -0
  18. package/dist/bootstrap/index.js.map +1 -0
  19. package/dist/bootstrap/registry.d.ts +17 -0
  20. package/dist/bootstrap/registry.d.ts.map +1 -0
  21. package/dist/bootstrap/registry.js +23 -0
  22. package/dist/bootstrap/registry.js.map +1 -0
  23. package/dist/index.d.ts +54 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +60 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/middleware.d.ts +125 -0
  28. package/dist/middleware.d.ts.map +1 -0
  29. package/dist/middleware.js +182 -0
  30. package/dist/middleware.js.map +1 -0
  31. package/dist/schema.d.ts +105 -0
  32. package/dist/schema.d.ts.map +1 -0
  33. package/dist/schema.js +132 -0
  34. package/dist/schema.js.map +1 -0
  35. package/dist/server.d.ts +141 -0
  36. package/dist/server.d.ts.map +1 -0
  37. package/dist/server.js +846 -0
  38. package/dist/server.js.map +1 -0
  39. package/dist/validation.d.ts +137 -0
  40. package/dist/validation.d.ts.map +1 -0
  41. package/dist/validation.js +182 -0
  42. package/dist/validation.js.map +1 -0
  43. package/package.json +48 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @fileoverview Zod-based command definition helpers
3
+ *
4
+ * This module provides utilities for defining commands using Zod schemas,
5
+ * with automatic JSON Schema generation for MCP tool definitions.
6
+ */
7
+ import { z, type ZodType, type ZodTypeDef } from 'zod';
8
+ import type { CommandResult, CommandContext, JsonSchema, CommandDefinition } from '@lushly-dev/afd-core';
9
+ /**
10
+ * Options for defining a command with Zod schema.
11
+ */
12
+ export interface ZodCommandOptions<TInput extends ZodType<unknown, ZodTypeDef, unknown>, TOutput> {
13
+ /** Unique command name using dot notation (e.g., 'todo.create') */
14
+ name: string;
15
+ /** Human-readable description of what the command does */
16
+ description: string;
17
+ /** Zod schema for input validation */
18
+ input: TInput;
19
+ /** Command handler function */
20
+ handler: (input: z.infer<TInput>, context: CommandContext) => Promise<CommandResult<TOutput>>;
21
+ /** Category for grouping related commands */
22
+ category?: string;
23
+ /** Whether this command performs side effects */
24
+ mutation?: boolean;
25
+ /** Command version for tracking changes */
26
+ version?: string;
27
+ /** Tags for additional categorization */
28
+ tags?: string[];
29
+ /** Estimated execution time category */
30
+ executionTime?: 'instant' | 'fast' | 'slow' | 'long-running';
31
+ /** Error codes this command may return */
32
+ errors?: string[];
33
+ }
34
+ /**
35
+ * A command definition that includes Zod schema for runtime validation.
36
+ */
37
+ export interface ZodCommandDefinition<TInput extends ZodType<unknown, ZodTypeDef, unknown> = ZodType, TOutput = unknown> {
38
+ /** Unique command name */
39
+ name: string;
40
+ /** Human-readable description */
41
+ description: string;
42
+ /** Zod schema for input validation */
43
+ inputSchema: TInput;
44
+ /** JSON Schema representation (for MCP tools) */
45
+ jsonSchema: JsonSchema;
46
+ /** Command handler */
47
+ handler: (input: z.infer<TInput>, context: CommandContext) => Promise<CommandResult<TOutput>>;
48
+ /** Category for grouping */
49
+ category?: string;
50
+ /** Whether this is a mutation */
51
+ mutation?: boolean;
52
+ /** Command version */
53
+ version?: string;
54
+ /** Tags for categorization */
55
+ tags?: string[];
56
+ /** Execution time category */
57
+ executionTime?: 'instant' | 'fast' | 'slow' | 'long-running';
58
+ /** Possible error codes */
59
+ errors?: string[];
60
+ /**
61
+ * Convert to standard CommandDefinition format.
62
+ */
63
+ toCommandDefinition(): CommandDefinition<z.infer<TInput>, TOutput>;
64
+ }
65
+ /**
66
+ * Define a command with Zod schema for type-safe input validation.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { z } from 'zod';
71
+ * import { defineCommand, success } from '@lushly-dev/afd-server';
72
+ *
73
+ * const createTodo = defineCommand({
74
+ * name: 'todo.create',
75
+ * description: 'Create a new todo item',
76
+ * category: 'todo',
77
+ * mutation: true,
78
+ * input: z.object({
79
+ * title: z.string().min(1).max(200),
80
+ * priority: z.enum(['low', 'medium', 'high']).default('medium'),
81
+ * }),
82
+ * async handler(input) {
83
+ * const todo = await createInDb(input);
84
+ * return success(todo);
85
+ * },
86
+ * });
87
+ * ```
88
+ */
89
+ export declare function defineCommand<TInput extends ZodType<unknown, ZodTypeDef, unknown>, TOutput>(options: ZodCommandOptions<TInput, TOutput>): ZodCommandDefinition<TInput, TOutput>;
90
+ /**
91
+ * Convert a Zod schema to JSON Schema format.
92
+ *
93
+ * @param schema - Zod schema to convert
94
+ * @returns JSON Schema representation
95
+ */
96
+ export declare function zodToJsonSchema(schema: ZodType): JsonSchema;
97
+ /**
98
+ * Get required field names from a Zod object schema.
99
+ */
100
+ export declare function getRequiredFields(schema: ZodType): string[];
101
+ /**
102
+ * Check if a Zod schema represents an object type.
103
+ */
104
+ export declare function isObjectSchema(schema: ZodType): schema is z.ZodObject<z.ZodRawShape>;
105
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,E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ist/schema.js ADDED
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @fileoverview Zod-based command definition helpers
3
+ *
4
+ * This module provides utilities for defining commands using Zod schemas,
5
+ * with automatic JSON Schema generation for MCP tool definitions.
6
+ */
7
+ import { z } from 'zod';
8
+ import { zodToJsonSchema as zodToJson } from 'zod-to-json-schema';
9
+ // ═══════════════════════════════════════════════════════════════════════════════
10
+ // MAIN FUNCTION
11
+ // ═══════════════════════════════════════════════════════════════════════════════
12
+ /**
13
+ * Define a command with Zod schema for type-safe input validation.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { z } from 'zod';
18
+ * import { defineCommand, success } from '@lushly-dev/afd-server';
19
+ *
20
+ * const createTodo = defineCommand({
21
+ * name: 'todo.create',
22
+ * description: 'Create a new todo item',
23
+ * category: 'todo',
24
+ * mutation: true,
25
+ * input: z.object({
26
+ * title: z.string().min(1).max(200),
27
+ * priority: z.enum(['low', 'medium', 'high']).default('medium'),
28
+ * }),
29
+ * async handler(input) {
30
+ * const todo = await createInDb(input);
31
+ * return success(todo);
32
+ * },
33
+ * });
34
+ * ```
35
+ */
36
+ export function defineCommand(options) {
37
+ const jsonSchema = zodToJsonSchema(options.input);
38
+ return {
39
+ name: options.name,
40
+ description: options.description,
41
+ inputSchema: options.input,
42
+ jsonSchema,
43
+ handler: options.handler,
44
+ category: options.category,
45
+ mutation: options.mutation,
46
+ version: options.version,
47
+ tags: options.tags,
48
+ executionTime: options.executionTime,
49
+ errors: options.errors,
50
+ toCommandDefinition() {
51
+ return {
52
+ name: options.name,
53
+ description: options.description,
54
+ category: options.category,
55
+ mutation: options.mutation,
56
+ version: options.version,
57
+ tags: options.tags,
58
+ executionTime: options.executionTime,
59
+ errors: options.errors,
60
+ parameters: jsonSchemaToParameters(jsonSchema),
61
+ returns: { type: 'object', description: 'Command result' },
62
+ handler: options.handler,
63
+ };
64
+ },
65
+ };
66
+ }
67
+ // ═══════════════════════════════════════════════════════════════════════════════
68
+ // SCHEMA CONVERSION HELPERS
69
+ // ═══════════════════════════════════════════════════════════════════════════════
70
+ /**
71
+ * Convert a Zod schema to JSON Schema format.
72
+ *
73
+ * @param schema - Zod schema to convert
74
+ * @returns JSON Schema representation
75
+ */
76
+ export function zodToJsonSchema(schema) {
77
+ const result = zodToJson(schema, {
78
+ $refStrategy: 'none',
79
+ target: 'jsonSchema7',
80
+ });
81
+ // The library returns a full JSON Schema document, extract the relevant part
82
+ if (typeof result === 'object' && result !== null) {
83
+ // Remove $schema if present
84
+ const { $schema, ...rest } = result;
85
+ // Ensure we have a valid JsonSchema with at least a type
86
+ const jsonSchema = rest;
87
+ if (!jsonSchema.type) {
88
+ // Default to object if type is not present
89
+ return { type: 'object', ...rest };
90
+ }
91
+ return jsonSchema;
92
+ }
93
+ return { type: 'object' };
94
+ }
95
+ /**
96
+ * Convert JSON Schema to CommandParameter array for @lushly-dev/afd-core compatibility.
97
+ */
98
+ function jsonSchemaToParameters(schema) {
99
+ const parameters = [];
100
+ if (schema.type === 'object' && schema.properties) {
101
+ // Handle required - it might be an array or undefined
102
+ const requiredFields = Array.isArray(schema.required) ? schema.required : [];
103
+ for (const [name, propSchema] of Object.entries(schema.properties)) {
104
+ const prop = propSchema;
105
+ parameters.push({
106
+ name,
107
+ type: prop.type ?? 'string',
108
+ description: prop.description ?? `Parameter: ${name}`,
109
+ required: requiredFields.includes(name),
110
+ default: prop.default,
111
+ enum: prop.enum,
112
+ schema: prop,
113
+ });
114
+ }
115
+ }
116
+ return parameters;
117
+ }
118
+ /**
119
+ * Get required field names from a Zod object schema.
120
+ */
121
+ export function getRequiredFields(schema) {
122
+ const jsonSchema = zodToJsonSchema(schema);
123
+ // Handle required - it might be an array or undefined
124
+ return Array.isArray(jsonSchema.required) ? jsonSchema.required : [];
125
+ }
126
+ /**
127
+ * Check if a Zod schema represents an object type.
128
+ */
129
+ export function isObjectSchema(schema) {
130
+ return schema instanceof z.ZodObject;
131
+ }
132
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +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C;YACtC,UAAU,CAAC,IAAI,CAAC;gBACf,IAAI;gBACJ,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,QAAQ;gBAC3B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,cAAc,IAAI,EAAE;gBACrD,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACvC,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI;aACZ,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAChD,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAC3C,sDAAsD;IACtD,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC7C,OAAO,MAAM,YAAY,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * @fileoverview MCP Server factory for AFD commands
3
+ *
4
+ * This module provides utilities for creating MCP-compliant servers
5
+ * from Zod-defined commands.
6
+ */
7
+ import type { CommandContext, CommandResult } from "@lushly-dev/afd-core";
8
+ import type { ZodCommandDefinition } from "./schema.js";
9
+ /**
10
+ * Transport type for MCP server.
11
+ *
12
+ * - `"stdio"`: Standard input/output transport for IDE/CLI integration (Cursor, Claude Code, etc.)
13
+ * - `"http"`: HTTP/SSE transport for browser-based clients
14
+ * - `"auto"`: Auto-detect based on whether stdin is a TTY (stdio if piped, http if TTY)
15
+ */
16
+ export type McpTransport = "stdio" | "http" | "auto";
17
+ /**
18
+ * Detect whether stdin is being piped (non-TTY).
19
+ * Used for auto-detection of transport mode.
20
+ *
21
+ * @returns true if stdin is a pipe (not interactive), false if it's a TTY
22
+ */
23
+ export declare function isStdinPiped(): boolean;
24
+ /**
25
+ * MCP Server configuration options.
26
+ */
27
+ export interface McpServerOptions {
28
+ /** Server name for identification */
29
+ name: string;
30
+ /** Server version */
31
+ version: string;
32
+ /** Commands to expose */
33
+ commands: ZodCommandDefinition[];
34
+ /** Port to listen on (default: 3100) */
35
+ port?: number;
36
+ /** Host to bind to (default: localhost) */
37
+ host?: string;
38
+ /**
39
+ * Enable development mode.
40
+ * When true:
41
+ * - Error responses include stack traces
42
+ * - CORS allows all origins (*)
43
+ * - Verbose validation errors are returned
44
+ *
45
+ * When false (default, secure by default):
46
+ * - Stack traces are omitted from error responses
47
+ * - CORS is restrictive (same-origin only unless cors option is set)
48
+ * - Validation errors are sanitized
49
+ */
50
+ devMode?: boolean;
51
+ /** Enable CORS for browser access (in production, requires explicit opt-in) */
52
+ cors?: boolean;
53
+ /**
54
+ * Transport protocol to use.
55
+ *
56
+ * - `"stdio"`: Standard input/output for IDE/agent integration (Cursor, Claude Code, Antigravity)
57
+ * - `"http"`: HTTP/SSE for browser-based clients and web UIs
58
+ * - `"auto"`: Auto-detect based on environment (stdio if piped, http if TTY) - **default**
59
+ *
60
+ * @default "auto"
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // For IDE integration (Cursor, Claude Code):
65
+ * createMcpServer({ transport: "stdio", ... });
66
+ *
67
+ * // For web UI:
68
+ * createMcpServer({ transport: "http", ... });
69
+ *
70
+ * // Auto-detect (recommended for most cases):
71
+ * createMcpServer({ transport: "auto", ... });
72
+ * ```
73
+ */
74
+ transport?: McpTransport;
75
+ /**
76
+ * @deprecated Use `transport: "stdio"` or `transport: "auto"` instead.
77
+ * Enable stdio transport (default: true when transport is not specified)
78
+ */
79
+ stdio?: boolean;
80
+ /** Middleware to run before command execution */
81
+ middleware?: CommandMiddleware[];
82
+ /** Called when a command is executed */
83
+ onCommand?: (command: string, input: unknown, result: CommandResult) => void;
84
+ /** Called on server errors */
85
+ onError?: (error: Error) => void;
86
+ /**
87
+ * Tool strategy for MCP tool listing.
88
+ * - "individual": Each command is exposed as a separate tool (default)
89
+ * - "grouped": Commands are grouped by category into consolidated tools
90
+ */
91
+ toolStrategy?: "individual" | "grouped";
92
+ /**
93
+ * Custom function to derive group name from command.
94
+ * Used when toolStrategy is "grouped".
95
+ * Defaults to using command.category or first segment of command name.
96
+ */
97
+ groupByFn?: (command: ZodCommandDefinition) => string | undefined;
98
+ }
99
+ /**
100
+ * Middleware function type.
101
+ */
102
+ export type CommandMiddleware = (commandName: string, input: unknown, context: CommandContext, next: () => Promise<CommandResult>) => Promise<CommandResult>;
103
+ /**
104
+ * MCP Server instance.
105
+ */
106
+ export interface McpServer {
107
+ /** Start the server */
108
+ start(): Promise<void>;
109
+ /** Stop the server */
110
+ stop(): Promise<void>;
111
+ /** Get server URL (returns "stdio://" for stdio transport) */
112
+ getUrl(): string;
113
+ /** Get registered commands */
114
+ getCommands(): ZodCommandDefinition[];
115
+ /**
116
+ * Get the resolved transport mode.
117
+ * Useful for debugging and logging.
118
+ */
119
+ getTransport(): "stdio" | "http";
120
+ /** Execute a command directly (for testing) */
121
+ execute(name: string, input: unknown, context?: CommandContext): Promise<CommandResult>;
122
+ }
123
+ /**
124
+ * Create an MCP server from Zod-defined commands.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { createMcpServer, defineCommand } from '@lushly-dev/afd-server';
129
+ *
130
+ * const server = createMcpServer({
131
+ * name: 'my-app',
132
+ * version: '1.0.0',
133
+ * commands: [createTodo, listTodos, deleteTodo],
134
+ * });
135
+ *
136
+ * await server.start();
137
+ * console.log(`Server running at ${server.getUrl()}`);
138
+ * ```
139
+ */
140
+ export declare function createMcpServer(options: McpServerOptions): McpServer;
141
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"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