MCPcopy Create free account
hub / github.com/TanStack/ai / fakeSource

Function fakeSource

packages/ai/tests/chat-mcp.test.ts:21–63  ·  view source on GitHub ↗
(
  toolNames: ReadonlyArray<string>,
  opts?: FakeSourceOpts,
)

Source from the content-addressed store, hash-verified

19}
20
21function fakeSource(
22 toolNames: ReadonlyArray<string>,
23 opts?: FakeSourceOpts,
24): MCPToolSource & {
25 readonly closed: boolean
26 readonly toolCallCount: number
27} {
28 let closed = false
29 let toolCallCount = 0
30
31 const source = {
32 get closed() {
33 return closed
34 },
35 get toolCallCount() {
36 return toolCallCount
37 },
38 tools: (options?: { lazy?: boolean }): Promise<Array<ServerTool>> => {
39 toolCallCount++
40 if (opts?.fail) {
41 return Promise.reject(
42 new Error(`discovery failed for ${toolNames[0] ?? 'unknown'}`),
43 )
44 }
45 const tools: Array<ServerTool> = toolNames.map(
46 (name) =>
47 ({
48 __toolSide: 'server' as const,
49 name,
50 description: `MCP tool: ${name}`,
51 execute: (_args: unknown) => ({ mcp: true, tool: name }),
52 }) satisfies ServerTool,
53 )
54 // Spy-able: caller can inspect toolCallCount and options via the spy wrapping tools()
55 void options // used by spy in lazyTools test
56 return Promise.resolve(tools)
57 },
58 close: async (): Promise<void> => {
59 closed = true
60 },
61 }
62 return source
63}
64
65// ============================================================================
66// Tests

Callers 1

chat-mcp.test.tsFile · 0.85

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected