Skip to content

Commit 296feb2

Browse files
authored
feat(shadcn): new mcp server (#8012)
* feat(shadcn): add getRegistriesConfig api * feat(shadcn): add new mcp command * feat(shadcn): add get_item_examples_from_registries and get_add_command_for_items * feat: remove getRegistriesConfig * chore: changeset
1 parent a941287 commit 296feb2

15 files changed

Lines changed: 1057 additions & 170 deletions

File tree

.changeset/chatty-windows-stop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": major
3+
---
4+
5+
add new mcp server and command

packages/shadcn/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"pub:next": "pnpm build && pnpm publish --no-git-checks --access public --tag next",
6161
"pub:release": "pnpm build && pnpm publish --access public",
6262
"test": "vitest run",
63-
"test:dev": "REGISTRY_URL=http://localhost:4000/r vitest run"
63+
"test:dev": "REGISTRY_URL=http://localhost:4000/r vitest run",
64+
"mcp:inspect": "pnpm dlx @modelcontextprotocol/inspector node dist/index.js mcp"
6465
},
6566
"dependencies": {
6667
"@antfu/ni": "^25.0.0",
@@ -71,6 +72,7 @@
7172
"@modelcontextprotocol/sdk": "^1.17.2",
7273
"commander": "^14.0.0",
7374
"cosmiconfig": "^9.0.0",
75+
"dedent": "^1.6.0",
7476
"deepmerge": "^4.3.1",
7577
"diff": "^8.0.2",
7678
"execa": "^9.6.0",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { server } from "@/src/mcp"
2+
import { handleError } from "@/src/utils/handle-error"
3+
import { logger } from "@/src/utils/logger"
4+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
5+
import { Command } from "commander"
6+
7+
export const mcp = new Command()
8+
.name("mcp")
9+
.description("starts the registry MCP server")
10+
.option(
11+
"-c, --cwd <cwd>",
12+
"the working directory. defaults to the current directory.",
13+
process.cwd()
14+
)
15+
.action(async () => {
16+
try {
17+
const transport = new StdioServerTransport()
18+
await server.connect(transport)
19+
} catch (error) {
20+
logger.break()
21+
handleError(error)
22+
}
23+
})
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import { server } from "@/src/mcp"
2-
import { handleError } from "@/src/utils/handle-error"
1+
import { highlighter } from "@/src/utils/highlighter"
32
import { logger } from "@/src/utils/logger"
4-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
53
import { Command } from "commander"
64

75
export const mcp = new Command()
86
.name("registry:mcp")
9-
.description("starts the registry MCP server [EXPERIMENTAL]")
7+
.description("starts the registry MCP server [DEPRECATED]")
108
.option(
119
"-c, --cwd <cwd>",
1210
"the working directory. defaults to the current directory.",
1311
process.cwd()
1412
)
1513
.action(async () => {
16-
try {
17-
const transport = new StdioServerTransport()
18-
await server.connect(transport)
19-
} catch (error) {
20-
logger.break()
21-
handleError(error)
22-
}
14+
logger.warn(
15+
`The ${highlighter.info(
16+
"shadcn registry:mcp"
17+
)} command is deprecated. Use the ${highlighter.info(
18+
"shadcn mcp"
19+
)} command instead.`
20+
)
21+
logger.break()
2322
})

packages/shadcn/src/commands/search.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const searchOptionsSchema = z.object({
2323

2424
export const search = new Command()
2525
.name("search")
26+
.alias("list")
2627
.description("search items from registries")
2728
.argument(
2829
"<registries...>",

packages/shadcn/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { build } from "@/src/commands/build"
44
import { diff } from "@/src/commands/diff"
55
import { info } from "@/src/commands/info"
66
import { init } from "@/src/commands/init"
7+
import { mcp } from "@/src/commands/mcp"
78
import { migrate } from "@/src/commands/migrate"
89
import { build as registryBuild } from "@/src/commands/registry/build"
910
import { mcp as registryMcp } from "@/src/commands/registry/mcp"
@@ -35,7 +36,7 @@ async function main() {
3536
.addCommand(migrate)
3637
.addCommand(info)
3738
.addCommand(build)
38-
39+
.addCommand(mcp)
3940
// Registry commands
4041
program.addCommand(registryBuild).addCommand(registryMcp)
4142

0 commit comments

Comments
 (0)