返回 slidev
stdio.ts
根目录 / packages / slidev / node / mcp / stdio.ts
1 import { StdioServerTransport } from '@modelcontextprotocol/server/stdio'
2 import { version } from '../../package.json'
3 import { parser } from '../parser'
4 import { getRoots } from '../resolver'
5 import { createSlidevMcpServer } from './server'
6
7 /**
8 * Start a Slidev MCP server over stdio, operating on the markdown files
9 * directly (no dev server required, so no live-navigation tool).
10 *
11 * Note: in stdio mode, stdout is reserved for the MCP protocol — nothing
12 * else may be printed to it.
13 */
14 export async function startMcpStdioServer(entry: string) {
15 const { userRoot } = await getRoots(entry)
16 const server = createSlidevMcpServer({
17 version,
18 entry,
19 // Reload from disk on every tool call, as the files may be edited
20 // externally between calls
21 getData: () => parser.load({ userRoot, roots: [userRoot] }, entry),
22 })
23 await server.connect(new StdioServerTransport())
24 }
25
25 lines TYPESCRIPT