Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/puny-monkeys-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

feat(cli): add new command `sv docs` to help Humans & Agents to navigate documentation quickly
35 changes: 35 additions & 0 deletions documentation/docs/20-commands/50-sv-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: sv docs
---

`sv docs` fetches Svelte and SvelteKit documentation directly from the terminal. It delegates to the [`@sveltejs/mcp`](https://www.npmjs.com/package/@sveltejs/mcp) package.

It outputs clean Markdown to standard output, making it useful for humans browsing docs without leaving the terminal, but also for AI coding agents — since there are no HTML tags or web page noise, agents can read the output directly. You can reference `sv docs` commands in files like `CLAUDE.md` or similar agent instructions to give your AI assistant access to up-to-date Svelte documentation.

## Usage

List all available documentation sections:

```sh
npx sv docs --list
```

Fetch documentation for a specific section:

```sh
npx sv docs [section]
```

For example:

```sh
npx sv docs svelte/snippet
npx sv docs kit/routing
npx sv docs routing
```

## Options

### `--list`

Lists all available documentation sections.
3 changes: 2 additions & 1 deletion packages/sv/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import pkg from './package.json' with { type: 'json' };
import { add } from './src/cli/add.ts';
import { check } from './src/cli/check.ts';
import { create } from './src/cli/create.ts';
import { docs } from './src/cli/docs.ts';
import { migrate } from './src/cli/migrate.ts';
import { helpConfig } from './src/core/common.ts';

// adds a gap of spacing between the executing command and the output
console.log();

program.name(pkg.name).version(pkg.version, '-v, --version').configureHelp(helpConfig);
program.addCommand(create).addCommand(add).addCommand(migrate).addCommand(check);
program.addCommand(create).addCommand(add).addCommand(migrate).addCommand(check).addCommand(docs);
program.parse();
49 changes: 49 additions & 0 deletions packages/sv/src/cli/docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { resolveCommand } from '@sveltejs/sv-utils';
import { Command } from 'commander';
import { execSync } from 'node:child_process';
import process from 'node:process';
import { forwardExitCode } from '../core/common.ts';
import { detectPackageManager } from '../core/package-manager.ts';

export const docs = new Command('docs')
.description('fetch Svelte/SvelteKit documentation from the terminal')
.argument(
'[section]',
'documentation section to fetch (e.g. "$state", "routing", "load functions")'
)
.option('--list', 'list all available documentation sections')
.addHelpText(
'after',
`
Examples:
npx sv docs --list list all available sections
npx sv docs svelte/snippet fetch docs for svelte snippets
npx sv docs kit/routing fetch docs for routing`
)
.action(async (section, options) => {
if (options.list) {
await runDocs(['list-sections']);
} else if (section) {
await runDocs(['get-documentation', section]);
} else {
// no section and no --list: show help
docs.help();
}
});

async function runDocs(args: string[]) {
const cwd = process.cwd();
const pm = await detectPackageManager(cwd);

try {
const cmdArgs = ['@sveltejs/mcp@latest', ...args];

// skips the download confirmation prompt for `npx`
if (pm === 'npm') cmdArgs.unshift('--yes');

const cmd = resolveCommand(pm, 'execute', cmdArgs)!;
execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit' });
} catch (error) {
forwardExitCode(error);
}
}
Loading