axum-apcore
Expose Axum routes as AI-perceivable modules.
Axum integration for the apcore AI-Perceivable Core ecosystem.
axum-apcore automatically scans your Axum routes and exposes them as apcore modules — with full execution, context mapping, MCP serving, and OpenAI tool export. Define your routes once, and both code and AI can discover, understand, and invoke them through enforced schemas and behavioral annotations.
Features
- Route scanning — Discover Axum routes via the native metadata registry or OpenAPI (utoipa) specs
ap_handler!macro — Register route metadata at compile time with zero boilerplateApContextextractor — Extract apcoreContext(identity, trace context) from Axum requests viaFromRequestParts- Module execution — Call any registered module programmatically with
call(),stream(), orcancellable_call() - Async task management — Submit background tasks with status tracking, cancellation, and cleanup
- MCP server — Serve registered modules as MCP tools (stdio, streamable-http, SSE transports)
- OpenAI export — Export modules as OpenAI-compatible tool definitions
- YAML bindings — Auto-discover modules from YAML binding files
- CLI — Scan, serve, export, and manage tasks from the command line
- Configuration —
APCORE_*environment variables for all settings - Observability — Tracing middleware, metrics collection, and structured logging via
tracing
API Overview
Core
| Type | Description |
|---|---|
AxumApcore |
Unified entry point — init, scan, register, call, stream, export |
ApcoreSettings |
Configuration from APCORE_* env vars with validation |
ApContext |
Axum extractor for apcore Context<Value> |
RequestIdentity |
Identity struct for auth middleware to inject into request extensions |
AxumContextFactory |
Creates apcore contexts from Axum request parts |
Scanning
| Type | Description |
|---|---|
NativeAxumScanner |
Scans routes from the compile-time metadata registry |
OpenAPIScanner |
Scans routes from a utoipa-generated OpenAPI spec (requires openapi feature) |
ap_handler! |
Macro for declarative route metadata registration |
Engine
| Type | Description |
|---|---|
AxumRegistryWriter |
Registers scanned modules into apcore's Registry |
AxumDiscoverer |
Discovers modules from YAML binding files |
AxumModuleValidator |
Validates module IDs against apcore constraints |
TaskManager |
Async task submission, tracking, and cancellation |
Requirements
- Rust >= 1.75
- Tokio async runtime
- Axum 0.8+
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "0.8", = ["json"] }
= { = "1", = ["full"] }
= "1"
= "0.3"
Feature flags
| Feature | Description | Dependencies |
|---|---|---|
cli |
CLI commands (scan, serve, export, tasks) | clap |
mcp |
MCP server and OpenAI tools export | apcore-mcp |
openapi |
OpenAPI spec scanning via utoipa | utoipa |
all |
Enable all optional features | — |
= { = "0.1", = ["all"] }
Quick Start
Register routes and call modules
use ;
use ;
use ;
use Arc;
// Define a handler
async
async
Register executable handlers
use ;
use ;
use Arc;
async
async
OpenAPI scanning
use OpenAPIScanner;
use json;
let scanner = new;
let spec = json!;
let modules = scanner.scan_spec.unwrap;
println!; // "users.get_user.get"
Cancellable execution with timeout
use Duration;
let result = apcore
.cancellable_call
.await;
Background tasks
// Submit a task
let task_id = apcore.submit_task.unwrap;
// Check status
let info = apcore.get_task_status;
// Get result when complete
let result = apcore.get_task_result;
// Cancel a running task
apcore.cancel_task;
Configuration
All settings are read from environment variables with the APCORE_ prefix:
| Variable | Default | Description |
|---|---|---|
APCORE_MODULE_DIR |
apcore_modules |
Directory for YAML binding files |
APCORE_AUTO_DISCOVER |
true |
Auto-discover modules on startup |
APCORE_BINDING_PATTERN |
*.binding.yaml |
Glob pattern for binding files |
APCORE_SCANNER_SOURCE |
native |
Scanner: native or openapi |
APCORE_SERVE_TRANSPORT |
streamable-http |
MCP transport: stdio, streamable-http, sse |
APCORE_SERVE_HOST |
127.0.0.1 |
MCP server host |
APCORE_SERVE_PORT |
9090 |
MCP server port |
APCORE_SERVER_NAME |
axum-apcore |
MCP server name |
APCORE_JWT_SECRET |
— | JWT secret for MCP auth |
APCORE_TRACING |
false |
Enable tracing middleware |
APCORE_METRICS |
false |
Enable metrics collection |
APCORE_TASK_MAX_CONCURRENT |
10 |
Max concurrent background tasks |
APCORE_TASK_MAX_TASKS |
100 |
Max total tasks in queue |
Examples
The examples/ directory contains runnable demos. Run any example with:
| Example | Description |
|---|---|
basic |
Full Axum app with ap_handler!, ApContext extractor, and server startup |
handler_registration |
Register executable handlers, call modules with call() and call_anonymous() |
async_tasks |
Submit background tasks, poll status, cancel, and list tasks |
openapi_scanner |
Scan a utoipa-generated OpenAPI spec with include/exclude filters |
mcp_server |
Create an MCP server and export OpenAI-compatible tool definitions |
Tests
Run all tests (unit + integration):
Run only unit tests:
Run only integration tests:
Run a specific test by name:
Run with output visible:
Development
Prerequisites
Install Rust via rustup:
|
Clone and build
Quality gates
All of these must pass before committing:
Lint and format
Build documentation
Architecture
axum-apcore follows the same module structure as fastapi-apcore:
| Rust Module | FastAPI Module | Purpose |
|---|---|---|
client |
client.py |
AxumApcore unified entry point |
config |
engine/config.py |
ApcoreSettings from APCORE_* env vars |
context |
engine/context.py |
ApContext extractor + AxumContextFactory |
scanner/native |
scanners/native.py |
Route metadata registry scanning |
scanner/openapi |
scanners/openapi.py |
utoipa OpenAPI spec scanning |
engine/registry |
engine/registry.py |
Singleton Registry/Executor management |
engine/extensions |
engine/extensions.py |
Discoverer + ModuleValidator |
engine/observability |
engine/observability.py |
Tracing/metrics/logging setup |
engine/tasks |
engine/tasks.py |
Async task management |
output/registry_writer |
output/registry_writer.py |
ScannedModule → Registry registration |
cli |
cli.py |
clap CLI (scan/serve/export/tasks) |
License
Apache-2.0
Links
- Core SDK: aiperceivable/apcore-rust
- Toolkit: aiperceivable/apcore-toolkit-rust
- Reference: aiperceivable/fastapi-apcore
- Website: aiperceivable.com
- Issues: GitHub Issues