feat(server): process-level plugin MCP tool source

Sibling of plugin-event-sink.ts: the plugins layer registers a source, and
src/mcp/tools.ts reads it as a defaulted argument. mcp-transport/ is not
touched at all, so it never learns that plugins exist and the tool-call
audit row for a plugin tool comes out of code that did not change.

Pull rather than push, unlike the event sink, because the answer depends
on the session's ctx: there is nothing a push could carry ahead of time,
and reading it per attach means activating or uninstalling a plugin takes
effect on the next session with nothing to invalidate. Same argument
channel-registry.ts makes for setPluginChannelSource.

An unset source means "no plugin tools" rather than an error, the right
answer for any app built without the plugins runtime. MCPSINK-003 pins
that case, which none of the sibling sinks covers today.

Not try/caught here: attach() already contains a throwing source and logs
which one failed, and catching again would swallow that.

The harness takes dynamicTools explicitly so suites exercise the path
without installing a process-level source.

MCPSINK-001 to MCPSINK-005.
This commit is contained in:
Renzo Beux
2026-08-28 13:20:08 -03:00
committed by Maurice
parent a6c96f4053
commit c56521b4a4
4 changed files with 131 additions and 4 deletions
+10 -2
View File
@@ -14,6 +14,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
import { Client } from '@modelcontextprotocol/sdk/client/index';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory';
import { registerTools } from '../../src/mcp/tools';
import type { McpAttachOptions } from '../../src/nest-mcp';
import { createMcpTestRegistry } from './mcp-test-controllers';
export interface McpHarness {
@@ -39,10 +40,17 @@ export interface McpHarnessOptions {
isStaticToken?: boolean;
/** Fire-once deprecation-notice closure (default: registerTools' () => null) */
getDeprecationNotice?: () => string | null;
/**
* Host-contributed tools for this session. Passed explicitly so a suite never
* has to install the process-level plugin source to exercise the path; left
* undefined, registerTools resolves it to that source, which is unset in
* every suite that does not register one.
*/
dynamicTools?: McpAttachOptions['dynamicTools'];
}
export async function createMcpHarness(options: McpHarnessOptions): Promise<McpHarness> {
const { userId, withTools = true, scopes = null, isStaticToken = false, getDeprecationNotice } = options;
const { userId, withTools = true, scopes = null, isStaticToken = false, getDeprecationNotice, dynamicTools } = options;
const server = new McpServer({ name: 'trek-test', version: '1.0.0' });
@@ -51,7 +59,7 @@ export async function createMcpHarness(options: McpHarnessOptions): Promise<McpH
// McpRegistryService to registerTools; the harness has no Nest app, so it
// builds the same registry by hand (see mcp-test-controllers.ts).
// registerTools' own ctx construction stays exercised.
registerTools(createMcpTestRegistry(), server, userId, scopes ?? null, isStaticToken, getDeprecationNotice);
registerTools(createMcpTestRegistry(), server, userId, scopes ?? null, isStaticToken, getDeprecationNotice, undefined, dynamicTools);
}
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();