FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test(filesystem): add MCP SDK regression coverage for directory_tree … · modelcontextprotocol/servers@71e3cfb · GitHub

Commit 71e3cfb

Browse files
test(filesystem): add MCP SDK regression coverage for directory_tree (#3245)
* test(filesystem): add directory_tree MCP SDK regression coverage * docs(filesystem): drop troubleshooting note from README
1 parent 781a93d commit 71e3cfb

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import * as fs from 'fs/promises';
3+
import * as path from 'path';
4+
import * as os from 'os';
5+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
7+
8+
describe('directory_tree MCP SDK regression', () => {
9+
let client: Client;
10+
let transport: StdioClientTransport;
11+
let testDir: string;
12+
13+
beforeEach(async () => {
14+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'mcp-fs-tree-'));
15+
testDir = await fs.realpath(tmp);
16+
17+
await fs.writeFile(path.join(testDir, 'root.txt'), 'root');
18+
await fs.mkdir(path.join(testDir, 'nested'));
19+
await fs.writeFile(path.join(testDir, 'nested', 'child.txt'), 'child');
20+
21+
const serverPath = path.resolve(__dirname, '../dist/index.js');
22+
transport = new StdioClientTransport({
23+
command: 'node',
24+
args: [serverPath, testDir],
25+
});
26+
27+
client = new Client(
28+
{ name: 'directory-tree-regression-test', version: '1.0.0' },
29+
{ capabilities: {} },
30+
);
31+
32+
await client.connect(transport);
33+
});
34+
35+
afterEach(async () => {
36+
await client?.close();
37+
await fs.rm(testDir, { recursive: true, force: true });
38+
});
39+
40+
it('returns structuredContent.content as a string (not an array) when called via MCP SDK', async () => {
41+
const result = await client.callTool({
42+
name: 'directory_tree',
43+
arguments: { path: testDir },
44+
});
45+
46+
// Regression test for issues where structuredContent was returned as an array,
47+
// which causes MCP SDK validation to throw -32602 (invalid structured content).
48+
const structured = result.structuredContent as { content: unknown };
49+
expect(structured).toBeDefined();
50+
expect(typeof structured.content).toBe('string');
51+
expect(Array.isArray(structured.content)).toBe(false);
52+
53+
const parsed = JSON.parse(structured.content as string);
54+
expect(Array.isArray(parsed)).toBe(true);
55+
expect(parsed.length).toBeGreaterThan(0);
56+
});
57+
});

‎src/filesystem/__tests__/structured-content.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe('structuredContent schema compliance', () => {
2222

2323
beforeEach(async () => {
2424
// Create a temp directory for testing
25-
testDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcp-fs-test-'));
25+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mcp-fs-test-'));
26+
// macOS temp dirs may be symlinked (/var -> /private/var); resolve for server allowlist checks.
27+
testDir = await fs.realpath(tmpDir);
2628

2729
// Create test files
2830
await fs.writeFile(path.join(testDir, 'test.txt'), 'test content');

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL