跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
开发与测试

lai-gen-mcp

Generate a Model Context Protocol (MCP) server that exposes a Langium DSL's parser and validator as an MCP tool, allowing any MCP-compatible client to validate DSL code and receive diagnostics.

eclipse-langium · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add eclipse-langium/langium-ai --skill lai-gen-mcp

技能说明


name: lai-gen-mcp description: Generate a Model Context Protocol (MCP) server that exposes a Langium DSL's parser and validator as an MCP tool, allowing any MCP-compatible client to validate DSL code and receive diagnostics. user-invocable: true

Generate MCP Server

This guide instructs an agent on how to generate a Model Context Protocol (MCP) server for an arbitrary Langium-based DSL. The generated server exposes a validate tool that accepts DSL source code and returns diagnostics (errors, warnings, hints, information) by running the input through the DSL's actual Langium parser and validator. Any MCP-compatible client (Claude Code, Cursor, VS Code, etc.) can then validate DSL code on the fly.

You may also use the lai and langium skills to achieve a better understanding of langium-ai and the Langium-based DSL in question.

When to Use

  • After a Langium project has been initialized with lai init and a descriptor exists
  • When you want to give an MCP-compatible AI assistant the ability to validate code written in your DSL
  • When building a feedback loop where an LLM generates DSL code and can self-check it via MCP

Prerequisites

The target Langium project must have:

  1. A working Langium grammar (.langium file) and generated TypeScript artifacts (ast.ts, grammar.ts, module file)
  2. A service creation function — every Langium project has a create<Name>Services function in its module file (e.g., createMyDslServices in src/my-dsl-module.ts). This is the entry point for all language services.
  3. Node.js and npm available in the project

Inputs

Gather the following from the project before generating:

  1. Language descriptor (language.descriptor.yml) or lai.config.jsonc — to find the grammar path, service paths, and language name
  2. The module file — contains the create<Name>Services(...) function. Typically located at src/<name>-module.ts or src/language/<name>-module.ts. The descriptor's services.module field points to it if present; otherwise search for createServices or create.*Services in the src/ directory.
  3. The language metadata — the LanguageMetaData export (usually in generated/ast.ts or generated/module.ts) tells you the language's file extensions

Determining the Output Location

Before generating any files, determine where the mcp/ folder should be placed. The location depends on whether the project is a monorepo or a single-package project.

Step 0: Detect Monorepo vs Single Package

Check for monorepo indicators in the project root:

  1. package.json workspaces field — if the root package.json has a workspaces array (or workspaces.packages), the project is a monorepo
  2. pnpm-workspace.yaml — presence of this file indicates a pnpm monorepo
  3. lerna.json — presence of this file indicates a Lerna monorepo
  4. nx.json — presence of this file indicates an Nx monorepo

If none of these are present, treat the project as a single-package project.

Single-Package Project

The default output location is mcp/ at the project root:

my-dsl-project/
  src/
  mcp/              <-- generated here
    mcp-server.ts
    tsconfig.json
  package.json

Monorepo Project

In a monorepo, the mcp/ folder should be placed inside the specific Langium package, not at the monorepo root. Use the lai.config.jsonc or language.descriptor.yml location to determine which package contains the DSL. For example:

my-monorepo/
  packages/
    my-dsl/
      src/
      mcp/          <-- generated here, alongside the DSL package
        mcp-server.ts
        tsconfig.json
      package.json
    other-package/
  package.json      <-- monorepo root, NOT here

If lai.config.jsonc is at the root of a monorepo but the Langium grammar and module live in a sub-package, prefer placing mcp/ inside that sub-package so that imports resolve correctly relative to the DSL source.

Confirm with the User

Before proceeding with file generation, always ask the user to confirm the proposed output location. Present the detected location and explain why it was chosen:

  • For single-package projects: "I'll generate the MCP server in mcp/ at the project root. Does that location work for you?"
  • For monorepo projects: "This appears to be a monorepo. I'll generate the MCP server in packages/my-dsl/mcp/ alongside the DSL package. Does that location work for you, or would you prefer a different path?"

Wait for the user's confirmation or alternative path before generating any files.

Output

The agent should produce:

  1. mcp/mcp-server.ts — the MCP server source file (inside the confirmed location)
  2. mcp/tsconfig.json — a minimal tsconfig for the MCP server
  3. Updated package.json — with required dependencies added (or instructions to install them). In a monorepo, update the DSL package's package.json, not the root.
  4. Configuration snippet — an MCP client config block the user can paste into their tool of choice

Step-by-Step Generation Process

Step 1: Locate the Service Creation Function

Find the module file in the Langium project. It exports a function like:

export function createMyDslServices(context: DefaultSharedCoreModule): {
    shared: LangiumSharedServices;
    MyDsl: MyDslServices;
}

Note:

  • The function name (e.g., createMyDslServices)
  • The service accessor key — the property name on the returned object that holds the language-specific services (e.g., MyDsl). This is the key you pass to LangiumEvaluator.
  • Whether it uses NodeFileSystem or EmptyFileSystem — the MCP server should use EmptyFileSystem since it validates in-memory strings, not files on disk

Step 2: Install Dependencies

The following npm packages are required. Add them to the project's package.json:

npm install @modelcontextprotocol/sdk langium-ai-tools zod
  • @modelcontextprotocol/sdk
阅读完整来源 ↗