@synergy-design-system/mcp 3.7.0 → 3.8.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 (39) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +207 -18
  3. package/dist/middleware/index.d.ts +1 -0
  4. package/dist/middleware/index.js +1 -0
  5. package/dist/middleware/logging.d.ts +5 -5
  6. package/dist/middleware/logging.js +72 -0
  7. package/dist/prompts/component-rules.d.ts +2 -0
  8. package/dist/prompts/component-rules.js +36 -0
  9. package/dist/prompts/index.d.ts +1 -0
  10. package/dist/prompts/index.js +1 -0
  11. package/dist/resources/index.d.ts +1 -0
  12. package/dist/resources/index.js +1 -0
  13. package/dist/resources/intent-categories-list.d.ts +7 -0
  14. package/dist/resources/intent-categories-list.js +25 -0
  15. package/dist/server.js +23 -6
  16. package/dist/tools/component-info.js +5 -2
  17. package/dist/tools/index.d.ts +5 -0
  18. package/dist/tools/index.js +5 -0
  19. package/dist/tools/intent-categories-list.d.ts +6 -0
  20. package/dist/tools/intent-categories-list.js +26 -0
  21. package/dist/tools/intent-component-guide.d.ts +6 -0
  22. package/dist/tools/intent-component-guide.js +33 -0
  23. package/dist/tools/intent-component-validate.d.ts +6 -0
  24. package/dist/tools/intent-component-validate.js +169 -0
  25. package/dist/tools/intent-options.d.ts +6 -0
  26. package/dist/tools/intent-options.js +48 -0
  27. package/dist/tools/intent-task-recommendations.d.ts +6 -0
  28. package/dist/tools/intent-task-recommendations.js +54 -0
  29. package/dist/types/prompt-response.d.ts +14 -0
  30. package/dist/types/prompt-response.js +1 -0
  31. package/dist/utilities/config.d.ts +74 -1
  32. package/dist/utilities/config.js +123 -1
  33. package/dist/utilities/index.d.ts +1 -0
  34. package/dist/utilities/index.js +1 -0
  35. package/dist/utilities/intent.d.ts +27 -0
  36. package/dist/utilities/intent.js +26 -0
  37. package/dist/utilities/metadata.d.ts +16 -0
  38. package/dist/utilities/metadata.js +109 -14
  39. package/package.json +2 -2
@@ -7,6 +7,7 @@ export * from './logging-types.js';
7
7
  export * from './local-file-logger.js';
8
8
  export * from './migration.js';
9
9
  export * from './metadata.js';
10
+ export * from './intent.js';
10
11
  export * from './token-counter.js';
11
12
  export * from './rules.js';
12
13
  export * from './server.js';
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Available intent phases for categorizing intents in the intent policy layer.
4
+ * These phases indicate the maturity and stability of intents, helping developers understand their expected behavior and potential changes.
5
+ * The phases include:
6
+ */
7
+ export declare const INTENT_PHASE_VALUES: readonly ["stable", "preview", "experimental", "deprecated"];
8
+ /**
9
+ * Default intent phases to include when listing intent categories, focusing on those that are still in development and may be subject to change.
10
+ */
11
+ export declare const INTENT_DEFAULT_PHASES: readonly ["experimental"];
12
+ export declare const INTENT_FRAMEWORK_VALUES: readonly ["react-wrapper", "react-web-components", "angular", "vue", "vanilla"];
13
+ export type IntentToolFramework = (typeof INTENT_FRAMEWORK_VALUES)[number];
14
+ export declare const INTENT_DEFAULT_FRAMEWORK: IntentToolFramework;
15
+ export declare const intentPhaseSchema: z.ZodEnum<{
16
+ stable: "stable";
17
+ deprecated: "deprecated";
18
+ experimental: "experimental";
19
+ preview: "preview";
20
+ }>;
21
+ export declare const intentFrameworkSchema: z.ZodEnum<{
22
+ "react-wrapper": "react-wrapper";
23
+ "react-web-components": "react-web-components";
24
+ angular: "angular";
25
+ vue: "vue";
26
+ vanilla: "vanilla";
27
+ }>;
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Available intent phases for categorizing intents in the intent policy layer.
4
+ * These phases indicate the maturity and stability of intents, helping developers understand their expected behavior and potential changes.
5
+ * The phases include:
6
+ */
7
+ export const INTENT_PHASE_VALUES = [
8
+ 'stable',
9
+ 'preview',
10
+ 'experimental',
11
+ 'deprecated',
12
+ ];
13
+ /**
14
+ * Default intent phases to include when listing intent categories, focusing on those that are still in development and may be subject to change.
15
+ */
16
+ export const INTENT_DEFAULT_PHASES = ['experimental'];
17
+ export const INTENT_FRAMEWORK_VALUES = [
18
+ 'react-wrapper',
19
+ 'react-web-components',
20
+ 'angular',
21
+ 'vue',
22
+ 'vanilla',
23
+ ];
24
+ export const INTENT_DEFAULT_FRAMEWORK = 'vanilla';
25
+ export const intentPhaseSchema = z.enum(INTENT_PHASE_VALUES);
26
+ export const intentFrameworkSchema = z.enum(INTENT_FRAMEWORK_VALUES);
@@ -1,4 +1,5 @@
1
1
  import type { ToolResponse } from '../types/tool-response.js';
2
+ import type { PromptResponse } from '../types/prompt-response.js';
2
3
  import { type WithErrorHandlerOptions } from '../middleware/index.js';
3
4
  /**
4
5
  * MetadataFile type representing a structured metadata file.
@@ -14,8 +15,23 @@ export type MetadataFile = {
14
15
  * @returns Final content array
15
16
  */
16
17
  export declare const toContentArray: (data: unknown[]) => ToolResponse;
18
+ type PromptDescriptionResolver<TArgs extends Record<string, unknown>> = string | ((args: TArgs) => string);
19
+ type PromptHandlerOptions<TArgs extends Record<string, unknown>> = WithErrorHandlerOptions & {
20
+ description?: PromptDescriptionResolver<TArgs>;
21
+ };
17
22
  /**
18
23
  * Creates a transparent tool handler that keeps tool bodies focused on
19
24
  * business logic while applying logging and error handling consistently.
20
25
  */
21
26
  export declare const toolHandler: <TArgs extends Record<string, unknown>>(toolName: string, handler: (args: TArgs) => Promise<unknown[]>, options?: WithErrorHandlerOptions) => (args: TArgs) => Promise<ToolResponse>;
27
+ /**
28
+ * Creates a transparent prompt handler that keeps prompt bodies focused on
29
+ * business logic while applying error handling consistently.
30
+ *
31
+ * Unlike toolHandler, promptHandler:
32
+ * - Does not apply compression (prompts are already text-based messages)
33
+ * - Returns PromptResponse directly instead of wrapping in ToolResponse
34
+ * - Provides error handling that returns an error message in prompt format
35
+ */
36
+ export declare const promptHandler: <TArgs extends Record<string, unknown>>(promptName: string, handler: (args: TArgs) => Promise<unknown[] | PromptResponse>, options?: PromptHandlerOptions<TArgs>) => (args: TArgs) => Promise<PromptResponse>;
37
+ export {};
@@ -1,4 +1,4 @@
1
- import { composeMiddlewares, withCompressionMiddleware, withErrorHandlingMiddleware, withToolLoggingMiddleware, } from '../middleware/index.js';
1
+ import { composeMiddlewares, withCompressionMiddleware, withErrorHandlingMiddleware, withPromptLoggingMiddleware, withToolLoggingMiddleware, } from '../middleware/index.js';
2
2
  import { getRuntimeConfig } from './config.js';
3
3
  /**
4
4
  * Creates a content array from an array of unknown data.
@@ -18,23 +18,118 @@ export const toContentArray = (data) => {
18
18
  content,
19
19
  };
20
20
  };
21
+ const baseMiddlewareStack = [
22
+ withErrorHandlingMiddleware,
23
+ ];
24
+ const toolMiddlewareStack = [
25
+ ...baseMiddlewareStack,
26
+ withToolLoggingMiddleware,
27
+ withCompressionMiddleware,
28
+ ];
29
+ const promptMiddlewareStack = [
30
+ ...baseMiddlewareStack,
31
+ withPromptLoggingMiddleware,
32
+ ];
33
+ const executeWithMiddleware = (name, handler, middlewareStack, options) => {
34
+ const rawHandler = composeMiddlewares(async (rawArgs) => handler(rawArgs), middlewareStack, {
35
+ config: getRuntimeConfig(),
36
+ options,
37
+ toolName: name,
38
+ });
39
+ return rawHandler;
40
+ };
41
+ const isPromptResponse = (value) => {
42
+ if (!value || typeof value !== 'object') {
43
+ return false;
44
+ }
45
+ const maybePrompt = value;
46
+ return typeof maybePrompt.description === 'string' && Array.isArray(maybePrompt.messages);
47
+ };
48
+ const toPromptResponse = (value, promptName) => {
49
+ if (isPromptResponse(value)) {
50
+ return value;
51
+ }
52
+ return {
53
+ description: `Result of ${promptName} prompt`,
54
+ messages: [
55
+ {
56
+ content: {
57
+ text: typeof value === 'string' ? value : JSON.stringify(value),
58
+ type: 'text',
59
+ },
60
+ role: 'assistant',
61
+ },
62
+ ],
63
+ };
64
+ };
65
+ const toPromptResponseFromEntries = (data, promptName, args, options) => {
66
+ const description = typeof options.description === 'function'
67
+ ? options.description(args)
68
+ : options.description ?? `Result of ${promptName} prompt`;
69
+ const messages = data
70
+ .filter(Boolean)
71
+ .map((entry) => ({
72
+ content: {
73
+ text: typeof entry === 'string' ? entry : JSON.stringify(entry),
74
+ type: 'text',
75
+ },
76
+ role: 'assistant',
77
+ }));
78
+ return {
79
+ description,
80
+ messages,
81
+ };
82
+ };
21
83
  /**
22
84
  * Creates a transparent tool handler that keeps tool bodies focused on
23
85
  * business logic while applying logging and error handling consistently.
24
86
  */
25
87
  export const toolHandler = (toolName, handler, options = {}) => async (args) => {
26
- const middlewareStack = [
27
- withErrorHandlingMiddleware,
28
- withToolLoggingMiddleware,
29
- withCompressionMiddleware,
30
- ];
31
- // Middlewares treat args opaquely as Record<string, unknown>; cast at the boundary.
32
- // Execution order (via reduceRight composition): error → logging → compression → handler
33
- // This ensures logging observes the compressed payload returned by compression middleware.
34
- const rawHandler = composeMiddlewares(async (rawArgs) => handler(rawArgs), middlewareStack, {
35
- config: getRuntimeConfig(),
36
- options,
37
- toolName,
38
- });
88
+ const rawHandler = executeWithMiddleware(toolName, handler, toolMiddlewareStack, options);
39
89
  return toContentArray(await rawHandler(args));
40
90
  };
91
+ /**
92
+ * Creates a transparent prompt handler that keeps prompt bodies focused on
93
+ * business logic while applying error handling consistently.
94
+ *
95
+ * Unlike toolHandler, promptHandler:
96
+ * - Does not apply compression (prompts are already text-based messages)
97
+ * - Returns PromptResponse directly instead of wrapping in ToolResponse
98
+ * - Provides error handling that returns an error message in prompt format
99
+ */
100
+ export const promptHandler = (promptName, handler, options = {}) => async (args) => {
101
+ const promptErrorOptions = {
102
+ ...options,
103
+ onError: async (error, context) => {
104
+ if (options.onError) {
105
+ return options.onError(error, context);
106
+ }
107
+ const suffix = context ? ` ${context}` : '';
108
+ const message = error instanceof Error ? error.message : String(error);
109
+ const errorText = `Error${suffix}: ${message}`;
110
+ return [
111
+ {
112
+ description: `Error in ${promptName} prompt`,
113
+ messages: [
114
+ {
115
+ content: {
116
+ text: errorText,
117
+ type: 'text',
118
+ },
119
+ role: 'assistant',
120
+ },
121
+ ],
122
+ },
123
+ ];
124
+ },
125
+ };
126
+ const rawHandler = executeWithMiddleware(promptName, async (rawArgs) => {
127
+ const result = await handler(rawArgs);
128
+ return isPromptResponse(result) ? [result] : result;
129
+ }, promptMiddlewareStack, promptErrorOptions);
130
+ const result = await rawHandler(args);
131
+ if (result.length === 1) {
132
+ return toPromptResponse(result[0], promptName);
133
+ }
134
+ return toPromptResponseFromEntries(result, promptName, args, options);
135
+ };
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "dependencies": {
10
10
  "@modelcontextprotocol/sdk": "^1.29.0",
11
11
  "zod": "^4.3.6",
12
- "@synergy-design-system/metadata": "3.7.0"
12
+ "@synergy-design-system/metadata": "3.8.0"
13
13
  },
14
14
  "description": "MCP Server for the Synergy Design System",
15
15
  "devDependencies": {
@@ -56,7 +56,7 @@
56
56
  "directory": "packages/mcp"
57
57
  },
58
58
  "type": "module",
59
- "version": "3.7.0",
59
+ "version": "3.8.0",
60
60
  "scripts": {
61
61
  "debug": "npx @modelcontextprotocol/inspector",
62
62
  "build": "pnpm run clean && tsc",