Files
TREK/server/src/mcp/tools.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

39 lines
1.6 KiB
TypeScript

import type { McpAttachOptions, McpRegistry } from '../nest-mcp';
import { getPluginMcpToolSource } from '../plugin-mcp-tools';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
/**
* Attaches the MCP surface to a session's server.
*
* Every domain registers through an @McpController class the container
* discovers, so there is nothing to wire here by hand any more. What is left
* is the seam that supplies the default arguments and the null-registry
* escape hatch. Production passes the container-discovered McpRegistryService
* (injected into the transport service); the no-Nest harness hands in
* createTestRegistry()'s build. A null registry (direct callers without either)
* skips the attach.
*
* `dynamicTools` defaults to the process-level plugin source rather than being
* passed down from the transport, so mcp-transport/ never learns that plugins
* exist and an app built without the plugins runtime resolves it to undefined.
* Tests pass it explicitly instead of reaching for the global.
*/
export async function registerTools(
registry: McpRegistry | null,
server: McpServer,
userId: number,
scopes: string[] | null,
isStaticToken = false,
getDeprecationNotice: () => string | null = () => null,
onInvoke?: McpAttachOptions['onInvoke'],
dynamicTools: McpAttachOptions['dynamicTools'] = getPluginMcpToolSource() ?? undefined,
around?: McpAttachOptions['around'],
): Promise<void> {
if (registry)
await registry.attach(
server,
{ userId, scopes, isStaticToken, getDeprecationNotice },
{ onInvoke, dynamicTools, around },
);
}