MCPcopy Index your code
hub / github.com/github/copilot-sdk / buildNamespaceTree

Function buildNamespaceTree

scripts/codegen/rust.ts:1668–1693  ·  view source on GitHub ↗

* Build a namespace tree from a list of methods. `groupOf(method)` returns the * dotted group path (e.g. "mcp.config" for "mcp.config.list" / "workspaces" * for "workspaces.listFiles"); the last segment of `rpcMethod` is the leaf * method name.

(
	rootTypeName: string,
	methods: RpcMethod[],
	stripPrefix: string,
)

Source from the content-addressed store, hash-verified

1666 * method name.
1667 */
1668function buildNamespaceTree(
1669 rootTypeName: string,
1670 methods: RpcMethod[],
1671 stripPrefix: string,
1672): NamespaceNode {
1673 const root = newNamespaceNode("", rootTypeName);
1674 for (const method of methods) {
1675 const trimmed = stripPrefix && method.rpcMethod.startsWith(stripPrefix)
1676 ? method.rpcMethod.slice(stripPrefix.length)
1677 : method.rpcMethod;
1678 const segments = trimmed.split(".");
1679 const groupSegments = segments.slice(0, -1);
1680 let node = root;
1681 for (const seg of groupSegments) {
1682 let child = node.children.get(seg);
1683 if (!child) {
1684 const childTypeName = `${node.typeName}${toPascalCase(seg)}`;
1685 child = newNamespaceNode(seg, childTypeName);
1686 node.children.set(seg, child);
1687 }
1688 node = child;
1689 }
1690 node.methods.push(method);
1691 }
1692 return root;
1693}
1694
1695/**
1696 * Determine if a method has typed params. Returns `{ hasParams, typeName }`.

Callers 1

generateRpcCodeFunction · 0.70

Calls 5

newNamespaceNodeFunction · 0.85
toPascalCaseFunction · 0.70
getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…