Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .mcp-server.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[STDERR] 🚀 Starting Dynamic Templates MCP Server v2.0...
[STDERR] ✅ MCP Server connected and ready!
📋 Available tools: generate_template, list_template_types, get_template_suggestions
🎨 Template types: 20 available
25 changes: 11 additions & 14 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,23 @@ const mcpUITool = tool({
const mcpClient = getMCPClient();

// Call the MCP server to generate the template
const result = await mcpClient.callTool({
name: 'generate_ui_template',
arguments: {
templateType,
title,
description,
config,
useCase,
theme,
primaryColor,
fullScreen
}
const result = await mcpClient.callTool('generate_ui_template', {
templateType,
title,
description,
config,
useCase,
theme,
primaryColor,
fullScreen
});

if (result.isError) {
throw new Error(result.content[0]?.text || 'Unknown MCP error');
throw new Error(result.content?.[0]?.text || 'Unknown MCP error');
}

// Parse the template configuration from MCP response
const templateConfig = JSON.parse(result.content[0]?.text || '{}');
const templateConfig = JSON.parse(result.content?.[0]?.text || '{}');

return {
success: true,
Expand Down
2 changes: 1 addition & 1 deletion app/api/mcp-chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The MCP server provides rich, contextual data for each template type. Be convers

// Generate response using AI SDK
const result = await generateText({
model,
model: model as any,
messages: aiMessages,
tools,
maxTokens: 2000,
Expand Down
10 changes: 5 additions & 5 deletions lib/mcp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class MCPClientService {
});

// Handle the result according to SDK response format
if (result.content && result.content.length > 0) {
if (result.content && Array.isArray(result.content) && result.content.length > 0) {
const content = result.content[0];

if (content.type === 'text') {
Expand All @@ -273,8 +273,7 @@ export class MCPClientService {
metadata: {
category: templateData.category || 'general',
complexity: templateData.complexity || 'medium',
tags: templateData.tags || [templateType],
toolUsed: generateTool.name
tags: templateData.tags || [templateType]
}
}
};
Expand Down Expand Up @@ -331,7 +330,7 @@ export class MCPClientService {
}
});

if (result.content && result.content.length > 0) {
if (result.content && Array.isArray(result.content) && result.content.length > 0) {
const content = result.content[0];
if (content.type === 'text') {
try {
Expand Down Expand Up @@ -389,10 +388,11 @@ export class MCPClientService {
}

try {
return await this.client.callTool({
const result = await this.client.callTool({
name: toolName,
arguments: arguments_
});
return result as any;
} catch (error) {
console.error(`Failed to call tool ${toolName}:`, error);
throw error;
Expand Down
8 changes: 4 additions & 4 deletions mcp-ui-server-v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions mcp-ui-server-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "@dynamic-templates/mcp-server",
"version": "2.0.0",
"description": "Production-ready MCP server for dynamic UI template generation with comprehensive template support",
"main": "dist/index.js",
"main": "dist/simple-server.js",
"type": "module",
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"dev": "tsx watch --clear-screen=false src/index.ts",
"dev": "tsx watch --clear-screen=false src/simple-server.ts",
"build": "tsc && npm run copy-resources",
"start": "node dist/index.js",
"start": "node dist/simple-server.js",
"clean": "rimraf dist",
"copy-resources": "cp -r src/resources dist/ 2>/dev/null || true",
"test": "vitest",
Expand All @@ -23,7 +23,7 @@
"debug": "tsx --inspect src/index.ts"
},
"bin": {
"dynamic-templates-mcp": "dist/index.js"
"dynamic-templates-mcp": "dist/simple-server.js"
},
"files": [
"dist",
Expand All @@ -43,7 +43,7 @@
"author": "Dynamic Templates Team",
"license": "MIT",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.12.1",
"@modelcontextprotocol/sdk": "^1.17.0",
"zod": "^3.23.8",
"uuid": "^10.0.0",
"date-fns": "^3.6.0",
Expand Down
Loading