Skip to content
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
2 changes: 1 addition & 1 deletion lat.md/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Clients invoke this as `lat mcp`. The `lat init` wizard registers the MCP server
- **lat_section** — show section content with outgoing/incoming refs (wraps [[cli#section]])
- **lat_search** — semantic search across sections (wraps [[cli#search]])
- **lat_expand** — expand `[[refs]]` in text (wraps [[cli#expand]])
- **lat_check** — validate links and code refs (wraps [[cli#check]])
- **lat_check** — validate links, code refs, indexes, and/or sections (wraps [[cli#check]]). Optional `scope` parameter: `all` (default), `md`, `code-refs`, `index`, `sections`
- **lat_refs** — find references to a section (wraps [[cli#refs]])

Each MCP tool calls the same command function as the CLI (e.g. `locateCommand`, `refsCommand`, `searchCommand`), passing a `CmdContext` with `plainStyler` and `mode: 'mcp'`. The `toMcp()` helper converts `CmdResult` to MCP response format. Uses `@modelcontextprotocol/sdk` with stdio transport. Resolves `lat.md/` from cwd.
Expand Down
35 changes: 31 additions & 4 deletions src/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { locateCommand } from '../cli/locate.js';
import { sectionCommand } from '../cli/section.js';
import { searchCommand } from '../cli/search.js';
import { expandCommand } from '../cli/expand.js';
import { checkAllCommand } from '../cli/check.js';
import {
checkAllCommand,
checkCodeRefsCommand,
checkIndexCommand,
checkMdCommand,
checkSectionsCommand,
} from '../cli/check.js';
import { refsCommand, type Scope } from '../cli/refs.js';

function toMcp(result: CmdResult) {
Expand Down Expand Up @@ -75,9 +81,30 @@ export async function startMcpServer(): Promise<void> {

server.tool(
'lat_check',
'Validate all wiki links, code references, and directory indexes in lat.md',
{},
async () => toMcp(await checkAllCommand(ctx)),
'Validate wiki links, code references, directory indexes, and/or section structure in lat.md',
{
scope: z
.enum(['all', 'md', 'code-refs', 'index', 'sections'])
.optional()
.default('all')
.describe(
'What to check: all (default), md, code-refs, index, or sections',
),
},
async ({ scope }: { scope: string }) => {
switch (scope) {
case 'md':
return toMcp(await checkMdCommand(ctx));
case 'code-refs':
return toMcp(await checkCodeRefsCommand(ctx));
case 'index':
return toMcp(await checkIndexCommand(ctx));
case 'sections':
return toMcp(await checkSectionsCommand(ctx));
default:
return toMcp(await checkAllCommand(ctx));
}
},
);

server.tool(
Expand Down
Loading