Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): take the guardrail server identity from the registry (m2)
Andy Pavia14de258e29f4
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex a2b7f3efb..b17578432 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.266",+ "version": "0.1.267","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.266",+ "version": "0.1.267","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex e7cad1ec5..e4fda202a 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.266",+ "version": "0.1.267","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/adapters/__tests__/toolRegistryAdapter.test.ts b/mcp-host/src/core/adapters/__tests__/toolRegistryAdapter.test.tsindex 31541097b..961713588 100644--- a/mcp-host/src/core/adapters/__tests__/toolRegistryAdapter.test.ts+++ b/mcp-host/src/core/adapters/__tests__/toolRegistryAdapter.test.ts@@ -134,6 +134,53 @@ describe('McpToolRegistryAdapter', () => {})})+ // `sourceRef` is the tool-lane guardrail's `server` identity, so a `server=` deny+ // rule matches on it. Slicing it off the display name at the first `__` truncates+ // any server whose own name contains one — the rule then fails to match, and a+ // deny that does not match lets the call through.+ it('takes the MCP server identity from the registry, not the __-sliced name', () => {+ const mockManager = {+ getAllTools: () => [+ {+ name: 'acme__tools__run_query',+ description: 'run a query',+ inputSchema: { type: 'object' },+ serverName: 'acme__tools',+ },+ ],+ callTool: vi.fn(),+ } as any++ const registry = new McpToolRegistryAdapter(mockManager)+ const tool = registry.get('acme__tools__run_query')++ expect(tool!.traceDescriptor?.({}, undefined)).toEqual({+ kind: 'mcp_server_tool',+ sourceRef: 'acme__tools', // not 'acme'+ })+ })++ it('falls back to the name prefix when the registry omits serverName', () => {+ const mockManager = {+ getAllTools: () => [+ {+ name: 'github__create_issue',+ description: 'create an issue',+ inputSchema: { type: 'object' },+ },+ ],+ callTool: vi.fn(),+ } as any++ const registry = new McpToolRegistryAdapter(mockManager)+ const tool = registry.get('github__create_issue')++ expect(tool!.traceDescriptor?.({}, undefined)).toEqual({+ kind: 'mcp_server_tool',+ sourceRef: 'github',+ })+ })+it('uses a text summary when MCP content contains only images', async () => {const mockManager = {getAllTools: () => [diff --git a/mcp-host/src/core/adapters/toolRegistryAdapter.ts b/mcp-host/src/core/adapters/toolRegistryAdapter.tsindex 55618c99d..f249a6f62 100644--- a/mcp-host/src/core/adapters/toolRegistryAdapter.ts+++ b/mcp-host/src/core/adapters/toolRegistryAdapter.ts@@ -1,3 +1,4 @@+import { serverNameOf } from '../../capabilities/toolCatalogTools'import { McpManager } from '../../mcp/manager'import { Tool, ToolRegistry } from '../interfaces'import { Attachment, ToolDefinition, ToolOutput } from '../types'@@ -78,7 +79,13 @@ class McpToolAdapter implements Tool {private readonly fullName: string,private readonly desc: string,private readonly schema: Record<string, unknown>,- private readonly mcpManager: McpManager+ private readonly mcpManager: McpManager,+ /**+ * Authoritative server name from `McpTool.serverName` (set by the MCP client+ * at connect). Carried explicitly because `traceDescriptor()` feeds the+ * tool-lane guardrail identity that `server=` rules match on — see below.+ */+ private readonly serverName: string) {}name() {@@ -97,10 +104,16 @@ class McpToolAdapter implements Tool {return false}traceDescriptor() {- const separator = this.fullName.indexOf('__')+ // `sourceRef` is the tool-lane guardrail's `server` identity (provenance.ts),+ // so a `server=` deny rule matches on THIS value. It used to be sliced off the+ // display name at the first `__`, which is a guess: a server whose own name+ // contains `__` derives truncated, the rule then fails to match, and a deny+ // that does not match lets the call through. Registration hands over the+ // registry's own `serverName` instead — the same value `serverNameOf` uses in+ // the tool catalog.return {kind: 'mcp_server_tool' as const,- sourceRef: separator > 0 ? this.fullName.slice(0, separator) : null,+ sourceRef: this.serverName || null,}}@@ -175,7 +188,9 @@ export class McpToolRegistryAdapter implements ToolRegistry {*/private refresh(): void {this.tools.clear()- // getAllTools() returns names already prefixed as serverName__toolName+ // getAllTools() returns names already prefixed as serverName__toolName, and+ // preserves the authoritative `serverName` alongside it. `serverNameOf` reads+ // that field and only falls back to parsing the prefix when it is absent.const allTools = this.mcpManager.getAllTools()for (const mcpTool of allTools) {this.tools.set(@@ -184,7 +199,8 @@ export class McpToolRegistryAdapter implements ToolRegistry {mcpTool.name,mcpTool.description || '',mcpTool.inputSchema || {},- this.mcpManager+ this.mcpManager,+ serverNameOf(mcpTool)))}diff --git a/mcp-host/src/core/guardrails/tool/provenance.ts b/mcp-host/src/core/guardrails/tool/provenance.tsindex c2c05227c..beba0587f 100644--- a/mcp-host/src/core/guardrails/tool/provenance.ts+++ b/mcp-host/src/core/guardrails/tool/provenance.ts@@ -21,11 +21,11 @@ export interface ToolIdentity {}/**- * Map a registry trace descriptor to a lane identity. `serverName` is passed in- * from the manager (registry-authoritative), NOT parsed from the tool name.- *- * TODO(phase1): wire the real `serverName` source; today `descriptor.sourceRef`- * for MCP tools is still `__`-derived (see file header).+ * Map a registry trace descriptor to a lane identity. For MCP tools the server is+ * `descriptor.sourceRef`, which `McpToolAdapter` fills from the registry's own+ * `McpTool.serverName` — never parsed from the tool name. The optional+ * `serverName` override exists for callers that resolved the server by another+ * route (the dynamic bridge); it wins when supplied.*/export function resolveToolIdentity(name: string,@@ -44,8 +44,10 @@ export function resolveToolIdentity(* An unknown tool defaults to `native` (the composite registry resolves native* first; an unresolved name is treated as native for matching purposes).*- * TODO(phase1): thread the registry-authoritative `serverName` from `McpManager`- * so the MCP `server` is not the `__`-derived `sourceRef` (see `resolveToolIdentity`).+ * The MCP `server` is registry-authoritative: `McpToolAdapter` stamps+ * `McpTool.serverName` into `sourceRef` at registration. It is NOT parsed out of+ * the display name — that guess truncates a server whose own name contains `__`,+ * and a `server=` rule that fails to match is a deny that does not deny.*/export function resolveToolIdentityFromRegistry(name: string,