nori/codegen/gleam_mcp

Generates a Gleam module that exposes operations as MCP tools (#52).

An operation opts in with an x-mcp extension:

x-mcp:
  tool: send_message       # tool name; defaults to the snake_case operationId
  scopes: [messages:write] # scopes the caller needs
  confirm: true            # side effect: the server runs it in two steps

The module holds the tool list (with inputSchema and outputSchema built from the same IR as the types), a ToolCall type with one variant per tool, and decode_call, which turns a tools/call request’s arguments into that variant using the same decoders, query records and constraint checks as the HTTP side. What a call does, and how confirm is honoured, stays in the application: the module only describes and decodes.

Arguments are one object: path and query parameters under their spec names, and the request body under body. Header and cookie parameters have no MCP equivalent and are left out.

Values

pub fn generate(
  codegen_ir: ir.CodegenIR,
  types_module: String,
  routes_module: String,
) -> String

The module source. types_module and routes_module are the module paths the generated types and routes live under ("generated" for generated/types).

pub fn has_tools(codegen_ir: ir.CodegenIR) -> Bool

Whether any operation in ir opts in with x-mcp.

✨ Search Document