Skip to content

fix: improve code robustness #11

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function VueMcp(options: VueMcpOptions = {}): Plugin {
mcpServer = (vite: ViteDevServer, ctx: VueMcpContext) => import('./server').then(m => m.createMcpServerDefault(options, vite, ctx)),
} = options

const cursorMcpOptions = typeof updateCursorMcpJson == 'boolean'
const cursorMcpOptions = typeof updateCursorMcpJson === 'boolean'
? { enabled: updateCursorMcpJson }
: updateCursorMcpJson

Expand All @@ -44,7 +44,7 @@ export function VueMcp(options: VueMcpOptions = {}): Plugin {
async configureServer(vite) {
const rpc = createServerRpc(ctx)

const rpcServer = createRPCServer<RpcFunctions, any>(
const rpcServer = createRPCServer<RpcFunctions, RpcFunctions>(
'vite-plugin-vue-mcp',
vite.ws,
rpc,
Expand Down Expand Up @@ -86,7 +86,7 @@ export function VueMcp(options: VueMcpOptions = {}): Plugin {
if (importee === vueMcpOptionsImportee) {
return resolvedVueMcpOptions
}
else if (importee.startsWith('virtual:vue-mcp-path:')) {
if (importee.startsWith('virtual:vue-mcp-path:')) {
const resolved = importee.replace('virtual:vue-mcp-path:', `${vueMcpPath}/`)
return `${resolved}${vueMcpResourceSymbol}`
}
Expand All @@ -105,7 +105,8 @@ export function VueMcp(options: VueMcpOptions = {}): Plugin {
&& (
(typeof appendTo === 'string' && filename.endsWith(appendTo))
|| (appendTo instanceof RegExp && appendTo.test(filename)))) {
code = `import 'virtual:vue-mcp-path:overlay.js';\n${code}`
const modifiedCode = `import 'virtual:vue-mcp-path:overlay.js';\n${code}`
return modifiedCode
}

return code
Expand Down
3 changes: 2 additions & 1 deletion src/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function flattenChildren(node) {
result.push(node)

if (Array.isArray(node.children)) {
node.children.forEach(child => traverse(child))
for (const child of node.children)
traverse(child)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ export function createServerRpc(ctx: VueMcpContext): RpcFunctions {
onPiniaInfoUpdated: (event: string, data: string) => {
ctx.hooks.callHook(event, data)
},
// edit component state
editComponentState: (options: { componentName: string, path: string[], value: string, valueType: string }) => {},
// highlight component
highlightComponent: (options: { componentName: string }) => {},
}
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface VueMcpOptions {
* Setup the MCP server, this is called when the MCP server is created
* You may also return a new MCP server to replace the default one
*/
mcpServerSetup?: (server: McpServer, viteServer: ViteDevServer) => Awaitable<void | McpServer>
mcpServerSetup?: (server: McpServer, viteServer: ViteDevServer) => Awaitable<undefined | McpServer>

/**
* The path to the MCP server, default is `/__mcp`
Expand Down