AI
Selm is built for agents on both sides of the wire: your apps can call MCP and ACP tools, a Platform.worker can be an MCP server, and the toolchain itself speaks those protocols so coding agents can check, fix, and run Selm without scraping text.
Use Port when you need raw CLI stdio. Use Mcp or Acp when the child speaks that protocol. Inside Server.application, connect from init and drive call / reply from update. HTTP handle reaches the core with Process.call or Process.send; do not open Mcp or Acp sessions from handle.
Language tools for agents
selm-mcp (MCP) and selm-acp (ACP) share one compiler tool surface from selm_agent: diagnostics with suggested edits, format, AST inspect, sandboxed run_code, and generate_tests. selm-lsp stays the editor path (hover, rename, the same quickfixes).
selm check --json prints the same diagnostic payload agents get from get_diagnostics, including suggestedEdits.
On connect, servers return writing rules from crates/selm_agent/MACHINE.md. Hosts that ignore instructions can call get_coding_guide.
cargo build -p selm_mcp -p selm_acp
# binaries: target/debug/selm-mcp target/debug/selm-acp
selm check --jsonPoint Cursor MCP at selm-mcp (see editors/mcp/README.md). Point an ACP host or Acp.connect at selm-acp (see editors/acp/README.md). Pass root or set cwd to the Selm project.
MCP in your app
Mcp is a stdio MCP client (Content-Length JSON-RPC). Mcp.connect spawns the server. Mcp.call issues requests. Mcp.notify sends notifications. Mcp.subscribe delivers Ready, Notification, and Closed.
API reference: docs/stdlib/Mcp/. Worked example: examples/07_mcp_search, a Server.application that owns a local fake MCP search session and exposes HTTP search.
cd examples/07_mcp_search
cargo run -p selm -- make
erl -noshell -pa build/dev/erlang/ebin -s selm_server startNeeds python3 on PATH (no network). Then, with the server running, try:
selm health
selm search Server.applicationAn MCP server in Selm
Mcp.Server is the other side of Mcp. A Platform.worker calls serve from init and subscribes. The runtime answers initialize, notifications/initialized, ping, and tools/list. tools/call arrives as ToolCall; reply with text, result, or error. Stdout is the Content-Length stream, so do not Debug.log, and do not pass --sname to selm run.
Worked example: examples/23_mcp_server, an echo tool. Cursor runs it with selm run and the example directory as cwd. selm-mcp is a different server: the compiler tools, not this module.
ACP in your app
Acp is a stdio Agent Client Protocol client (newline-delimited JSON-RPC). Acp.connect runs initialize (and authenticate when the agent advertises auth). After Connected, create a session with call "session/new" and prompt with call "session/prompt". Answer inbound AgentRequest values with Acp.reply.
Connect to selm-acp for a Selm-native agent, or to Cursor / Claude Code. API reference: docs/stdlib/Acp/. Worked example: examples/08_acp_agent.
cd examples/08_acp_agent
cargo run -q -p selm --bin selm -- make
erl -noshell -pa build/dev/erlang/ebin -s selm_server start