Skip to main content

MCP Server

@keq-request/cli includes a built-in Model Context Protocol (MCP) server that exposes your project's API directory as tools callable by AI assistants (Claude, Cursor, etc.).

Starting​

keq mcp [options]
OptionDescription
-c --config <config_file_path>Path to the configuration file
--tolerantTolerant mode: ignores invalid Swagger/OpenAPI document structure
--debugPrint debug information

The MCP Server communicates via the stdio transport protocol, making it suitable for launching as a subprocess of an AI editor.

Configuring AI Editors​

tip

It's recommended to configure the MCP Server in the project directory rather than globally, so each project can independently manage its own API context.

Claude Code​

Add to .mcp.json in your project root:

{
  "mcpServers": {
    "keq": {
      "command": "npx",
      "args": ["@keq-request/cli", "mcp"]
    }
  }
}

Cursor​

Add to .cursor/mcp.json in your project:

{
  "mcpServers": {
    "keq": {
      "command": "npx",
      "args": ["keq", "mcp"]
    }
  }
}

VS Code​

Add to .vscode/mcp.json in your project:

{
  "servers": {
    "keq": {
      "command": "npx",
      "args": ["keq", "mcp"]
    }
  }
}

Available Tools​

The MCP Server registers the following tools for AI assistants to call:

search_apis​

Semantic search for API endpoints using natural language, supporting cross-language matching in Chinese and English.

ParameterTypeRequiredDescription
querystringYesNatural language search query
modulestring[]NoFilter by module name
limitnumberNoMaximum number of results (default: 10)

get_api_detail​

Get the complete definition of a specified API, including request parameters, request body, and response body JSON Schema.

ParameterTypeRequiredDescription
modulestringYesModule name
methodstringYesHTTP method (GET, POST, PUT, DELETE, etc.)
pathnamestringYesAPI path (e.g., /api/v1/users)

list_modules​

List all API modules configured in .keqrc.

No parameters required.

list_apis​

List structured information for all API endpoints (module, method, path, operationId, summary).

ParameterTypeRequiredDescription
modulestring[]NoFilter by module name
methodstringNoFilter by HTTP method
pathnamestringNoFilter by path (supports glob wildcards)
includesstring[]NoContent to include, options: operations, components (default: ['operations'])

build_apis​

Generate type-safe TypeScript client code for specified API endpoints. Files are written to the output directory configured in .keqrc.

ParameterTypeRequiredDescription
modulestring[]NoModules to generate code for
methodstringNoFilter by HTTP method
pathnamestringNoFilter by path (supports glob wildcards, e.g., /api/v1/users/**)
freshbooleanNoClear output directory before building (default: false)

list_generated_files​

List generated TypeScript client files. Optionally list only invalid/outdated files.

ParameterTypeRequiredDescription
invalidbooleanNoWhen true, only lists outdated files not in current build output (default: false)

get_filter_rules​

View the current .keqfilter file contents. Filter rules control which APIs generate code.

No parameters required.

add_filter_rule​

Add a filter rule to .keqfilter. deny rules exclude APIs from code generation, allow rules include them.

ParameterTypeRequiredDescription
modestringYesRule mode: deny or allow
modulestringNoModule name pattern (supports glob, default: *)
methodstringNoHTTP method pattern (default: *)
pathnamestringYesPath pattern (supports glob)
buildbooleanNoWhether to automatically rebuild after adding the rule (default: false)

remove_filter_rule​

Remove a specified filter rule from .keqfilter.

ParameterTypeRequiredDescription
modestringYesBlock the rule belongs to: deny or allow
modulestringYesExact match module name pattern
methodstringYesExact match method pattern
pathnamestringYesExact match path pattern
buildbooleanNoWhether to automatically rebuild after removing the rule (default: false)

Auto-Reload​

The MCP Server monitors changes to .keqrc and .keqfilter files. When these files are modified, the server automatically recompiles the API index without requiring a manual restart.

Process Lifecycle​

The MCP Server runs as a stdio subprocess, launched on demand by the AI editor. To prevent multiple editor windows from accumulating long-lived processes and exhausting system memory, the server automatically exits in any of the following cases:

  • The client disconnects (the editor closes or drops the MCP connection)
  • The parent process exits (the editor process disappears)
  • A termination signal is received (SIGINT / SIGTERM / SIGHUP)
  • It stays idle for over 30 minutes without any tool call

No manual intervention is needed after it exits — the AI editor will automatically restart the server on next use.

tip

The semantic search model (used by search_apis) is lazily loaded, only loaded on the first search_apis call. Using only list_apis, list_modules, get_api_detail, and other tools will not consume model memory. As a result, after a process restart, only the first semantic search incurs a one-time model loading delay.