cre8-mcp 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.
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Cre8 MCP Tool Handlers
3
+ *
4
+ * Functions that implement the Cre8 Design System MCP tools.
5
+ */
6
+ import { readFileSync } from 'fs';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+ // Load catalog
10
+ let catalog;
11
+ function loadCatalog() {
12
+ if (catalog)
13
+ return catalog;
14
+ try {
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ const catalogPath = join(__dirname, '..', 'data', 'components.json');
18
+ catalog = JSON.parse(readFileSync(catalogPath, 'utf-8'));
19
+ }
20
+ catch {
21
+ const catalogPath = join(process.cwd(), 'apps', 'cre8-mcp', 'data', 'components.json');
22
+ catalog = JSON.parse(readFileSync(catalogPath, 'utf-8'));
23
+ }
24
+ return catalog;
25
+ }
26
+ /**
27
+ * list_components - Lists all available Cre8 components
28
+ */
29
+ export function handleListComponents(input) {
30
+ const cat = loadCatalog();
31
+ let components = cat.components;
32
+ if (input.category) {
33
+ components = components.filter((c) => c.category.toLowerCase() === input.category.toLowerCase());
34
+ }
35
+ // Group by category
36
+ const grouped = {};
37
+ for (const comp of components) {
38
+ if (!grouped[comp.category]) {
39
+ grouped[comp.category] = [];
40
+ }
41
+ grouped[comp.category].push({
42
+ name: comp.name,
43
+ description: comp.description,
44
+ });
45
+ }
46
+ const result = {
47
+ library: cat.library,
48
+ version: cat.version,
49
+ categories: Object.entries(grouped).map(([category, comps]) => ({
50
+ category,
51
+ components: comps,
52
+ })),
53
+ totalComponents: components.length,
54
+ };
55
+ return JSON.stringify(result, null, 2);
56
+ }
57
+ /**
58
+ * get_component - Gets detailed info for a specific component
59
+ */
60
+ export function handleGetComponent(input) {
61
+ const cat = loadCatalog();
62
+ // Find component (case-insensitive, with or without Cre8 prefix)
63
+ const searchName = input.name.toLowerCase().replace(/^cre8/, '');
64
+ const component = cat.components.find((c) => c.name.toLowerCase() === input.name.toLowerCase() ||
65
+ c.name.toLowerCase().replace(/^cre8/, '') === searchName);
66
+ if (!component) {
67
+ return JSON.stringify({
68
+ error: `Component "${input.name}" not found`,
69
+ suggestion: 'Use list_components to see available components',
70
+ });
71
+ }
72
+ const result = {
73
+ name: component.name,
74
+ category: component.category,
75
+ description: component.description,
76
+ import: `import { ${component.name} } from '@tmorrow/cre8-react';`,
77
+ props: component.props,
78
+ examples: component.examples || [],
79
+ };
80
+ return JSON.stringify(result, null, 2);
81
+ }
82
+ /**
83
+ * get_patterns - Gets layout patterns and templates
84
+ */
85
+ export function handleGetPatterns(input) {
86
+ const cat = loadCatalog();
87
+ if (input.name) {
88
+ const pattern = cat.patterns.find((p) => p.name.toLowerCase() === input.name.toLowerCase());
89
+ if (!pattern) {
90
+ return JSON.stringify({
91
+ error: `Pattern "${input.name}" not found`,
92
+ available: cat.patterns.map((p) => p.name),
93
+ });
94
+ }
95
+ return JSON.stringify(pattern, null, 2);
96
+ }
97
+ return JSON.stringify({
98
+ patterns: cat.patterns.map((p) => ({
99
+ name: p.name,
100
+ description: p.description,
101
+ })),
102
+ }, null, 2);
103
+ }
104
+ /**
105
+ * search_components - Search components by name or description
106
+ */
107
+ export function handleSearchComponents(input) {
108
+ const cat = loadCatalog();
109
+ const query = input.query.toLowerCase();
110
+ const matches = cat.components.filter((c) => c.name.toLowerCase().includes(query) ||
111
+ c.description.toLowerCase().includes(query) ||
112
+ c.category.toLowerCase().includes(query));
113
+ if (matches.length === 0) {
114
+ return JSON.stringify({
115
+ message: `No components found matching "${input.query}"`,
116
+ suggestion: 'Try a broader search term or use list_components',
117
+ });
118
+ }
119
+ return JSON.stringify({
120
+ query: input.query,
121
+ results: matches.map((c) => ({
122
+ name: c.name,
123
+ category: c.category,
124
+ description: c.description,
125
+ })),
126
+ count: matches.length,
127
+ }, null, 2);
128
+ }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Cre8 Design System MCP Server
4
+ *
5
+ * Provides component intelligence for @tmorrow/cre8-react to AI agents.
6
+ */
7
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Cre8 Design System MCP Server
4
+ *
5
+ * Provides component intelligence for @tmorrow/cre8-react to AI agents.
6
+ */
7
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
8
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
10
+ import { tools, ListComponentsSchema, GetComponentSchema, GetPatternsSchema, SearchComponentsSchema } from './tools.js';
11
+ import { handleListComponents, handleGetComponent, handleGetPatterns, handleSearchComponents, } from './handlers.js';
12
+ // Create server instance
13
+ const server = new Server({
14
+ name: 'cre8-mcp',
15
+ version: '0.1.0',
16
+ }, {
17
+ capabilities: {
18
+ tools: {},
19
+ },
20
+ });
21
+ // List available tools
22
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
23
+ tools,
24
+ }));
25
+ // Handle tool calls
26
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
27
+ const { name, arguments: args } = request.params;
28
+ try {
29
+ let result;
30
+ switch (name) {
31
+ case 'list_components': {
32
+ const input = ListComponentsSchema.parse(args);
33
+ result = handleListComponents(input);
34
+ break;
35
+ }
36
+ case 'get_component': {
37
+ const input = GetComponentSchema.parse(args);
38
+ result = handleGetComponent(input);
39
+ break;
40
+ }
41
+ case 'get_patterns': {
42
+ const input = GetPatternsSchema.parse(args);
43
+ result = handleGetPatterns(input);
44
+ break;
45
+ }
46
+ case 'search_components': {
47
+ const input = SearchComponentsSchema.parse(args);
48
+ result = handleSearchComponents(input);
49
+ break;
50
+ }
51
+ default:
52
+ throw new Error(`Unknown tool: ${name}`);
53
+ }
54
+ return {
55
+ content: [{ type: 'text', text: result }],
56
+ };
57
+ }
58
+ catch (error) {
59
+ const message = error instanceof Error ? error.message : 'Unknown error';
60
+ return {
61
+ content: [{ type: 'text', text: `Error: ${message}` }],
62
+ isError: true,
63
+ };
64
+ }
65
+ });
66
+ // Start the server
67
+ async function main() {
68
+ const transport = new StdioServerTransport();
69
+ await server.connect(transport);
70
+ console.error('Cre8 MCP Server running on stdio');
71
+ }
72
+ main().catch((error) => {
73
+ console.error('Fatal error:', error);
74
+ process.exit(1);
75
+ });
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Cre8 MCP Proxy - Local stdio server that proxies to remote REST API
4
+ *
5
+ * Usage: npx cre8-mcp-proxy
6
+ *
7
+ * Add to Claude Desktop config:
8
+ * {
9
+ * "mcpServers": {
10
+ * "cre8-mcp": {
11
+ * "command": "npx",
12
+ * "args": ["-y", "cre8-mcp-proxy"]
13
+ * }
14
+ * }
15
+ * }
16
+ */
17
+ export {};
package/dist/proxy.js ADDED
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Cre8 MCP Proxy - Local stdio server that proxies to remote REST API
4
+ *
5
+ * Usage: npx cre8-mcp-proxy
6
+ *
7
+ * Add to Claude Desktop config:
8
+ * {
9
+ * "mcpServers": {
10
+ * "cre8-mcp": {
11
+ * "command": "npx",
12
+ * "args": ["-y", "cre8-mcp-proxy"]
13
+ * }
14
+ * }
15
+ * }
16
+ */
17
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
18
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
19
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
20
+ const API_URL = process.env.CRE8_API_URL || 'https://a2ui-bridgecre8-mcp-production.up.railway.app';
21
+ const tools = [
22
+ {
23
+ name: 'list_components',
24
+ description: 'Lists all available Cre8 React components grouped by category',
25
+ inputSchema: {
26
+ type: 'object',
27
+ properties: {
28
+ category: {
29
+ type: 'string',
30
+ description: 'Filter by category: Actions, Forms, Layout, Typography, Navigation, Disclosure, Feedback, Data, Media, Marketing',
31
+ },
32
+ },
33
+ },
34
+ },
35
+ {
36
+ name: 'get_component',
37
+ description: 'Gets detailed information about a specific Cre8 component',
38
+ inputSchema: {
39
+ type: 'object',
40
+ properties: {
41
+ name: {
42
+ type: 'string',
43
+ description: 'Component name (e.g., "Cre8Button" or "Button")',
44
+ },
45
+ },
46
+ required: ['name'],
47
+ },
48
+ },
49
+ {
50
+ name: 'get_patterns',
51
+ description: 'Gets pre-built UI patterns and templates using Cre8 components',
52
+ inputSchema: {
53
+ type: 'object',
54
+ properties: {
55
+ name: {
56
+ type: 'string',
57
+ description: 'Pattern name to get details (optional)',
58
+ },
59
+ },
60
+ },
61
+ },
62
+ {
63
+ name: 'search_components',
64
+ description: 'Search Cre8 components by name, description, or category',
65
+ inputSchema: {
66
+ type: 'object',
67
+ properties: {
68
+ query: {
69
+ type: 'string',
70
+ description: 'Search query (e.g., "button", "form", "navigation")',
71
+ },
72
+ },
73
+ required: ['query'],
74
+ },
75
+ },
76
+ ];
77
+ async function fetchAPI(endpoint) {
78
+ const response = await fetch(`${API_URL}${endpoint}`);
79
+ if (!response.ok) {
80
+ throw new Error(`API error: ${response.statusText}`);
81
+ }
82
+ return JSON.stringify(await response.json(), null, 2);
83
+ }
84
+ const server = new Server({ name: 'cre8-mcp', version: '0.1.0' }, { capabilities: { tools: {} } });
85
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
86
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
87
+ const { name, arguments: args } = request.params;
88
+ try {
89
+ let result;
90
+ switch (name) {
91
+ case 'list_components': {
92
+ const category = args.category;
93
+ const endpoint = category ? `/components?category=${encodeURIComponent(category)}` : '/components';
94
+ result = await fetchAPI(endpoint);
95
+ break;
96
+ }
97
+ case 'get_component': {
98
+ const componentName = args.name;
99
+ result = await fetchAPI(`/components/${encodeURIComponent(componentName)}`);
100
+ break;
101
+ }
102
+ case 'get_patterns': {
103
+ const patternName = args.name;
104
+ const endpoint = patternName ? `/patterns/${encodeURIComponent(patternName)}` : '/patterns';
105
+ result = await fetchAPI(endpoint);
106
+ break;
107
+ }
108
+ case 'search_components': {
109
+ const query = args.query;
110
+ result = await fetchAPI(`/search?q=${encodeURIComponent(query)}`);
111
+ break;
112
+ }
113
+ default:
114
+ throw new Error(`Unknown tool: ${name}`);
115
+ }
116
+ return { content: [{ type: 'text', text: result }] };
117
+ }
118
+ catch (error) {
119
+ const message = error instanceof Error ? error.message : 'Unknown error';
120
+ return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
121
+ }
122
+ });
123
+ async function main() {
124
+ const transport = new StdioServerTransport();
125
+ await server.connect(transport);
126
+ console.error(`Cre8 MCP Proxy connected to ${API_URL}`);
127
+ }
128
+ main().catch((error) => {
129
+ console.error('Fatal error:', error);
130
+ process.exit(1);
131
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Cre8 MCP REST API Server
3
+ *
4
+ * Exposes component patterns and search as HTTP endpoints.
5
+ */
6
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Cre8 MCP REST API Server
3
+ *
4
+ * Exposes component patterns and search as HTTP endpoints.
5
+ */
6
+ import { serve } from '@hono/node-server';
7
+ import { Hono } from 'hono';
8
+ import { cors } from 'hono/cors';
9
+ import { handleGetPatterns, handleSearchComponents, handleListComponents, handleGetComponent, } from './handlers.js';
10
+ const app = new Hono();
11
+ // CORS - allow all
12
+ app.use('*', cors({
13
+ origin: '*',
14
+ allowMethods: ['GET', 'OPTIONS'],
15
+ }));
16
+ // Health check
17
+ app.get('/health', (c) => c.json({ status: 'ok', service: 'cre8-mcp' }));
18
+ // Info endpoint
19
+ app.get('/', (c) => c.json({
20
+ name: 'cre8-mcp',
21
+ version: '0.1.0',
22
+ description: 'Cre8 Design System MCP Server - Component intelligence for AI agents',
23
+ endpoints: {
24
+ health: 'GET /health',
25
+ components: 'GET /components',
26
+ component: 'GET /components/:name',
27
+ patterns: 'GET /patterns',
28
+ pattern: 'GET /patterns/:name',
29
+ search: 'GET /search?q=query',
30
+ },
31
+ usage: 'npx @anthropic-ai/cre8-mcp (coming soon) or run locally with: npx -y cre8-mcp-proxy',
32
+ }));
33
+ // GET /components
34
+ app.get('/components', (c) => {
35
+ const category = c.req.query('category');
36
+ const result = handleListComponents({ category });
37
+ return c.json(JSON.parse(result));
38
+ });
39
+ // GET /components/:name
40
+ app.get('/components/:name', (c) => {
41
+ const result = handleGetComponent({ name: c.req.param('name') });
42
+ return c.json(JSON.parse(result));
43
+ });
44
+ // GET /patterns
45
+ app.get('/patterns', (c) => {
46
+ const input = {};
47
+ const result = handleGetPatterns(input);
48
+ return c.json(JSON.parse(result));
49
+ });
50
+ // GET /patterns/:name
51
+ app.get('/patterns/:name', (c) => {
52
+ const input = { name: c.req.param('name') };
53
+ const result = handleGetPatterns(input);
54
+ return c.json(JSON.parse(result));
55
+ });
56
+ // GET /search?q=query
57
+ app.get('/search', (c) => {
58
+ const q = c.req.query('q');
59
+ if (!q) {
60
+ return c.json({ error: 'Missing required query parameter: q' }, 400);
61
+ }
62
+ const input = { query: q };
63
+ const result = handleSearchComponents(input);
64
+ return c.json(JSON.parse(result));
65
+ });
66
+ // Start server
67
+ const port = parseInt(process.env.PORT || '3001', 10);
68
+ console.log(`Cre8 MCP API starting on port ${port}`);
69
+ const server = serve({
70
+ fetch: app.fetch,
71
+ port,
72
+ }, (info) => {
73
+ console.log(`Server running on http://localhost:${info.port}`);
74
+ });
75
+ process.on('SIGTERM', () => {
76
+ console.log('SIGTERM received, shutting down...');
77
+ server.close();
78
+ });
79
+ process.on('SIGINT', () => {
80
+ console.log('SIGINT received, shutting down...');
81
+ server.close();
82
+ });
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Cre8 MCP Tool Definitions
3
+ */
4
+ import { z } from 'zod';
5
+ export declare const tools: ({
6
+ name: string;
7
+ description: string;
8
+ inputSchema: {
9
+ type: "object";
10
+ properties: {
11
+ category: {
12
+ type: string;
13
+ description: string;
14
+ };
15
+ name?: undefined;
16
+ query?: undefined;
17
+ };
18
+ required?: undefined;
19
+ };
20
+ } | {
21
+ name: string;
22
+ description: string;
23
+ inputSchema: {
24
+ type: "object";
25
+ properties: {
26
+ name: {
27
+ type: string;
28
+ description: string;
29
+ };
30
+ category?: undefined;
31
+ query?: undefined;
32
+ };
33
+ required: string[];
34
+ };
35
+ } | {
36
+ name: string;
37
+ description: string;
38
+ inputSchema: {
39
+ type: "object";
40
+ properties: {
41
+ name: {
42
+ type: string;
43
+ description: string;
44
+ };
45
+ category?: undefined;
46
+ query?: undefined;
47
+ };
48
+ required?: undefined;
49
+ };
50
+ } | {
51
+ name: string;
52
+ description: string;
53
+ inputSchema: {
54
+ type: "object";
55
+ properties: {
56
+ query: {
57
+ type: string;
58
+ description: string;
59
+ };
60
+ category?: undefined;
61
+ name?: undefined;
62
+ };
63
+ required: string[];
64
+ };
65
+ })[];
66
+ export declare const ListComponentsSchema: z.ZodObject<{
67
+ category: z.ZodOptional<z.ZodString>;
68
+ }, "strip", z.ZodTypeAny, {
69
+ category?: string | undefined;
70
+ }, {
71
+ category?: string | undefined;
72
+ }>;
73
+ export declare const GetComponentSchema: z.ZodObject<{
74
+ name: z.ZodString;
75
+ }, "strip", z.ZodTypeAny, {
76
+ name: string;
77
+ }, {
78
+ name: string;
79
+ }>;
80
+ export declare const GetPatternsSchema: z.ZodObject<{
81
+ name: z.ZodOptional<z.ZodString>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ name?: string | undefined;
84
+ }, {
85
+ name?: string | undefined;
86
+ }>;
87
+ export declare const SearchComponentsSchema: z.ZodObject<{
88
+ query: z.ZodString;
89
+ }, "strip", z.ZodTypeAny, {
90
+ query: string;
91
+ }, {
92
+ query: string;
93
+ }>;
package/dist/tools.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Cre8 MCP Tool Definitions
3
+ */
4
+ import { z } from 'zod';
5
+ export const tools = [
6
+ {
7
+ name: 'list_components',
8
+ description: 'Lists all available Cre8 React components from @tmorrow/cre8-react. ' +
9
+ 'Returns components grouped by category (Actions, Forms, Layout, Navigation, etc.). ' +
10
+ 'Optionally filter by category.',
11
+ inputSchema: {
12
+ type: 'object',
13
+ properties: {
14
+ category: {
15
+ type: 'string',
16
+ description: 'Filter by category: Actions, Forms, Layout, Typography, Navigation, Disclosure, Feedback, Data, Media, Marketing',
17
+ },
18
+ },
19
+ },
20
+ },
21
+ {
22
+ name: 'get_component',
23
+ description: 'Gets detailed information about a specific Cre8 component including props, ' +
24
+ 'import statement, and usage examples. Works with or without the "Cre8" prefix.',
25
+ inputSchema: {
26
+ type: 'object',
27
+ properties: {
28
+ name: {
29
+ type: 'string',
30
+ description: 'Component name (e.g., "Cre8Button" or "Button")',
31
+ },
32
+ },
33
+ required: ['name'],
34
+ },
35
+ },
36
+ {
37
+ name: 'get_patterns',
38
+ description: 'Gets pre-built UI patterns and templates using Cre8 components. ' +
39
+ 'Includes common patterns like Login Form, Data Table, Page Layout, etc. ' +
40
+ 'Optionally get a specific pattern by name.',
41
+ inputSchema: {
42
+ type: 'object',
43
+ properties: {
44
+ name: {
45
+ type: 'string',
46
+ description: 'Pattern name to get details (optional)',
47
+ },
48
+ },
49
+ },
50
+ },
51
+ {
52
+ name: 'search_components',
53
+ description: 'Search Cre8 components by name, description, or category. ' +
54
+ 'Useful for finding components that match a specific need.',
55
+ inputSchema: {
56
+ type: 'object',
57
+ properties: {
58
+ query: {
59
+ type: 'string',
60
+ description: 'Search query (e.g., "button", "form", "navigation")',
61
+ },
62
+ },
63
+ required: ['query'],
64
+ },
65
+ },
66
+ ];
67
+ // Zod schemas for input validation
68
+ export const ListComponentsSchema = z.object({
69
+ category: z.string().optional(),
70
+ });
71
+ export const GetComponentSchema = z.object({
72
+ name: z.string(),
73
+ });
74
+ export const GetPatternsSchema = z.object({
75
+ name: z.string().optional(),
76
+ });
77
+ export const SearchComponentsSchema = z.object({
78
+ query: z.string(),
79
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "cre8-mcp",
3
+ "version": "0.1.0",
4
+ "description": "Cre8 Design System MCP Server - Component intelligence for AI agents",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "cre8-mcp": "./dist/index.js",
10
+ "cre8-mcp-proxy": "./dist/proxy.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "dev": "tsx watch src/index.ts",
15
+ "start": "node dist/index.js",
16
+ "start:api": "node dist/server.js",
17
+ "dev:api": "tsx watch src/server.ts"
18
+ },
19
+ "dependencies": {
20
+ "@hono/node-server": "^1.19.9",
21
+ "@modelcontextprotocol/sdk": "^1.0.0",
22
+ "hono": "^4.11.4",
23
+ "zod": "^3.23.8"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^20.11.0",
27
+ "tsx": "^4.7.0",
28
+ "typescript": "^5.6.3"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "data"
33
+ ]
34
+ }