MCPconceptExamples

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

Edit this page on GitHub

C++ MCP examples

mcp_tools consumer 0.1.0 · Source

Connect the server using the setup guide, then call list_sessions from your MCP client.

List sessions

This is the params object for an MCP tools/call request. Send it through the connected client:

{
"name": "list_sessions",
"arguments": {}
}

Use the returned session IDs when choosing a window or pane. The tool reference describes this port’s result and optional arguments.

Internals

The following examples are for applications that embed or extend the server. Installing and connecting an MCP client does not require this code.

The MCP consumer separates its tool model from JSON-RPC encoding. Source applications can inspect that model without starting a tmux server.

Inspect the consumer catalog

This program uses the declarations in the consumer header:

#include <iostream>
#include "libtmux_consumers/mcp.hpp"
int main() {
const auto catalog = libtmux::mcp::default_tools();
if (!catalog) {
std::cerr << catalog.error() << '\n';
return 1;
}
for (const auto& tool : catalog->tools()) {
std::cout << tool.name << '\n';
}
}

Build this within an application that includes the repository’s mcp_tools CMake target. The header and target belong to the source consumer; the installed core package does not export them.

The consumer tests exercise the same catalog and direct calls. This small listing program is a source-derived example, not one of those collected tests.

Drive the executable

After connecting an MCP client using the guide, start with list_sessions, then list_windows and list_panes. Preserve returned object identities for subsequent calls.

On POSIX, use capture_pane to inspect a discovered pane, then wait_for_text for a bounded wait. Read its match/timeout result and final capture before choosing another operation.

The protocol tests cover client lifecycle, validation, concurrency, and cancellation. Native Windows advertises the same catalog; unsupported psmux operations fail explicitly when called.

Esc

Type to search.

Reference previewOpen reference