Skip to content

Commit 619416a

Browse files
committed
Add AI Elements MCP server
1 parent a7128ab commit 619416a

File tree

5 files changed

+345
-5
lines changed

5 files changed

+345
-5
lines changed

.changeset/all-parrots-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-elements": patch
3+
---
4+
5+
Add AI Elements MCP server

apps/docs/content/docs/mcp.mdx

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: MCP Server
3+
description: AI Elements supports the Model Context Protocol (MCP) for model-driven development.
4+
---
5+
6+
The **Model Context Protocol (MCP)** is an open standard that allows AI assistants like Claude, Cursor, and other AI-powered tools to securely connect with external data sources and systems. Think of it as a "universal remote" that lets your AI tools access real-world data and functionality.
7+
8+
AI Elements supports MCP to supercharge your AI development workflow.
9+
10+
## Installation Guide
11+
12+
### Step 1: Choose Your AI Tool
13+
14+
First, make sure you're using an AI development tool that supports MCP:
15+
16+
- [Claude Desktop](https://claude.ai/download) (Free - recommended for beginners)
17+
- [Cursor](https://www.cursor.com/) (AI-powered code editor)
18+
- [Windsurf by Codeium](https://windsurf.com/) (AI development platform)
19+
- Other MCP-compatible tools
20+
21+
### Step 2: Locate Your Configuration File
22+
23+
Depending on your AI tool, you'll need to edit one of these files:
24+
25+
- **Claude Desktop**: `.cursor/mcp.json`
26+
- **Cursor**: `.cursor/mcp.json`
27+
- **Windsurf**: `.codeium/windsurf/mcp_config.json`
28+
- **Other tools**: Check your tool's MCP documentation
29+
30+
### Step 3: Add AI Elements Configuration
31+
32+
Copy and paste this configuration into your MCP config file:
33+
34+
```json
35+
{
36+
"mcpServers": {
37+
"ai-elements": {
38+
"command": "npx",
39+
"args": [
40+
"-y",
41+
"mcp-remote",
42+
"https://registry.ai-sdk.dev/api/mcp"
43+
]
44+
}
45+
}
46+
}
47+
```
48+
49+
### Step 4: Restart Your AI Tool
50+
51+
Close and reopen your AI application for the changes to take effect.
52+
53+
### Step 5: Verify the Connection
54+
55+
Test the integration by asking your AI assistant:
56+
57+
> "What AI Elements components are available for building an AI app?"
58+
59+
If successful, your AI should be able to list and explain AI Elements components!
60+
61+
## Multiple MCP Servers
62+
63+
You can use AI Elements alongside other MCP servers:
64+
65+
```json
66+
{
67+
"mcpServers": {
68+
"ai-elements": {
69+
"command": "npx",
70+
"args": ["-y", "mcp-remote", "https://registry.ai-sdk.dev/api/mcp"]
71+
},
72+
"github": {
73+
"command": "npx",
74+
"args": ["-y", "@modelcontextprotocol/server-github"]
75+
},
76+
"filesystem": {
77+
"command": "npx",
78+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
79+
}
80+
}
81+
}
82+
```
83+
84+
## Usage Examples
85+
86+
### Getting Component Information
87+
88+
Ask your AI assistant:
89+
90+
> Show me how to use the AI Elements PromptInput component with different variants
91+
92+
Expected response will include current documentation and code examples.
93+
94+
### Building Layouts
95+
96+
> Help me create an AI app layout using AI Elements components
97+
98+
Your AI can suggest appropriate layout components and provide implementation code.
99+
100+
### Styling Guidance
101+
102+
> What are the recommended spacing tokens in AI Elements?
103+
104+
Get up-to-date information about design tokens and styling conventions.
105+
106+
## Security and Privacy
107+
108+
### Data Handling
109+
110+
- The AI Elements MCP server only provides public component documentation
111+
- No personal data or code is transmitted to our servers
112+
- All communication happens through your chosen AI tool's security layer
113+
114+
### Authentication
115+
116+
- No authentication required for public component information
117+
- Future premium features may require API keys
118+
- Always use official AI Elements MCP endpoints
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { promises as fs, readdirSync } from "node:fs";
2+
import { join } from "node:path";
3+
import { track } from "@vercel/analytics/server";
4+
import { createMcpHandler } from "mcp-handler";
5+
import type { RegistryItem } from "shadcn/schema";
6+
import { z } from "zod";
7+
8+
const packageDir = join(process.cwd(), "..", "..", "packages", "elements");
9+
const srcDir = join(packageDir, "src");
10+
const packageFiles = readdirSync(srcDir, { withFileTypes: true });
11+
const tsxFiles = packageFiles.filter(
12+
(file) => file.isFile() && file.name.endsWith(".tsx")
13+
);
14+
15+
const componentNames = tsxFiles.map((file) => file.name.replace(".tsx", ""));
16+
17+
const handler = createMcpHandler(
18+
(server) => {
19+
server.tool(
20+
"get_ai_elements_components",
21+
"Provides a list of all AI Elements components.",
22+
{},
23+
async () => {
24+
if (process.env.NODE_ENV === "production") {
25+
try {
26+
await track("MCP: Get components");
27+
} catch (error) {
28+
console.error(error);
29+
}
30+
}
31+
32+
return {
33+
content: [{ type: "text", text: JSON.stringify(componentNames) }],
34+
};
35+
}
36+
);
37+
38+
server.tool(
39+
"get_ai_elements_component",
40+
"Provides information about an AI Elements component.",
41+
{ component: z.enum(componentNames as [string, ...string[]]) },
42+
async ({ component }) => {
43+
const tsxFile = tsxFiles.find(
44+
(file) => file.name === `${component}.tsx`
45+
);
46+
47+
if (!tsxFile) {
48+
return {
49+
content: [
50+
{ type: "text", text: `Component ${component} not found` },
51+
],
52+
};
53+
}
54+
55+
if (process.env.NODE_ENV === "production") {
56+
try {
57+
await track("MCP: Get component", {
58+
component,
59+
});
60+
} catch (error) {
61+
console.error(error);
62+
}
63+
}
64+
65+
// Read the component file
66+
const filePath = join(srcDir, tsxFile.name);
67+
const content = await fs.readFile(filePath, "utf-8");
68+
const parsedContent = content.replace(/@repo\/shadcn-ui\//g, "@/");
69+
70+
// Create a registry item for this component
71+
const componentInfo: RegistryItem = {
72+
name: component,
73+
type: "registry:component",
74+
title: component
75+
.split("-")
76+
.map((word: string) => word.charAt(0).toUpperCase() + word.slice(1))
77+
.join(" "),
78+
description: `AI-powered ${component.replace("-", " ")} component.`,
79+
files: [
80+
{
81+
path: `registry/default/ai-elements/${tsxFile.name}`,
82+
type: "registry:component",
83+
content: parsedContent,
84+
target: `components/ai-elements/${tsxFile.name}`,
85+
},
86+
],
87+
};
88+
89+
return {
90+
content: [
91+
{ type: "text", text: JSON.stringify(componentInfo, null, 2) },
92+
],
93+
};
94+
}
95+
);
96+
},
97+
{},
98+
{
99+
disableSse: true,
100+
basePath: "/api",
101+
maxDuration: 60,
102+
verboseLogs: true,
103+
}
104+
);
105+
106+
export { handler as GET, handler as POST };

apps/registry/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
},
99
"dependencies": {
1010
"@vercel/analytics": "^1.5.0",
11+
"mcp-handler": "^1.0.3",
1112
"next": "16.0.0",
1213
"react": "19.2.0",
1314
"react-dom": "19.2.0",
1415
"shadcn": "^3.5.0",
15-
"ts-morph": "^27.0.2"
16+
"ts-morph": "^27.0.2",
17+
"zod": "^4.1.12"
1618
},
1719
"devDependencies": {
1820
"@types/node": "^24",

0 commit comments

Comments
 (0)