Markdown Helpers¶
Feature spec for code-forge implementation planning. Source: extracted from CHANGELOG 0.15.0 (Markdown tool descriptions; F-035-style cross-SDK rollout). Created: 2026-05-10
Purpose¶
The Markdown helpers provide a shared formatting layer that both the MCP Server Factory and the OpenAI Converter use to render rich, structured tool descriptions through apcore-toolkit's render_module_markdown. They expose a small public API per language so callers can opt into Markdown rendering via the rich_description / richDescription option without depending on apcore-toolkit's internal layout, and so they can prime the renderer cache once at startup (TypeScript) to keep buildTool synchronous.
The helpers are intentionally thin: every public symbol either calls into apcore-toolkit when it is available or falls back silently (returning None/null or the raw descriptor.description) when it is not. There is no error path — toolkit unavailability is treated as a deployment choice, not a failure.
Scope¶
Included:
- is_available / isMarkdownAvailable — detect at runtime whether apcore-toolkit's Markdown renderer is importable.
- render_module_markdown(descriptor) (Python) / render_module_markdown(descriptor, display: bool) (Rust — the extra display flag selects the toolkit's display style) / renderModuleMarkdownSync(descriptor) (TS) — return rendered Markdown for a module, or None/null when the toolkit is unavailable or the render produced a non-text variant.
- descriptor_to_scanned_module(descriptor) (Python+Rust) — internal-but-public adapter from ModuleDescriptor to ScannedModule (the toolkit input type).
- prime_markdown_toolkit() / primeMarkdownToolkit() — pre-load the dynamically-imported renderer module so subsequent calls are synchronous. TypeScript and Rust only. Python has no such symbol (its toolkit import is synchronous and there is nothing to prime); do not write Python code that calls it.
Reachability (0.17.x) — measured, not inferred.
- TypeScript: none of these helpers are importable from the package.
isMarkdownAvailable,primeMarkdownToolkitandrenderModuleMarkdownSyncare exported fromsrc/markdown.tsbut are not re-exported bysrc/index.ts, andpackage.jsondeclaresexportsas"."only — so there is no subpath to reach them either.import { primeMarkdownToolkit } from "apcore-mcp"does not resolve. The "Required call site (TypeScript)" in theprime_markdown_toolkitcontract below is therefore not satisfiable by a package consumer today; it applies to in-repo callers.- Python:
prime_markdown_toolkitdoes not exist, andmarkdown.__all__lists onlyis_available,render_module_markdown,descriptor_to_scanned_module.- Rust:
is_available()returnstrueunconditionally.lib.rsdeclarespub mod markdown;with no[features]gate, so apcore-toolkit is a compile-time dependency — if the crate links, the renderer is present. The "toolkit unavailable →None" row below cannot arise in Rust.- Separately, the
rich_descriptionflag that makes any of this reach an MCP client is not exposed onserve()/async_serve()/ the CLI in any SDK — only onMCPServerFactorydirectly. See PRD F-047 / F-049.
Excluded:
- Implementation of the Markdown renderer itself (lives in apcore-toolkit; this feature only adapts to it).
- Schema-level rendering (handled by SchemaConverter and OpenAIConverter separately).
- Caching of rendered Markdown beyond the toolkit's own internal cache.
Core Responsibilities¶
- Toolkit Detection —
is_availablechecks whether apcore-toolkit's Markdown renderer can be imported in this process. Result MUST be cached after the first successful resolution; subsequent calls do not re-import. (Python memoizes withlru_cache; TypeScript caches the resolved dynamic import; Rust links the toolkit statically and returns a constanttrue.) - Renderer Adapter —
render_module_markdownbuilds theScannedModuleview (descriptor_to_scanned_module) and forwards to apcore-toolkit'srender_module(...)when available. - Prime-on-Startup (TS) —
primeMarkdownToolkit()resolves the dynamicimport("apcore-toolkit/markdown")Promise so that synchronousrenderModuleMarkdownSync(descriptor)callers see a populated cache.
Interfaces¶
Inputs¶
- ModuleDescriptor — the apcore SDK descriptor type the helper renders.
Outputs¶
- str | None (Python), string | null (TS), Option
(Rust) — rendered Markdown text, or absence when toolkit unavailable.
Dependencies¶
- apcore-toolkit (Python:
apcore-toolkit; TypeScript:apcore-toolkit; Rust:apcore-toolkitcrate) — provides the Markdown renderer.
Notes¶
- The helper layer is the only place in apcore-mcp that touches
apcore-toolkit. This keeps the optional dependency edge auditable and avoids leaking toolkit types into other modules. - All public helpers MUST be safe to call when toolkit is not installed — never raise, never log at ERROR.
Contract: is_available¶
Detect whether apcore-toolkit's Markdown renderer is importable in this process. Result is memoized for the lifetime of the process. Names per language: Python
is_available(), TypeScriptisMarkdownAvailable(), Rustis_available().
Inputs¶
- (no parameters)
Errors¶
- No errors raised — import failures are caught and treated as "not available".
Returns¶
- On first call:
bool—trueif the toolkit's Markdown module imports successfully,falseotherwise. Result is cached. - On subsequent calls: cached
bool.
Properties¶
- async: false
- thread_safe: true (idempotent memoization; concurrent first-call races resolve to the same value)
- pure: false (depends on the runtime module-resolution outcome)
- idempotent: true
Contract: render_module_markdown¶
Render a structured Markdown description for an apcore module via apcore-toolkit. Returns
None/nullwhen toolkit is not installed. Names per language: Pythonrender_module_markdown(descriptor), TypeScriptrenderModuleMarkdownSync(descriptor)(sync) andrenderModuleMarkdown(descriptor)(async — see Notes), Rustrender_module_markdown(descriptor).
Inputs¶
- descriptor: ModuleDescriptor, required — the module's full descriptor (id, description, metadata, annotations, input_schema, output_schema)
Errors¶
- No errors raised — when the toolkit raises during render, the helper logs at WARNING and returns
None/null(callers fall back todescriptor.description).
Returns¶
- On success (toolkit available):
str | None(Python) /string | null(TS) /Option<String>(Rust) — rendered Markdown text - On toolkit unavailable:
None/null/None— caller falls back to raw description - On render failure:
None/null/None(logged WARNING; never raises)
Properties¶
- async: false (sync variants — Python, Rust, and TS
renderModuleMarkdownSync) - thread_safe: true
- pure: false (depends on toolkit availability)
- idempotent: true
Notes¶
- TypeScript only: an async variant
renderModuleMarkdown(descriptor)exists that awaits the dynamic toolkit import before rendering. Prefer the syncrenderModuleMarkdownSyncafter aprimeMarkdownToolkit()call at startup. (As of 0.15.0 the async variant has zero internal callers and may be removed in a future release — see audit D9-002.)
Contract: descriptor_to_scanned_module¶
Internal-but-public adapter that builds the
ScannedModulevalue the toolkit consumes from an apcoreModuleDescriptor. Names per language: Pythondescriptor_to_scanned_module(descriptor), Rustdescriptor_to_scanned_module(descriptor). Not exposed in TypeScript (the TS path constructs the toolkit input inline).
Inputs¶
- descriptor: ModuleDescriptor, required (duck-typed) — must expose
id,description,metadata,annotations,input_schema,output_schema
Errors¶
- No errors raised — missing optional fields default to empty values:
- missing
description→"" - missing
metadata→{}/Map::new() - missing
annotations→ empty annotation set - missing
input_schema→ empty object
Returns¶
- On success:
ScannedModulevalue with fields populated from the descriptor
Properties¶
- async: false
- thread_safe: true
- pure: true
- idempotent: true
Visibility note¶
Although pub / exported, this helper is intended for internal apcore-mcp use. Demoting it to pub(crate) (Rust) / removing from __all__ (Python) is tracked as D9-013 and will not break the public surface. External consumers should call render_module_markdown(descriptor) directly.
Contract: prime_markdown_toolkit¶
Pre-load the apcore-toolkit Markdown module so that subsequent synchronous render calls do not pay the dynamic-import cost. Required call site (TypeScript): application startup, before any synchronous
buildTool/convertDescriptorinvocation that usesrichDescription: true. Python and Rust: the helper is exposed for API parity but is a no-op (toolkit imports are synchronous in those languages and resolve eagerly on firstis_available()/render_module_markdown()call).
Inputs¶
- (no parameters)
Errors¶
- No errors raised — toolkit-load failures are caught and logged at WARNING. Subsequent
render_module_markdowncalls returnNone/null(fallback path).
Returns¶
- TypeScript:
Promise<void>— resolves once the dynamic import has settled (success or fallback) - Python / Rust:
None/()— synchronous no-op for parity
Properties¶
- async: true (TS); false (Python, Rust)
- thread_safe: true (idempotent prime; concurrent calls share the same in-flight Promise in TS)
- pure: false (mutates a module-level cache in TS)
- idempotent: true