-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathprotocol_core.das
More file actions
84 lines (75 loc) · 4.26 KB
/
Copy pathprotocol_core.das
File metadata and controls
84 lines (75 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// daslang MCP layer over the provider-neutral core (mcp_core).
//
// Adds the two das-compiler concerns the neutral core deliberately leaves out:
// the module-resolution arguments (project / project_root / load_modules) —
// their advertised schema plus the make_file_tool helper that injects them —
// and das_mcp_server(), which wires those arg names into the McpServer config
// so the core extracts them for every tool. It re-exports mcp_core publicly, so
// registry_das / registry_cpp / main / cpp_main require only this module and see
// the full surface (make_tool, ToolDef, serve_stdio, …) unchanged.
options gen2
options rtti
module protocol_core
require mcp_core public
require tools/common public
// ── Module-resolution argument schemas (das-compiler specific) ────────
let PROJECT_PROP = PropertySchema(_type = "string", description = "Path to a .das_project file for custom module resolution")
let PROJECT_ROOT_PROP = PropertySchema(_type = "string", description = "Project root directory (parent of modules/) for daspkg-style module resolution; equivalent to daslang's -project_root CLI flag. Use when working on an external module via a <DummyRoot>/modules/<your-module> junction.")
let LOAD_MODULES_PROP = PropertySchema(
_type = "array",
description = "List of individual module folders (each containing .das_module) to load directly, equivalent to daslang's -load_module CLI flag (repeatable). Each path is the module's own folder — no <project_root>/modules/<name> wrapper. Path basenames shadow same-named entries in dasroot and project_root. Use to work on an external module without the junction trick.",
items = new PropertySchema(_type = "string", description = "Path to a module folder (the one containing .das_module). Absolute paths are recommended; live_launch absolutizes them before spawning daslang-live so its -cwd flag doesn't shift the base, but other tools forward verbatim.")
)
def make_file_tool(name, description : string) : MakeFileTool {
return MakeFileTool(
name = name,
description = description,
inputSchema = InputSchema(
_type = "object",
properties = {
"file" => PropertySchema(
_type = "string",
description = "Path to the .das file"
),
"project" => PROJECT_PROP,
"project_root" => PROJECT_ROOT_PROP,
"load_modules" => LOAD_MODULES_PROP
},
required = ["file"]
)
)
}
// The daslang server config: serverInfo plus the module-resolution args the
// core extracts for every tool into the handler's extra1 / extra2 / extra_list
// slots (project, project_root, load_modules).
def das_mcp_server(name, version : string) : McpServer {
return McpServer(
info = ServerInfo(name = name, version = version),
str_extra_args <- ["project", "project_root"],
arr_extra_arg = "load_modules"
)
}
// Annotate every tool result with the cross-tree guard: a CROSS-TREE WARNING
// when `file` points outside the server's own tree, whose answer used the
// wrong tree's module sources + compiled-in bindings and may be stale.
// Installed as the neutral core's result filter so mcp_core stays neutral.
[init] def install_crosstree_guard() {
install_tool_result_filter(@@(result : string; args : JsonValue?) : string {
return guard_crosstree(result, get_string_arg(args, "file"), get_string_arg(args, "project_root"))
})
}
// shutdown is shared by every entry point (main + cpp_main). It runs on the
// main thread and exits the process before the response is written.
def register_shutdown(var reg : array<ToolDef>) {
reg |> emplace(ToolDef(
tool <- make_tool(
"shutdown",
"Shut down the MCP server. Claude Code will auto-restart it, picking up any code changes to MCP tools. Tool registration changes still require a manual restart.",
{ "unused" => PropertySchema(_type = "string", description = "ignored") },
[]),
main_thread = true,
handler = @@(arg1, arg2, arg3, arg4, arg5, arg6, project, project_root : string; load_modules : array<string>) : string {
unsafe(exit(0))
return make_tool_result("shutting down")
}))
}