Add documentation infrastructure for RTL symbols

Introduces `RtlDocEntry` and `RtlRegistration` structs to store and
manage documentation for native functions and constants. The
`Environment` struct is updated to include a registry for these
documentation entries.

The `register_native_fn` and `register_constant` methods now return an
`RtlRegistration` builder, allowing for optional chaining of `.doc()`,
`.description()`, and `.examples()` methods before the registration is
finalized when the builder is dropped.

Macros `rtl_fn!` and `rtl_const!` are introduced to simplify the
registration process with documentation.

The MCP server is extended with `get_rtl_docs` and `get_symbol_doc`
tools to expose this documentation externally.

Specific RTL functions and constants (e.g., `+`, `-`, `*`, `/`, `NaN`,
`true`, `false`, `date`, `now`, math functions, `series`, `push`, `len`,
`create-random-ohlc`, `create-ticker`, `pipe`) have been updated to
include their respective documentation using the new infrastructure.

The `Signature` and `StaticType` types have gained `to_doc_string`
methods for generating human-readable documentation strings.
This commit is contained in:
2026-03-25 15:02:19 +01:00
parent 446bdcd42d
commit b436e09840
9 changed files with 400 additions and 69 deletions
+33
View File
@@ -17,6 +17,13 @@ pub struct CodeInput {
pub code: String,
}
/// Input struct for tools that look up a single RTL symbol by name.
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
pub struct SymbolInput {
/// The RTL symbol name to look up (e.g. "+", "push", "series").
pub name: String,
}
/// MCP server exposing the Myc compiler as a set of tools for LLMs.
#[derive(Clone)]
pub struct MycMcpServer {
@@ -115,6 +122,32 @@ impl MycMcpServer {
fn get_language_spec(&self) -> String {
LANGUAGE_SPEC.to_string()
}
/// Returns documentation for all documented RTL symbols.
#[tool(description = "Return documentation for ALL built-in RTL functions and constants at once. \
Prefer get_symbol_doc for individual lookups to save tokens. \
Use this only when you need a full overview of the entire standard library.")]
fn get_rtl_docs(&self) -> String {
let env = Self::make_env();
let docs = env.list_rtl_docs();
if docs.is_empty() {
"No documented RTL symbols found.".to_string()
} else {
docs.join("\n\n")
}
}
/// Returns documentation for a single RTL symbol by name.
#[tool(description = "Return the type signature, description, and examples for a single \
built-in RTL symbol. Use list_builtins to see all available names, then call this \
for each symbol you need details on. More token-efficient than get_rtl_docs.")]
fn get_symbol_doc(&self, Parameters(SymbolInput { name }): Parameters<SymbolInput>) -> String {
let env = Self::make_env();
match env.get_rtl_doc(&name) {
Some(doc) => doc,
None => format!("No documentation found for symbol '{}'.", name),
}
}
}
#[tool_handler]