Skip to content

Commit f558907

Browse files
committed
chore: fix MCP
1 parent 2a2c6d5 commit f558907

File tree

1 file changed

+128
-91
lines changed

1 file changed

+128
-91
lines changed

packages/cta-mcp/src/mcp.ts

+128-91
Original file line numberDiff line numberDiff line change
@@ -103,74 +103,91 @@ function createServer({
103103
version: '1.0.0',
104104
})
105105

106-
server.tool('listTanStackReactAddOns', {}, () => {
107-
return {
108-
content: [{ type: 'text', text: JSON.stringify(tanStackReactAddOns) }],
109-
}
110-
})
106+
server.tool(
107+
'listTanStackReactAddOns',
108+
'List the available add-ons for creating TanStack React applications',
109+
{},
110+
() => {
111+
const framework = getFrameworkById('react-cra')!
112+
return {
113+
content: [
114+
{
115+
type: 'text',
116+
text: JSON.stringify(
117+
framework
118+
.getAddOns()
119+
.filter((addOn) => addOn.templates.includes('file-router'))
120+
.map((addOn) => ({
121+
id: addOn.id,
122+
description: addOn.description,
123+
})),
124+
),
125+
},
126+
],
127+
}
128+
},
129+
)
111130

112131
server.tool(
113132
'createTanStackReactApplication',
133+
'Create a new TanStack React application',
114134
{
115135
projectName: z
116136
.string()
117137
.describe(
118138
'The package.json module name of the application (will also be the directory name)',
119139
),
120140
cwd: z.string().describe('The directory to create the application in'),
121-
addOns: z
122-
.array(
123-
z.enum([
124-
'clerk',
125-
'convex',
126-
'form',
127-
'netlify',
128-
'sentry',
129-
'shadcn',
130-
'start',
131-
'store',
132-
'tanstack-query',
133-
'tanchat',
134-
]),
135-
)
136-
.describe('The IDs of the add-ons to install'),
141+
addOns: z.array(z.string()).describe('The IDs of the add-ons to install'),
137142
targetDir: z
138143
.string()
139144
.describe(
140145
'The directory to create the application in. Use the absolute path of the directory you want the application to be created in',
141146
),
142147
},
143148
async ({ projectName, addOns, cwd, targetDir }) => {
144-
const framework = getFrameworkById('react')!
149+
const framework = getFrameworkById('react-cra')!
145150
try {
146151
process.chdir(cwd)
147-
const chosenAddOns = await finalizeAddOns(
148-
framework,
149-
'file-router',
150-
Array.from(
151-
new Set([...(addOns as unknown as Array<string>), ...forcedAddOns]),
152-
),
153-
)
154-
await createApp(
155-
{
156-
projectName: projectName.replace(/^\//, './'),
152+
try {
153+
const chosenAddOns = await finalizeAddOns(
157154
framework,
158-
typescript: true,
159-
tailwind: true,
160-
packageManager: 'pnpm',
161-
mode: 'file-router',
162-
addOns: true,
163-
chosenAddOns,
164-
git: true,
165-
variableValues: {},
166-
},
167-
{
168-
silent: true,
169-
environment: createDefaultEnvironment(),
170-
name,
171-
cwd: targetDir,
172-
},
173-
)
155+
'file-router',
156+
Array.from(
157+
new Set([
158+
...(addOns as unknown as Array<string>),
159+
...forcedAddOns,
160+
]),
161+
),
162+
)
163+
await createApp(
164+
{
165+
projectName: projectName.replace(/^\//, './'),
166+
framework,
167+
typescript: true,
168+
tailwind: true,
169+
packageManager: 'pnpm',
170+
mode: 'file-router',
171+
addOns: true,
172+
chosenAddOns,
173+
git: true,
174+
variableValues: {},
175+
},
176+
{
177+
silent: true,
178+
environment: createDefaultEnvironment(),
179+
name,
180+
cwd: targetDir,
181+
},
182+
)
183+
} catch (error) {
184+
console.error(error)
185+
return {
186+
content: [
187+
{ type: 'text', text: `Error creating application: ${error}` },
188+
],
189+
}
190+
}
174191
return {
175192
content: [{ type: 'text', text: 'Application created successfully' }],
176193
}
@@ -184,33 +201,42 @@ function createServer({
184201
},
185202
)
186203

187-
server.tool('listTanStackSolidAddOns', {}, () => {
188-
return {
189-
content: [{ type: 'text', text: JSON.stringify(tanStackSolidAddOns) }],
190-
}
191-
})
204+
server.tool(
205+
'listTanStackSolidAddOns',
206+
'List the available add-ons for creating TanStack Solid applications',
207+
{},
208+
() => {
209+
const framework = getFrameworkById('solid')!
210+
return {
211+
content: [
212+
{
213+
type: 'text',
214+
text: JSON.stringify(
215+
framework
216+
.getAddOns()
217+
.filter((addOn) => addOn.templates.includes('file-router'))
218+
.map((addOn) => ({
219+
id: addOn.id,
220+
description: addOn.description,
221+
})),
222+
),
223+
},
224+
],
225+
}
226+
},
227+
)
192228

193229
server.tool(
194230
'createTanStackSolidApplication',
231+
'Create a new TanStack Solid application',
195232
{
196233
projectName: z
197234
.string()
198235
.describe(
199236
'The package.json module name of the application (will also be the directory name)',
200237
),
201238
cwd: z.string().describe('The directory to create the application in'),
202-
addOns: z
203-
.array(
204-
z.enum([
205-
'solid-ui',
206-
'form',
207-
'sentry',
208-
'store',
209-
'tanstack-query',
210-
'tanchat',
211-
]),
212-
)
213-
.describe('The IDs of the add-ons to install'),
239+
addOns: z.array(z.string()).describe('The IDs of the add-ons to install'),
214240
targetDir: z
215241
.string()
216242
.describe(
@@ -221,33 +247,44 @@ function createServer({
221247
const framework = getFrameworkById('solid')!
222248
try {
223249
process.chdir(cwd)
224-
const chosenAddOns = await finalizeAddOns(
225-
framework,
226-
'file-router',
227-
Array.from(
228-
new Set([...(addOns as unknown as Array<string>), ...forcedAddOns]),
229-
),
230-
)
231-
await createApp(
232-
{
233-
projectName: projectName.replace(/^\//, './'),
250+
try {
251+
const chosenAddOns = await finalizeAddOns(
234252
framework,
235-
typescript: true,
236-
tailwind: true,
237-
packageManager: 'pnpm',
238-
mode: 'file-router',
239-
addOns: true,
240-
chosenAddOns,
241-
git: true,
242-
variableValues: {},
243-
},
244-
{
245-
silent: true,
246-
environment: createDefaultEnvironment(),
247-
name,
248-
cwd: targetDir,
249-
},
250-
)
253+
'file-router',
254+
Array.from(
255+
new Set([
256+
...(addOns as unknown as Array<string>),
257+
...forcedAddOns,
258+
]),
259+
),
260+
)
261+
await createApp(
262+
{
263+
projectName: projectName.replace(/^\//, './'),
264+
framework,
265+
typescript: true,
266+
tailwind: true,
267+
packageManager: 'pnpm',
268+
mode: 'file-router',
269+
addOns: true,
270+
chosenAddOns,
271+
git: true,
272+
variableValues: {},
273+
},
274+
{
275+
silent: true,
276+
environment: createDefaultEnvironment(),
277+
name,
278+
cwd: targetDir,
279+
},
280+
)
281+
} catch (error) {
282+
return {
283+
content: [
284+
{ type: 'text', text: `Error creating application: ${error}` },
285+
],
286+
}
287+
}
251288
return {
252289
content: [{ type: 'text', text: 'Application created successfully' }],
253290
}

0 commit comments

Comments
 (0)