Skip to content

Commit b12f2c7

Browse files
authored
Consolidates all mcp tools to take frameworks as arguments (#116)
This PR makes the MCP tools work across frameworks, reducing the number of tools an agent needs to create Tanstack applications. This is important because Agents work better with 5-6 tools. (Two for every JS framework isn't ideal!) ![image](https://github.com/user-attachments/assets/9950a47c-d388-4c16-8524-3573488f4f17) Closes #101
1 parent e4f8554 commit b12f2c7

File tree

3 files changed

+20
-97
lines changed

3 files changed

+20
-97
lines changed

frameworks/react-cra/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function createFrameworkDefinition(): FrameworkDefinition {
2424

2525
return {
2626
id: 'react-cra',
27-
name: 'react',
27+
name: 'React',
2828
description: 'Templates for React CRA',
2929
version: '0.1.0',
3030
base: files,

frameworks/solid/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function createFrameworkDefinition(): FrameworkDefinition {
2424

2525
return {
2626
id: 'solid',
27-
name: 'solid',
27+
name: 'Solid',
2828
description: 'Solid templates for Tanstack Router Applications',
2929
version: '0.1.0',
3030
base: files,

packages/cta-cli/src/mcp.ts

Lines changed: 18 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// do same for listTanStackReactAddOns and listTanStackSolidAddOns
2+
// remove the react and solid variants
3+
14
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
25
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js'
36
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
@@ -9,6 +12,8 @@ import {
912
createDefaultEnvironment,
1013
finalizeAddOns,
1114
getFrameworkById,
15+
getFrameworkByName,
16+
getFrameworks,
1217
} from '@tanstack/cta-engine'
1318

1419
function createServer({
@@ -24,101 +29,17 @@ function createServer({
2429
version: '1.0.0',
2530
})
2631

27-
server.tool(
28-
'listTanStackReactAddOns',
29-
'List the available add-ons for creating TanStack React applications',
30-
{},
31-
() => {
32-
const framework = getFrameworkById('react-cra')!
33-
return {
34-
content: [
35-
{
36-
type: 'text',
37-
text: JSON.stringify(
38-
framework
39-
.getAddOns()
40-
.filter((addOn) => addOn.modes.includes('file-router'))
41-
.map((addOn) => ({
42-
id: addOn.id,
43-
description: addOn.description,
44-
})),
45-
),
46-
},
47-
],
48-
}
49-
},
50-
)
32+
const frameworks = getFrameworks();
33+
const frameworkNames = frameworks.map((framework) => framework.name);
5134

5235
server.tool(
53-
'createTanStackReactApplication',
54-
'Create a new TanStack React application',
36+
'listTanStackAddOns',
37+
'List the available add-ons for creating TanStack applications',
5538
{
56-
projectName: z
57-
.string()
58-
.describe(
59-
'The package.json module name of the application (will also be the directory name)',
60-
),
61-
cwd: z.string().describe('The directory to create the application in'),
62-
addOns: z.array(z.string()).describe('The IDs of the add-ons to install'),
63-
targetDir: z
64-
.string()
65-
.describe(
66-
'The directory to create the application in. Use the absolute path of the directory you want the application to be created in',
67-
),
39+
framework: z.string().describe(`The framework to use. Available frameworks: ${frameworkNames.join(', ')}`),
6840
},
69-
async ({ projectName, addOns, cwd, targetDir }) => {
70-
const framework = getFrameworkById('react-cra')!
71-
try {
72-
process.chdir(cwd)
73-
try {
74-
const chosenAddOns = await finalizeAddOns(
75-
framework,
76-
'file-router',
77-
Array.from(
78-
new Set([
79-
...(addOns as unknown as Array<string>),
80-
...forcedAddOns,
81-
]),
82-
),
83-
)
84-
await createApp(createDefaultEnvironment(), {
85-
projectName: projectName.replace(/^\//, './'),
86-
targetDir,
87-
framework,
88-
typescript: true,
89-
tailwind: true,
90-
packageManager: 'pnpm',
91-
mode: 'file-router',
92-
chosenAddOns,
93-
git: true,
94-
})
95-
} catch (error) {
96-
console.error(error)
97-
return {
98-
content: [
99-
{ type: 'text', text: `Error creating application: ${error}` },
100-
],
101-
}
102-
}
103-
return {
104-
content: [{ type: 'text', text: 'Application created successfully' }],
105-
}
106-
} catch (error) {
107-
return {
108-
content: [
109-
{ type: 'text', text: `Error creating application: ${error}` },
110-
],
111-
}
112-
}
113-
},
114-
)
115-
116-
server.tool(
117-
'listTanStackSolidAddOns',
118-
'List the available add-ons for creating TanStack Solid applications',
119-
{},
120-
() => {
121-
const framework = getFrameworkById('solid')!
41+
({ framework: frameworkName }) => {
42+
const framework = getFrameworkByName(frameworkName)!
12243
return {
12344
content: [
12445
{
@@ -139,9 +60,10 @@ function createServer({
13960
)
14061

14162
server.tool(
142-
'createTanStackSolidApplication',
143-
'Create a new TanStack Solid application',
63+
'createTanStackApplication',
64+
'Create a new TanStack application',
14465
{
66+
framework: z.string().describe(`The framework to use. Available frameworks: ${frameworkNames.join(', ')}`),
14567
projectName: z
14668
.string()
14769
.describe(
@@ -155,8 +77,8 @@ function createServer({
15577
'The directory to create the application in. Use the absolute path of the directory you want the application to be created in',
15678
),
15779
},
158-
async ({ projectName, addOns, cwd, targetDir }) => {
159-
const framework = getFrameworkById('solid')!
80+
async ({ framework:frameworkName, projectName, addOns, cwd, targetDir }) => {
81+
const framework = getFrameworkByName(frameworkName)!
16082
try {
16183
process.chdir(cwd)
16284
try {
@@ -182,6 +104,7 @@ function createServer({
182104
git: true,
183105
})
184106
} catch (error) {
107+
console.error(error)
185108
return {
186109
content: [
187110
{ type: 'text', text: `Error creating application: ${error}` },

0 commit comments

Comments
 (0)