Skip to content

Commit e065464

Browse files
Update docs
V2.21
1 parent a5a18c8 commit e065464

17 files changed

Lines changed: 439 additions & 272 deletions

File tree

README.md

Lines changed: 89 additions & 226 deletions
Large diffs are not rendered by default.

examples/mcp_stdio/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# mcp_stdio demo
2+
3+
This example builds a standalone MCP stdio server process that an MCP host can launch directly.
4+
5+
## What it demonstrates
6+
7+
- `initialize`, `tools/list`, and `tools/call` over MCP stdio
8+
- `Content-Length` framed JSON-RPC request and response handling
9+
- one process that exposes both stateless and stateful tools
10+
- concurrent `tools/call` handling through the MCP stdio server
11+
12+
## Key files
13+
14+
- `mcp_stdio_server_demo.cpp`: demo executable that registers tools and serves MCP over stdio
15+
- `test_mcp.ps1`: smoke test that drives initialize, tools/list, one stateless call, and one stateful create/call/destroy flow
16+
17+
## Typical use
18+
19+
```powershell
20+
cmake -S . -B build
21+
cmake --build build --target mcp_stdio_server_demo
22+
.\build\mcp_stdio_server_demo.exe
23+
```
24+
25+
To run the smoke test:
26+
27+
```powershell
28+
.\examples\mcp_stdio\test_mcp.ps1
29+
```
30+
31+
## Related guides
32+
33+
- MCP component overview: `../../include/mcp/README.md`
34+
- top-level project overview: `../../README.md`

include/func_registry/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# func_registry
2+
3+
`func_registry` is the lowest-level public module in `llm_invoke_cpp`.
4+
5+
Use it when you want native function registration and local dispatch without JSON, schema export, scheduling, or protocol adapters.
6+
7+
## What this component does
8+
9+
- registers native free functions, lambdas, and other callables under stable names
10+
- dispatches calls by name at runtime
11+
- exposes lightweight function metadata and concise human-readable summaries
12+
- stays dependency-free apart from the C++ standard library
13+
14+
## Public headers
15+
16+
- `func_registry.hpp`: main registry API and registration entry point
17+
- `any_callable.hpp`: callable type erasure used by the registry
18+
- `call_result.hpp`: normalized result wrapper for registry calls
19+
- `function_traits.hpp`: callable signature extraction helpers
20+
- `function_summary.hpp`: concise summary rendering for registered functions
21+
22+
## When to stop at this layer
23+
24+
Stay at `func_registry` if your caller already knows C++ types and you only need in-process function lookup and dispatch.
25+
26+
Move up the stack when you need:
27+
28+
- tool-facing metadata: see `include/tool_meta`
29+
- enum/schema/type metadata: see `include/type_meta`
30+
- JSON invocation: see `include/json_invoke`
31+
32+
## Related guides
33+
34+
- top-level overview: `../../README.md`
35+
- tool metadata: `../tool_meta/README.md`
36+
- type metadata: `../type_meta/README.md`

include/json_invoke/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# json_invoke
2+
3+
`json_invoke` is the stateless JSON-callable tool layer.
4+
5+
Use it when your caller already speaks JSON and your tools do not need session-scoped object handles.
6+
7+
## What this component does
8+
9+
- registers stateless native functions as JSON-callable tools
10+
- converts between JSON payloads and native C++ argument and return types
11+
- exports tool summaries, tool specs, and JSON schemas
12+
- exposes tracing hooks for invocation-level observability
13+
14+
## Public headers
15+
16+
- `json_invoke.hpp`: main stateless JSON invocation adapter
17+
- `json_introspection.hpp`: standalone JSON tool and schema export helpers
18+
- `json_error.hpp`: `JsonInvokeError` definition
19+
- `json_tool_execution_semantics.hpp`: execution semantics metadata helpers
20+
- `json_trace.hpp`: tracing event model and JSON serialization helpers
21+
- `json_traits.hpp`: custom JSON binding hook for user types
22+
23+
## Choose this layer when
24+
25+
- your request envelope is already JSON-based
26+
- tools are stateless
27+
- you want schema export but do not need session object lifecycles or scheduling
28+
29+
Move up to `json_session_invoke` when you need `create -> method -> destroy` flows.
30+
31+
## Related guides
32+
33+
- type metadata: `../type_meta/README.md`
34+
- session tools: `../json_session_invoke/README.md`
35+
- tracing helper utilities: `../tools/README.md`
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# json_session_invoke
2+
3+
`json_session_invoke` is the high-level session and stateful-tool layer.
4+
5+
Use it when one JSON-facing adapter should host both stateless tools and stateful object lifecycles such as `create -> method -> destroy`.
6+
7+
## What this component does
8+
9+
- composes `json_invoke` into one session-oriented adapter
10+
- models opaque session object handles and object options
11+
- registers factories, stateful methods, and destroy tools
12+
- overlays tool schemas so LLM-facing contracts stay handle-oriented
13+
- exposes readonly metadata that upper scheduling layers use for classification
14+
15+
## Public headers
16+
17+
- `json_session_invoke.hpp`: main session-oriented adapter and fluent stateful builder
18+
- `session_objects.hpp`: public handle and object option types
19+
20+
`detail/` contains implementation internals and is not part of the public surface.
21+
22+
## Choose this layer when
23+
24+
- tools need per-session state
25+
- one adapter should mix stateless and stateful tools
26+
- you want scheduler-facing metadata without building scheduling policy here
27+
28+
Move up to `task_scheduler` when multiple requests must be classified and coordinated safely.
29+
30+
## Related guides
31+
32+
- stateless JSON tools: `../json_invoke/README.md`
33+
- scheduling layer: `../task_scheduler/README.md`

include/json_session_invoke/json_session_invoke.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class BasicJsonSessionInvokeAdapter {
6161
class StatefulRegistrationBuilder {
6262
public:
6363
StatefulRegistrationBuilder(
64-
BasicJsonSessionInvokeAdapter& adapter,
64+
BasicJsonSessionInvokeAdapter& json_session_invoke_adapter,
6565
std::string configured_object_type_name,
6666
ObjectOptions options)
67-
: adapter_(adapter)
67+
: json_session_invoke_adapter_(json_session_invoke_adapter)
6868
, configured_object_type_name_(std::move(configured_object_type_name))
6969
, options_(std::move(options))
7070
{
@@ -74,7 +74,7 @@ class BasicJsonSessionInvokeAdapter {
7474
StatefulRegistrationBuilder& operator=(const StatefulRegistrationBuilder&) = delete;
7575

7676
StatefulRegistrationBuilder(StatefulRegistrationBuilder&& other) noexcept
77-
: adapter_(other.adapter_)
77+
: json_session_invoke_adapter_(other.json_session_invoke_adapter_)
7878
, configured_object_type_name_(std::move(other.configured_object_type_name_))
7979
, options_(std::move(other.options_))
8080
, created_(other.created_)
@@ -304,7 +304,8 @@ class BasicJsonSessionInvokeAdapter {
304304
{
305305
return registerDestroyWithMetadata(
306306
destroy_tool_name,
307-
BasicJsonSessionInvokeAdapter::makeDestroyMetadata(adapter_.defaultDestroyDescription()),
307+
BasicJsonSessionInvokeAdapter::makeDestroyMetadata(
308+
json_session_invoke_adapter_.defaultDestroyDescription()),
308309
scheduling_scope);
309310
}
310311

@@ -369,7 +370,7 @@ class BasicJsonSessionInvokeAdapter {
369370
func_registry::FunctionMetadata metadata,
370371
ToolSchedulingScope scheduling_scope)
371372
{
372-
adapter_.template registerFactory<T>(
373+
json_session_invoke_adapter_.template registerFactory<T>(
373374
factory_tool_name,
374375
std::forward<Fn>(fn),
375376
std::move(metadata),
@@ -388,7 +389,7 @@ class BasicJsonSessionInvokeAdapter {
388389
ToolSchedulingScope scheduling_scope)
389390
{
390391
validateMethodType<Fn>();
391-
adapter_.template registerStatefulMethod<T>(
392+
json_session_invoke_adapter_.template registerStatefulMethod<T>(
392393
method_tool_name,
393394
std::forward<Fn>(fn),
394395
std::move(metadata),
@@ -401,21 +402,25 @@ class BasicJsonSessionInvokeAdapter {
401402
func_registry::FunctionMetadata metadata,
402403
ToolSchedulingScope scheduling_scope)
403404
{
404-
adapter_.template registerDestroy<T>(destroy_tool_name, std::move(metadata), scheduling_scope);
405+
json_session_invoke_adapter_.template registerDestroy<T>(
406+
destroy_tool_name,
407+
std::move(metadata),
408+
scheduling_scope);
405409
destroy_registered_ = true;
406410
return *this;
407411
}
408412

409413
void ensureDefaultDestroyRegistered() noexcept
410414
{
411-
if (!active_ || !created_ || destroy_registered_ || !adapter_.stateful_defaults_.auto_register_destroy)
415+
if (!active_ || !created_ || destroy_registered_
416+
|| !json_session_invoke_adapter_.stateful_defaults_.auto_register_destroy)
412417
{
413418
return;
414419
}
415420

416421
destroy_registered_ = true;
417422
const std::string destroy_tool_name = defaultDestroyToolName();
418-
if (adapter_.isFunctionRegistered(destroy_tool_name))
423+
if (json_session_invoke_adapter_.isFunctionRegistered(destroy_tool_name))
419424
{
420425
return;
421426
}
@@ -424,7 +429,8 @@ class BasicJsonSessionInvokeAdapter {
424429
{
425430
registerDestroyWithMetadata(
426431
destroy_tool_name,
427-
BasicJsonSessionInvokeAdapter::makeDestroyMetadata(adapter_.defaultDestroyDescription()),
432+
BasicJsonSessionInvokeAdapter::makeDestroyMetadata(
433+
json_session_invoke_adapter_.defaultDestroyDescription()),
428434
ToolSchedulingScope::object_lane);
429435
}
430436
catch (...)
@@ -458,7 +464,7 @@ class BasicJsonSessionInvokeAdapter {
458464
return BasicJsonSessionInvokeAdapter::defaultDestroyToolName(configured_object_type_name_);
459465
}
460466

461-
BasicJsonSessionInvokeAdapter& adapter_;
467+
BasicJsonSessionInvokeAdapter& json_session_invoke_adapter_;
462468
std::string configured_object_type_name_;
463469
ObjectOptions options_;
464470
bool created_{false};

include/mcp/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# mcp
2+
3+
`mcp` contains the protocol-facing adapters that expose the native tool runtime to real MCP clients.
4+
5+
Use it when you want to serve tools over MCP stdio or host MCP semantics behind an HTTP endpoint.
6+
7+
## What this component does
8+
9+
- implements MCP stdio request/response handling with `Content-Length` framing
10+
- maps normalized runtime results into MCP response shapes
11+
- provides a framework-agnostic HTTP gateway core for one MCP endpoint
12+
13+
## Public headers
14+
15+
- `mcp_stdio_server.hpp`: stdio JSON-RPC MCP server built on top of `tool_runtime`
16+
- `mcp_http_gateway.hpp`: framework-agnostic HTTP MCP core
17+
18+
## Choose this layer when
19+
20+
- a real MCP-capable host or client should talk to your native tools
21+
- transport concerns should stay above the runtime and scheduling layers
22+
23+
## Related guides
24+
25+
- protocol-neutral runtime: `../tool_runtime/README.md`
26+
- stdio demo: `../../examples/mcp_stdio/README.md`
27+
- HTTP demo: `../../examples/mcp_http/README.md`
28+
- LLM-host demo: `../../examples/mcp_llm/README.md`

include/mcp/mcp_stdio_server.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <utility>
2222
#include <vector>
2323

24-
#include <runtime/runtime_facade.hpp>
24+
#include <tool_runtime/tool_runtime_facade.hpp>
2525

2626
namespace mcp {
2727

@@ -258,11 +258,6 @@ class BasicMcpStdioServer {
258258
return makeSuccessResponse(id, handleToolsList(params));
259259
}
260260

261-
if (method == "tools/call")
262-
{
263-
return handleToolsCall(id, params);
264-
}
265-
266261
return makeErrorResponse(id, -32601, "Method not found: " + method);
267262
}
268263
catch (const json_invoke::JsonInvokeError& e)

include/task_scheduler/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# task_scheduler
2+
3+
`task_scheduler` separates request classification and execution policy from the session adapter.
4+
5+
Use it when JSON tool requests may overlap and you need predictable concurrency rules.
6+
7+
## What this component does
8+
9+
- classifies requests into scheduling categories such as free-read, object-exclusive, tool-exclusive, factory-lane, and session-barrier
10+
- queues and runs classified tasks with keyed exclusivity rules
11+
- exposes a one-step facade for submit-and-wait style callers
12+
13+
## Public headers
14+
15+
- `request_classifier.hpp`: derives scheduling plans from tool metadata and request shape
16+
- `task_scheduler.hpp`: scheduler-side abstractions and keyed scheduler implementation
17+
- `task_scheduler_facade.hpp`: one-object facade that hides classify + queue + invoke
18+
19+
## Choose this layer when
20+
21+
- requests are JSON-based and may run concurrently
22+
- concurrency policy should be explicit and reusable
23+
- protocol adapters should not directly own queueing logic
24+
25+
Move up to `tool_runtime` when a protocol adapter wants normalized tool descriptors and invoke results.
26+
27+
## Related guides
28+
29+
- session adapter: `../json_session_invoke/README.md`
30+
- protocol-neutral runtime layer: `../tool_runtime/README.md`

include/task_scheduler/request_classifier.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ struct TaskExecutionPlan {
3131
template<bool EnableThreadSafety = false>
3232
class BasicRequestClassifier {
3333
public:
34-
using AdapterType = json_session_invoke::BasicJsonSessionInvokeAdapter<EnableThreadSafety>;
35-
using ToolSchedulingScope = typename AdapterType::ToolSchedulingScope;
36-
using ToolMetadataView = typename AdapterType::ToolMetadataView;
37-
using ToolStatefulKind = typename AdapterType::ToolStatefulKind;
38-
39-
explicit BasicRequestClassifier(const AdapterType& adapter)
40-
: adapter_(adapter)
34+
using JsonSessionInvokeAdapterType =
35+
json_session_invoke::BasicJsonSessionInvokeAdapter<EnableThreadSafety>;
36+
using ToolSchedulingScope = typename JsonSessionInvokeAdapterType::ToolSchedulingScope;
37+
using ToolMetadataView = typename JsonSessionInvokeAdapterType::ToolMetadataView;
38+
using ToolStatefulKind = typename JsonSessionInvokeAdapterType::ToolStatefulKind;
39+
40+
explicit BasicRequestClassifier(const JsonSessionInvokeAdapterType& json_session_invoke_adapter)
41+
: json_session_invoke_adapter_(json_session_invoke_adapter)
4142
{
4243
}
4344

@@ -63,7 +64,7 @@ class BasicRequestClassifier {
6364
private:
6465
TaskExecutionPlan classifyParsedRequest(const std::string& tool_name, const json& args) const
6566
{
66-
const auto metadata = adapter_.findToolMetadata(tool_name);
67+
const auto metadata = json_session_invoke_adapter_.findToolMetadata(tool_name);
6768
if (!metadata.has_value())
6869
{
6970
throw JsonInvokeError("function_not_found", "function not found: " + tool_name);
@@ -234,7 +235,7 @@ class BasicRequestClassifier {
234235
return SchedulingKey{object_id};
235236
}
236237

237-
const AdapterType& adapter_;
238+
const JsonSessionInvokeAdapterType& json_session_invoke_adapter_;
238239
};
239240

240241
using RequestClassifierThreadSafe = BasicRequestClassifier<true>;

0 commit comments

Comments
 (0)