@lushly-dev/afd-server 0.4.0 → 0.5.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/README.md +110 -0
- package/dist/bootstrap/afd-context.d.ts +60 -0
- package/dist/bootstrap/afd-context.d.ts.map +1 -0
- package/dist/bootstrap/afd-context.js +132 -0
- package/dist/bootstrap/afd-context.js.map +1 -0
- package/dist/bootstrap/afd-help.d.ts +2 -1
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +4 -1
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/index.d.ts +1 -0
- package/dist/bootstrap/index.d.ts.map +1 -1
- package/dist/bootstrap/index.js +1 -0
- package/dist/bootstrap/index.js.map +1 -1
- package/dist/bootstrap/registry.d.ts +4 -0
- package/dist/bootstrap/registry.d.ts.map +1 -1
- package/dist/bootstrap/registry.js +8 -1
- package/dist/bootstrap/registry.js.map +1 -1
- package/dist/execution.d.ts +19 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +389 -0
- package/dist/execution.js.map +1 -0
- package/dist/handoff-schema.d.ts +14 -14
- package/dist/http-handler.d.ts +28 -0
- package/dist/http-handler.d.ts.map +1 -0
- package/dist/http-handler.js +292 -0
- package/dist/http-handler.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lazy-tools.d.ts +64 -0
- package/dist/lazy-tools.d.ts.map +1 -0
- package/dist/lazy-tools.js +144 -0
- package/dist/lazy-tools.js.map +1 -0
- package/dist/schema.d.ts +25 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +20 -1
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +138 -0
- package/dist/server-types.d.ts.map +1 -0
- package/dist/server-types.js +13 -0
- package/dist/server-types.js.map +1 -0
- package/dist/server.d.ts +6 -121
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +67 -1125
- package/dist/server.js.map +1 -1
- package/dist/tool-router.d.ts +36 -0
- package/dist/tool-router.d.ts.map +1 -0
- package/dist/tool-router.js +246 -0
- package/dist/tool-router.js.map +1 -0
- package/dist/tools.d.ts +428 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +244 -0
- package/dist/tools.js.map +1 -0
- package/package.json +3 -3
package/dist/schema.js
CHANGED
|
@@ -40,8 +40,21 @@ export function defineCommand(options) {
|
|
|
40
40
|
console.warn(`[AFD] ${nameCheck.reason}`);
|
|
41
41
|
}
|
|
42
42
|
const jsonSchema = zodToJsonSchema(options.input);
|
|
43
|
+
const outputJsonSchema = options.output ? zodToJsonSchema(options.output) : undefined;
|
|
43
44
|
// Build tags with automatic handoff tags if handoff is enabled
|
|
44
45
|
const tags = buildHandoffTags(options.tags, options.handoff, options.handoffProtocol);
|
|
46
|
+
// Validate examples against input schema at define-time
|
|
47
|
+
if (options.examples) {
|
|
48
|
+
for (const example of options.examples) {
|
|
49
|
+
const parsed = options.input.safeParse(example.input);
|
|
50
|
+
if (!parsed.success) {
|
|
51
|
+
const issues = parsed.error.issues
|
|
52
|
+
.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`)
|
|
53
|
+
.join(', ');
|
|
54
|
+
throw new Error(`Example "${example.title}" for command "${options.name}" fails schema validation: ${issues}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
return {
|
|
46
59
|
name: options.name,
|
|
47
60
|
description: options.description,
|
|
@@ -60,6 +73,10 @@ export function defineCommand(options) {
|
|
|
60
73
|
destructive: options.destructive,
|
|
61
74
|
confirmPrompt: options.confirmPrompt,
|
|
62
75
|
expose: options.expose,
|
|
76
|
+
examples: options.examples,
|
|
77
|
+
outputSchema: options.output,
|
|
78
|
+
outputJsonSchema,
|
|
79
|
+
contexts: options.contexts,
|
|
63
80
|
toCommandDefinition() {
|
|
64
81
|
return {
|
|
65
82
|
name: options.name,
|
|
@@ -74,8 +91,10 @@ export function defineCommand(options) {
|
|
|
74
91
|
handoff: options.handoff,
|
|
75
92
|
handoffProtocol: options.handoffProtocol,
|
|
76
93
|
expose: options.expose,
|
|
94
|
+
examples: options.examples,
|
|
95
|
+
contexts: options.contexts,
|
|
77
96
|
parameters: jsonSchemaToParameters(jsonSchema),
|
|
78
|
-
returns: { type: 'object', description: 'Command result' },
|
|
97
|
+
returns: outputJsonSchema ?? { type: 'object', description: 'Command result' },
|
|
79
98
|
handler: options.handler,
|
|
80
99
|
};
|
|
81
100
|
},
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAiC,CAAC,EAAE,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,eAAe,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA+KlE,kFAAkF;AAClF,gBAAgB;AAChB,kFAAkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAC5B,OAA2C;IAE3C,MAAM,SAAS,GAAG,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,UAAU,GAAG,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,MAA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AAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAE7E,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,GAAG,UAAwB,CAAC;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,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MCP server type definitions and transport utilities.
|
|
3
|
+
*/
|
|
4
|
+
import type { CommandContext, CommandMiddleware, CommandResult, PipelineRequest, PipelineResult } from '@lushly-dev/afd-core';
|
|
5
|
+
import type { ZodCommandDefinition } from './schema.js';
|
|
6
|
+
/**
|
|
7
|
+
* Transport type for MCP server.
|
|
8
|
+
*
|
|
9
|
+
* - `"stdio"`: Standard input/output transport for IDE/CLI integration (Cursor, Claude Code, etc.)
|
|
10
|
+
* - `"http"`: HTTP/SSE transport for browser-based clients
|
|
11
|
+
* - `"auto"`: Auto-detect based on whether stdin is a TTY (stdio if piped, http if TTY)
|
|
12
|
+
*/
|
|
13
|
+
export type McpTransport = 'stdio' | 'http' | 'auto';
|
|
14
|
+
/**
|
|
15
|
+
* Detect whether stdin is being piped (non-TTY).
|
|
16
|
+
* Used for auto-detection of transport mode.
|
|
17
|
+
*
|
|
18
|
+
* @returns true if stdin is a pipe (not interactive), false if it's a TTY
|
|
19
|
+
*/
|
|
20
|
+
export declare function isStdinPiped(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* MCP Server configuration options.
|
|
23
|
+
*/
|
|
24
|
+
export interface McpServerOptions {
|
|
25
|
+
/** Server name for identification */
|
|
26
|
+
name: string;
|
|
27
|
+
/** Server version */
|
|
28
|
+
version: string;
|
|
29
|
+
/** Commands to expose */
|
|
30
|
+
commands: ZodCommandDefinition[];
|
|
31
|
+
/** Port to listen on (default: 3100) */
|
|
32
|
+
port?: number;
|
|
33
|
+
/** Host to bind to (default: localhost) */
|
|
34
|
+
host?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Enable development mode.
|
|
37
|
+
* When true:
|
|
38
|
+
* - Error responses include stack traces
|
|
39
|
+
* - CORS allows all origins (*)
|
|
40
|
+
* - Verbose validation errors are returned
|
|
41
|
+
*
|
|
42
|
+
* When false (default, secure by default):
|
|
43
|
+
* - Stack traces are omitted from error responses
|
|
44
|
+
* - CORS is restrictive (same-origin only unless cors option is set)
|
|
45
|
+
* - Validation errors are sanitized
|
|
46
|
+
*/
|
|
47
|
+
devMode?: boolean;
|
|
48
|
+
/** Enable CORS for browser access (in production, requires explicit opt-in) */
|
|
49
|
+
cors?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Transport protocol to use.
|
|
52
|
+
*
|
|
53
|
+
* - `"stdio"`: Standard input/output for IDE/agent integration (Cursor, Claude Code, Antigravity)
|
|
54
|
+
* - `"http"`: HTTP/SSE for browser-based clients and web UIs
|
|
55
|
+
* - `"auto"`: Auto-detect based on environment (stdio if piped, http if TTY) - **default**
|
|
56
|
+
*
|
|
57
|
+
* @default "auto"
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // For IDE integration (Cursor, Claude Code):
|
|
62
|
+
* createMcpServer({ transport: "stdio", ... });
|
|
63
|
+
*
|
|
64
|
+
* // For web UI:
|
|
65
|
+
* createMcpServer({ transport: "http", ... });
|
|
66
|
+
*
|
|
67
|
+
* // Auto-detect (recommended for most cases):
|
|
68
|
+
* createMcpServer({ transport: "auto", ... });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
transport?: McpTransport;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use `transport: "stdio"` or `transport: "auto"` instead.
|
|
74
|
+
* Enable stdio transport (default: true when transport is not specified)
|
|
75
|
+
*/
|
|
76
|
+
stdio?: boolean;
|
|
77
|
+
/** Middleware to run before command execution */
|
|
78
|
+
middleware?: CommandMiddleware[];
|
|
79
|
+
/** Called when a command is executed */
|
|
80
|
+
onCommand?: (command: string, input: unknown, result: CommandResult) => void;
|
|
81
|
+
/** Called on server errors */
|
|
82
|
+
onError?: (error: Error) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Tool strategy for MCP tool listing.
|
|
85
|
+
* - "individual": Each command is exposed as a separate tool (default)
|
|
86
|
+
* - "grouped": Commands are grouped by category into consolidated tools
|
|
87
|
+
* - "lazy": Exposes afd-discover, afd-detail, and afd-call meta-tools instead of enumerating every command
|
|
88
|
+
*/
|
|
89
|
+
toolStrategy?: 'individual' | 'grouped' | 'lazy';
|
|
90
|
+
/**
|
|
91
|
+
* Custom function to derive group name from command.
|
|
92
|
+
* Used when toolStrategy is "grouped".
|
|
93
|
+
* Defaults to using command.category or first segment of command name.
|
|
94
|
+
*/
|
|
95
|
+
groupByFn?: (command: ZodCommandDefinition) => string | undefined;
|
|
96
|
+
/** Context configurations for tool scoping. When provided, enables context-based tool filtering. */
|
|
97
|
+
contexts?: ContextConfig[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Context configuration for tool scoping.
|
|
101
|
+
*/
|
|
102
|
+
export interface ContextConfig {
|
|
103
|
+
/** Context name (kebab-case) */
|
|
104
|
+
name: string;
|
|
105
|
+
/** Human-readable description */
|
|
106
|
+
description?: string;
|
|
107
|
+
/** Keywords that suggest this context */
|
|
108
|
+
triggers?: string[];
|
|
109
|
+
/** Higher = suggested first in listings */
|
|
110
|
+
priority?: number;
|
|
111
|
+
}
|
|
112
|
+
export type { CommandMiddleware } from '@lushly-dev/afd-core';
|
|
113
|
+
/**
|
|
114
|
+
* MCP Server instance.
|
|
115
|
+
*/
|
|
116
|
+
export interface McpServer {
|
|
117
|
+
/** Start the server */
|
|
118
|
+
start(): Promise<void>;
|
|
119
|
+
/** Stop the server */
|
|
120
|
+
stop(): Promise<void>;
|
|
121
|
+
/** Get server URL (returns "stdio://" for stdio transport) */
|
|
122
|
+
getUrl(): string;
|
|
123
|
+
/** Get registered commands */
|
|
124
|
+
getCommands(): ZodCommandDefinition[];
|
|
125
|
+
/**
|
|
126
|
+
* Get the resolved transport mode.
|
|
127
|
+
* Useful for debugging and logging.
|
|
128
|
+
*/
|
|
129
|
+
getTransport(): 'stdio' | 'http';
|
|
130
|
+
/** Execute a command directly (for testing) */
|
|
131
|
+
execute(name: string, input: unknown, context?: CommandContext): Promise<CommandResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Execute a pipeline of chained commands directly (for testing).
|
|
134
|
+
* Enables multi-step workflows with variable resolution.
|
|
135
|
+
*/
|
|
136
|
+
executePipeline(request: PipelineRequest, context?: CommandContext): Promise<PipelineResult>;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=server-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server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IAEjD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,MAAM,GAAG,SAAS,CAAC;IAElE,oGAAoG;IACpG,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IAEb,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,uBAAuB;IACvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,8DAA8D;IAC9D,MAAM,IAAI,MAAM,CAAC;IAEjB,8BAA8B;IAC9B,WAAW,IAAI,oBAAoB,EAAE,CAAC;IAEtC;;;OAGG;IACH,YAAY,IAAI,OAAO,GAAG,MAAM,CAAC;IAEjC,+CAA+C;IAC/C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAExF;;;OAGG;IACH,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC7F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MCP server type definitions and transport utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Detect whether stdin is being piped (non-TTY).
|
|
6
|
+
* Used for auto-detection of transport mode.
|
|
7
|
+
*
|
|
8
|
+
* @returns true if stdin is a pipe (not interactive), false if it's a TTY
|
|
9
|
+
*/
|
|
10
|
+
export function isStdinPiped() {
|
|
11
|
+
return !process.stdin.isTTY;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=server-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-types.js","sourceRoot":"","sources":["../src/server-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwBH;;;;;GAKG;AACH,MAAM,UAAU,YAAY;IAC3B,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AAC7B,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,127 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview MCP Server factory for AFD commands
|
|
2
|
+
* @fileoverview MCP Server factory for AFD commands.
|
|
3
3
|
*
|
|
4
|
-
* This module provides
|
|
5
|
-
*
|
|
4
|
+
* This module provides the `createMcpServer` factory that wires together
|
|
5
|
+
* execution, tool routing, and transport layers into a single MCP server.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
|
|
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
|
-
export type { CommandMiddleware } from '@lushly-dev/afd-core';
|
|
100
|
-
/**
|
|
101
|
-
* MCP Server instance.
|
|
102
|
-
*/
|
|
103
|
-
export interface McpServer {
|
|
104
|
-
/** Start the server */
|
|
105
|
-
start(): Promise<void>;
|
|
106
|
-
/** Stop the server */
|
|
107
|
-
stop(): Promise<void>;
|
|
108
|
-
/** Get server URL (returns "stdio://" for stdio transport) */
|
|
109
|
-
getUrl(): string;
|
|
110
|
-
/** Get registered commands */
|
|
111
|
-
getCommands(): ZodCommandDefinition[];
|
|
112
|
-
/**
|
|
113
|
-
* Get the resolved transport mode.
|
|
114
|
-
* Useful for debugging and logging.
|
|
115
|
-
*/
|
|
116
|
-
getTransport(): 'stdio' | 'http';
|
|
117
|
-
/** Execute a command directly (for testing) */
|
|
118
|
-
execute(name: string, input: unknown, context?: CommandContext): Promise<CommandResult>;
|
|
119
|
-
/**
|
|
120
|
-
* Execute a pipeline of chained commands directly (for testing).
|
|
121
|
-
* Enables multi-step workflows with variable resolution.
|
|
122
|
-
*/
|
|
123
|
-
executePipeline(request: PipelineRequest, context?: CommandContext): Promise<PipelineResult>;
|
|
124
|
-
}
|
|
7
|
+
import type { McpServer, McpServerOptions } from './server-types.js';
|
|
8
|
+
export type { CommandMiddleware, ContextConfig, McpServer, McpServerOptions, McpTransport, } from './server-types.js';
|
|
9
|
+
export { isStdinPiped } from './server-types.js';
|
|
125
10
|
/**
|
|
126
11
|
* Create an MCP server from Zod-defined commands.
|
|
127
12
|
*
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAKrE,YAAY,EACX,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,YAAY,GACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA0KpE"}
|