-
-
Notifications
You must be signed in to change notification settings - Fork 59
feat(cli): add new add-on mcp
to configure your project
#735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6969d7e
don't display empty array next step
jycouet 82c77b6
add in list
jycouet 9ac8ce2
feat(cli): add new add-on `mcp` to configure your project
jycouet 81b276e
v0 doc
jycouet f044105
update types
jycouet 3705b85
cleanup
jycouet 1427544
using client & matching other questions styles in sv
jycouet c77bbc1
default to remote
jycouet cf2dd66
inline local remote link
jycouet 3a23077
clean code
jycouet c9c2a0d
list mcp in list of adders
jycouet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'sv': patch | ||
--- | ||
|
||
feat(cli): add new add-on `mcp` to configure your project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: mcp | ||
--- | ||
|
||
[Svelte MCP](/docs/mcp/overview) can help your LLM write better Svelte code. | ||
|
||
## Usage | ||
|
||
```sh | ||
npx sv add mcp | ||
``` | ||
|
||
## What you get | ||
|
||
- A good mcp configuration for your project depending on your IDE | ||
|
||
## Options | ||
|
||
### ide | ||
|
||
The IDE you want to use like `'claude-code'`, `'cursor'`, `'gemini'`, `'opencode'`, `'vscode'`, `'other'`. | ||
|
||
```sh | ||
npx sv add mcp=ide:cursor,vscode | ||
``` | ||
|
||
### setup | ||
|
||
The setup you want to use. | ||
|
||
```sh | ||
npx sv add mcp=setup:local | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect } from '@playwright/test'; | ||
import { setupTest } from '../_setup/suite.ts'; | ||
import mcp from '../../mcp/index.ts'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
const { test, testCases } = setupTest( | ||
{ mcp }, | ||
{ | ||
kinds: [ | ||
{ | ||
type: 'default', | ||
options: { | ||
mcp: { ide: ['claude-code', 'cursor', 'gemini', 'opencode', 'vscode'], setup: 'local' } | ||
} | ||
} | ||
], | ||
browser: false, | ||
// test only one as it's not depending on project variants | ||
filter: (addonTestCase) => addonTestCase.variant === 'kit-ts', | ||
preInstallAddon: ({ cwd }) => { | ||
// prepare an existing file | ||
fs.mkdirSync(path.resolve(cwd, `.cursor`)); | ||
fs.writeFileSync( | ||
path.resolve(cwd, `.cursor/mcp.json`), | ||
JSON.stringify( | ||
{ | ||
mcpServers: { | ||
svelte: { some: 'thing' }, | ||
anotherMCP: {} | ||
} | ||
}, | ||
null, | ||
2 | ||
), | ||
{ encoding: 'utf8' } | ||
); | ||
} | ||
} | ||
); | ||
|
||
test.concurrent.for(testCases)('mcp $variant', (testCase, ctx) => { | ||
const cwd = ctx.cwd(testCase); | ||
|
||
const cursorPath = path.resolve(cwd, `.cursor/mcp.json`); | ||
const cursorMcpContent = fs.readFileSync(cursorPath, 'utf8'); | ||
|
||
// should keep other MCPs | ||
expect(cursorMcpContent).toContain(`anotherMCP`); | ||
// should have the svelte level | ||
expect(cursorMcpContent).toContain(`svelte`); | ||
// should have local conf | ||
expect(cursorMcpContent).toContain(`@sveltejs/mcp`); | ||
// should remove old svelte config | ||
expect(cursorMcpContent).not.toContain(`thing`); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { defineAddon, defineAddonOptions } from '@sveltejs/cli-core'; | ||
import { parseJson } from '@sveltejs/cli-core/parsers'; | ||
|
||
const options = defineAddonOptions() | ||
.add('ide', { | ||
question: 'Which client would you like to use?', | ||
type: 'multiselect', | ||
default: [], | ||
options: [ | ||
{ value: 'claude-code', label: 'claude code' }, | ||
{ value: 'cursor', label: 'Cursor' }, | ||
{ value: 'gemini', label: 'Gemini' }, | ||
{ value: 'opencode', label: 'opencode' }, | ||
{ value: 'vscode', label: 'VSCode' }, | ||
{ value: 'other', label: 'Other' } | ||
], | ||
required: true | ||
}) | ||
.add('setup', { | ||
question: 'What setup you want to use?', | ||
type: 'select', | ||
default: 'remote', | ||
options: [ | ||
{ value: 'local', label: 'Local', hint: 'will use stdio' }, | ||
{ value: 'remote', label: 'Remote', hint: 'will use a remote endpoint' } | ||
], | ||
required: true | ||
}) | ||
.build(); | ||
|
||
export default defineAddon({ | ||
id: 'mcp', | ||
shortDescription: 'Svelte MCP', | ||
homepage: 'https://svelte.dev/docs/mcp', | ||
options, | ||
run: ({ sv, options }) => { | ||
const getLocalConfig = (o?: { type?: 'stdio' | 'local'; env?: boolean }) => { | ||
return { | ||
...(o?.type ? { type: o.type } : {}), | ||
command: 'npx', | ||
args: ['-y', '@sveltejs/mcp'], | ||
...(o?.env ? { env: {} } : {}) | ||
}; | ||
}; | ||
const getRemoteConfig = (o?: { type?: 'http' | 'remote' }) => { | ||
return { | ||
...(o?.type ? { type: o.type } : {}), | ||
url: 'https://mcp.svelte.dev/mcp' | ||
}; | ||
}; | ||
|
||
const configurator: Record< | ||
(typeof options.ide)[number], | ||
| { | ||
schema?: string; | ||
mcpServersKey?: string; | ||
filePath: string; | ||
typeLocal?: 'stdio' | 'local'; | ||
typeRemote?: 'http' | 'remote'; | ||
env?: boolean; | ||
} | ||
| { other: true } | ||
> = { | ||
'claude-code': { | ||
filePath: '.mcp.json', | ||
typeLocal: 'stdio', | ||
typeRemote: 'http', | ||
env: true | ||
}, | ||
cursor: { | ||
filePath: '.cursor/mcp.json' | ||
}, | ||
gemini: { | ||
filePath: '.gemini/settings.json' | ||
}, | ||
opencode: { | ||
schema: 'https://opencode.ai/config.json', | ||
mcpServersKey: 'mcp', | ||
filePath: 'opencode.json', | ||
typeLocal: 'local', | ||
typeRemote: 'remote' | ||
}, | ||
vscode: { | ||
mcpServersKey: 'servers', | ||
filePath: '.vscode/mcp.json' | ||
}, | ||
other: { | ||
other: true | ||
} | ||
}; | ||
|
||
for (const ide of options.ide) { | ||
const value = configurator[ide]; | ||
if ('other' in value) continue; | ||
|
||
const { mcpServersKey, filePath, typeLocal, typeRemote, env, schema } = value; | ||
sv.file(filePath, (content) => { | ||
const { data, generateCode } = parseJson(content); | ||
if (schema) { | ||
data['$schema'] = schema; | ||
} | ||
const key = mcpServersKey || 'mcpServers'; | ||
data[key] ??= {}; | ||
data[key].svelte = | ||
options.setup === 'local' | ||
? getLocalConfig({ type: typeLocal, env }) | ||
: getRemoteConfig({ type: typeRemote }); | ||
return generateCode(); | ||
}); | ||
} | ||
}, | ||
nextSteps({ highlighter, options }) { | ||
const steps = []; | ||
|
||
if (options.ide.includes('other')) { | ||
steps.push( | ||
`For other clients: ${highlighter.website(`https://svelte.dev/docs/mcp/${options.setup}-setup#Other-clients`)}` | ||
); | ||
} | ||
|
||
return steps; | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.