Skip to content

Commit 5ad1053

Browse files
committed
refactor: simplify
1 parent efa762e commit 5ad1053

2 files changed

Lines changed: 6 additions & 70 deletions

File tree

packages/devframe/src/cli/connect.test.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { DevframeDefinition } from '../types/devframe'
44
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client'
55
import { afterEach, describe, expect, it } from 'vitest'
66
import { createDevServer } from '../adapters/dev'
7-
import { buildInstanceRequestHeaders, resolveAuthToken, selectInstanceRecord, toIndexedTool } from './connect'
7+
import { buildInstanceRequestHeaders, resolveAuthToken } from './connect'
88

99
const TOKEN = 'a-high-entropy-connect-test-token'
1010

@@ -60,39 +60,6 @@ describe('buildInstanceRequestHeaders', () => {
6060
})
6161
})
6262

63-
describe('selectInstanceRecord', () => {
64-
it('prefers an MCP-capable base when several instances share a port', () => {
65-
const withoutMcp = makeRecord({ id: 'ui-only', mcp: null })
66-
const withMcp = makeRecord({ id: 'vite-devtools', basePath: '/__devtools/' })
67-
68-
expect(selectInstanceRecord([withoutMcp, withMcp], 9999)).toBe(withMcp)
69-
})
70-
})
71-
72-
describe('connector discovery metadata', () => {
73-
it('keeps downstream tool schemas available to gateway agents', () => {
74-
expect(toIndexedTool({
75-
name: 'refetch',
76-
description: 'Refetch queries.',
77-
inputSchema: {
78-
type: 'object',
79-
properties: { arg0: { type: 'object' } },
80-
required: ['arg0'],
81-
},
82-
annotations: { readOnlyHint: false },
83-
})).toEqual({
84-
name: 'refetch',
85-
description: 'Refetch queries.',
86-
inputSchema: {
87-
type: 'object',
88-
properties: { arg0: { type: 'object' } },
89-
required: ['arg0'],
90-
},
91-
annotations: { readOnlyHint: false },
92-
})
93-
})
94-
})
95-
9663
describe('connector bearer against a live authenticated MCP route', () => {
9764
let server: StartedServer | undefined
9865

packages/devframe/src/cli/connect.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,12 @@ export interface ConnectServerHandle {
6666
}
6767

6868
/** One discovered instance in the `list-instances` payload: the registry record plus its probed MCP surface. */
69-
interface IndexedTool {
70-
name: string
71-
title?: string
72-
description?: string
73-
inputSchema: unknown
74-
outputSchema?: unknown
75-
annotations?: unknown
76-
}
69+
interface IndexedInstanceTools extends Pick<Tool, 'name' | 'title' | 'description' | 'inputSchema' | 'outputSchema' | 'annotations'> {}
7770

7871
interface IndexedInstance extends Omit<DevframeInstanceRecord, 'mcp'> {
7972
mcp: {
8073
url: string
81-
tools?: IndexedTool[]
74+
tools?: IndexedInstanceTools[]
8275
error?: string
8376
} | null
8477
hint?: string
@@ -252,23 +245,8 @@ async function probePort(port: number, timeoutMs?: number): Promise<DevframeInst
252245
}
253246
}
254247

255-
async function listInstanceTools(sdk: ConnectSdk, url: string, token: string | undefined): Promise<IndexedTool[]> {
256-
return withInstanceClient(sdk, url, token, async (client) => {
257-
const listed = await client.listTools()
258-
return listed.tools.map(toIndexedTool)
259-
})
260-
}
261-
262-
/** Preserve downstream tool metadata needed by an agent before invocation. */
263-
export function toIndexedTool(tool: IndexedTool): IndexedTool {
264-
return {
265-
name: tool.name,
266-
...(tool.title ? { title: tool.title } : {}),
267-
...(tool.description ? { description: tool.description } : {}),
268-
inputSchema: tool.inputSchema,
269-
...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
270-
...(tool.annotations ? { annotations: tool.annotations } : {}),
271-
}
248+
async function listInstanceTools(sdk: ConnectSdk, url: string, token: string | undefined): Promise<IndexedInstanceTools[]> {
249+
return withInstanceClient(sdk, url, token, async client => (await client.listTools()).tools)
272250
}
273251

274252
async function call(
@@ -283,7 +261,7 @@ async function call(
283261
instancesDir: options.instancesDir,
284262
timeoutMs: options.timeoutMs,
285263
})
286-
const record = selectInstanceRecord(live, args.port)
264+
const record = live.find(record => record.port === args.port && record.mcp)
287265
?? await probePort(args.port, options.timeoutMs)
288266
if (!record)
289267
throw diagnostics.DF0050({ port: args.port })
@@ -303,15 +281,6 @@ async function call(
303281
})
304282
}
305283

306-
/** Select the agent-capable instance when several bases share one port. */
307-
export function selectInstanceRecord(
308-
records: readonly DevframeInstanceRecord[],
309-
port: number,
310-
): DevframeInstanceRecord | undefined {
311-
const matching = records.filter(record => record.port === port)
312-
return matching.find(record => record.mcp) ?? matching[0]
313-
}
314-
315284
async function withInstanceClient<T>(
316285
sdk: ConnectSdk,
317286
url: string,

0 commit comments

Comments
 (0)